41 lines
1.2 KiB
Bash
Executable File
41 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -u
|
|
set -e
|
|
|
|
my_user_tmp=$(grep -r "Git Site Deploys" /etc/passwd | cut -d':' -f1)
|
|
read -p "Repository Username [$my_user_tmp]: " my_user
|
|
my_user=${my_user:-"$my_user_tmp"}
|
|
|
|
while [ -z "${my_site:-}" ]; do
|
|
read -p "Site name (ex: example.com): " my_site
|
|
done
|
|
|
|
my_repo_tmp=$(eval echo "~$my_user")
|
|
read -p "Repository [$my_repo_tmp/${my_site}.git]: " my_repos
|
|
my_repo=${my_repos:-"$my_repo_tmp/${my_site}.git"}
|
|
|
|
read -p "Deploy to [/srv/www/beta.therootcompany.com/$my_site]: " my_deploy
|
|
my_deploy=${my_www:-"/srv/www/beta.therootcompany.com/$my_site"}
|
|
|
|
echo ""
|
|
echo ""
|
|
|
|
set -x
|
|
sudo git init --bare --shared=group "${my_repo}"
|
|
sudo bash -c "cat << EOF > ${my_repo}/hooks/post-receive
|
|
#!/usr/bin/env bash
|
|
mkdir -p '${my_deploy}'
|
|
# always deploys from the default (master) branch
|
|
git --work-tree='${my_deploy}' --git-dir='${my_repo}' checkout -f
|
|
echo Deployed branch 'master' to '${my_deploy}'
|
|
EOF
|
|
"
|
|
sudo chmod a+x "${my_repo}/hooks/post-receive"
|
|
sudo chown -R ${my_user}:${my_user} "$my_repo"
|
|
set +x
|
|
|
|
echo ""
|
|
echo "Authorized users can push to this repo by adding it as a remote. Example:"
|
|
echo " git remote add origin ${my_user}@$(hostname):${my_repo}"
|
|
echo ""
|