Compare commits

..

No commits in common. "0305148d3894710408a94ba85d5103ef0eb333cb" and "ee23867a2ca04035cda0fb2d1c2a2d848e03b7b5" have entirely different histories.

4 changed files with 48 additions and 58 deletions

View file

@ -37,10 +37,8 @@ The safe update script which is listed below.
## Universal Safe Update ## Universal Safe Update
The script is located in [scripts/git-safe-update.sh](../scripts/git-safe-update.sh). The script below can be used to update any repository.
Copy the file to `/path/to/safe-update` and make it executable. It takes two arguments:
It can be used to update any repository. It takes two arguments:
1. Path of a non-bare Git repository 1. Path of a non-bare Git repository
2. Intended owner of the files 2. Intended owner of the files
@ -51,10 +49,51 @@ 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. 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 ## Git Hook
Install the following script as the `post-receive` hook. Install the following script as the `post-receive` hook.
In this case to `/path/to/main.git/hooks/post-receive`. In this case in `/path/to/main.git/hooks/post-receive`.
It executes `safe-update` only when the master branch is updated. It executes `safe-update` only when the master branch is updated.
@ -67,6 +106,8 @@ if [ "$ref" = "refs/heads/master" ]; then
fi fi
``` ```
Listing 2: `post-receive` hook script.
## Deployment Target Git Configuration ## Deployment Target Git Configuration
Because the Git repository lies on the same machine, Because the Git repository lies on the same machine,

View file

@ -1,12 +0,0 @@
#!/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

@ -1,39 +0,0 @@
#!/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/bash #!/bin/sh
while dd if=/dev/zero bs=1M count=$(($RANDOM/16)) of=$RANDOM.bin; do echo OK; done while $(dd if=/dev/zero bs=1M count=$(($RANDOM/16)) of=z$RANDOM.bin); do echo OK; done