From 7ead24e4f3e3d0586de53a9a6a55655d76d13594 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Sun, 9 Apr 2023 14:42:32 +0200 Subject: [PATCH] 1st step of init_homepath rework --- init_homepath | 112 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 86 insertions(+), 26 deletions(-) diff --git a/init_homepath b/init_homepath index f17814b..28e58a0 100755 --- a/init_homepath +++ b/init_homepath @@ -1,30 +1,90 @@ -#!/bin/sh +#!/usr/bin/python3 # -BASE_FOLDERS="Downloads media_images Videos C64" -VIP_FOLDERS="prj prj/Arduino Schreibtisch" +import subprocess +import sys + +def proceed(): + while True: + uf = input("\nProceed? [Y/n/q]") + if len(uf) == 0: + uf = "y" + if uf.lower() in ["y", "n", "q"]: + break + if uf == "q": + sys.exit(1) + else: + return uf == "y" + + +BASE_GIT_URL = "https://git.mount-mockery.de/dirk" +REPOS = ( + (BASE_GIT_URL + "/" + "bin.git", "~/bin"), + (BASE_GIT_URL + "/" + "bash.git", "~/.bash"), + (BASE_GIT_URL + "/" + "config_files.git", "~/.config_files"), +) +print("Cloning the following repositories:") +for data in REPOS: + print(" %s --> %s" % data) +if proceed(): + for url, target in REPOS: + command = "git clone %s %s" % (url, target) + sys.stdout.write("Cloning %s" % url) + process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process.wait() + if process.returncode == 0: + print("\t\t[ SUCCESS ]") + else: + print("\t\t[ FAILED ]") + print(" ", process.stderr.read().decode("utf-8")) + +CONFIG_COMMANDS = ( + "GS=`grep .bash/enabled ~/.bashrc`; [ ${#GS} -ne 0 ] || cat ~/.bash/BASHRC_ADDON >> ~/.bashrc", + "mkdir -p ~/.cache/vim && mkdir -p ~/.vim && ln -s ~/.config_files/vimrc ~/.vimrc && ln -s ~/.config_files/vim_skeletons ~/.vim/skeletons", + "which tmux && ln -s ~/.config_files/tmux.conf ~/.tmux.conf", + "mkdir -p ~/.config && ln -s ~/.config_files/powerline_gitstatus ~/.config/powerline", + "mkdir -p ~/.ssh && chmod 700 ~/.ssh && ln -s ~/.config_files/ssh_config ~/.ssh/config", +) +print("\n\n\nAdding the configuration to your environment:") +for command in CONFIG_COMMANDS: + print(" ", command) +if proceed(): + for command in CONFIG_COMMANDS: + sys.stdout.write("Executing %s" % command) + process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process.wait() + if process.returncode == 0: + print("\t\t[ SUCCESS ]") + else: + print("\t\t[ FAILED ]") + print(" ", process.stderr.read().decode("utf-8")) + +#BASE_FOLDERS="Downloads media_images Videos C64" +#VIP_FOLDERS="prj prj/Arduino Schreibtisch" + + +#echo The following folders will be deleted: +#for folder in $BASE_FOLDERS; do +# echo -e "* $HOME/\033[1m$folder\033[0m" +#done +#for folder in $VIP_FOLDERS; do +# echo -e "* $HOME/\033[1m$folder\033[0m" +#done +#echo +#read -r -p "Are you sure? [y/N] " response +#case "$response" in +# [yY][eE][sS]|[yY]) +# for folder in $BASE_FOLDERS; do +# rm -rf $HOME/`basename $folder`; ln -s /usr/data/$USER/local/$folder $HOME +# done +# rm -rf $HOME/data; ln -s /usr/data/$USER/data data +# for folder in $VIP_FOLDERS; do +# rm -rf $HOME/`basename $folder`; ln -s /usr/data/$USER/data/$folder $HOME +# done +# ;; +# *) +# echo No folder initialisation! +# ;; +#esac -echo The following folders will be deleted: -for folder in $BASE_FOLDERS; do - echo -e "* $HOME/\033[1m$folder\033[0m" -done -for folder in $VIP_FOLDERS; do - echo -e "* $HOME/\033[1m$folder\033[0m" -done -echo -read -r -p "Are you sure? [y/N] " response -case "$response" in - [yY][eE][sS]|[yY]) - for folder in $BASE_FOLDERS; do - rm -rf $HOME/`basename $folder`; ln -s /usr/data/$USER/local/$folder $HOME - done - rm -rf $HOME/data; ln -s /usr/data/$USER/data data - for folder in $VIP_FOLDERS; do - rm -rf $HOME/`basename $folder`; ln -s /usr/data/$USER/data/$folder $HOME - done - ;; - *) - echo No folder initialisation! - ;; -esac