Wizzard working out of docker

This commit is contained in:
Václav Valíček (YCNet) 2018-02-23 10:38:47 +01:00
parent 81b6097351
commit c35290ae2d
No known key found for this signature in database
GPG Key ID: 7CF44871CEA75938

View File

@ -2,8 +2,7 @@
set -euo pipefail
IFS=$'\n\t'
volume_prefix=cloner
mirror_image="valicek1/repo-cloner-mirror"
dir_prefix=cloner
function die(){
echo $@ 1>&2
@ -15,11 +14,7 @@ function checkProjectName(){
name=$1
# should not be empty
[ -n "$read_project_name" ] || die "Empty project name is not allowed"
set +e
docker volume inspect $volume_prefix-$1 > /dev/null 2>&1
exists=$?
set -e
if [ $exists -eq 0 ]
if [ -d /data/$dir_prefix-$name ]
then
die "Target volume for project '$name' exists - please try again!"
fi
@ -94,19 +89,7 @@ function reuseSSHKey(){
rm $scratch
echo "Checking key..."
chmod 0600 $keyfile
ssh-keygen -y -f $keyfile -P ""
}
function createVolume(){
# create volume $1
local volname=$1
echo "Creating docker volume $volname"
docker volume create $volname > /dev/null
echo "Populating volume with stuff..."
local filler="cloner-creator-filler-$(hostname)"
tar c /data | docker run -v $volname:/data -i --name $filler --rm busybox:latest tar -C / -x
ssh-keygen -y -f $keyfile -P "" || true # will fail in the end, so script will continue and clean up the mess
}
# start reading vars
@ -146,9 +129,10 @@ else
read_submodule_limit=N
fi
root=/data/$dir_prefix-$read_project_name
# start generating config
mkdir -p /data/config
createConfigFile /data/config/cloner.cfg
mkdir -p $root/config
createConfigFile $root/config/cloner.cfg
# 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]: "
@ -158,37 +142,34 @@ read read_ssh
# ssh resolutions?
# create dir if needed
[[ "$read_ssh" =~ ^[nN]$ ]] || mkdir -p /data/config/auth/ssh
[[ "$read_ssh" =~ ^[nN]$ ]] || mkdir -p $root/config/auth/ssh
# generate new key
if [[ "$read_ssh" =~ ^[Cc]$ ]]
then
# create key
generateSSHKey /data/config/auth/ssh "cloner-deploy-key-$read_project_name"
generateSSHKey $root/config/auth/ssh "cloner-deploy-key-$read_project_name"
fi
# use existing key
if [[ "$read_ssh" =~ ^[Uu]$ ]]
then
# load key
reuseSSHKey /data/config/auth/ssh/id_rsa
reuseSSHKey $root/config/auth/ssh/id_rsa
fi
volume_name=$volume_prefix-$read_project_name
createVolume $volume_name
echo "First run - initialization of repos..."
if ! docker run -it -v $volume_name:/data --name cloner-runner-$read_project_name --rm $mirror_image
if ! env BASE=$root run-checker
then
echo -n "First run failed - remove image? [Y/n]"
echo -n "First run failed - remove directory? [Y/n]"
read read_cleanup
[ -n "$read_cleanup" ] || read_cleanup=Y
if [[ "$read_cleanup" =~ ^[Yy]$ ]]
then
docker volume rm $volume_name
rm -Rf $root
fi
else
echo "Setup has finished!"
touch $root/.enabled
fi