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/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 new file mode 100644 index 0000000..ca19867 --- /dev/null +++ b/scripts/git-safe-update.sh @@ -0,0 +1,39 @@ +#!/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; } + +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!" 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