76 lines
2.4 KiB
Bash
76 lines
2.4 KiB
Bash
#!/bin/bash
|
|
# postinst: truenas-proxmox v3.x install/upgrade script
|
|
# Installs the TrueNAS custom storage plugin and UI panel for Proxmox VE.
|
|
# No patches to PVE core files — only adds our own files and one <script> line.
|
|
set -e
|
|
|
|
INSTALL_DIR="/usr/share/truenas-proxmox"
|
|
PLUGIN_DST="/usr/share/perl5/PVE/Storage/Custom/TrueNAS.pm"
|
|
JS_DST="/usr/share/pve-manager/js/truenas-storage.js"
|
|
HELP_DST="/usr/share/pve-docs/truenas-storage.html"
|
|
TPL="/usr/share/pve-manager/index.html.tpl"
|
|
SCRIPT_TAG=' <script type="text/javascript" src="/pve2/js/truenas-storage.js?ver=[% version %]"></script>'
|
|
LOG_FILE="/var/log/truenas-proxmox-install.log"
|
|
|
|
log() {
|
|
echo "[truenas-proxmox] $*" | tee -a "$LOG_FILE"
|
|
}
|
|
|
|
install_plugin() {
|
|
log "Installing ${PLUGIN_DST}"
|
|
mkdir -p "$(dirname "$PLUGIN_DST")"
|
|
cp "${INSTALL_DIR}/TrueNAS.pm" "$PLUGIN_DST"
|
|
}
|
|
|
|
install_ui() {
|
|
log "Installing ${JS_DST}"
|
|
cp "${INSTALL_DIR}/truenas-storage.js" "$JS_DST"
|
|
|
|
log "Installing ${HELP_DST}"
|
|
cp "${INSTALL_DIR}/truenas-storage-help.html" "$HELP_DST"
|
|
|
|
if grep -qF 'truenas-storage.js' "$TPL" 2>/dev/null; then
|
|
log "index.html.tpl already has truenas-storage.js — skipping"
|
|
return 0
|
|
fi
|
|
|
|
log "Adding <script> tag to ${TPL}"
|
|
sed -i "/pvemanagerlib\.js/a\\${SCRIPT_TAG}" "$TPL"
|
|
}
|
|
|
|
restart_pve_services() {
|
|
# Bare statements (not `cmd && log ...`) so `set -e` actually aborts on
|
|
# failure instead of silently skipping past it — see tests/test-restart-services.sh.
|
|
log "Restarting Proxmox VE services ..."
|
|
pvedaemon restart
|
|
log "pvedaemon restarted"
|
|
pveproxy restart
|
|
log "pveproxy restarted"
|
|
pvestatd restart
|
|
log "pvestatd restarted"
|
|
systemctl restart pve-ha-lrm pve-ha-crm
|
|
log "pve-ha-lrm, pve-ha-crm restarted"
|
|
log "Done. Refresh your Proxmox browser tab."
|
|
}
|
|
|
|
# Guard so tests can `source` this file (to exercise its functions) without
|
|
# running dpkg's maintainer-script logic below.
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
case "$1" in
|
|
configure)
|
|
log "Configuring truenas-proxmox (previous version: ${2:-none})"
|
|
install_plugin
|
|
install_ui
|
|
restart_pve_services
|
|
;;
|
|
abort-upgrade|abort-remove|abort-deconfigure)
|
|
;;
|
|
*)
|
|
echo "$0: called with unknown argument '$1'" >&2
|
|
exit 0
|
|
;;
|
|
esac
|
|
|
|
exit 0
|
|
fi
|