install: system install with the polkit policy, uninstall, and a pacman package
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
parent
7b13c1658e
commit
9bdb4a1adf
1 changed files with 164 additions and 25 deletions
|
|
@ -1,30 +1,112 @@
|
|||
#!/usr/bin/env bash
|
||||
# Builds Tunal in release mode and installs it for the current user.
|
||||
# bash scripts/install.sh installs under ~/.local
|
||||
# PREFIX=/some/dir bash scripts/install.sh
|
||||
# The polkit policy needs root, so its install line is printed, not run.
|
||||
# Builds Tunal in release mode and installs it.
|
||||
# bash scripts/install.sh for the current user, under ~/.local
|
||||
# bash scripts/install.sh --system under /usr with the polkit policy (asks sudo once)
|
||||
# bash scripts/install.sh [--system] --uninstall removes what that install put there
|
||||
# PREFIX=/some/dir bash scripts/install.sh another place for the user install
|
||||
# --no-build installs the release binary that is already built; DESTDIR stages the files for
|
||||
# packagers (packaging/arch/PKGBUILD uses both).
|
||||
set -euo pipefail
|
||||
|
||||
usage() {
|
||||
sed -n '2,8s/^# \?//p' "${BASH_SOURCE[0]}"
|
||||
}
|
||||
|
||||
system=false
|
||||
uninstall=false
|
||||
build=true
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--system) system=true ;;
|
||||
--uninstall) uninstall=true ;;
|
||||
--no-build) build=false ;;
|
||||
-h | --help) usage; exit 0 ;;
|
||||
*) echo "Unknown option: $arg" >&2; usage >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
prefix="${PREFIX:-$HOME/.local}"
|
||||
|
||||
cd "$root"
|
||||
cargo build --release -p tunal
|
||||
dest="${DESTDIR:-}"
|
||||
target="${CARGO_TARGET_DIR:-target}"
|
||||
if $system; then
|
||||
# The policy names /usr/bin/tunal, so the system install has one place.
|
||||
prefix=/usr
|
||||
else
|
||||
prefix="${PREFIX:-$HOME/.local}"
|
||||
fi
|
||||
policy=org.tunal.Tunal.elevated-helper.policy
|
||||
|
||||
install -Dm755 target/release/tunal "$prefix/bin/tunal"
|
||||
install -Dm644 assets/tunal.desktop "$prefix/share/applications/tunal.desktop"
|
||||
install -Dm644 assets/tunal.svg "$prefix/share/icons/hicolor/scalable/apps/tunal.svg"
|
||||
install -Dm644 assets/tunal.png "$prefix/share/icons/hicolor/256x256/apps/tunal.png"
|
||||
# mode, file in the repository (or the build), place it goes
|
||||
files=(
|
||||
755 "$target/release/tunal" "$prefix/bin/tunal"
|
||||
644 assets/tunal.desktop "$prefix/share/applications/tunal.desktop"
|
||||
644 assets/tunal.svg "$prefix/share/icons/hicolor/scalable/apps/tunal.svg"
|
||||
644 assets/tunal.png "$prefix/share/icons/hicolor/256x256/apps/tunal.png"
|
||||
)
|
||||
if $system; then
|
||||
files+=(644 "assets/polkit/$policy" "/usr/share/polkit-1/actions/$policy")
|
||||
fi
|
||||
|
||||
command -v update-desktop-database >/dev/null && update-desktop-database "$prefix/share/applications" || true
|
||||
command -v gtk-update-icon-cache >/dev/null && gtk-update-icon-cache -qtf "$prefix/share/icons/hicolor" || true
|
||||
# Only a real system install needs root; a staged one belongs to whoever stages it.
|
||||
as_root=()
|
||||
if $system && [[ -z "$dest" ]]; then
|
||||
if command -v pacman >/dev/null && owner="$(pacman -Qoq /usr/bin/tunal 2>/dev/null)"; then
|
||||
echo "/usr/bin/tunal belongs to the pacman package '$owner'; use pacman for it." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
command -v sudo >/dev/null || { echo "The system install needs sudo (or run it as root)." >&2; exit 1; }
|
||||
as_root=(sudo)
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! $uninstall; then
|
||||
if $build; then
|
||||
cargo build --release --locked -p tunal
|
||||
fi
|
||||
[[ -x "$target/release/tunal" ]] || { echo "No release binary; run without --no-build." >&2; exit 1; }
|
||||
fi
|
||||
|
||||
if [[ ${#as_root[@]} -gt 0 ]]; then
|
||||
echo "Root rights are needed for $prefix:"
|
||||
sudo -v
|
||||
fi
|
||||
|
||||
for ((i = 0; i < ${#files[@]}; i += 3)); do
|
||||
to="$dest${files[i + 2]}"
|
||||
if $uninstall; then
|
||||
"${as_root[@]}" rm -f -- "$to"
|
||||
else
|
||||
"${as_root[@]}" install -Dm"${files[i]}" -- "${files[i + 1]}" "$to"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -z "$dest" ]]; then
|
||||
if command -v update-desktop-database >/dev/null; then
|
||||
"${as_root[@]}" update-desktop-database "$prefix/share/applications" || true
|
||||
fi
|
||||
if command -v gtk-update-icon-cache >/dev/null; then
|
||||
"${as_root[@]}" gtk-update-icon-cache -qtf "$prefix/share/icons/hicolor" || true
|
||||
fi
|
||||
fi
|
||||
|
||||
if $uninstall; then
|
||||
echo "Removed Tunal from $prefix"
|
||||
exit 0
|
||||
fi
|
||||
[[ -z "$dest" ]] || exit 0
|
||||
|
||||
echo "Installed Tunal under $prefix"
|
||||
case ":$PATH:" in
|
||||
*":$prefix/bin:"*) ;;
|
||||
*) echo "Note: $prefix/bin is not in PATH." ;;
|
||||
esac
|
||||
echo
|
||||
echo "Root operations (Tunal asks polkit for the password) need the policy file, which"
|
||||
echo "belongs to /usr/bin/tunal. Install the binary there too, then run:"
|
||||
echo " sudo install -Dm644 $root/assets/polkit/org.tunal.Tunal.elevated-helper.policy /usr/share/polkit-1/actions/org.tunal.Tunal.elevated-helper.policy"
|
||||
if $system; then
|
||||
if [[ -e "$HOME/.local/bin/tunal" ]]; then
|
||||
echo "An older copy in ~/.local may start instead. To remove it:"
|
||||
echo " bash scripts/install.sh --uninstall"
|
||||
fi
|
||||
else
|
||||
case ":$PATH:" in
|
||||
*":$prefix/bin:"*) ;;
|
||||
*) echo "Note: $prefix/bin is not in PATH." ;;
|
||||
esac
|
||||
echo "For the full administrator password prompt, install with --system instead."
|
||||
fi
|
||||
|
|
|
|||
Loading…
Reference in a new issue