repo-cloner/old/dockerbin/wizzard

90 lines
2.3 KiB
Plaintext
Raw Normal View History

2018-02-09 11:49:16 +01:00
#!/bin/bash
function checkProjectName(){
# check, if volume does not exist yet
name=$1
# should not be empty
[ -n "$read_project_name" ] || die "Empty project name is not allowed"
2018-02-23 10:38:47 +01:00
if [ -d /data/$dir_prefix-$name ]
2018-02-09 11:49:16 +01:00
then
die "Target volume for project '$name' exists - please try again!"
fi
}
function generateSSHKey(){
# generates ssh key with $1 path and $2 description
local keyfile=$1/identity
2018-02-09 11:49:16 +01:00
local description=$2
echo "Creating SSH deployment key.."
ssh-keygen -f $keyfile -t ed25519 -C "$description" -N ""
2018-02-09 11:49:16 +01:00
echo
echo "Public key is:"
echo "-----------------------------------------------------"
cat $keyfile.pub
echo "-----------------------------------------------------"
echo -n "Please make sure that key is set up at your git hosting and press enter.."
read
}
function reuseSSHKey(){
# pastes ssh key to file $1 with vim
local keyfile=$1
local scratch=$(mktemp)
echo "# Please paste private ssh key here and save this file" > $scratch
vim $scratch
sed -e 's/#.*$//' $scratch > $keyfile
rm $scratch
echo "Checking key..."
2018-02-23 11:28:45 +01:00
chmod 0700 $keyfile
2018-02-23 10:38:47 +01:00
ssh-keygen -y -f $keyfile -P "" || true # will fail in the end, so script will continue and clean up the mess
2018-02-09 11:49:16 +01:00
}
2018-02-23 10:38:47 +01:00
root=/data/$dir_prefix-$read_project_name
2018-02-09 11:49:16 +01:00
# start generating config
2018-02-23 10:38:47 +01:00
mkdir -p $root/config
createConfigFile $root/config/cloner.cfg
2018-02-09 11:49:16 +01:00
# use ssh config?
echo -n "Would you like to use SSH auth? ([C]reate new key/[U]se existing key/[N]o) [C/u/n]: "
read read_ssh
[ -n "$read_ssh" ] || read_ssh=C
[[ "$read_ssh" =~ ^[CcUuNn]$ ]] || die "Invalid SSH key option, script is exiting now.."
# ssh resolutions?
# create dir if needed
2018-02-23 10:38:47 +01:00
[[ "$read_ssh" =~ ^[nN]$ ]] || mkdir -p $root/config/auth/ssh
2018-02-09 11:49:16 +01:00
# generate new key
if [[ "$read_ssh" =~ ^[Cc]$ ]]
then
# create key
2018-02-23 10:38:47 +01:00
generateSSHKey $root/config/auth/ssh "cloner-deploy-key-$read_project_name"
2018-02-09 11:49:16 +01:00
fi
# use existing key
if [[ "$read_ssh" =~ ^[Uu]$ ]]
then
# load key
reuseSSHKey $root/config/auth/ssh/identity
2018-02-09 11:49:16 +01:00
fi
2018-02-09 11:49:16 +01:00
echo "First run - initialization of repos..."
2018-02-23 10:38:47 +01:00
if ! env BASE=$root run-checker
2018-02-09 11:49:16 +01:00
then
2018-02-23 10:38:47 +01:00
echo -n "First run failed - remove directory? [Y/n]"
2018-02-09 11:49:16 +01:00
read read_cleanup
[ -n "$read_cleanup" ] || read_cleanup=Y
if [[ "$read_cleanup" =~ ^[Yy]$ ]]
then
2018-02-23 10:38:47 +01:00
rm -Rf $root
2018-02-09 11:49:16 +01:00
fi
else
createDetectorConfig $root/config/detector.cfg
2018-02-09 11:49:16 +01:00
echo "Setup has finished!"
2018-02-23 10:38:47 +01:00
touch $root/.enabled
2018-02-09 11:49:16 +01:00
fi