|
|
@@ -0,0 +1,116 @@
|
|
|
+#!/usr/bin/python3
|
|
|
+# run as: root/user
|
|
|
+
|
|
|
+import os
|
|
|
+import sys
|
|
|
+import shutil
|
|
|
+
|
|
|
+SPATH = os.path.abspath(__file__)
|
|
|
+SDIR = os.path.dirname(SPATH)
|
|
|
+
|
|
|
+# Bash to loop through dir and source files
|
|
|
+BASHRC_STR = \
|
|
|
+""" # Dots Base Files
|
|
|
+for file in ~/.dots/base/*; do
|
|
|
+ if [ -r \"$file\" ]; then
|
|
|
+ source \"$file\"
|
|
|
+ fi
|
|
|
+done
|
|
|
+
|
|
|
+# Dots User Files
|
|
|
+for file in ~/.dots/user/*; do
|
|
|
+ if [ -r \"$file\" ]; then
|
|
|
+ source \"$file\"
|
|
|
+ fi
|
|
|
+done """
|
|
|
+
|
|
|
+def run(command: str):
|
|
|
+ os.system(command)
|
|
|
+
|
|
|
+def get_prompt() -> str:
|
|
|
+ # Check for argument input
|
|
|
+ if len(sys.argv) < 2:
|
|
|
+ print('::[Dots Installation Script]::')
|
|
|
+ print('Usage: install <prompt to use: (seafly|parrot|powerline)>')
|
|
|
+ sys.exit(1)
|
|
|
+
|
|
|
+ # Ensure user choice is valid
|
|
|
+ prompts = ['seafly', 'parrot', 'powerline']
|
|
|
+ uprompt = sys.argv[1]
|
|
|
+
|
|
|
+ if uprompt not in prompts:
|
|
|
+ print('Please choose a valid prompt file!')
|
|
|
+ print('seafly | parrot | powerline')
|
|
|
+ sys.exit(1)
|
|
|
+
|
|
|
+ return uprompt
|
|
|
+
|
|
|
+def string_in_file(path: str, string: str) -> bool:
|
|
|
+ try:
|
|
|
+ epath = os.path.expandvars(path) # expand Bash Environment Variables
|
|
|
+ with open(epath, 'r') as file:
|
|
|
+ file_contents = file.read()
|
|
|
+
|
|
|
+ if string in file_contents:
|
|
|
+ return True
|
|
|
+ else:
|
|
|
+ return False
|
|
|
+ except Exception as e:
|
|
|
+ print(f'General Exception (string_in_file): {e}')
|
|
|
+
|
|
|
+def add_string(path: str, string: str) -> bool:
|
|
|
+ try:
|
|
|
+ epath = os.path.expandvars(path) # expand Bash Environment Variables
|
|
|
+ with open(epath, 'a') as file:
|
|
|
+ file.write(string + '\n')
|
|
|
+ return True
|
|
|
+ except Exception as e:
|
|
|
+ print(f'General Exception (add_string): {e}')
|
|
|
+ return False
|
|
|
+
|
|
|
+# Create path and children if not exists
|
|
|
+def create_path(path) -> bool:
|
|
|
+ try:
|
|
|
+ epath = os.path.expandvars(path) # expand Bash Environment Variables
|
|
|
+ os.makedirs(epath, exist_ok = True)
|
|
|
+ return True
|
|
|
+ except Exception as e:
|
|
|
+ print(f'General Exception (create_path): {e}')
|
|
|
+ return False
|
|
|
+
|
|
|
+def copy_file(source: str, destination: str) -> bool:
|
|
|
+ try:
|
|
|
+ src = os.path.expandvars(source) # expand Bash Environment Variables
|
|
|
+ dst = os.path.expandvars(destination)
|
|
|
+ shutil.copy2(src, dst)
|
|
|
+ return True
|
|
|
+ except Exception as e:
|
|
|
+ print(f'General Exception (copy_file): {e}')
|
|
|
+ return False
|
|
|
+
|
|
|
+def main():
|
|
|
+ uprompt = get_prompt()
|
|
|
+
|
|
|
+ # NVIM
|
|
|
+ create_path('$HOME/.config/nvim/')
|
|
|
+ copy_file(f'{SDIR}/app_config/nvim', '$HOME/.config/nvim/init.vim')
|
|
|
+
|
|
|
+ # TMUX
|
|
|
+ copy_file(f'{SDIR}/app_config/tmux.conf', '$HOME/.tmux.conf')
|
|
|
+
|
|
|
+ # Create dots working dir
|
|
|
+ run(f'rm -rf $HOME/.dots/base/') # Remove old config
|
|
|
+ create_path('$HOME/.dots/base/')
|
|
|
+ create_path('$HOME/.dots/user/')
|
|
|
+
|
|
|
+ # Set default aliases
|
|
|
+ copy_file(f'{SDIR}/aliases/default_aliases', f'$HOME/.dots/base')
|
|
|
+ copy_file(f'{SDIR}/prompts/{uprompt}-prompt', f'$HOME/.dots/base')
|
|
|
+
|
|
|
+ # Add Bashrc Config
|
|
|
+ if not string_in_file('$HOME/.bashrc', BASHRC_STR):
|
|
|
+ add_string('$HOME/.bashrc', BASHRC_STR)
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ main()
|