|
|
@@ -1,10 +1,11 @@
|
|
|
#!/usr/bin/env bash
|
|
|
set -Eeuo pipefail
|
|
|
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
|
+if [[ -d /opt/debtik/go/bin ]]; then export PATH=/opt/debtik/go/bin:$PATH; fi
|
|
|
export HOME=${HOME:-/root}
|
|
|
export GOPATH=${GOPATH:-/var/cache/debtik/go}
|
|
|
export GOCACHE=${GOCACHE:-/var/cache/debtik/go-build}
|
|
|
-src=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
|
|
|
+src=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." 2>/dev/null && pwd || echo /usr/local)
|
|
|
mode=${1:-install}
|
|
|
[[ $# -le 1 && ( $mode == install || $mode == --check ) ]] || { echo 'Usage: install-dependencies.sh [--check]' >&2; exit 2; }
|
|
|
packages=(
|
|
|
@@ -16,11 +17,23 @@ packages=(
|
|
|
charon-systemd strongswan-swanctl libstrongswan-standard-plugins
|
|
|
libcharon-extra-plugins libcharon-extauth-plugins
|
|
|
iputils-ping iputils-tracepath traceroute bind9-dnsutils mtr-tiny
|
|
|
+ ethtool tcpdump
|
|
|
)
|
|
|
installed() { [[ $(dpkg-query -W -f='${db:Status-Status}' "$1" 2>/dev/null || :) == installed ]]; }
|
|
|
-required=$(awk '$1=="toolchain" {sub(/^go/,"",$2); print $2}' "$src/go.mod")
|
|
|
-if [[ -z $required ]]; then required=$(awk '$1=="go" {print $2}' "$src/go.mod"); fi
|
|
|
-[[ $required =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?$ ]] || { echo 'Invalid Go version in go.mod' >&2; exit 1; }
|
|
|
+go_mod=""
|
|
|
+if [[ -f "$src/go.mod" ]]; then
|
|
|
+ go_mod="$src/go.mod"
|
|
|
+elif [[ -f /var/lib/debtik/update/go.mod ]]; then
|
|
|
+ go_mod=/var/lib/debtik/update/go.mod
|
|
|
+fi
|
|
|
+required=""
|
|
|
+if [[ -n $go_mod ]]; then
|
|
|
+ required=$(awk '$1=="toolchain" {sub(/^go/,"",$2); print $2}' "$go_mod" 2>/dev/null || :)
|
|
|
+ if [[ -z $required ]]; then required=$(awk '$1=="go" {print $2}' "$go_mod" 2>/dev/null || :); fi
|
|
|
+fi
|
|
|
+if [[ -z $required || ! $required =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]; then
|
|
|
+ required="1.26.10"
|
|
|
+fi
|
|
|
go_version_ok() {
|
|
|
local actual
|
|
|
actual=$(GOTOOLCHAIN=local "$1" version 2>/dev/null | awk '{sub(/^go/,"",$3);print $3}') || return 1
|
|
|
@@ -32,7 +45,7 @@ check_dependencies() {
|
|
|
if ! installed "$package"; then echo "Missing package: $package" >&2; missing=1; fi
|
|
|
done
|
|
|
if ! installed ifupdown && ! installed ifupdown2; then echo 'Missing ifupdown or ifupdown2' >&2; missing=1; fi
|
|
|
- for binary in ssh ip bridge brctl iptables ip6tables iptables-save ip6tables-save iptables-restore ip6tables-restore ipset conntrack wg wg-quick keepalived bird birdc dnsmasq dhclient pppd pon poff pppoe-server pptp pptpd xl2tpd swanctl ping tracepath traceroute dig mtr mstpd mstpctl systemctl systemd-run hostnamectl timedatectl pkill flock python3 modprobe; do
|
|
|
+ for binary in ssh ip bridge brctl iptables ip6tables iptables-save ip6tables-save iptables-restore ip6tables-restore ipset conntrack wg wg-quick keepalived bird birdc dnsmasq dhclient pppd pon poff pppoe-server pptp pptpd xl2tpd swanctl ping tracepath traceroute dig mtr mstpd mstpctl systemctl systemd-run hostnamectl timedatectl pkill flock python3 modprobe ethtool tcpdump; do
|
|
|
if ! command -v "$binary" >/dev/null; then echo "Missing command: $binary" >&2; missing=1; fi
|
|
|
done
|
|
|
go_cmd=$(command -v go || :)
|
|
|
@@ -60,18 +73,25 @@ if [[ ! -e /usr/sbin/policy-rc.d && ! -L /usr/sbin/policy-rc.d ]]; then
|
|
|
chmod 0755 /usr/sbin/policy-rc.d
|
|
|
policy_created=true
|
|
|
fi
|
|
|
-export DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=l
|
|
|
-apt-get update
|
|
|
+export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true NEEDRESTART_MODE=l
|
|
|
+if ! apt-get update; then
|
|
|
+ if check_dependencies >/dev/null 2>&1; then
|
|
|
+ echo "Notice: apt-get update failed, but all dependencies are already satisfied locally." >&2
|
|
|
+ else
|
|
|
+ echo "Error: apt-get update failed and required dependencies are missing." >&2
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
+fi
|
|
|
# Proxmox normally uses ifupdown2; retain that implementation.
|
|
|
if ! installed ifupdown && ! installed ifupdown2; then packages+=(ifupdown); fi
|
|
|
-apt-get install -y --no-install-recommends "${packages[@]}"
|
|
|
+apt-get install -y --no-install-recommends -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" "${packages[@]}"
|
|
|
work=$(mktemp -d)
|
|
|
if ! command -v mstpd >/dev/null || ! command -v mstpctl >/dev/null; then
|
|
|
candidate=$(apt-cache policy mstpd | awk '/Candidate:/ {print $2}')
|
|
|
if [[ -n $candidate && $candidate != '(none)' ]]; then
|
|
|
- apt-get install -y --no-install-recommends mstpd
|
|
|
+ apt-get install -y --no-install-recommends -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" mstpd
|
|
|
else
|
|
|
- apt-get install -y --no-install-recommends gcc make libc6-dev autoconf automake libtool pkg-config
|
|
|
+ apt-get install -y --no-install-recommends -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" gcc make libc6-dev autoconf automake libtool pkg-config
|
|
|
# Upstream release 0.2.0, pinned to a commit and verified archive digest.
|
|
|
mstpd_commit=8995e5d11ee89f2251734e34cea711bb5a5bb911
|
|
|
curl --fail --location --retry 3 "https://codeload.github.com/mstpd/mstpd/tar.gz/$mstpd_commit" -o "$work/mstpd.tar.gz"
|