From 090205fd92bb31233ff7293ab236f222d8bef8f3 Mon Sep 17 00:00:00 2001 From: Justin Timperio Date: Sat, 12 Sep 2020 12:43:01 -0400 Subject: [PATCH] More fixes to build and setup process --- build/BUILDPKG_FULL_TEMPLATE | 2 ++ build/BUILDPKG_GIT_TEMPLATE | 2 ++ build/INSTALL_TEMPLATE | 11 -------- build/alpha-upgrade.sh | 52 +++++++++++++++++++----------------- core/pacback.py | 1 - core/session.py | 29 +++----------------- 6 files changed, 34 insertions(+), 63 deletions(-) diff --git a/build/BUILDPKG_FULL_TEMPLATE b/build/BUILDPKG_FULL_TEMPLATE index 4fdbbf0..c8d5da2 100644 --- a/build/BUILDPKG_FULL_TEMPLATE +++ b/build/BUILDPKG_FULL_TEMPLATE @@ -29,4 +29,6 @@ package() { cp -dr --no-preserve='ownership' LICENSE "${pkgdir}"/usr/share/licences/pacback cp -dr --no-preserve='ownership' config "${pkgdir}"/etc/pacback.conf ln -sf /usr/share/pacback/core/pacback.py "${pkgdir}"/usr/bin/pacback + mkdir -p /var/lib/pacback/restore-points + mkdir -p /var/lib/pacback/snapshots } diff --git a/build/BUILDPKG_GIT_TEMPLATE b/build/BUILDPKG_GIT_TEMPLATE index 1259464..93d61f3 100644 --- a/build/BUILDPKG_GIT_TEMPLATE +++ b/build/BUILDPKG_GIT_TEMPLATE @@ -42,4 +42,6 @@ package() { cp -dr --no-preserve='ownership' pacback/build/config "${pkgdir}"/etc/pacback.conf cp -dr --no-preserve='ownership' pacback/build/alpha-upgrade.sh "${pkgdir}"/tmp ln -sf /usr/share/pacback/core/pacback.py "${pkgdir}"/usr/bin/pacback + mkdir -p /var/lib/pacback/restore-points + mkdir -p /var/lib/pacback/snapshots } diff --git a/build/INSTALL_TEMPLATE b/build/INSTALL_TEMPLATE index 34ed632..1205618 100644 --- a/build/INSTALL_TEMPLATE +++ b/build/INSTALL_TEMPLATE @@ -4,17 +4,6 @@ post_install() { # Installs Snapshot Hook pacback -ih - - # Create Directories - if [ ! -d '/var/lib/pacback']; then - mkdir '/var/lib/pacback' - fi - if [ ! -d '/var/lib/pacback/snapshots']; then - mkdir '/var/lib/pacback/snapshots' - fi - if [ ! -d '/var/lib/pacback/restore-points']; then - mkdir '/var/lib/pacback/restore-points' - fi } post_upgrade() { diff --git a/build/alpha-upgrade.sh b/build/alpha-upgrade.sh index d1c3188..62148cd 100755 --- a/build/alpha-upgrade.sh +++ b/build/alpha-upgrade.sh @@ -9,38 +9,40 @@ base_path='/var/lib/pacback' -# Fix First Line -find $base_path -type f -name '*.meta' -exec sed -i '1 s/^====== Pacback RP.*/======= Pacback Info =======/' {} + +if [ -d '$base_path' ]; then + # Fix First Line + find $base_path -type f -name '*.meta' -exec sed -i '1 s/^====== Pacback RP.*/======= Pacback Info =======/' {} + -# Fix Version Field -find $base_path -type f -name '*.meta' -exec sed -i 's/^Pacback Version:/Version:/' {} + + # Fix Version Field + find $base_path -type f -name '*.meta' -exec sed -i 's/^Pacback Version:/Version:/' {} + -## Removed For Safety During Multiple Runs -## This Value is Not Essential For Runtime -# Add Creation Time -# find $base_path -type f -name '*.meta' -exec sed -i '/^Date Created:.*/a Time Created: 00:00:00' {} + + ## Removed For Safety During Multiple Runs + ## This Value is Not Essential For Runtime + # Add Creation Time + # find $base_path -type f -name '*.meta' -exec sed -i '/^Date Created:.*/a Time Created: 00:00:00' {} + -# Add Type Fields -find $base_path -type f -name '*.meta' -exec sed -i '/^Time Created:.*/a Type: Restore Point' {} + -find $base_path -type f -name '*.meta' -exec sed -i 's/^Packages in RP: 0/SubType: Light/' {} + + # Add Type Fields + find $base_path -type f -name '*.meta' -exec sed -i '/^Time Created:.*/a Type: Restore Point' {} + + find $base_path -type f -name '*.meta' -exec sed -i 's/^Packages in RP: 0/SubType: Light/' {} + -# Remove Fields If No Packages Are Cached -find $base_path -type f -name '*.meta' -exec sed -i '/^Size of Packages in RP: 0B/d' {} + + # Remove Fields If No Packages Are Cached + find $base_path -type f -name '*.meta' -exec sed -i '/^Size of Packages in RP: 0B/d' {} + -############################## -# Patch Full Restore Points -############################ + ############################## + # Patch Full Restore Points + ############################ -# Add SubType Field -find $base_path -type f -name '*.meta' -exec sed -i '/^Packages in RP:.*/i SubType: Full' {} + + # Add SubType Field + find $base_path -type f -name '*.meta' -exec sed -i '/^Packages in RP:.*/i SubType: Full' {} + -# Fix Fields If Package Are Cached -find $base_path -type f -name '*.meta' -exec sed -i 's/^Packages in RP:/Packages Cached:/' {} + -find $base_path -type f -name '*.meta' -exec sed -i 's/^Size of Packages in RP:/Package Cache Size:/' {} + + # Fix Fields If Package Are Cached + find $base_path -type f -name '*.meta' -exec sed -i 's/^Packages in RP:/Packages Cached:/' {} + + find $base_path -type f -name '*.meta' -exec sed -i 's/^Size of Packages in RP:/Package Cache Size:/' {} + -# Fix Custom Dir Fields -find $base_path -type f -name '*.meta' -exec sed -i 's/^Dirs /Dir /' {} + + # Fix Custom Dir Fields + find $base_path -type f -name '*.meta' -exec sed -i 's/^Dirs /Dir /' {} + -# Change Package Cache Folder Name -find $base_path/restore-points -type d -name 'pac_cache' -exec rename 'pac_cache' 'pkg-cache' {} + + # Change Package Cache Folder Name + find $base_path/restore-points -type d -name 'pac_cache' -exec rename 'pac_cache' 'pkg-cache' {} + +fi diff --git a/core/pacback.py b/core/pacback.py index 6c94467..9f7e145 100755 --- a/core/pacback.py +++ b/core/pacback.py @@ -98,7 +98,6 @@ # Safely Init the Environment session.lock(config) - session.setup(config) signal.signal(signal.SIGINT, partial(session.sig_catcher, config)) ###################### diff --git a/core/session.py b/core/session.py index 013068d..dc8b629 100644 --- a/core/session.py +++ b/core/session.py @@ -27,11 +27,14 @@ def lock(config): paf.start_log(fname, config['log']) paf.write_to_log(fname, 'Passed Root Check', config['log']) paf.write_to_log(fname, 'Started Active Session', config['log']) + if os.path.exists('/etc/pacback.conf') is False: + paf.write_to_log(fname, 'User Config File Is Missing!', config['log']) except (IOError, OSError): sys.exit('Critical Error! Pacback Already Has An Active Session Running.') + def unlock(config): ''' Removes the session lock defined by config['slock']. @@ -151,29 +154,3 @@ def load_config(): default.update(user_config) return default - - -################## -# Setup Pacback -################ - -def setup(config): - ''' - Check if all the need folders and files are present for a active session - ''' - fname = 'session.setup()' - # Init Base Paths if First Run - if os.path.exists(config['basepath']) is False: - paf.mk_dir(config['basepath'], sudo=False) - paf.write_to_log(fname, 'Created Basepath Folder at ' + config['basepath'], config['log']) - - if os.path.exists(config['rp_paths']) is False: - paf.mk_dir(config['rp_paths'], sudo=False) - paf.write_to_log(fname, 'Created Restore Point Folder at ' + config['rp_paths'], config['log']) - - if os.path.exists(config['ss_paths']) is False: - paf.mk_dir(config['ss_paths'], sudo=False) - paf.write_to_log(fname, 'Created Snapshot Folder at ' + config['ss_paths'], config['log']) - - if os.path.exists('/etc/pacback.conf') is False: - paf.write_to_log(fname, 'User Config File Is Missing!', config['log'])