diff --git a/Dockerfile b/Dockerfile index be66982..3a45dbe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -118,11 +118,11 @@ FROM scanservjs-core # default - you will need to specifically target it. # ============================================================================== FROM scanservjs-core AS scanservjs-hplip +COPY hplip.sh /hplip.sh RUN apt-get update \ && apt-get install -yq libsane-hpaio \ && apt-get clean \ - && rm -rf /var/lib/apt/lists/* \ - && echo hpaio >> /etc/sane.d/dll.conf + && rm -rf /var/lib/apt/lists/* # brscan4 image # diff --git a/entrypoint.sh b/entrypoint.sh index 89ca552..e78b812 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -41,54 +41,6 @@ fi unset IFS set +f -if [ $(dpkg-query -W -f='${Status}' libsane-hpaio 2>/dev/null | grep -c "ok installed") -eq 1 ]; -then - # assume user does not want to install plugin - HP_PLUGIN="${HP_PLUGIN:=false}" - if [ "$PLUGIN" != "false" ]; then - echo "Checking HP_PLUGIN status..." - # determine installed HPLIP version - RE="HP Linux Imaging and Printing System \(ver\. (.+?)\)" - cmd_output=$(hp-plugin --help 2>&1) - #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" - - # if variable is true then try to determine plugin version automatically - if [ "$HP_PLUGIN" = "true" ]; then - - # 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 'HP Driver installed but HP_PLUGIN ENV not invoked' - fi - - if [ ! -z "$INSTALL_PLUGIN_VERSION" ]; then - printf 'Attempting to install 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 -P /tmp "https://developers.hp.com/sites/default/files/hplip-$INSTALL_PLUGIN_VERSION-plugin.run" - fi - chmod +x "$PLUGIN_FILE" - yes | "$PLUGIN_FILE" --noprogress --accept --nox11 -- -i - echo "Plugin installed!" - fi -else - echo 'HP driver not installed, no plugin check required.' -fi - +/hplip.sh || true node ./server/server.js diff --git a/hplip.sh b/hplip.sh new file mode 100755 index 0000000..316a111 --- /dev/null +++ b/hplip.sh @@ -0,0 +1,54 @@ +#!/bin/sh +set -e + +if [ $(dpkg-query -W -f='${Status}' libsane-hpaio 2>/dev/null | grep -c "ok installed") -eq 1 ]; +then + # assume user does not want to install plugin + HP_PLUGIN="${HP_PLUGIN:=false}" + if [ "$PLUGIN" != "false" ]; then + echo "Checking HP_PLUGIN status..." + # determine installed HPLIP version + RE="HP Linux Imaging and Printing System \(ver\. (.+?)\)" + cmd_output=$(hp-plugin --help 2>&1) + #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" + + # if variable is true then try to determine plugin version automatically + if [ "$HP_PLUGIN" = "true" ]; then + + # 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 'HP Driver installed but HP_PLUGIN ENV not invoked' + fi + + if [ ! -z "$INSTALL_PLUGIN_VERSION" ]; then + printf 'Attempting to install 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 "Plugin installed!" + fi +else + echo 'HP driver not installed, no plugin check required.' +fi