install: system install with the polkit policy, uninstall, and a pacman package

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
astar76 2026-11-25 02:26:26 -06:00
commit 9bdb4a1adf
5 changed files with 164 additions and 25 deletions

3
.gitignore vendored
View file

@ -1,2 +1,5 @@
target/
*.swp
packaging/arch/src/
packaging/arch/pkg/
*.pkg.tar.zst

View file

@ -14,17 +14,27 @@ Needs a recent stable Rust toolchain.
## Install
Pick one. Each builds in release mode, and running it again updates Tunal.
**Arch package** (binary, polkit policy, desktop entry and icons under `/usr`; remove with `sudo pacman -R tunal`):
```
cd packaging/arch && makepkg -si
```
**Any distribution, whole system** (the same files; asks for the `sudo` password once; add `--uninstall` to remove):
```
bash scripts/install.sh --system
```
**Current user only** (under `~/.local`, or `PREFIX=/some/dir`; no password; no polkit policy, so root operations show the generic password prompt; add `--uninstall` to remove):
```
bash scripts/install.sh
```
Builds in release mode and installs the `tunal` binary, desktop entry and icons under `~/.local` (set `PREFIX=/some/dir` to change that). Folders then open with Tunal from application launchers.
Root operations go through `pkexec`, which only accepts an installed binary. Put `tunal` at `/usr/bin/tunal` and install the polkit policy once (the script prints the line):
```
sudo install -Dm644 assets/polkit/org.tunal.Tunal.elevated-helper.policy /usr/share/polkit-1/actions/org.tunal.Tunal.elevated-helper.policy
```
Remove one kind before installing another: the package won't replace files from `--system`, and a copy in `~/.local/bin` can start instead of the system one.
## Shortcuts

View file

@ -303,5 +303,10 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done,
- Verified: clippy, fmt, release build, seek / sidebar / icon browser / new launcher under Xvfb, pack + unpack of each format with the same commands by hand.
- Not done: no test run (user: save credits); file picker not opened live; encrypted archives only report that they need a password.
## System install and pacman package (user request)
- Done: `scripts/install.sh --system` (under /usr with the polkit policy, one sudo prompt), `--uninstall`, `--no-build`, `DESTDIR`; `packaging/arch/PKGBUILD` (builds this checkout, stages with the same script, version = workspace version + commit count); README install section. The user confirmed the polkit prompt works from /usr/bin.
- Verified: package built and listed, its binary drew a PNG; user install + uninstall in a scratch PREFIX; --system with a stand-in sudo.
- Not done: the package and --system not run against the real /usr.
## Later
-

39
packaging/arch/PKGBUILD Normal file
View file

@ -0,0 +1,39 @@
# Builds the package from this checkout: cd packaging/arch && makepkg -si
_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
pkgname=tunal
# The workspace version plus the commit, so every update installs as an upgrade.
pkgver="$(sed -n 's/^version = "\(.*\)"/\1/p' "$_root/Cargo.toml" | head -n1).r$(git -C "$_root" rev-list --count HEAD).g$(git -C "$_root" rev-parse --short=7 HEAD)"
pkgrel=1
pkgdesc="File manager with Material You styling, music tags, devices and SFTP"
arch=(x86_64 aarch64)
url="https://archlinux.tail7c4f5e.ts.net/git/astar76/Tunal"
license=(GPL-3.0-or-later Apache-2.0)
depends=(
alsa-lib fontconfig glibc hicolor-icon-theme libgcc libglvnd libx11 libxcursor libxi
libxkbcommon libxkbcommon-x11 wayland xdg-utils
)
makedepends=(cargo git)
optdepends=(
"polkit: administrator file operations"
"xdg-desktop-portal: accent colour, dark mode and file pickers"
"ffmpeg: video thumbnails"
"7zip: 7z and most other archives"
"libarchive: tar archives"
"zip: zip archives"
"usbmuxd: iOS devices"
)
options=(!debug !lto)
build() {
cd "$_root"
# The checkout's own build cache, with its flags, so an update only compiles what changed.
unset RUSTFLAGS CFLAGS CXXFLAGS LDFLAGS CARGO_TARGET_DIR
cargo build --release --locked -p tunal
}
package() {
cd "$_root"
DESTDIR="$pkgdir" bash scripts/install.sh --system --no-build
install -Dm644 -t "$pkgdir/usr/share/licenses/$pkgname" assets/fonts/LICENSE
}

View file

@ -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