-
Notifications
You must be signed in to change notification settings - Fork 53
/
update.bash
executable file
·89 lines (79 loc) · 3.5 KB
/
update.bash
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
BASEDIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OS="$(grep -o '^ID=.*$' /etc/os-release | cut -d'=' -f2)"
if [[ "$(id -u)" -ne 0 ]]; then
echo "ERROR: You need to be ROOT (sudo can be used)."
exit 1
fi
if ! [[ -f /usr/local/sbin/zram-config || -f /usr/sbin/zram-config ]]; then
echo -e "ERROR: zram-config is not installed.\\nPlease run \"sudo ${BASEDIR}/install.bash\" to install zram-config instead."
exit 1
fi
if [[ $OS == "alpine" ]] && ! [[ "$(apk info 2> /dev/null | grep -E '^(gcc|meson|fts-dev|linux-headers|util-linux-misc|musl-dev)' | tr '\n' ' ')" == "fts-dev gcc meson util-linux-misc musl-dev linux-headers " ]]; then
echo "Installing needed packages (gcc, meson, fts-dev, linux-headers, util-linux-misc, musl-dev)"
apk add gcc meson fts-dev linux-headers util-linux-misc musl-dev || exit 1
elif ! dpkg -s 'gcc' 'meson' 'libc6-dev' &> /dev/null; then
echo "Installing needed packages (gcc, meson, libc6-dev)"
apt-get install --yes gcc meson libc6-dev || exit 1
fi
if [[ $OS == "ubuntu" ]] && [[ $(bc -l <<< "$(grep -o '^VERSION_ID=.*$' /etc/os-release | cut -d'=' -f2 | tr -d '"') >= 21.10") -eq 1 ]]; then
echo "Install zram module package for Ubuntu (linux-modules-extra-raspi)"
if ! dpkg -s 'linux-modules-extra-raspi' &> /dev/null; then
apt-get install --yes linux-modules-extra-raspi || exit 1
fi
fi
if [[ $1 != "custom" ]]; then
git -C "$BASEDIR" fetch origin
git -C "$BASEDIR" fetch --tags --force --prune
git -C "$BASEDIR" clean --force -x -d
git -C "$BASEDIR" checkout main
git -C "$BASEDIR" reset --hard origin/main
git -C "$BASEDIR" submodule update --init --recursive
fi
rm -rf "$BASEDIR"/overlayfs-tools/builddir
meson setup "$BASEDIR"/overlayfs-tools/builddir "$BASEDIR"/overlayfs-tools || exit 1
meson compile -C "$BASEDIR"/overlayfs-tools/builddir || exit 1
meson install -C "$BASEDIR"/overlayfs-tools/builddir || exit 1
echo "Stopping zram-config service"
if [[ $OS == "alpine" ]]; then
rc-service zram-config stop
else
systemctl stop zram-config.service
fi
echo "Updating zram-config files"
if [[ "$OS" == "alpine" ]]; then
install -m 755 "$BASEDIR"/zram-config /usr/sbin/
install -m 755 "$BASEDIR"/service/OpenRC/zram-config.openrc /etc/init.d/zram-config
else
install -m 755 "$BASEDIR"/zram-config /usr/local/sbin/
install -m 644 "$BASEDIR"/service/SystemD/zram-config.service /etc/systemd/system/zram-config.service
if ! grep -qs "ReadWritePaths=/usr/local/share/zram-config/log" /lib/systemd/system/logrotate.service; then
echo "ReadWritePaths=/usr/local/share/zram-config/log" >> /lib/systemd/system/logrotate.service
fi
fi
install -m 755 "$BASEDIR"/uninstall.bash /usr/local/share/zram-config/uninstall.bash
if ! [[ -f /etc/ztab ]]; then
install -m 644 "$BASEDIR"/ztab /etc/ztab
fi
if ! [[ -d /usr/local/share/zram-config/log ]]; then
mkdir -p /usr/local/share/zram-config/log
fi
if ! [[ -h /var/log/zram-config ]]; then
ln -s /usr/local/share/zram-config/log /var/log/zram-config
fi
if ! [[ -f /etc/logrotate.d/zram-config ]]; then
install -m 644 "$BASEDIR"/service/zram-config.logrotate /etc/logrotate.d/zram-config
fi
if ! [[ -d /usr/local/lib/zram-config ]]; then
mkdir -p /usr/local/lib/zram-config
fi
echo "Starting zram-config service"
if [[ $OS == "alpine" ]]; then
rc-update add zram-config boot
rc-service zram-config start
else
systemctl daemon-reload
systemctl enable --now zram-config.service
fi
echo "##### zram-config has been updated #####"
echo "##### edit /etc/ztab to configure options #####"