#!/bin/sh
# Puts a Netbine update the app downloaded and verified in place, and gives the program back
# the network rights it needs for the tunnel. The app runs this through pkexec, so the desktop
# asks for the administrator password first.
#   netbine-update <folder with the new netbine>
set -eu
src="${1:?usage: netbine-update <folder>}"
dir="$(dirname "$(readlink -f "$0")")"
[ -f "$src/netbine" ] || { echo "no netbine in $src" >&2; exit 1; }
install -m 0755 "$src/netbine" "$dir/netbine.new"
mv -f "$dir/netbine.new" "$dir/netbine"
if [ -f "$src/netbine-update" ]; then
    install -m 0755 "$src/netbine-update" "$dir/netbine-update.new"
    mv -f "$dir/netbine-update.new" "$dir/netbine-update"
fi
setcap cap_net_admin,cap_net_raw+ep "$dir/netbine"
