Compare commits

..

3 commits

3 changed files with 123 additions and 17 deletions

View file

@ -1,6 +1,10 @@
# Changelog Backuppy
## [1.02.000] - 2021-05-05
## [0.6] - 2021-05-06
### Added
- Write alias to Backuppy.sh into .bashrc/.zshrc only if not already existing
## [0.5.2] - 2021-05-05
### Added
- Now fully functional as the shell version
@ -11,11 +15,11 @@
### Fixed
- Fixed problem with the Bash/ZSH config
## [1.01.001] - 2021-05-04
## [0.5.1] - 2021-05-04
### Changed
- Use E-MAIL constant
## [1.01.000] - 2021-05-04
## [0.5] - 2021-05-04
### Added
- Graphical installer based on Python3 with PySide2 GUI framework (Qt-bindings for Python)
- Changelog.MD

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""
project: Backuppy
version: 1.02.000
version: 0.6
file: install.py
summary: main entry python file
"""
@ -10,16 +10,14 @@ summary: main entry python file
import os
# Third party imports
from PySide2 import QtCore
from PySide2 import QtGui
from PySide2 import QtCore, QtWidgets
from PySide2 import QtWidgets
# local imports
from languages import english
from languages import german
# local globals
VERSION: str = "1.02.000"
VERSION: str = "0.6"
EMAIL: str = "fotocoder@joschu.ch"
TARGET_SCRIPT: str = "Backuppy.sh"
EXCLUDE_FILE: str = "exclude.txt"
@ -44,7 +42,7 @@ def get_lang_text(search_str: str):
def trace(message_txt: str):
""" Print a formatted message to std out. """
print(f"[ OK ]", message_txt)
print("[ OK ]" + message_txt)
class BackuppyWizard(QtWidgets.QWizard):
def __init__(self, parent=None):
@ -295,20 +293,29 @@ def create_shell_script(command_str: str):
user_home = os.environ.get("HOME")
## STEP 1: update shell config scripts with alias for backuppy
# .zshrc case1 and case2
if current_shell in ("/usr/bin/zsh", "/bin/zsh"):
# Appending to bash config file
# Check for installed ZSH
if current_shell.upper().find("ZSH") > 0:
rc_filepath = os.path.join(user_home, ".zshrc")
# .bashrc case1 and case2
elif current_shell in ("/usr/bin/bash", "/bin/bash"):
# Appending to zsh config file
# Check for installed BASH
if current_shell.upper().find("BASH") > 0:
rc_filepath = os.path.join(user_home, ".bashrc")
# Append our alias if not already existing
if os.path.isfile(rc_filepath):
with open(rc_filepath, 'a') as file1:
fileRc = open(rc_filepath, "r") # open file in read mode
backuppy_entry_exists = False
for line in fileRc:
if "alias backuppy=" in line:
backuppy_entry_exists = True
break
if not backuppy_entry_exists:
trace(f"Writing {ALIAS_STR} to config file '{rc_filepath}'.")
file1.write("\n# Following line was created by Backuppy\n" + ALIAS_STR + "\n")
fileRc = open(rc_filepath, "a") # open file in append mode
fileRc.write("\n# Following line was created by Backuppy\n" + ALIAS_STR + "\n")
fileRc.close()
## STEP 2: Create the exclude script if desired
if EXCLUDE:

95
install_cli.py Normal file
View file

@ -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")