#!/usr/bin/bash TEST_FILE="./TESTPRINT.pdf" custom_ppd="false" # Function to URL-encode strings (for passwords with #, @, etc.) # This was made with AI because.. I duno URI coding :p urlencode() { local string="${1}" local strlen=${#string} local encoded="" local pos c o for (( pos=0 ; pos /dev/null # in case user doesn't have it set to autorun if sudo lpadmin -p "$PRINTER" -v "smb://$ENCODED_USER:$ENCODED_PASS@crete/ob2/$PRINTER" -E -P "$PPD_FILE" > /dev/null; then echo " Successfully added $PRINTER! " else echo "Failed to add printer. Check your credentials." exit 1 fi read -r -p " --- Would you like to print a test file? Est. $creds credits! (y/N): " confirmation if [[ "$confirmation" =~ ^[Yy]$ ]]; then if [[ ! -f "$TEST_FILE" ]]; then echo "Test document ($TEST_FILE) not found in current directory." read -r -p "Would you like to download it? (y/N): " confirmation if [[ "$confirmation" =~ ^[Yy]$ ]]; then curl -fsSL "https://raw.githubusercontent.com/Johang727/website/master/print/$TEST_FILE" -o "$TEST_FILE" || { echo "Download failed. Check your connection or grab it manually at print.johang.dev" exit 1 } else echo "Printing test file will be omitted." fi fi if [[ -f "$TEST_FILE" ]]; then echo "Sending 2-page duplex test..." lp -d "$PRINTER" -o sides=two-sided-long-edge -o Duplex=DuplexNoTumble "$TEST_FILE" echo "Sent! The print may take up to a minute to register on the printer, please be patient!" fi fi echo " --- For the most consistent printing, use the CLI directly: lp -d $PRINTER -o sides=two-sided-long-edge -o Duplex=DuplexNoTumble Note: Print jobs on the printer will be under $USER rather than $ENCODED_USER. Regardless, $ENCODED_USER will be charged."