Compare commits
2 commits
ee23867a2c
...
0305148d38
Author | SHA1 | Date | |
---|---|---|---|
0305148d38 | |||
67349bb308 |
4 changed files with 58 additions and 48 deletions
|
@ -37,8 +37,10 @@ The safe update script which is listed below.
|
||||||
|
|
||||||
## Universal Safe Update
|
## Universal Safe Update
|
||||||
|
|
||||||
The script below can be used to update any repository.
|
The script is located in [scripts/git-safe-update.sh](../scripts/git-safe-update.sh).
|
||||||
It takes two arguments:
|
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
|
1. Path of a non-bare Git repository
|
||||||
2. Intended owner of the files
|
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.
|
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 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.
|
It executes `safe-update` only when the master branch is updated.
|
||||||
|
|
||||||
|
@ -106,8 +67,6 @@ 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,
|
||||||
|
|
12
scripts/backup-decrypt.sh
Normal file
12
scripts/backup-decrypt.sh
Normal 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
|
39
scripts/git-safe-update.sh
Normal file
39
scripts/git-safe-update.sh
Normal 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!"
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Reference in a new issue