Просмотр исходного кода

1st step of init_homepath rework

84582af
Dirk Alders 1 год назад
Родитель
Сommit
7ead24e4f3
1 измененных файлов: 88 добавлений и 28 удалений
  1. 88
    28
      init_homepath

+ 88
- 28
init_homepath Просмотреть файл

@@ -1,30 +1,90 @@
1
-#!/bin/sh
1
+#!/usr/bin/python3
2 2
 #
3 3
 
4
-BASE_FOLDERS="Downloads media_images Videos C64"
5
-VIP_FOLDERS="prj prj/Arduino Schreibtisch"
6
-
7
-
8
-echo The following folders will be deleted:
9
-for folder in $BASE_FOLDERS; do
10
-	echo -e "* $HOME/\033[1m$folder\033[0m"
11
-done
12
-for folder in $VIP_FOLDERS; do
13
-	echo -e "* $HOME/\033[1m$folder\033[0m"
14
-done
15
-echo
16
-read -r -p "Are you sure? [y/N] " response
17
-case "$response" in
18
-    [yY][eE][sS]|[yY]) 
19
-        for folder in $BASE_FOLDERS; do
20
-            rm -rf $HOME/`basename $folder`; ln -s /usr/data/$USER/local/$folder $HOME
21
-        done
22
-        rm -rf $HOME/data; ln -s /usr/data/$USER/data data
23
-        for folder in $VIP_FOLDERS; do
24
-            rm -rf $HOME/`basename $folder`; ln -s /usr/data/$USER/data/$folder $HOME
25
-        done
26
-        ;;
27
-    *)
28
-        echo No folder initialisation!
29
-        ;;
30
-esac
4
+import subprocess
5
+import sys
6
+
7
+def proceed():
8
+    while True:
9
+        uf = input("\nProceed? [Y/n/q]")
10
+        if len(uf) == 0:
11
+            uf = "y"
12
+        if uf.lower() in ["y", "n", "q"]:
13
+            break
14
+    if uf == "q":
15
+        sys.exit(1)
16
+    else:
17
+        return uf == "y"
18
+
19
+
20
+BASE_GIT_URL = "https://git.mount-mockery.de/dirk"
21
+REPOS = (
22
+    (BASE_GIT_URL + "/" + "bin.git", "~/bin"),
23
+    (BASE_GIT_URL + "/" + "bash.git", "~/.bash"),
24
+    (BASE_GIT_URL + "/" + "config_files.git", "~/.config_files"),
25
+)
26
+print("Cloning the following repositories:")
27
+for data in REPOS:
28
+	print("    %s --> %s" % data)
29
+if proceed():
30
+    for url, target in REPOS:
31
+        command = "git clone %s %s" % (url, target)
32
+        sys.stdout.write("Cloning %s" % url)
33
+        process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
34
+        process.wait()
35
+        if process.returncode == 0:
36
+            print("\t\t[ SUCCESS ]")
37
+        else:
38
+            print("\t\t[ FAILED  ]")
39
+            print("   ", process.stderr.read().decode("utf-8"))
40
+
41
+CONFIG_COMMANDS = (
42
+    "GS=`grep .bash/enabled ~/.bashrc`; [ ${#GS} -ne 0 ] || cat ~/.bash/BASHRC_ADDON >> ~/.bashrc",
43
+    "mkdir -p ~/.cache/vim && mkdir -p ~/.vim && ln -s ~/.config_files/vimrc ~/.vimrc && ln -s ~/.config_files/vim_skeletons ~/.vim/skeletons",
44
+    "which tmux && ln -s ~/.config_files/tmux.conf ~/.tmux.conf",
45
+    "mkdir -p ~/.config && ln -s ~/.config_files/powerline_gitstatus ~/.config/powerline",
46
+    "mkdir -p ~/.ssh && chmod 700 ~/.ssh && ln -s ~/.config_files/ssh_config ~/.ssh/config",
47
+)
48
+print("\n\n\nAdding the configuration to your environment:")
49
+for command in CONFIG_COMMANDS:
50
+    print("   ", command)
51
+if proceed():
52
+    for command in CONFIG_COMMANDS:
53
+        sys.stdout.write("Executing %s" % command)
54
+        process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
55
+        process.wait()
56
+        if process.returncode == 0:
57
+            print("\t\t[ SUCCESS ]")
58
+        else:
59
+            print("\t\t[ FAILED  ]")
60
+            print("   ", process.stderr.read().decode("utf-8"))
61
+
62
+#BASE_FOLDERS="Downloads media_images Videos C64"
63
+#VIP_FOLDERS="prj prj/Arduino Schreibtisch"
64
+
65
+
66
+#echo The following folders will be deleted:
67
+#for folder in $BASE_FOLDERS; do
68
+#	echo -e "* $HOME/\033[1m$folder\033[0m"
69
+#done
70
+#for folder in $VIP_FOLDERS; do
71
+#	echo -e "* $HOME/\033[1m$folder\033[0m"
72
+#done
73
+#echo
74
+#read -r -p "Are you sure? [y/N] " response
75
+#case "$response" in
76
+#    [yY][eE][sS]|[yY]) 
77
+#        for folder in $BASE_FOLDERS; do
78
+#            rm -rf $HOME/`basename $folder`; ln -s /usr/data/$USER/local/$folder $HOME
79
+#        done
80
+#        rm -rf $HOME/data; ln -s /usr/data/$USER/data data
81
+#        for folder in $VIP_FOLDERS; do
82
+#            rm -rf $HOME/`basename $folder`; ln -s /usr/data/$USER/data/$folder $HOME
83
+#        done
84
+#        ;;
85
+#    *)
86
+#        echo No folder initialisation!
87
+#        ;;
88
+#esac
89
+
90
+

Загрузка…
Отмена
Сохранить