installer and packaging

This commit is contained in:
2026-06-28 09:57:06 -05:00
parent b860b031bb
commit df8a59d03b
6 changed files with 396 additions and 0 deletions
Executable
+146
View File
@@ -0,0 +1,146 @@
#!/usr/bin/env sh
set -eu
usage() {
cat <<EOF
Usage: ./install.sh [install|uninstall] [options]
Commands:
install Build and install wayviewer
uninstall Remove files installed by this script
Options:
--prefix PATH Install prefix, default: \$HOME/.local
--system Install to /usr/local
--debug Build Debug instead of Release
--build-dir PATH Build directory, default: build or build-debug
--destdir PATH Stage install or uninstall under DESTDIR
--help Show this help
EOF
}
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
action=install
build_type=Release
prefix=${WAYVIEWER_PREFIX:-"$HOME/.local"}
build_dir=
destdir=
while [ "$#" -gt 0 ]; do
case "$1" in
install)
action=install
;;
uninstall|remove)
action=uninstall
;;
--prefix)
shift
[ "$#" -gt 0 ] || { echo "install.sh: missing value for --prefix" >&2; exit 2; }
prefix=$1
;;
--system)
prefix=/usr/local
;;
--debug)
build_type=Debug
;;
--build-dir)
shift
[ "$#" -gt 0 ] || { echo "install.sh: missing value for --build-dir" >&2; exit 2; }
build_dir=$1
;;
--destdir)
shift
[ "$#" -gt 0 ] || { echo "install.sh: missing value for --destdir" >&2; exit 2; }
destdir=$1
;;
--help|-h)
usage
exit 0
;;
*)
echo "install.sh: unknown option: $1" >&2
usage >&2
exit 2
;;
esac
shift
done
if [ -z "$build_dir" ]; then
if [ "$build_type" = Debug ]; then
build_dir=$script_dir/build-debug
else
build_dir=$script_dir/build
fi
fi
run_install() {
command -v cmake >/dev/null 2>&1 || { echo "install.sh: cmake is required" >&2; exit 1; }
command -v pkg-config >/dev/null 2>&1 || { echo "install.sh: pkg-config is required" >&2; exit 1; }
cmake -S "$script_dir" -B "$build_dir" \
-DCMAKE_BUILD_TYPE="$build_type" \
-DCMAKE_INSTALL_PREFIX="$prefix" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake --build "$build_dir"
if [ -n "$destdir" ]; then
DESTDIR=$destdir cmake --install "$build_dir"
elif mkdir -p "$prefix" 2>/dev/null && [ -w "$prefix" ]; then
cmake --install "$build_dir"
elif command -v sudo >/dev/null 2>&1; then
sudo cmake --install "$build_dir"
else
echo "install.sh: $prefix is not writable and sudo was not found" >&2
exit 1
fi
if command -v update-desktop-database >/dev/null 2>&1; then
applications_dir=${destdir}${prefix}/share/applications
if [ -d "$applications_dir" ]; then
update-desktop-database "$applications_dir" >/dev/null 2>&1 || true
fi
fi
}
run_uninstall() {
manifest=$build_dir/install_manifest.txt
if [ ! -f "$manifest" ]; then
echo "install.sh: no install manifest found at $manifest" >&2
echo "install.sh: run install first or pass the matching --build-dir" >&2
exit 1
fi
while IFS= read -r path || [ -n "$path" ]; do
target=${destdir}${path}
if [ -e "$target" ] || [ -L "$target" ]; then
if [ -w "$(dirname "$target")" ]; then
rm -f "$target"
elif command -v sudo >/dev/null 2>&1; then
sudo rm -f "$target"
else
echo "install.sh: cannot remove $target and sudo was not found" >&2
exit 1
fi
echo "Removed $target"
fi
done < "$manifest"
if command -v update-desktop-database >/dev/null 2>&1; then
applications_dir=${destdir}${prefix}/share/applications
if [ -d "$applications_dir" ]; then
update-desktop-database "$applications_dir" >/dev/null 2>&1 || true
fi
fi
}
case "$action" in
install)
run_install
;;
uninstall)
run_uninstall
;;
esac