Skip to content

Instantly share code, notes, and snippets.

@mdobson
Created December 5, 2013 14:16
Show Gist options
  • Save mdobson/7805775 to your computer and use it in GitHub Desktop.
Save mdobson/7805775 to your computer and use it in GitHub Desktop.
SSH Command interception
#!/usr/bin/env bash
set -eo pipefail;
case "$1" in
git-hook)
APP=$2
while read oldrev newrev refname
do
# Only run this script for the master branch. You can remove this
# if block if you wish to run it for others as well.
if [[ $refname = "refs/heads/master" ]] ; then
echo "Archiving rev $newrev." >> "$HOME/.logs"
git archive $newrev > "$HOME/tmp/$newrev.tar"
fi
done
;;
git-*)
APP="$(echo $2 | sed 's/\///' | sed "s/'//g")"
APP_PATH=$HOME/$APP
echo "Staging to $APP_PATH with args $@" >> "$HOME/.logs"
if [[ $1 == "git-receive-pack" && ! -d $APP_PATH ]]; then
git init --bare $APP_PATH > /dev/null
PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive"
cat > $PRERECEIVE_HOOK <<EOF
#!/usr/bin/env bash
set -e; set -o pipefail;
cat | githook git-hook $APP
EOF
chmod +x $PRERECEIVE_HOOK
echo "Hook and repo generated." >> "$HOME/.logs"
fi
args="$( echo $@ | sed 's/\///' )"
echo "shell results $args" >> "$HOME/.logs"
git-shell -c "$args"
;;
help)
echo "no help for you" | cat
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment