From 1dfe37a97086c80878219405e13c4bc33fc2ccd7 Mon Sep 17 00:00:00 2001 From: Paul S Date: Thu, 6 May 2021 12:40:12 +0200 Subject: [PATCH] Ported shell script "install.sh" to Python --- install_cli.py | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 install_cli.py diff --git a/install_cli.py b/install_cli.py new file mode 100644 index 0000000..c3215e3 --- /dev/null +++ b/install_cli.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 + +# Dependencies +import os +import time + +# Variables +MYDIR = os.getcwd() +SHELL = os.environ.get("SHELL") +HOME = os.environ.get("HOME") + +# Intro +# language + +language = input("Hello, first of all, which language do you prefer: German [DE] or English [EN]?\n> ") +if language.upper() == "DE": + from languages.german import * + print("Perfekt, nun ist das deutsche Sprachpaket aktiviert. Willkommen!\n") +else: + from languages.english import * + print("Perfect, the English language package is now activated. Welcome!.\n") + +time.sleep(1) + +print("\n" + intromsg1 + "\n") +time.sleep(1) + +print("\n" + intromsg2 + "\n") +time.sleep(1) + +# Installer + +# creates the file 'Backuppy.sh' +fBackuppy = open("Backuppy.sh", "w") +fBackuppy.write("#!/bin/bash") +os.chmod("Backuppy.sh", 0o777) # make file executable + +# which Rsync options are available and which one you want to use +print(rsyncopt + "\n") +time.sleep(1) + +# asks if you want to exclude files/directories from backup and creates an exclude file in case of Yes +exclude = input(excludefile1 + "\n> ") +if exclude.upper() in ("J", "Y"): + print(excludefile2 + "\n") + fExclude = open("exclude.txt", "w") + fExclude.close() +else: + print(excludefile3 + "\n") +time.sleep(1) + +# Asks for the source directory which should be saved +print(srcdir1) +time.sleep(1) +sourcedir = input(srcdir2 + "\n> ") + +print(f"{srcdir3_1} {sourcedir} {srcdir3_2}") +time.sleep(1) + +# asks for the destination directory in which the backup should be saved +targetdir = input(targetdir1 + "\n> ") +print(f"{targetdir2_1} {targetdir} {targetdir2_2}") +time.sleep(1) + +# alias entry in .bashrc or .zshrc +print(SHELL) + +# .zshrc case1 and case2 +if SHELL.upper().find("ZSH") >0: + # Appending to bash config file + fRc = open(os.path.join(HOME, ".zshrc"), "a") # append mode + fRc.write("\n" + f"alias backuppy='sudo {MYDIR}/Backuppy.sh'" + "\n") + fRc.close() + +# .bashrc case1 and case2 +elif SHELL.upper().find("BASH") >0: + # Appending to zsh config file + fRc = open(os.path.join(HOME, ".bashrc"), "a") # append mode + fRc.write("\n" + f"alias backuppy='sudo {MYDIR}/Backuppy.sh'" + "\n") + fRc.close() + +# collects all the information needed to execute the rsync command and creates it. +print(collect + "\n") +time.sleep(1) +print(f"rsync -aqp --exclude-from={MYDIR}/exclude.txt {sourcedir} {targetdir}\n") +time.sleep(1) + +# enter the rsync command in Backuppy.sh +fBackuppy.write("\n" + f"rsync -aqp --exclude-from={MYDIR}/exclude.txt {sourcedir} {targetdir}" + "\n") +fBackuppy.close() + +# Outro +print(outro1) +time.sleep(2) +print(outro2 + " fotocoder@joschu.ch")