forked from foundObjects/pve-nag-buster
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall.sh
executable file
·114 lines (94 loc) · 3.23 KB
/
install.sh
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/sh
# shellcheck disable=SC2064
set -eu
#
# This file installs the non-subscription repos and the dkpg hook
#
# ensure a predictable environment
PATH=/usr/sbin:/usr/bin:/sbin:/bin
\unalias -a
# installer main body:
_main() {
# ensure $1 exists so 'set -u' doesn't error out
{ [ "$#" -eq "0" ] && set -- ""; } > /dev/null 2>&1
case "$1" in
"--uninstall")
# uninstall, requires root
assert_root
_uninstall
;;
"--install" | "")
# install dpkg hooks, requires root
assert_root
_install "$@"
;;
*)
# unknown flags, print usage and exit
_usage
;;
esac
exit 0
}
_uninstall() {
set -x
[ -f "/etc/apt/apt.conf.d/86pve-nags" ] &&
rm -f "/etc/apt/apt.conf.d/86pve-nags"
[ -f "/usr/share/pve-nag-buster.sh" ] &&
rm -f "/usr/share/pve-nag-buster.sh"
echo "Script and dpkg hooks removed, please manually remove /etc/apt/sources.list.d/pve-no-subscription.list if desired"
}
_install() {
# create hooks and no-subscription repo list, install hook script, run once
VERSION_CODENAME=''
ID=''
. /etc/os-release
if [ -n "$VERSION_CODENAME" ]; then
RELEASE="$VERSION_CODENAME"
else
RELEASE=$(awk -F"[)(]+" '/VERSION=/ {print $2}' /etc/os-release)
fi
# create the pve-no-subscription list
echo "Creating PVE no-subscription repo list ..."
cat <<- EOF > "/etc/apt/sources.list.d/pve-no-subscription.list"
# .list file automatically generated by pve-nag-buster at $(date)
#
# If pve-nag-buster is installed again this file will be overwritten
#
deb http://download.proxmox.com/debian/pve $RELEASE pve-no-subscription
EOF
# create the ceph reef no-subscription list
echo "Creating Ceph no-subscription repo list ..."
cat <<- EOF > "/etc/apt/sources.list.d/ceph-no-subscription.list"
# .list file automatically generated by pve-nag-buster at $(date)
#
# If pve-nag-buster is installed again this file will be overwritten
#
deb http://download.proxmox.com/debian/ceph-reef $RELEASE no-subscription
deb http://download.proxmox.com/debian/ceph-quincy $RELEASE no-subscription
EOF
# create dpkg pre/post install hooks for persistence
echo "Creating dpkg hooks in /etc/apt/apt.conf.d ..."
cat <<- 'EOF' > "/etc/apt/apt.conf.d/86pve-nags"
DPkg::Pre-Install-Pkgs {
"while read -r pkg; do case $pkg in *proxmox-widget-toolkit* | *pve-manager*) touch /tmp/.pve-nag-buster && exit 0; esac done < /dev/stdin";
};
DPkg::Post-Invoke {
"[ -f /tmp/.pve-nag-buster ] && { /usr/share/pve-nag-buster.sh; rm -f /tmp/.pve-nag-buster; }; exit 0";
};
EOF
# install the hook script
if [ ! -f "pve-nag-buster.sh" ]; then
# fetch from github if there is no local one available
echo "Fetching hook script from GitHub ..."
wget https://raw.githubusercontent.com/Yrlish/pve-nag-buster/master/pve-nag-buster.sh \
-q --show-progress -O "pve-nag-buster.sh"
fi
echo "Installing hook script as /usr/share/pve-nag-buster.sh"
install -o root -m 0550 "pve-nag-buster.sh" "/usr/share/pve-nag-buster.sh"
echo "Running patch script"
/usr/share/pve-nag-buster.sh
return 0
}
assert_root() { [ "$(id -u)" -eq '0' ] || { echo "This action requires root." && exit 1; }; }
_usage() { echo "Usage: $(basename "$0") (--uninstall)"; }
_main "$@"