5
0
Fork 0

Merge branch 'main' of git.service.wiseadvice.eu:wiseadvice_public_repos/wa_public_init_repo

main
Holger Wasem 2024-05-03 10:13:51 +02:00
commit 9dfcf549ac
1 changed files with 80 additions and 68 deletions

144
init.sh
View File

@ -2,9 +2,6 @@
WA_REPO=$HOME/wa_repos WA_REPO=$HOME/wa_repos
echo "################################################" echo "################################################"
echo " basic init of wiseadvice node " echo " basic init of wiseadvice node "
echo "################################################" echo "################################################"
@ -68,97 +65,108 @@ function start_ssh_agent(){
if [ -d "$WA_REPO" ]; then
echo "$WA_REPO does exist, skipping cloning"
source $WA_REPO/export_client_name.sh
echo "found client name: $CLIENT_NAME"
source $HOME/.zshrc
git_pull
else
echo -n "client name: "
read -r CLIENT_NAME
if [ ! -f $HOME/.ssh/deploy_key ]; then
echo "create ssh key"
echo -n "ssh passphrase: "
stty_orig=$(stty -g) # save original terminal setting.
stty -echo
read -r passphrase
stty "$stty_orig" # restore terminal setting.
echo "1. client name: $CLIENT_NAME" function init_repos(){
mkdir -p $HOME/.ssh if [ -d "$WA_REPO" ]; then
echo "$WA_REPO does exist, skipping cloning"
source $WA_REPO/export_client_name.sh
echo "found client name: $CLIENT_NAME"
source $HOME/.zshrc
ssh-keygen -t rsa -N "$passphrase" -C "deploy_key_$CLIENT_NAME" -f $HOME/.ssh/deploy_key git_pull
else
echo -n "client name: "
read -r CLIENT_NAME
echo "please upload now pub key bay logging into user $CLIENT_NAME keys ..." if [ ! -f $HOME/.ssh/deploy_key ]; then
echo "firefox https://git.service.wiseadvice.eu/user/settings/keys" echo "create ssh key"
echo " " echo -n "ssh passphrase: "
cat $HOME/.ssh/deploy_key.pub stty_orig=$(stty -g) # save original terminal setting.
fi stty -echo
read -r passphrase
stty "$stty_orig" # restore terminal setting.
echo "1. client name: $CLIENT_NAME"
echo " " mkdir -p $HOME/.ssh
echo -n "ready to pull? type yes: "
read -r ready_to_pull ssh-keygen -t rsa -N "$passphrase" -C "deploy_key_$CLIENT_NAME" -f $HOME/.ssh/deploy_key
echo "please upload now pub key by logging into user $CLIENT_NAME keys ..."
echo "if user does not exit. login with admin user and create new user with name: $CLIENT_NAME"
echo "make sure the user $CLIENT_NAME is in team shared_deployments and is allowed to pull repository cimp_$CLIENT_NAME"
if [ "$ready_to_pull" = "yes" ]; then echo "https://git.service.wiseadvice.eu/user/settings/keys"
start_ssh_agent echo " "
echo "preparing" cat $HOME/.ssh/deploy_key.pub
if grep "git.service.wiseadvice.eu" $HOME/.ssh/config > /dev/null
then
echo "ssh configuration already set"
else
echo "set ssh configuration"
cat <<EOT >> $HOME/.ssh/config
Host git.service.wiseadvice.eu
HostName git.service.wiseadvice.eu
IdentityFile ~/.ssh/deploy_key
Port 8422
IdentitiesOnly yes
EOT
fi fi
echo " "
echo -n "ready to pull? type yes: "
read -r ready_to_pull
mkdir -p $WA_REPO if [ "$ready_to_pull" = "yes" ]; then
start_ssh_agent
echo "export CLIENT_NAME=$CLIENT_NAME" > $WA_REPO/export_client_name.sh echo "preparing"
source $WA_REPO/export_client_name.sh
cd $WA_REPO if grep "git.service.wiseadvice.eu" $HOME/.ssh/config > /dev/null
clone_repo_with_retry cimp_$CLIENT_NAME then
clone_repo_with_retry shared_resources_k8s echo "ssh configuration already set"
clone_repo_with_retry common_sysadmin else
echo "set ssh configuration"
cat <<EOT >> $HOME/.ssh/config
Host git.service.wiseadvice.eu
HostName git.service.wiseadvice.eu
IdentityFile ~/.ssh/deploy_key
Port 8422
IdentitiesOnly yes
EOT
fi
ln -sf $WA_REPO/common_sysadmin/k8s $HOME/kubeconfs_common mkdir -p $WA_REPO
ln -sf $WA_REPO/shared_resources_k8s/k8s $HOME/kubeconfs_common
ln -sf $WA_REPO/shared_resources_k8s/manifest.sh $HOME/.zshrc
ln -sf $WA_REPO/cimp_$CLIENT_NAME/k8s $HOME/kubeconfs
echo "source .zshrc after pull" echo "export CLIENT_NAME=$CLIENT_NAME" > $WA_REPO/export_client_name.sh
source $HOME/.zshrc source $WA_REPO/export_client_name.sh
else
echo "Aborting" cd $WA_REPO
exit 0 clone_repo_with_retry cimp_$CLIENT_NAME
clone_repo_with_retry shared_resources_k8s
clone_repo_with_retry common_sysadmin
ln -sf $WA_REPO/common_sysadmin/k8s $HOME/kubeconfs_common
ln -sf $WA_REPO/shared_resources_k8s/k8s $HOME/kubeconfs_common
ln -sf $WA_REPO/shared_resources_k8s/manifest.sh $HOME/.zshrc
ln -sf $WA_REPO/cimp_$CLIENT_NAME/k8s $HOME/kubeconfs
echo "source .zshrc after pull"
echo "change default SHELL of user sysadmin:"
chsh -s /usr/bin/zsh
source $HOME/.zshrc
else
echo "Aborting"
exit 0
fi
fi fi
fi }
mainmenu() { mainmenu() {
echo -ne " echo -ne "
MAIN MENU MAIN MENU
1) Init Master 1) Init Master
2) Join Worker 2) Join Worker
3) Reset Cluster and start over again
0) Exit 0) Exit
Choose an option: " Choose an option: "
read -r ans read -r ans
@ -173,6 +181,9 @@ Choose an option: "
echo "initializing K8s Worker Set-Up" echo "initializing K8s Worker Set-Up"
source $WA_REPO/shared_resources_k8s/k8s/init_worker.sh source $WA_REPO/shared_resources_k8s/k8s/init_worker.sh
;; ;;
3)
kubeadm_reset
;;
0) 0)
echo "Bye bye." echo "Bye bye."
exit 0 exit 0
@ -184,4 +195,5 @@ Choose an option: "
esac esac
} }
init_repos
mainmenu mainmenu