Last active
March 8, 2024 15:28
-
-
Save mofosyne/6baab7509ccd93f74d3fa225ea57d75d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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..." |
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
Also had to try and get an old LBP3000 printer working as well so did this as well
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 :)