Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 106 lines (97 sloc) 3.04 KB
#!/bin/bash
#--- Check if script is executed in SUDO context ---
if [ $(id -u) != 0 ]; then
echo "Please use \"sudo\" to run this script."
exit 1
fi
#--- Start installation ---
echo "Install ZHAW FollowMe Printers:"
echo "*******************************"
echo
echo "This script installs the ZHAW FollowMe MFP printers to your local system."
echo "Due to some SAMBA problems, it is impossible to install the Printers directly."
echo "A Docker container will be locally installed, which acts as a wrapper to fix this problem."
echo
echo "Your password will be stored plain text within the cups container: /etc/cups/printers.conf"
echo
echo "To uninstall the printer run: uninstall_followme_mfp_printer.sh"
echo
#--- Check if Docker is installed and install it if not ---
echo "Check if docker is installed..."
echo
if [ $(dpkg -l | grep -c "ii docker") == 0 ]; then
echo "Installing Docker..."
apt-get install docker.io -y 2>&1 > /dev/null
else
echo "Docker already installed -> OK"
echo
fi
#--- Add user to lpadmin group if not already member ---
echo
echo "Check if you're member of the local printer admin group..."
echo
if [ $(id ${SUDO_USER:-${USER}} | grep -c lpadmin) == 0 ]; then
echo "Your not member of lpadmin. Adding you to this group."
usermod ${SUDO_USER:-${USER}} -G lpadmin -a
else
echo "Your already member of lpadmin."
echo
fi
#--- Ask for credentials which will be stored in the container ---
echo
echo "Enter credentials to use in Docker container:"
echo
printf "Username: "; read TMPUSER
unset TMPPASSWORD
prompt="Password: "
while IFS= read -p "$prompt" -r -s -n 1 char
do
if [[ $char == $'\0' ]]
then
break
fi
prompt='*'
TMPPASSWORD+="$char"
done
#--- Remove container if existing ---
if [ $(docker ps -a -f name=cups-zhaw | grep -c cups-zhaw) != 0 ]; then
docker rm -f cups-zhaw
fi
#- Legacy container
if [ $(docker ps -a -f name=cups | grep -c cups) != 0 ]; then
docker rm -f cups
fi
#--- Start new container using credentials from above ---
echo
echo "Going to start container...."
echo
docker run -d --restart unless-stopped --name cups -e "USER=$TMPUSER" -e "PASSWORD=$TMPPASSWORD" zhawinit/cups-zhaw:latest
echo
echo "Done..."
echo
echo "Adding local printer which connects to wrapper..."
echo
#--- Add local printer which connects to wrapper ---
#- Get local IP of cups container
CONTAINERIP=$(docker inspect cups-zhaw | grep IPA | tail -n1 | sed 's/.*"\([[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\).*/\1/g')
#- Check if local printer exists
FOLLOWME_EXISTENT=$(lpstat -s 2>/dev/null | grep -c FollowMe)
#- Add printer if not already present
if [ $FOLLOWME_EXISTENT != 0 ]; then
echo
echo "Printer already exists. Not installing new device."
echo
else
lpadmin -p FollowMe -P build_container/FollowMe.ppd -v ipp://$CONTAINERIP:631/printers/FollowMe 2>&1 > /dev/null
echo
echo "Local printer FollowMe installed."
echo
if [ $(lpstat -s | grep -c "no system default destination") == 1 ]; then
lpoptions -d FollowMe
fi
cupsenable FollowMe
cupsaccept FollowMe
lpstat -d
lpstat -v
echo
fi
You can’t perform that action at this time.