Skip to content

Commit

Permalink
Robustify install.sh a bit (#32)
Browse files Browse the repository at this point in the history
* install: Don't hardcode sudo

It's possible that sudo isn't needed or one wants to use doas

* install: Don't ignore errors

Currently the script basically can't fail

* install: Don't assume /usr/local/bin exists

* install: Allow ldconfig to fail

ldconfig isn't possible when installing as regular user which
is e.g. required in packaging environments.
  • Loading branch information
agx authored Sep 16, 2023
1 parent 1e47049 commit 05fab8d
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions install.sh.in
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
#!/bin/bash

set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

ARG1=${1:-install}
SUDO=${SUDO:-sudo}

if [ "$ARG1" == "install" ]; then
sudo cp "$SCRIPT_DIR/varnamcli" "@INSTALL_PREFIX@/bin/varnamcli"
"${SUDO}" mkdir -p "/usr/local/bin/"
"${SUDO}" cp "$SCRIPT_DIR/varnamcli" "@INSTALL_PREFIX@/bin/varnamcli"

sudo mkdir -p "@INSTALL_PREFIX@/lib/pkgconfig"
sudo cp "$SCRIPT_DIR/@LIB_NAME@" "@INSTALL_PREFIX@/lib/@LIB_NAME@.@VERSION@"
sudo ln -s "@INSTALL_PREFIX@/lib/@LIB_NAME@.@VERSION@" "@INSTALL_PREFIX@/lib/@LIB_NAME@"
sudo cp "$SCRIPT_DIR/govarnam.pc" "@INSTALL_PREFIX@/lib/pkgconfig/"
"${SUDO}" mkdir -p "@INSTALL_PREFIX@/lib/pkgconfig"
"${SUDO}" cp "$SCRIPT_DIR/@LIB_NAME@" "@INSTALL_PREFIX@/lib/@LIB_NAME@.@VERSION@"
"${SUDO}" ln -s "@INSTALL_PREFIX@/lib/@LIB_NAME@.@VERSION@" "@INSTALL_PREFIX@/lib/@LIB_NAME@"
"${SUDO}" cp "$SCRIPT_DIR/govarnam.pc" "@INSTALL_PREFIX@/lib/pkgconfig/"

sudo mkdir -p "@INSTALL_PREFIX@/include/libgovarnam"
sudo cp "$SCRIPT_DIR/"*.h "@INSTALL_PREFIX@/include/libgovarnam/"
sudo ldconfig
"${SUDO}" mkdir -p "@INSTALL_PREFIX@/include/libgovarnam"
"${SUDO}" cp "$SCRIPT_DIR/"*.h "@INSTALL_PREFIX@/include/libgovarnam/"
"${SUDO}" ldconfig || true

sudo mkdir -p "@INSTALL_PREFIX@/share/varnam/schemes"
"${SUDO}" mkdir -p "@INSTALL_PREFIX@/share/varnam/schemes"

msg="Installation finished"
echo "$msg"

notify-send "$msg" &> /dev/null || true
elif [ "$ARG1" == "uninstall" ]; then
sudo rm "@INSTALL_PREFIX@/bin/varnamcli" "@INSTALL_PREFIX@/lib/@LIB_NAME@.@VERSION@" "@INSTALL_PREFIX@/lib/@LIB_NAME@" "@INSTALL_PREFIX@/lib/pkgconfig/govarnam.pc"
sudo rm "@INSTALL_PREFIX@/include/libgovarnam/"*
sudo rmdir "@INSTALL_PREFIX@/include/libgovarnam"
sudo rm "@INSTALL_PREFIX@/share/varnam/schemes/"*
sudo rmdir "@INSTALL_PREFIX@/share/varnam/schemes/"
"${SUDO}" rm "@INSTALL_PREFIX@/bin/varnamcli" "@INSTALL_PREFIX@/lib/@LIB_NAME@.@VERSION@" "@INSTALL_PREFIX@/lib/@LIB_NAME@" "@INSTALL_PREFIX@/lib/pkgconfig/govarnam.pc"
"${SUDO}" rm "@INSTALL_PREFIX@/include/libgovarnam/"*
"${SUDO}" rmdir "@INSTALL_PREFIX@/include/libgovarnam"
"${SUDO}" rm "@INSTALL_PREFIX@/share/varnam/schemes/"*
"${SUDO}" rmdir "@INSTALL_PREFIX@/share/varnam/schemes/"

msg="Uninstallation finished"
echo $msg
Expand Down

0 comments on commit 05fab8d

Please sign in to comment.