forked from pool/clone-master-clean-up
Accepting request 736254 from home:AngelaBriel:clone-master-clean-up
- 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) OBS-URL: https://build.opensuse.org/request/show/736254 OBS-URL: https://build.opensuse.org/package/show/systemsmanagement/clone-master-clean-up?expand=0&rev=5
This commit is contained in:
parent
fba7e978de
commit
ebd9e81b60
@ -1,3 +1,16 @@
|
||||
-------------------------------------------------------------------
|
||||
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 <jengelh@inai.de>
|
||||
|
||||
|
@ -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
|
||||
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/*
|
||||
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# spec file for package clone-master-clean-up
|
||||
#
|
||||
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
|
||||
# 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
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
|
||||
Name: clone-master-clean-up
|
||||
Version: 1.4
|
||||
Version: 1.5
|
||||
Release: 0
|
||||
Summary: Tool to clean up a system for cloning preparation
|
||||
License: GPL-2.0-or-later
|
||||
|
Loading…
x
Reference in New Issue
Block a user