Compare commits

..

2 commits

Author SHA1 Message Date
0305148d38 Decrypt backup script and some fixes 2015-10-26 15:49:56 +01:00
67349bb308 Move git-safe-update script 2015-10-26 15:43:01 +01:00
4 changed files with 58 additions and 48 deletions

View file

@ -37,8 +37,10 @@ The safe update script which is listed below.
## Universal Safe Update
The script below can be used to update any repository.
It takes two arguments:
The script is located in [scripts/git-safe-update.sh](../scripts/git-safe-update.sh).
Copy the file to `/path/to/safe-update` and make it executable.
It can be used to update any repository. It takes two arguments:
1. Path of a non-bare Git repository
2. Intended owner of the files
@ -49,51 +51,10 @@ The chapter below describes how to configure `sudo` to enable root access.
Note that the user always knows what is going on in case of a failure.
```sh
#!/bin/sh
ok_msg() { echo "\033[32m$1\033[0m"; }
info_msg() { echo "\033[36m$1\033[0m"; }
exit_msg() { echo "\033[31m$1\033[0m"; exit 1; }
is_clean()
{
local IFS=$'\n'
status="$(git status -s -uno)"
if [ -z "$status" ]; then
return 0
else
echo "$status"
return 1
fi
}
[ ! -z "$2" ] || exit_msg "USAGE: $0 <gitdir> <user>"
DIR="$1"
USER="$2"
cd "$DIR" || exit_msg "Not a directory: $DIR"
[ -d .git ] || exit_msg "Not a Git repository: $DIR"
info_msg "Deploying to $DIR $(cat .git/HEAD) ..."
is_clean || exit_msg "Directory not clean!"
git fetch || exit_msg "Fetch failed!"
git reset --hard FETCH_HEAD || exit_msg "Checkout failed!"
if [ -x $CUSTOM_UPDATE ]; then
info_msg "Running custom update ..."
$CUSTOM_UPDATE
fi
chown -R $USER . || exit_msg "chown $USER failed!"
ok_msg "Done!"
```
Listing 1: `safe-update` script.
## Git Hook
Install the following script as the `post-receive` hook.
In this case in `/path/to/main.git/hooks/post-receive`.
In this case to `/path/to/main.git/hooks/post-receive`.
It executes `safe-update` only when the master branch is updated.
@ -106,8 +67,6 @@ if [ "$ref" = "refs/heads/master" ]; then
fi
```
Listing 2: `post-receive` hook script.
## Deployment Target Git Configuration
Because the Git repository lies on the same machine,

12
scripts/backup-decrypt.sh Normal file
View file

@ -0,0 +1,12 @@
#!/bin/sh
USAGE="USAGE: $0 <pwfile> <parts...>"
if [ -z "$2" ]; then echo "$USAGE" >&2; exit 1; fi
passfile="$1"
shift
cat "$@" \
| gpg -d --passphrase-file "$passfile" --batch \
| lz4 -d

View file

@ -0,0 +1,39 @@
#!/bin/sh
USAGE="USAGE: $0 <gitdir> <user>"
ok_msg() { echo "\033[32m$1\033[0m"; }
info_msg() { echo "\033[36m$1\033[0m"; }
exit_msg() { echo "\033[31m$1\033[0m"; exit 1; }
is_clean()
{
local IFS=$'\n'
status="$(git status -s -uno)"
if [ -z "$status" ]; then
return 0
else
echo "$status"
return 1
fi
}
[ ! -z "$2" ] || exit_msg "$USAGE"
DIR="$1"
USER="$2"
CUSTOM_UPDATE=./deploy/update
cd "$DIR" || exit_msg "Not a directory: $DIR"
[ -d .git ] || exit_msg "Not a Git repository: $DIR"
info_msg "Deploying to $DIR $(cat .git/HEAD) ..."
is_clean || exit_msg "Directory not clean!"
git fetch || exit_msg "Fetch failed!"
git reset --hard FETCH_HEAD || exit_msg "Checkout failed!"
if [ -x $CUSTOM_UPDATE ]; then
info_msg "Running custom update ..."
$CUSTOM_UPDATE
fi
chown -R $USER . || info_msg "chown $USER failed!"
ok_msg "Done!"

View file

@ -1,3 +1,3 @@
#!/bin/sh
#!/bin/bash
while $(dd if=/dev/zero bs=1M count=$(($RANDOM/16)) of=z$RANDOM.bin); do echo OK; done
while dd if=/dev/zero bs=1M count=$(($RANDOM/16)) of=$RANDOM.bin; do echo OK; done