From: Didier Raboud <odyx@debian.org>
Date: Tue, 4 Oct 2016 11:43:54 +0200
Subject: Improve getweb also for installing the firmware

Fix the icm file installing code to create inexistant folders
---
 getweb.in | 80 +++++++++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 58 insertions(+), 22 deletions(-)

diff --git a/getweb.in b/getweb.in
index 5215e02..11f2aa6 100755
--- a/getweb.in
+++ b/getweb.in
@@ -1,8 +1,10 @@
 #!/bin/sh
 
+set -e
+
 #
 # (c) Copyright Rick Richardson 2008
-#
+# This version has been modified by Debian
 
 #
 # PLEASE don't remove the copyright statements.  They should 
@@ -12,6 +14,13 @@
 VERSION='$Id: getweb.in,v 1.114 2015/02/12 00:22:02 rick Exp $'
 
 WGETOPTS="--passive-ftp -q"
+ARM2HPDL="/usr/bin/arm2hpdl"
+
+if [ $(id -ru) -ne 0 ]; then
+    echo "You need to be root"
+    exit 1
+fi
+
 
 usage() {
 cat <<EOF
@@ -79,7 +88,7 @@ Usage:
 
     $ ./getweb 1000	# Get HP LJ 1000 firmware file
     $ ./getweb 1005	# Get HP LJ 1005 firmware file
-    $ ./getweb 1018	# Get HP LJ 1005 firmware file
+    $ ./getweb 1018	# Get HP LJ 1018 firmware file
     $ ./getweb 1020	# Get HP LJ 1020 firmware file
 
     $ ./getweb p1005	# Get HP LJ P1005 firmware file
@@ -91,8 +100,6 @@ Usage:
     $ ./getweb all	# Get everything above
 
     $ ./getweb 2300dl_fw # Get Minolta 2300DL v2.55 firmware (experts only)
-
-    $ ./getweb update	# Get latest version of this software.
 EOF
     exit 1
 }
@@ -107,7 +114,7 @@ error() {
 }
 
 SYSTEM=`uname -s`
-WGET=`type wget 2>/dev/null`
+WGET=`which wget`
 if [ "$SYSTEM" = Darwin -a "$WGET" = "" ]
 then
     WGETOPTS=
@@ -117,6 +124,20 @@ then
     }
 fi
 
+putfw() {
+    inputname=$1
+    outputname=$2
+    $ARM2HPDL $inputname > /usr/share/foo2zjs/firmware/$outputname
+    rm $inputname
+}
+
+puticm() {
+    drivername=$1
+    icmfolder=/usr/share/"$drivername"/icm/
+    [ -d $icmfolder ] || mkdir -p $icmfolder
+    mv *.icm $icmfolder
+}
+
 #
 #	Download a .EXE file from the web, unzip it, and extract the
 #	files we want
@@ -163,6 +184,7 @@ getone() {
 	    #lj1488en.exe \
 	    #sihp1000.img
 	copyright "(c) Copyright Hewlett-Packard 2001"
+	putfw sihp1000.img sihp1000.dl
 	;;
     lj1005|1005)
 	gettgz \
@@ -178,12 +200,14 @@ getone() {
 	    http://foo2zjs.rkkda.com/firmware sihpP1005.tar.gz \
 	    ""
 	copyright "(c) Copyright Hewlett-Packard 2009"
+	putfw sihp1005.img sihp1005.dl
 	;;
     lj1018|1018)
 	gettgz \
 	    http://foo2zjs.rkkda.com/firmware sihp1018.tar.gz \
 	    ""
 	copyright "(c) Copyright Hewlett-Packard 2005"
+	putfw sihp1018.img sihp1018.dl
 	;;
     lj1020|1020)
 	# http://ftp.hp.com/pub/softlib/software8/COL14041/lj-39322-2/hp_LJ_1020-1022_Full_Solution.exe
@@ -191,24 +215,28 @@ getone() {
 	    http://foo2zjs.rkkda.com/firmware sihp1020.tar.gz \
 	    ""
 	copyright "(c) Copyright Hewlett-Packard 2005"
+	putfw sihp1020.img sihp1020.dl
 	;;
     [pP]100[57])
 	gettgz \
 	    http://foo2zjs.rkkda.com/firmware sihpP1005.tar.gz \
 	    ""
 	copyright "(c) Copyright Hewlett-Packard 2009"
+	putfw sihpP1005.img sihpP1005.dl
 	;;
     [pP]100[68])
 	gettgz \
 	    http://foo2zjs.rkkda.com/firmware sihpP1006.tar.gz \
 	    ""
 	copyright "(c) Copyright Hewlett-Packard 2009"
+	putfw sihpP1006.img sihpP1006.dl
 	;;
     [pP]1505)
 	gettgz \
 	    http://foo2zjs.rkkda.com/firmware sihpP1505.tar.gz \
 	    ""
 	copyright "(c) Copyright Hewlett-Packard 2009"
+	putfw sihpP1505.img sihpP1505.dl
 	;;
     2200dl|2200)
 	if true; then
@@ -221,6 +249,7 @@ getone() {
 		"*.icm"
 	fi
 	copyright "(c) Copyright Minolta-QMS 1999"
+	puticm foo2zjs
 	;;
     2300dl|2300)
 	if true; then
@@ -236,6 +265,7 @@ getone() {
 	    http://foo2zjs.rkkda.com/icm km2430.tar.gz \
 	    ""
 	copyright "(c) Copyright Minolta-QMS 2001"
+	puticm foo2zjs
 	;;
     2300dl_fw)
 	# 2300DL firmware upgrade to v2.55
@@ -264,12 +294,14 @@ getone() {
 	    done
 	fi
 	copyright "(c) Copyright Minolta-QMS 1998"
+	puticm foo2zjs
 	;;
     2430)
 	gettgz \
 	    http://foo2zjs.rkkda.com/icm km2430.tar.gz \
 	    ""
 	copyright "(c) Copyright Konica Minolta 2003"
+	puticm foo2zjs
 	;;
     2530|2490|6115|2480|1600w|1680|1690|4690|110|6121)
 	gettgz \
@@ -281,6 +313,7 @@ getone() {
 	    http://foo2lava.rkkda.com/icm km-1600.tar.gz \
 	    ""
 	copyright "(c) Copyright Rick Richardson 2009.  All Rights Reserved"
+	puticm foo2lava
 	;;
     1500)
 	gettgz \
@@ -292,12 +325,14 @@ getone() {
 	    ""
 	copyright "(c) Copyright Hewlett-Packard 2003"
 	copyright "(c) Copyright Rick Richardson 2006.  All Rights Reserved"
+	puticm foo2oak
 	;;
     1025)
 	gettgz \
 	    http://foo2zjs.rkkda.com/icm hp-cp1025.tar.gz \
 	    ""
 	copyright "(c) Copyright Rick Richardson 2010.  All Rights Reserved"
+	puticm foo2zjs
 	;;
     1215|1600|2600*)
 	gettgz \
@@ -312,6 +347,7 @@ getone() {
 	    http://foo2hp.rkkda.com/icm hp1215.tar.gz \
 	    ""
 	copyright "(c) Copyright Rick Richardson 2008.  All Rights Reserved"
+	puticm foo2hp
 	;;
     300|310|315|325|360|365|2160|3160|3175|3185|6110)
 	gettgz \
@@ -322,6 +358,7 @@ getone() {
 	    http://foo2qpdl.rkkda.com/icm samclp315.tar.gz \
 	    ""
 	copyright "(c) Copyright Rick Richardson 2008.  All Rights Reserved"
+	puticm foo2qpdl
 	;;
     600|610)
 	;;
@@ -331,6 +368,7 @@ getone() {
 	    http://foo2slx.rkkda.com/icm lexc500.tar.gz \
 	    ""
 	copyright "(c) Copyright Lexmark 2006"
+	puticm foo2slx
 	;;
 
     oki)
@@ -346,48 +384,56 @@ getone() {
 	    mv "$base.ICM" "$base.icm"
 	done
 	copyright "(c) Copyright Okidata 2005, 2006"
+	puticm foo2hiperc
 	;;
     301)
 	gettgz \
 	    http://foo2hiperc.rkkda.com/icm okic301.tar.gz \
 	    ""
 	copyright "(c) Copyright Okidata 2012"
+	puticm foo2hiperc
 	;;
     c310)
 	gettgz \
 	    http://foo2hiperc.rkkda.com/icm okic310.tar.gz \
 	    ""
 	copyright "(c) Copyright Okidata 2010"
+	puticm foo2hiperc
 	;;
     c511)
 	gettgz \
 	    http://foo2hiperc.rkkda.com/icm okic511.tar.gz \
 	    ""
 	copyright "(c) Copyright Okidata 2012"
+	puticm foo2hiperc
 	;;
     c810)
 	gettgz \
 	    http://foo2hiperc.rkkda.com/icm okic810.tar.gz \
 	    ""
 	copyright "(c) Copyright Okidata 2012"
+	puticm foo2hiperc
 	;;
     3100|3200|5100|5150|5200|5250)
 	gettgz \
 	    http://foo2hiperc.rkkda.com/icm okic3200.tar.gz \
 	    ""
 	copyright "(c) Copyright Okidata 2005"
+	puticm foo2hiperc
 	;;
     3300|3400|3530)
 	gettgz \
 	    http://foo2hiperc.rkkda.com/icm okic3400.tar.gz \
 	    ""
 	copyright "(c) Copyright Okidata 2006"
+	puticm foo2hiperc
 	;;
     5500|5600|5800|160)
 	gettgz \
 	    http://foo2hiperc.rkkda.com/icm okic5600.tar.gz \
 	    ""
 	copyright "(c) Copyright Okidata 2006"
+	puticm foo2hiperc
 	;;
 
     xPPD)
@@ -443,23 +489,6 @@ getone() {
 		# | sed -e 's/\(^\*NickName.*\)"/\1 (foo2zjs recommended)"/'
 	done
 	;;
-    update)
-	url=${URLZJS}
-	file=foo2zjs.tar.gz
-	wget $WGETOPTS -O $file $url/$file ||
-		error "Couldn't download $url/$exefile"
-	mv getweb getweb.old
-	HERE=`pwd`
-	cd .. 
-	tar zxf $HERE/$file
-	cd $HERE
-	echo "The tarball is extracted and the current directory is up to date."
-	echo -e "Remove the tarball (y/n)? \c"
-	read ans
-	if [ "$ans" = y ]; then
-	    rm -f $file
-	fi
-	;;
     "")
 	usage
 	;;
@@ -474,6 +503,10 @@ if [ $# = 0 ]; then
     usage
 fi
 
+OLDPWD=`pwd`
+NEWPWD=`mktemp --tmpdir --directory foo2zjs.XXXXXX`
+cd "$NEWPWD"
+
 for i in $*
 do
     case "$1" in
@@ -518,3 +551,6 @@ do
 	;;
     esac
 done
+
+cd "$OLDPWD"
+rmdir "$NEWPWD"
