35 lines
1.4 KiB
Bash
35 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
[[ ${EUID} -eq 0 ]] || { echo 'install-asterisk-native.sh must run as root' >&2; exit 1; }
|
|
START=false
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--start) START=true ;;
|
|
*) echo "unknown option: $arg" >&2; exit 2 ;;
|
|
esac
|
|
done
|
|
|
|
PACKAGE_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
|
|
cd -- "$PACKAGE_DIR"
|
|
. /etc/os-release
|
|
[[ ${ID:-} == debian && ${VERSION_ID:-} == 13 ]] || { echo 'Debian 13 is required' >&2; exit 1; }
|
|
[[ $(uname -m) == x86_64 ]] || { echo 'amd64 host is required' >&2; exit 1; }
|
|
STAGE=asterisk-22.10.1-native-stage.tar
|
|
sha256sum -c "$STAGE.sha256"
|
|
[[ -f asterisk.service ]] || { echo 'asterisk.service is missing' >&2; exit 1; }
|
|
getent group asterisk >/dev/null || groupadd --system asterisk
|
|
id -u asterisk >/dev/null 2>&1 || useradd --system --home-dir /var/lib/asterisk --shell /usr/sbin/nologin --gid asterisk asterisk
|
|
# Keep management-owned /etc/asterisk configuration intact.
|
|
tar --exclude='etc/asterisk/*' -xpf "$STAGE" -C /
|
|
ldconfig
|
|
install -d -o asterisk -g asterisk -m 0750 /var/lib/asterisk /var/log/asterisk /var/spool/asterisk /var/run/asterisk
|
|
install -o root -g root -m 0644 asterisk.service /etc/systemd/system/asterisk.service
|
|
systemctl daemon-reload
|
|
systemctl enable asterisk.service
|
|
if [[ "$START" == true ]]; then
|
|
systemctl restart asterisk.service
|
|
fi
|
|
/usr/sbin/asterisk -V
|
|
printf 'installed asterisk=22.10.1 start=%s config_preserved=true\n' "$START"
|