Skip to content

Instantly share code, notes, and snippets.

@ryancdotorg
Created December 19, 2013 06:37
Show Gist options
  • Save ryancdotorg/8035262 to your computer and use it in GitHub Desktop.
Save ryancdotorg/8035262 to your computer and use it in GitHub Desktop.
My guest wifi password rotation script, including qr code generator.
#!/bin/bash
TEMP_DIR="/run/shm"
FONT_DIR="/usr/local/share/fonts"
# generate a 12 character password comprised of lower case letters
NEW_PASS=`\
dd if=/dev/urandom bs=1 count=32 2>/dev/null | \
tr '\200-\377' '\0-\177' | \
tr '\0-\77' '\100-\177' | \
tr '\100-\137' '\140-\177' | \
tr -d 'l\`{|}~\177' | \
head -c12`
NEW_SSID="YourGuestSSID"
# https://code.google.com/p/zxing/wiki/BarcodeContents
QR_DATA="WIFI:T:WPA;S:$NEW_SSID;P:$NEW_PASS;;"
# generate the qr code
qrencode -o "$TEMP_DIR/wifi-qr0.png" "$QR_DATA"
# add upper label
convert "$TEMP_DIR/wifi-qr0.png" -background black -fill white -gravity center -font "$FONT_DIR/Fixedsys500c.ttf" +antialias -pointsize 15 label:'Guest WiFi' +swap -append "$TEMP_DIR/wifi-qr1.png"
# add lower label
convert "$TEMP_DIR/wifi-qr1.png" -background black -fill white -gravity center -font "$FONT_DIR/Fixedsys500c.ttf" +antialias -pointsize 15 label:"$NEW_SSID\n $NEW_PASS " -append "$TEMP_DIR/wifi-qr2.png"
# update config file for marvell uap
perl -i -pe "s/PSK=\".*\"/PSK=\"$NEW_PASS\"/" /etc/uaputl.conf
# restart the ap with the new password
/usr/bin/uaputl bss_stop
/usr/bin/uaputl sys_reset
/usr/bin/uaputl sys_config /etc/uaputl.conf
/usr/bin/uaputl sys_cfg_radio_ctl 0
/usr/bin/uaputl bss_start
# this is included in a web page displayed on a chumby in my living room
cp "$TEMP_DIR/wifi-qr2.png" /var/www/guest-wifi.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment