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

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