add git project template
This commit is contained in:
parent
2fc2133f99
commit
e6631a053c
|
@ -15,11 +15,23 @@ my_www=${my_www:-"/srv/www"}
|
|||
echo ""
|
||||
|
||||
set -x
|
||||
# user
|
||||
sudo adduser --disabled-password --gecos "Git Site Deploys" --home "$my_repos" --no-create-home $my_user >/dev/null
|
||||
|
||||
# ssh
|
||||
sudo mkdir -p "$my_repos/.ssh" "$my_www"
|
||||
sudo chmod 0700 "$my_repos/.ssh"
|
||||
sudo ssh-keygen -t rsa -N "" -C "$my_user@$(hostname)" -f "$my_repos/.ssh/id_rsa"
|
||||
sudo install -m 0600 /dev/null "$my_repos/.ssh/authorized_keys"
|
||||
|
||||
# git templates
|
||||
sudo rsync -a git-templates/project/ "$my_repos/git-template/"
|
||||
sudo install -m 0644 /dev/null "$my_repos/.gitconfig"
|
||||
my_config='[init]
|
||||
templatedir = '"$my_repos/git-template"
|
||||
sudo bash -c "echo '$my_config' >> '$my_repos/.gitconfig'"
|
||||
|
||||
# fix permissions
|
||||
sudo chown -R $my_user:$my_user "$my_repos" "$my_www"
|
||||
set +x
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
rsync -a project/ project-test/
|
||||
my_input='old1 new1 name1
|
||||
000 fff refs/heads/master
|
||||
'
|
||||
echo "$my_input" | ./project-test/hooks/pre-receive
|
||||
./project-test/hooks/update ref_name old_rev new_rev
|
||||
echo "$my_input" | ./project-test/hooks/post-receive
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
set -u
|
||||
|
||||
my_input=$(cat)
|
||||
echo "$my_input" | while read my_line; do
|
||||
exit 159
|
||||
done
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
set -u
|
||||
|
||||
my_input=$(cat)
|
||||
echo "$my_input" | while read my_line; do
|
||||
exit 160
|
||||
done
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
set -u
|
||||
set -e
|
||||
|
||||
my_input=$(cat)
|
||||
echo "$my_input" | while read my_line; do
|
||||
echo "Success $my_line"
|
||||
done
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
set -u
|
||||
|
||||
my_input=$(cat)
|
||||
echo "$my_input" | while read my_line; do
|
||||
echo "$my_line"
|
||||
done
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
set -u
|
||||
|
||||
my_input=$(cat)
|
||||
echo "$my_input" | while read my_line; do
|
||||
exit 160
|
||||
done
|
|
@ -0,0 +1,2 @@
|
|||
#!/usr/bin/env bash
|
||||
echo "Hello $1 $2 $3"
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
echo "Fail $1 $2 $3"
|
||||
exit 158
|
|
@ -0,0 +1,2 @@
|
|||
#!/usr/bin/env bash
|
||||
echo "Goodbye $1 $2 $3"
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env bash
|
||||
set -u
|
||||
set -e
|
||||
|
||||
# post-receive
|
||||
# this accepts multiple lines of input at a time
|
||||
# it defers exit on failure until after all scripts have run
|
||||
|
||||
my_input=$(cat)
|
||||
my_dir=$(dirname $0)
|
||||
my_success="true"
|
||||
|
||||
for my_hook in ${my_dir}/post-receive.d/*; do
|
||||
|
||||
# Let the user know if the hook isn't executable, but don't bail
|
||||
if [ ! -x "${my_hook}" ] || [ ! -f "${my_hook}" ]; then
|
||||
>&2 echo "${my_hook} is not (or does not point to) an executable file"
|
||||
fi
|
||||
|
||||
# Allow the script to fail so we can bubble the exit code and ensure an error message
|
||||
set +e
|
||||
echo "${my_input}" | ("${my_hook}")
|
||||
my_exit_code=$?
|
||||
set -e
|
||||
|
||||
# Don't bail on script failure
|
||||
if [ "0" != "${my_exit_code}" ]; then
|
||||
my_success=""
|
||||
>&2 echo "${my_hook} failed with exit code ${my_exit_code}"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "${my_success}" ]; then
|
||||
echo "some post-receives failed"
|
||||
exit 156
|
||||
fi
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env bash
|
||||
set -u
|
||||
set -e
|
||||
|
||||
# pre-receive
|
||||
# this accepts multiple lines of input at a time
|
||||
# it fails at the first of any child script failing
|
||||
|
||||
my_input=$(cat)
|
||||
my_dir=$(dirname $0)
|
||||
|
||||
for my_hook in ${my_dir}/pre-receive.d/*; do
|
||||
|
||||
# Bail and let the user know if the hook isn't executable
|
||||
if [ ! -x "${my_hook}" ] || [ ! -f "${my_hook}" ]; then
|
||||
>&2 echo "${my_hook} is not (or does not point to) an executable file"
|
||||
exit 155
|
||||
fi
|
||||
|
||||
# Allow the script to fail so we can bubble the exit code and ensure an error message
|
||||
# and subscript it so that any set -e won't cause this to fail
|
||||
set +e
|
||||
|
||||
# foo="$(echo bar; exit 3)"; echo $?; echo $foo
|
||||
#my_output="$(echo "${my_input}" | "${my_hook}")"
|
||||
echo "${my_input}" | ("${my_hook}")
|
||||
my_exit_code=$?
|
||||
set -e
|
||||
|
||||
#echo my_output: $my_output
|
||||
|
||||
# Bail on the first script failure
|
||||
if [ "0" != "${my_exit_code}" ]; then
|
||||
>&2 echo "${my_hook} failed with exit code ${my_exit_code}"
|
||||
exit ${my_exit_code}
|
||||
fi
|
||||
done
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env bash
|
||||
set -u
|
||||
set -e
|
||||
|
||||
# update script
|
||||
# this accepts a single line up input in three args
|
||||
# it fails at the first of any child script failing (and that branch fails to update)
|
||||
|
||||
my_dir=$(dirname $0)
|
||||
my_exit_code=""
|
||||
|
||||
for my_hook in ${my_dir}/update.d/*; do
|
||||
|
||||
# Bail and let the user know if the hook isn't executable
|
||||
if [ ! -x "${my_hook}" ] || [ ! -f "${my_hook}" ]; then
|
||||
>&2 echo "${my_hook} is not (or does not point to) an executable file"
|
||||
exit 155
|
||||
fi
|
||||
|
||||
# Allow the script to fail so we can bubble the exit code and ensure an error message
|
||||
set +e
|
||||
("${my_hook}" $1 $2 $3)
|
||||
my_exit_code=$?
|
||||
set -e
|
||||
|
||||
# Bail on the first script failure
|
||||
if [ "0" != "${my_exit_code}" ]; then
|
||||
>&2 echo "${my_hook} failed with exit code ${my_exit_code}"
|
||||
exit ${my_exit_code}
|
||||
fi
|
||||
done
|
|
@ -0,0 +1 @@
|
|||
.gitconfig
|
Loading…
Reference in New Issue