git-scripts/add-repo-user.sh

46 lines
1.2 KiB
Bash
Raw Normal View History

2019-06-01 00:17:28 +00:00
#!/usr/bin/env bash
set -e
set -u
read -p "Repository Username [www-repos]: " my_user
#${my_user:=www-repos}
my_user=${my_user:-"www-repos"}
read -p "Repository Directory [/srv/$my_user]: " my_repos
my_repos=${my_repos:-"/srv/$my_user"}
read -p "Deploy Directory [/srv/www]: " my_www
my_www=${my_www:-"/srv/www"}
echo ""
set -x
2019-06-01 23:21:13 +00:00
# user
2019-06-01 00:17:28 +00:00
sudo adduser --disabled-password --gecos "Git Site Deploys" --home "$my_repos" --no-create-home $my_user >/dev/null
2019-06-01 23:21:13 +00:00
# ssh
2019-06-01 00:17:28 +00:00
sudo mkdir -p "$my_repos/.ssh" "$my_www"
sudo chmod 0700 "$my_repos/.ssh"
2019-06-01 05:09:59 +00:00
sudo ssh-keygen -t rsa -N "" -C "$my_user@$(hostname)" -f "$my_repos/.ssh/id_rsa"
2019-06-01 00:17:28 +00:00
sudo install -m 0600 /dev/null "$my_repos/.ssh/authorized_keys"
2019-06-01 23:21:13 +00:00
# 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
2019-06-01 00:17:28 +00:00
sudo chown -R $my_user:$my_user "$my_repos" "$my_www"
set +x
echo ""
echo ""
echo "To enable git deploys from this account you will need to add its public key to your git deployer:"
echo ""
2019-06-01 05:12:36 +00:00
echo "$my_repos/.ssh/id_rsa.pub:"
echo ""
2019-06-01 05:09:59 +00:00
sudo cat "$my_repos/.ssh/id_rsa.pub"
2019-06-01 00:17:28 +00:00
echo ""