forked from turnkeylinux/common
/
etckeeper
executable file
·51 lines (42 loc) · 1.83 KB
/
etckeeper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash -e
# Hack to install etckeeper without python2 (not really a hard depends)
# See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=921447
#
# Note that any future etckeeper updates will (re)install python2; so this
# only reduces the size until the next update of etckeeper
# Download pkg from Debian and unpack
tmp_dir=etckeeper.tmp
mkdir $tmp_dir
apt-get update -qq || true
apt-get download etckeeper -y
dpkg-deb -R etckeeper_*.deb $tmp_dir
# process the control file to find the relevant part that needs tweaking
line=$(grep -n "^Depends:" $tmp_dir/DEBIAN/control)
line_no=$(echo "$line" | cut -d: -f1)
line=$(echo $line | cut -d: -f2-)
# match py2 dep to remove
py2_dep1=$(echo $line | sed "s|^.*\(python[^,]*[<][^,]*2[^,]*,* \).*$|\1|")
# match py2 dep and to bump to py3
py2_dep2=$(echo $line | sed "s|^.*\(python[^,]*[>=][^,]*2.[0-9][^,]*,*\)|\1|")
py3_dep=$(echo $py2_dep2 | sed "s|python:|python3:|;s|2.7.*)|3.5~)|")
# Update python2 dependency to python3
# This may be a bit fragile, so test length and fail loudly if too long
# currently these 2 deps are 21 & 24 chars respecively in buster
if [[ ${#py2_dep1} -lt 23 ]] && [[ ${#py2_dep2} -lt 26 ]]; then
# remove dependency on 'python:any (<< 2.8)'
sed -i "${line_no}s|${py2_dep1}||" $tmp_dir/DEBIAN/control
# modify dependency on '>= 2.7~' to be '>= 3.5~'
sed -i "${line_no}s|${py2_dep2}|${py3_dep}|" $tmp_dir/DEBIAN/control
else
echo "[FATAL] $(basename $0) Failed to patch etckeeper dpkg status"
exit 1
fi
# Repack, install and cleanup
dpkg-deb -b $tmp_dir etckeeper_fixed.deb
DEBIAN_FRONTEND=noninteractive apt-get install -y \
-o DPkg::Options::=--force-confdef -o DPkg::Options::=--force-confold \
./etckeeper_fixed.deb
rm -r etckeeper*
# un-initialize etckeeper (not related to above hack)
echo "inithooks.conf" >> /etc/.gitignore
etckeeper uninit -f