#! /bin/bash # Script for downloading and installing of RMIR # # Author: Bengt Martensson, barf@bengt-martensson.de # License: public domain PROJECT=rmir COMMANDS="rmir rmdu rmpb remotemaster irptransmogrifier" # Where the files are installed, modify if desired. # Can be overridden from the command line. if [ $(id -u) -eq 0 ] ; then PREFIX=/usr/local else PREFIX=${HOME} fi # Where the desktop files go if [ $(id -u) -eq 0 ] ; then DESKTOPDIR=${PREFIX}/share/applications else DESKTOPDIR=${PREFIX}/.local/share/applications fi # URL for downloading current version. URL=https://sourceforge.net/projects/controlremote/files/latest/download INDEX_URL=https://sourceforge.net/projects/controlremote/files/RMIRDevelopment/ # Temporary file to download to DOWNLOAD=${TMPDIR:-/tmp}/${PROJECT}$$.zip INDEX_DOWNLOAD=${TMPDIR:-/tmp}/${PROJECT}_index$$ mkdesktop() { upper="$(echo $1 | tr '[a-z]' '[A-Z]')" # Construct paths to the new files and to the jar file desktop_file=${RMHOME}/${upper}.desktop # Create the .desktop files. cat > "$desktop_file" << EOF [Desktop Entry] Comment=$2 Categories=AudioVideo Terminal=false Name=${upper} Exec="${LINKDIR}/$1" Type=Application Icon=${RMHOME}/${upper}.ico StartupNotify=true Version=1.0 EOF ln -sf "$desktop_file" "${DESKTOPDIR}" } assert_dialout() { # Test if the dialout group exists, exit with message if not if ! grep -q dialout /etc/group ; then echo "There is no group named \"dialout\" on your system." \ "Access to serial devices cannot be guaranteed." return fi # Dialout group exists, test if user is a member, exit if so if id -Gn | grep -q dialout ; then return fi # User is not a member, test if user is root, exit if so if [ "$(id -u)" -eq 0 ]; then return fi # User is not root, so ask if user wishes to be added if ! modify_user ; then echo "You will need to run the command \"sudo usermod -aG dialout $USER\" " \ "before \"$USER\" can use a USB serial interface with RMIR. " \ "Then you need to log out and log in again for the change to take effect." fi } modify_user() { # If no terminal access, bail out if ! tty --quiet ; then return 1 fi echo "To use a USB serial interface with RMIR, \"$USER\" needs to be a member of the " \ "dialout group, which is currently not so. This script can add \"$USER\" " \ "to that group using sudo." read -p "Add \"$USER\" to group \"dialout\" (y/n)? " ans if [ "${ans}" = "y" ] ; then sudo usermod -aG dialout $USER || return 1 echo "You will need to log out and log in again for the change to take effect." return 0 else return 1 fi } mklink() { if [ "$(readlink -f -- "$1")" != "${WRAPPER}" ] ; then ln --symbolic --force "$(realpath --relative-to="${LINKDIR}" "${WRAPPER}")" "${LINKDIR}/$1" echo "Command $1 created." fi } mkwrapper() { cat > "${WRAPPER}" <> ${WRAPPER} echo "SCALE_ARG=\"-scaling ${SCALE_FACTOR}\"" >> ${WRAPPER} echo "" >> ${WRAPPER} fi if [ -n "${WRITEABLE}" ] ; then cat >> ${WRAPPER} <> "${WRAPPER}" < /dev/null ; then echo "The command \"wget\" is missing or broken." echo "Please install it, for example with apt-get or dnf." exit 1 fi } # Command to invoke the Java JVM. Can be an absolute or relative file name, # or a command sought in the PATH. if [ -z "$JAVA" ] ; then JAVA=java fi # Where to install the files if [ -z "$RMHOME" ] ; then RMHOME=${PREFIX}/share/${PROJECT} fi # Where the executable links go. if [ -z "$LINKDIR" ] ; then LINKDIR=${PREFIX}/bin fi usage() { echo "Usage: $0 [OPTIONS] [zip-file]" echo "" echo "Installs RMIR, RMDU, and RMPB in the system, compatible with the" echo "Freedesktop standard (https://www.freedesktop.org)." echo "If a zip-file is not given as argument, it is downloaded from" echo "${URL}." echo "" echo "Options:" echo " -d, --development Try to download from the development folder instead of \"latest\"." echo " -?, -h, --help Display this help and exit." echo " -j, --java command-for-java Command to invoke Java, default \"${JAVA}\"." echo " -s, --scale scale-factor scale factor for the GUI, default 1. Not supported by all JVMs." echo " -H, --rmhome RM-install-dir Directory in which to install, default ${RMHOME}." echo " -l, --link directory-for-links Directory in which to create start links, default ${LINKDIR}." echo " -u, --uninstall Undo previous installation." echo " -w, --writeable-install Write config and logs in installation directory." echo "" echo "This script should be run with the privileges necessary for writing" echo "to the locations selected." } while [ -n "$1" ] ; do case $1 in -d | --development ) DEVELOPMENT="y" ;; -\? | -h | --help ) usage exit 0 ;; -j | --java ) shift JAVA="$1" ;; -s | --scale ) shift SCALE_FACTOR="$1" ;; -l | --linkdir ) shift LINKDIR="$1" ;; -H | --home | --rmhome ) shift RMHOME=$(realpath --canonicalize-missing "$1") ;; -u | --uninstall ) UNINSTALL="y" ;; -w | --writeable-install ) WRITEABLE="y" ;; * ) ZIP="$1" ;; esac shift done # Generated wrapper WRAPPER=${RMHOME}/${PROJECT}.sh if [ -n "${UNINSTALL}" ] ; then read -p "You sure you want to deinstall RMIR in directory ${RMHOME} (y/n)? " ans if [ "${ans}" != "y" ] ; then echo "Bailing out, nothing deleted." exit 0 fi rm -rf "${RMHOME}" for c in ${COMMANDS}; do upper="$(echo $c | tr '[a-z]' '[A-Z]')" rm -f "${DESKTOPDIR}/$upper.desktop" rm -f "${LINKDIR}/$c" done rm -f ${LINKDIR}/remotemaster echo "RMIR and friends successfully uninstalled." read -p "Want to delete the error file and your personal preferences (y/n)? " ans if [ "${ans}" = "y" ] ; then XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-${HOME}/.config} XDG_CACHE_HOME=${XDG_CACHE_HOME:-${HOME}/.cache} CACHE_HOME=${XDG_CACHE_HOME}/${PROJECT} CONFIG_HOME=${XDG_CONFIG_HOME}/${PROJECT} CONFIG=${CONFIG_HOME}/properties rm -f "${CONFIG}" "${CACHE_HOME}/rmaster.err" else echo "Personal configuration files have not been deleted." fi exit 0 fi if [ -n "${DEVELOPMENT}" ] ; then if [ -n "${ZIP}" ] ; then echo "Must not use --development together with file name" exit 1 fi # Download the index file and parse it. # This is not a well-formed XML file (it is HTML, with "junk" within