Skip to content

Instantly share code, notes, and snippets.

@mofosyne
Last active March 8, 2024 15:28
Show Gist options
  • Save mofosyne/6baab7509ccd93f74d3fa225ea57d75d to your computer and use it in GitHub Desktop.
Save mofosyne/6baab7509ccd93f74d3fa225ea57d75d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Automated application of WiFi Print Server: From a Raspberry Pi Zero W to Windows 10/11 By brighterfusion from instructables
# This helper script was written by Brian Khuu on 2023 for https://www.instructables.com/WiFi-Print-Server-From-a-Raspberry-Pi-Zero-W-to-Wi/
# To run this shell script on gist (ref: https://gist.github.com/mob-sakai/174a32b95572e7d8fdbf8e6f43a528f6)
# Run this script via curl:
# bash <(curl -sL https://gist.githubusercontent.com/mofosyne/6baab7509ccd93f74d3fa225ea57d75d/raw/rpi_print_server_setup.bash)
# Run this script via wget:
# bash <(wget -o /dev/null -nv -O - https://gist.githubusercontent.com/mofosyne/6baab7509ccd93f74d3fa225ea57d75d/raw/rpi_print_server_setup.bash)
echo "Automated application of WiFi Print Server: From a Raspberry Pi Zero W to Windows 10/11 By brighterfusion from instructables"
echo "Assuming you have already done Step 1 of prepping and loading in the MicroSD card and loggin in here via ssh"
### Install Packages ###
echo "### Step 2: Initialize the RPi and Install Packages ###"
# Sync RPI system
sudo apt update -y && sudo apt upgrade -y
# Install
sudo apt install -y cups samba
# Install the CUPS print server and SAMBA file sharing packages. This will take a several additional minutes.
sudo usermod -a -G lpadmin $USER
### Config CUPS ###
echo "### Step 3: Config CUPS ###"
# Add an administrative user for the printer. Replace pi with your username
sudo usermod -a -G lpadmin $USER
# Enable web-based admin pages
sudo cupsctl --remote-any
# Restart CUPS
sudo systemctl restart cups
### Configure SAMBA ###
echo "### Step 4: Config SAMBA ###"
# now we want to edit `/etc/samba/smb.conf`
# * Under [printers]:
# guest ok = yes
# * Under [print$]:
# read only = no
SMBCONFPATCH=$(cat << EOF
--- smb.conf 2023-01-28 15:20:37.254209346 +1100
+++ editedsmb.conf 2023-01-28 15:36:54.867346266 +1100
@@ -215,7 +215,7 @@
browseable = no
path = /var/spool/samba
printable = yes
- guest ok = no
+ guest ok = yes
read only = yes
create mask = 0700
@@ -225,7 +225,7 @@
comment = Printer Drivers
path = /var/lib/samba/printers
browseable = yes
- read only = yes
+ read only = no
guest ok = no
# Uncomment to allow remote administration of Windows print drivers.
# You may need to replace 'lpadmin' with the name of the group your
EOF
)
if ! echo "$SMBCONFPATCH" | sudo patch -R -p0 -s -f --dry-run /etc/samba/smb.conf; then
echo "$SMBCONFPATCH" | sudo patch -p0 /etc/samba/smb.conf
else
echo "/etc/samba/smb.conf already patched";
fi
# Restart Samba service.
sudo systemctl restart smbd
echo "Automated Portion Done..."
echo "Now you can proceed to Step 5: On CUPS Config Web Site..."
@mofosyne
Copy link
Author

mofosyne commented Jan 28, 2023

Also had to try and get an old LBP3000 printer working as well so did this as well

#!/usr/bin/env bash
# LBP3000 CAPT driver on raspberry pi compile process
# Based on https://namvu.net/2021/07/setup-a-family-printer-with-a-raspberry-pi-1-and-canon-lbp-2900/
# But updated to use https://github.com/mounaiban/captdriver which is a more maintained fork

# Installing CUPS and the rest of the perquisites:
sudo apt install -y build-essential git autoconf libtool cups libcups2-dev libcupsimage2-dev

# Grab the source code:
git clone https://github.com/mounaiban/captdriver.git

# Compile the driver
pushd captdriver
autoreconf -i
./configure
make
make ppd
popd

# Install captdriver
#   The make install command above only copies the rastertocapt binary to the /usr/local/bin directory, 
#   while setting the necessary file ownerships and permissions. 
#   The cp command is still needed to place a copy of rastertocapt inside the CUPS filter directory.
pushd captdriver
sudo make install
popd

# Copy the files to their relevant locations
pushd captdriver
sudo cp src/rastertocapt /usr/lib/cups/filter/
sudo cp ppd/Canon*.ppd /usr/share/ppd/custom/
popd

Update: Seems like the above method is not reliable for LBP3000 on raspbian and should be done on ubuntu server distro instead on a raspberry pi zero V2 (Ref: mounaiban/captdriver#8 )

Update: Able to get this working on a normal linux x64 PC but would rather this work on raspberry pi zero V1 . However for now, cleaned up the script and placed it in this gist in case anyone needs it https://gist.github.com/mofosyne/c84d23d863454478b4d192b9ca9afd5b let me know if this helped you :)

@mofosyne
Copy link
Author

Also I'm sure there is a cleaner way to patch /etc/samba/smb.conf without using patch... but haven't figured out one yet. toml-cli looks good, but not sure how easy it would be to get into raspberry pi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment