hplip/hp-plugin.in
2023-08-03 16:56:06 +02:00

47 lines
1.3 KiB
Bash

#!/usr/bin/bash
# get version from base hplip rpm - it is always in the second column
VER=$(@bindir@/rpm -q hplip | @bindir@/awk -F '-' '{print $2}')
if test "x$VER" = "x"
then
@bindir@/echo "Version was not acquired - exiting..."
exit 1
fi
# link to the plugin
PLUGIN_SOURCE="https://www.openprinting.org/download/printdriver/auxfiles/HP/plugins/hplip-${VER}-plugin.run"
# plugin name
PLUGIN_FILE="hplip-${VER}-plugin.run"
# create a hidden hplip dir to store a file indicating the plugin version after successful install
# the directory can be used by other hplip tools, so we don't have to remove it if the failure happens
if [ ! -d ~/.hplip ]
then
@bindir@/mkdir ~/.hplip || (@bindir@/echo "Cannot create the ~/.hplip dir, exiting" && exit 1)
fi
@bindir@/curl --create-dir -O --output-dir ~/.hplip ${PLUGIN_SOURCE}
if [ ! -f ~/.hplip/${PLUGIN_FILE} ]
then
@bindir@/echo "The downloaded file does not exist - error during downloading, exiting..."
exit 1
fi
@bindir@/bash ~/.hplip/${PLUGIN_FILE}
if [ $? -ne 0 ]
then
@bindir@/echo "Plugin installation failed, exiting..."
@bindir@/rm -f ~/.hplip/${PLUGIN_FILE} &> /dev/null
exit 1
fi
@bindir@/rm -f ~/.hplip/${PLUGIN_FILE} &> /dev/null
@bindir@/rm -f ~/.hplip/plugin-installed-* &> /dev/null
@bindir@/touch ~/.hplip/plugin-installed-$VER
exit 0