Minor progress in wizzard

Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
2022-08-06 02:11:44 +02:00
parent ebc5b68ddd
commit 92bf69f4f3
5 changed files with 276 additions and 200 deletions

View File

@@ -1,26 +1,4 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
if [[ ! ":$PATH:" == *":/usr/local/bin:"* ]]
then
export PATH="/usr/local/bin:$PATH"
fi
# if started as root
if [ $UID -eq 0 ]
then
chown executor:executor /data
su executor -c $0
exit $?
fi
dir_prefix=cloner
function die(){
echo $@ 1>&2
exit 1
}
function checkProjectName(){
# check, if volume does not exist yet
@@ -33,64 +11,6 @@ function checkProjectName(){
fi
}
function createConfigFile(){
# creates config file, writes it to $1 location
loc=$1
# vars
local tmpl_name=$read_project_name
local tmpl_url=$read_url
local tmpl_interval=$read_interval
local tmpl_submodules=$read_submodules
if [ $read_submodule_limit = "N" ]
then
local tmpl_submodules_depth_enabled='# '
local tmpl_submodules_depth=50000
else
local tmpl_submodules_depth_enabled=''
local tmpl_submodules_depth=$read_submodule_limit
fi
cat > $loc <<-EOF
# cloner.cfg
# main config
# created at $(date +"%Y-%m-%d %X")
# main url - url of main repo - just to clone
cloner_repo_url=$tmpl_url
# project name (names of volumes are derrived from this
cloner_project_name=$tmpl_name
# cloner interval (in minutes, default=0 - run always)
cloner_interval=$tmpl_interval
# do you need submodules support? (1/0)
cloner_submodules=$tmpl_submodules
# max depth of submodule scan (default = unlimited, uncomment to use)
${tmpl_submodules_depth_enabled}cloner_submodule_depth=$tmpl_submodules_depth
EOF
}
function createDetectorConfig(){
# $1 - file
local cfgFile=$1
mkdir -p $(dirname $cfgFile)
if [ $read_detector -eq 1 ]
then
cat > $cfgFile <<-EOF
# this file is config for detector
# now, it is empty - to disable detector, just delete it!
EOF
fi
}
function generateSSHKey(){
# generates ssh key with $1 path and $2 description
local keyfile=$1/identity
@@ -120,55 +40,6 @@ function reuseSSHKey(){
ssh-keygen -y -f $keyfile -P "" || true # will fail in the end, so script will continue and clean up the mess
}
# start reading vars
echo -n "Enter project name: "
read read_project_name
checkProjectName "$read_project_name"
# repository URL
echo -n "Enter git repository URL: "
read read_url
[ -n "$read_url" ] || die "Empty url is not allowed!"
# check interval
echo -n "Enter check interval in minutes [5]: "
read read_interval
[ -n "$read_interval" ] || read_interval=5
[[ "$read_interval" =~ ^[0-9]+$ ]] || echo "Entered interval is not number. Try again.."
# submodule use
echo -n "Mirror including submodules? [Y/n]"
read read_submodules
[ -n "$read_submodules" ] || read_submodules=Y
[[ "$read_submodules" =~ ^[Yy]$ ]] && read_submodules=1 || read_submodules=0
# submodule limit
if [ $read_submodules -eq 1 ]
then
echo -n "Limit for submodule discovery [<number>/N]: "
read read_submodule_limit
[ -n "$read_submodule_limit" ] || read_submodule_limit=N
if ! [[ "$read_submodule_limit" =~ ^[Nn]$ ]]
then
[[ "$read_submodule_limit" =~ ^[0-9]+$ ]] || die "Submodule limit must be n,N or number!"
fi
else
read_submodule_limit=N
fi
# determine CI?
echo -n "Do you want to enable CI support? (detector) [Y/n]"
read read_detector
[ -n "$read_detector" ] || read_detector=Y
if ! [[ "$read_detector" =~ ^[Yy]$ ]]
then
read_detector=0
else
read_detector=1
fi
root=/data/$dir_prefix-$read_project_name
# start generating config