diff --git a/clone-master-clean-up.changes b/clone-master-clean-up.changes index c70e5cf..c20347d 100644 --- a/clone-master-clean-up.changes +++ b/clone-master-clean-up.changes @@ -1,3 +1,21 @@ +------------------------------------------------------------------- +Tue Oct 8 13:24:41 UTC 2019 - abriel@suse.com + +- Bump version to 1.5 +- Don't show output from pushd/popd +- Make snapper snapshot removal more generic + The output format is not really meant for machine reading, it's + format has changed thus the simple parser broke. + This now makes the parser more generic (using data from d-bus), + also now it is ensured the snapshots are deleted in the correct + order. + (bsc#1149322) + +------------------------------------------------------------------- +Tue Aug 27 07:06:00 UTC 2019 - Jan Engelhardt + +- Use noun phrase in descriptions. + ------------------------------------------------------------------- Wed Aug 7 11:00:14 UTC 2019 - Egbert Eich @@ -74,4 +92,3 @@ Fri Oct 23 09:05:07 UTC 2015 - hguo@suse.com Mon Sep 14 12:35:46 UTC 2015 - hguo@suse.com - Initial version, initial release. - diff --git a/clone-master-clean-up.sh b/clone-master-clean-up.sh index 5ce8aaf..dc4145e 100644 --- a/clone-master-clean-up.sh +++ b/clone-master-clean-up.sh @@ -71,12 +71,12 @@ for seed in /var/lib/systemd/random-seed /var/lib/misc/random-seed; do done echo 'Clearing systemd journal' -pushd /etc/systemd +pushd /etc/systemd > /dev/null cp journald.conf journald.conf.bak echo -e '\nSystemMaxUse=1K' >> journald.conf systemctl restart systemd-journald mv journald.conf.bak journald.conf -popd +popd > /dev/null echo 'Clearing systemd machine ID file' truncate -s 0 /etc/machine-id @@ -108,14 +108,59 @@ EOF echo 'Enabling YaST Firstboot if necessary' [ -e /etc/YaST2/firstboot.xml ] && touch /var/lib/YaST2/reconfig_system + if [ "$CMCU_RSNAP" = "yes" ]; then +SNAPPER_CMD="snapper delete" if [ -d /.snapshots ]; then - echo "Remove all btrfs snapshots from /.snapshot" - for s in `snapper list | awk '/pre/||/post/{print $3}'`; do - snapper delete $s - done + echo "Removing all pre/post btrfs snapshots from /.snapshot" + snapshots=$(dbus-send --type=method_call --system --print-reply \ + --dest=org.opensuse.Snapper \ + /org/opensuse/Snapper \ + org.opensuse.Snapper.ListSnapshots string:root \ + 2>/dev/null | awk -- " +BEGIN {arr=0; cnt=0; u2=0; u4=0; del=0} +/array \[/ {arr++} +/struct {/ {if (arr==1) cnt++} +/}/ {if(arr==1&&--cnt==0){if(del==1) print id \"|\" lst;del=0;u4=0;u2=0}} +/\]/ {arr--} +# Don't delete current snapshot +/string "current"/ {if (arr==1 && cnt==1) del=0} +# ID: 1st uint32 value of each top struct in top array +/uint32/ {if (arr==1 && cnt==1) if (++u4==1)id=\$2; else if (u4==2)lst=\$2} +# Type: 1st uint16 value of each top struct in top array +/uint16/ {if (arr==1 && cnt==1){if (++u2==1) {if (\$2==1 || \$2==2){del=1}}}} +") + + # Create chains + OFS=$IFS + IFS=" " + while read line; do + [[ $line =~ ([^\|]+)\|(.*) ]] + last[${BASH_REMATCH[1]}]=${BASH_REMATCH[2]}; + [ -z "${next[${BASH_REMATCH[1]}]}" ] && next[${BASH_REMATCH[1]}]=0 + next[${BASH_REMATCH[2]}]=${BASH_REMATCH[1]} + done <<< $snapshots + IFS=$OFS + # Find end of each chain and work backwards + for i in ${!next[@]}; do + [ -n "${next[$i]}" ] || continue # unpopulated + a=${next[$i]}; unset next[$i]; b=$i + while true; do + if [ $a -eq 0 ] + then + while true; do + unset next[$b]; $SNAPPER_CMD $b + b=${last[$b]} + [ $b -eq 0 ] && break 2 + done + else + b=$a; a=${next[$a]}; unset next[$b] + fi + done + done fi fi + if [ "$CMCU_ZYPP_REPOS" = "yes" ]; then echo "Clean up all zypper repositories" rm -rf /etc/zypp/repos.d/* diff --git a/clone-master-clean-up.spec b/clone-master-clean-up.spec index 3e3d1a7..abad8ff 100644 --- a/clone-master-clean-up.spec +++ b/clone-master-clean-up.spec @@ -1,7 +1,7 @@ # # spec file for package clone-master-clean-up # -# Copyright (c) 2017 SUSE LLC +# Copyright (c) 2017-2019 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -12,16 +12,17 @@ # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. -# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# Please submit bugfixes or comments via https://bugs.opensuse.org/ # + Name: clone-master-clean-up -Version: 1.4 +Version: 1.5 Release: 0 -License: GPL-2.0+ -Summary: Clean up a system for cloning preparation -Url: https://www.suse.com +Summary: Tool to clean up a system for cloning preparation +License: GPL-2.0-or-later Group: System/Management +Url: https://www.suse.com Source0: clone-master-clean-up.sh Source1: clone-master-clean-up.1 Source2: sysconfig.clone-master-clean-up @@ -29,7 +30,10 @@ Source3: custom_remove.template Source10: LICENSE Source11: README.md BuildRoot: %{_tmppath}/%{name}-%{version}-build -Requires: systemd sed curl coreutils +Requires: coreutils +Requires: curl +Requires: sed +Requires: systemd Requires(post): %fillup_prereq BuildArch: noarch @@ -37,9 +41,9 @@ BuildArch: noarch %define _fillupdir /var/adm/fillup-templates %endif - %description -Clean up a system for cloning preparation by cleaning up usage history and log files, etc. +A tool to clean up a system for cloning preparation by cleaning up +usage history and log files, etc. %prep @@ -65,8 +69,8 @@ mkdir -p %{buildroot}/%{_sysconfdir}/%{name}/ %fillup_only -n clone-master-clean-up %files -%doc %{basename:%{S:11}} -%license %{basename:%{S:10}} +%doc README.md +%license LICENSE %{_sbindir}/* %{_mandir}/man1/* %{_fillupdir}/* @@ -74,3 +78,5 @@ mkdir -p %{buildroot}/%{_sysconfdir}/%{name}/ %dir %{_sysconfdir}/%{name} %{_datadir}/%{name}/custom_remove.template %ghost %config %{_sysconfdir}/%{name}/custom_remove + +%changelog