From 67349bb3088c74a6a4ebdee675ad40502f238f52 Mon Sep 17 00:00:00 2001 From: Adrian Date: Mon, 26 Oct 2015 15:43:01 +0100 Subject: [PATCH 1/2] Move git-safe-update script --- doc/Push-to-Deploy.md | 51 ++++---------------------------------- scripts/git-safe-update.sh | 36 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 46 deletions(-) create mode 100644 scripts/git-safe-update.sh diff --git a/doc/Push-to-Deploy.md b/doc/Push-to-Deploy.md index 84298c6..096b5c2 100644 --- a/doc/Push-to-Deploy.md +++ b/doc/Push-to-Deploy.md @@ -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 " - -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, diff --git a/scripts/git-safe-update.sh b/scripts/git-safe-update.sh new file mode 100644 index 0000000..1051f88 --- /dev/null +++ b/scripts/git-safe-update.sh @@ -0,0 +1,36 @@ +#!/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 " + +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!" From 0305148d3894710408a94ba85d5103ef0eb333cb Mon Sep 17 00:00:00 2001 From: Adrian Date: Mon, 26 Oct 2015 15:49:56 +0100 Subject: [PATCH 2/2] Decrypt backup script and some fixes --- scripts/backup-decrypt.sh | 12 ++++++++++++ scripts/git-safe-update.sh | 7 +++++-- scripts/zerofree.sh | 4 ++-- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 scripts/backup-decrypt.sh diff --git a/scripts/backup-decrypt.sh b/scripts/backup-decrypt.sh new file mode 100644 index 0000000..85c35af --- /dev/null +++ b/scripts/backup-decrypt.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +USAGE="USAGE: $0 " + +if [ -z "$2" ]; then echo "$USAGE" >&2; exit 1; fi + +passfile="$1" +shift + +cat "$@" \ + | gpg -d --passphrase-file "$passfile" --batch \ + | lz4 -d diff --git a/scripts/git-safe-update.sh b/scripts/git-safe-update.sh index 1051f88..ca19867 100644 --- a/scripts/git-safe-update.sh +++ b/scripts/git-safe-update.sh @@ -1,5 +1,7 @@ #!/bin/sh +USAGE="USAGE: $0 " + 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; } @@ -16,10 +18,11 @@ is_clean() fi } -[ ! -z "$2" ] || exit_msg "USAGE: $0 " +[ ! -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" @@ -32,5 +35,5 @@ if [ -x $CUSTOM_UPDATE ]; then info_msg "Running custom update ..." $CUSTOM_UPDATE fi -chown -R $USER . || exit_msg "chown $USER failed!" +chown -R $USER . || info_msg "chown $USER failed!" ok_msg "Done!" diff --git a/scripts/zerofree.sh b/scripts/zerofree.sh index ed4cfa3..e7bb7c6 100644 --- a/scripts/zerofree.sh +++ b/scripts/zerofree.sh @@ -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