forked from sbs20/scanservjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Automate HPLIP driver and plugin installation
* Removes HPLIP docker stage in favor of installation at run time based on ENV (HP_AIO) * Automates downloading and installing matching HPLIP binary plugin based on libsane-hpaio installed version using ENV (HP_PLUGIN) sbs20#701 sbs20#724
- Loading branch information
Showing
6 changed files
with
118 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,4 +41,6 @@ fi | |
unset IFS | ||
set +f | ||
|
||
/scripts/hpaio.sh || true | ||
|
||
node ./server/server.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
HP_AIO="${HP_AIO:=false}" | ||
HP_PLUGIN="${HP_PLUGIN:=false}" | ||
|
||
if [ "$HP_AIO" = "true" ] || [ "$HP_PLUGIN" != "false" ]; | ||
then | ||
if [ $(dpkg-query -W -f='${Status}' libsane-hpaio 2>/dev/null | grep -c "ok installed") -eq 0 ]; | ||
then | ||
|
||
if [ "$HP_AIO" = "true" ]; | ||
then | ||
echo "HP_AIO is true and libsane-hpaio is not installed. Installing now." | ||
else | ||
echo "HP_PLUGIN is not false and libsane-hpaio is not installed. Installing now." | ||
fi | ||
|
||
apt-get -qq update > /dev/null \ | ||
&& apt-get install -yq libsane-hpaio > /dev/null \ | ||
&& apt-get -q clean > /dev/null \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
echo "libsane-hpaio installed!" | ||
else | ||
echo "libsane-hpaio is already installed" | ||
fi | ||
fi | ||
|
||
# only install plugin if user specifies (assuming coming from docker) | ||
if [ "$HP_PLUGIN" != "false" ]; | ||
then | ||
/scripts/hplip.sh || true | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
# if coming from docker user needs to set HP_PLUGIN to true | ||
# otherwise if running manually (local install) assume if user tries to run script it should try to install plugin (duh) | ||
HP_PLUGIN="${HP_PLUGIN:=true}" | ||
if [ "$PLUGIN" != "false" ]; then | ||
|
||
# if variable is true then try to determine plugin version automatically | ||
if [ "$HP_PLUGIN" = "true" ]; then | ||
|
||
echo "Trying to determine HPLIP plugin version from 'hp-plugin' command..." | ||
set +e | ||
# determine installed HPLIP version | ||
RE="HP Linux Imaging and Printing System \(ver\. (.+?)\)" | ||
#cmd_output=$(hp-plugin --help 2>&1)$? | ||
cmd_output=$(hp-plugin --help 2>&1) | ||
cmd_exit=$? | ||
set -e | ||
if [ "$cmd_exit" != "0" ]; | ||
then | ||
echo "'hp-plugin' command does not seem to be installed! Cannot determine plugin version automatically so will skip plugin installation." | ||
echo "'hp-plugin' command output: $cmd_output" | ||
exit 1 | ||
fi | ||
#https://stackoverflow.com/a/2778096 | ||
RAW_VERSION="$(echo "$cmd_output" | sed -rn "s/$RE/\1/p")" | ||
# Remove ansi coloring so its just a raw string | ||
#https://stackoverflow.com/a/51141872 | ||
HPLIP_VERSION=$(echo "$RAW_VERSION" | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g') | ||
printf 'HPLIP Version: %s\n' "$HPLIP_VERSION" | ||
|
||
# check if plugin is already installed | ||
# files installed to these locations https://wiki.gentoo.org/wiki/HPLIP#Binary_plugins | ||
if [ -d /usr/share/hplip/data/firmware ]; then | ||
printf 'A plugin is already installed. To force (re)install specify version in ENV like HP_PLUGIN=%s\n' "$HPLIP_VERSION" | ||
else | ||
INSTALL_PLUGIN_VERSION=$HPLIP_VERSION | ||
fi | ||
else | ||
INSTALL_PLUGIN_VERSION=$HPLIP_VERSION | ||
fi | ||
else | ||
echo "To install HPLIP plugin the env HP_PLUGIN must be either 'true' or specify a version" | ||
exit 1 | ||
fi | ||
|
||
if [ ! -z "$INSTALL_PLUGIN_VERSION" ]; then | ||
printf 'Attempting to install HPLIP plugin version %s\n' "$INSTALL_PLUGIN_VERSION" | ||
PLUGIN_FILE="/tmp/hplip-$INSTALL_PLUGIN_VERSION-plugin.run" | ||
|
||
if [ ! -f "$PLUGIN_FILE" ]; then | ||
echo 'Plugin does not already existing, downloading...' | ||
wget --backups 0 -q -P /tmp "https://developers.hp.com/sites/default/files/hplip-$INSTALL_PLUGIN_VERSION-plugin.run" || true | ||
fi | ||
echo "Making plugin runnable..." | ||
chmod +x "$PLUGIN_FILE" | ||
echo "Starting plugin install..." | ||
# has to run as root in order to prevent erroneous invisible password prompt after license accept | ||
su root -c "yes y | $PLUGIN_FILE --noprogress --accept --nox11 -- -i" | ||
echo "HPLIP plugin installed!" | ||
fi |