A bin folder, holding helpfull scripts and commands
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

init_homepath 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/usr/bin/python3
  2. #
  3. import os
  4. import shutil
  5. import subprocess
  6. import sys
  7. class bcolors:
  8. HEADER = '\033[95m'
  9. OKBLUE = '\033[94m'
  10. OKCYAN = '\033[96m'
  11. OKGREEN = '\033[92m'
  12. WARNING = '\033[93m'
  13. FAIL = '\033[91m'
  14. ENDC = '\033[0m'
  15. BOLD = '\033[1m'
  16. UNDERLINE = '\033[4m'
  17. def proceed(ask="Proceed?"):
  18. while True:
  19. uf = input("\n%s [Y/n/q]" % ask)
  20. if len(uf) == 0:
  21. uf = "y"
  22. if uf.lower() in ["y", "n", "q"]:
  23. break
  24. if uf == "q":
  25. sys.exit(1)
  26. else:
  27. return uf.lower() == "y"
  28. def delete_destination():
  29. return proceed("/!\\ Delete Destination including ALL files? /!\\")
  30. def failed(error_msg):
  31. print(" " + bcolors.WARNING + error_msg.rstrip("\n") + bcolors.ENDC)
  32. print(" [" + bcolors.FAIL + " FAILED " + bcolors.ENDC + "]")
  33. def success():
  34. print(" [" + bcolors.OKGREEN + " SUCCESS " + bcolors.ENDC + "]")
  35. BASE_GIT_URL = "https://git.mount-mockery.de/dirk"
  36. REPOS = (
  37. (BASE_GIT_URL + "/" + "bin.git", "~/bin"),
  38. (BASE_GIT_URL + "/" + "bash.git", "~/.bash"),
  39. (BASE_GIT_URL + "/" + "config_files.git", "~/.config_files"),
  40. )
  41. print("Cloning the following repositories:")
  42. for data in REPOS:
  43. print(" %s --> %s" % data)
  44. if proceed():
  45. for url, target in REPOS:
  46. command = "git clone %s %s" % (url, target)
  47. print("Cloning %s" % url)
  48. process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  49. process.wait()
  50. if process.returncode == 0:
  51. success()
  52. else:
  53. failed(process.stderr.read().decode("utf-8"))
  54. CONFIG_COMMANDS = (
  55. "GS=`grep .bash/enabled ~/.bashrc`; [ ${#GS} -ne 0 ] || cat ~/.bash/BASHRC_ADDON >> ~/.bashrc",
  56. "mkdir -p ~/.cache/vim && mkdir -p ~/.vim && ln -s ~/.config_files/vimrc ~/.vimrc && ln -s ~/.config_files/vim_skeletons ~/.vim/skeletons",
  57. "which tmux && ln -s ~/.config_files/tmux.conf ~/.tmux.conf",
  58. "mkdir -p ~/.config && ln -s ~/.config_files/powerline_gitstatus ~/.config/powerline",
  59. "mkdir -p ~/.ssh && chmod 700 ~/.ssh && ln -s ~/.config_files/ssh_config ~/.ssh/config",
  60. )
  61. print("\n\n\nAdding the configuration to your environment:")
  62. for command in CONFIG_COMMANDS:
  63. print(" ", command)
  64. if proceed():
  65. for command in CONFIG_COMMANDS:
  66. print("Executing %s" % command)
  67. process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  68. process.wait()
  69. if process.returncode == 0:
  70. success()
  71. else:
  72. failed(process.stderr.read().decode("utf-8"))
  73. DATA_LINKS = (
  74. ('~/data', 'prj'),
  75. ('~/data', 'prj/Arduino'),
  76. ('~/data', 'Schreibtisch'),
  77. ('/usr/data/dirk/local', 'C64'),
  78. ('/usr/data/dirk/local', 'Downloads'),
  79. ('/usr/data/dirk/local', 'media_images'),
  80. ('/usr/data/dirk/local', 'Videos'),
  81. )
  82. print("\n\n\nAdding the ~/data softlinks to your home directory")
  83. for src_path, path in DATA_LINKS:
  84. print(" %s -> %s" % (os.path.join(src_path, path), os.path.join('~', os.path.basename(path))))
  85. if proceed():
  86. delete_dest = delete_destination()
  87. for src_path, path in DATA_LINKS:
  88. src = os.path.expanduser(os.path.join(src_path, path))
  89. dest = os.path.expanduser(os.path.join("~", os.path.basename(path)))
  90. print(" Creating symlink: %s -> %s" % (src, dest))
  91. # Check existance of dest
  92. if not os.path.exists(src):
  93. failed("Source %s does not exists." % src)
  94. continue
  95. if os.path.exists(dest):
  96. if delete_dest:
  97. try:
  98. os.remove(dest)
  99. except IsADirectoryError:
  100. shutil.rmtree(dest)
  101. else:
  102. failed("Destination %s already exists." % dest)
  103. continue
  104. # Create Symbolic Link
  105. os.symlink(src, dest)
  106. success()