38 lines
1.5 KiB
Bash
38 lines
1.5 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
|
|
NONPROD=0
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--start) START=true ;;
|
|
--nonprod) NONPROD=1 ;;
|
|
*) echo "unknown option: $arg" >&2; exit 2 ;;
|
|
esac
|
|
done
|
|
|
|
PACKAGE_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
|
|
cd -- "$PACKAGE_DIR"
|
|
. /etc/os-release
|
|
[[ -f native-platform.sh && -f build-platform ]] || { echo 'native build platform metadata is missing' >&2; exit 1; }
|
|
source ./native-platform.sh
|
|
require_native_platform "$ID" "$VERSION_ID" "$(uname -m)" "$(<build-platform)" "$NONPROD"
|
|
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"
|