I would like to make a bash script that will create a git-hook, so I can run $ bash ./create-hook.sh example.com
and it creates this file:
#!/bin/sh
NAME="example.com"
TARGET="/var/www/${NAME}"
TEMP="/var/www/${NAME}_temp"
REPO="/srv/git/${NAME}.git"
mkdir -p $TEMP
git --work-tree=$TEMP --git-dir=$REPO checkout -f
rm -rf $TARGET/*
mv $TEMP/* $TARGET
rm -rf $TEMP
# etc.
```
So here is the current status of the script (not working):
#!/bin/sh
if [[ $# -eq 0 ]]
then
echo 'No name provided'
exit 1
fi
sudo bash -c 'cat << EOF > post-receive
TARGET="/var/www/$1"
TEMP="/var/www/$1_temp"
REPO="/srv/git/$1.git"
mkdir -p \$TEMP
git --work-tree=\$TEMP --git-dir=\$REPO checkout -f
rm -rf \$TARGET/*
mv $TEMP/* \$TARGET
rm -rf \$TEMP
How to pass the variable $1
from the command line to the created file?