From ccfc724f3953fbd9305bc2d451232a4bf72970c1 Mon Sep 17 00:00:00 2001 From: cimryan Date: Thu, 18 Oct 2018 12:51:57 -0700 Subject: [PATCH] Replace update-rpi-mac-linux.sh with non-lgpl alternative. --- .../setup-piForHeadlessConfig.sh | 88 +++++++++++++++ mac_linux_archive/update-rpi-mac-linux.sh | 102 ------------------ 2 files changed, 88 insertions(+), 102 deletions(-) create mode 100755 mac_linux_archive/setup-piForHeadlessConfig.sh delete mode 100755 mac_linux_archive/update-rpi-mac-linux.sh diff --git a/mac_linux_archive/setup-piForHeadlessConfig.sh b/mac_linux_archive/setup-piForHeadlessConfig.sh new file mode 100755 index 0000000..4e6572b --- /dev/null +++ b/mac_linux_archive/setup-piForHeadlessConfig.sh @@ -0,0 +1,88 @@ +#/bin/bash -eu + +# This script will modify the cmdline.txt file on a freshly flashed Raspbian Stretch/Lite +# It readies it for SSH, USB OTG, USB networking, and Wifi +# +# Pass it the path to the location at which the "boot" filesystem is mounted. +# E.g. on a Mac: +# ./setup-piForHeadlessConfig.sh /Volumes/boot +# or on Ubuntu: +# ./setup-piForHeadlessConfig.sh /media/$USER/boot +# cd /Volumes/boot (or wherever the boot folder is mounted) +# chmod +x setup-piForHeadlessConfig.sh +# ./setup-piForHeadlessConfig.sh +# +# Put the card in your Pi, and reboot! + +# Creates the ssh file if needed, since Raspbian now disables +# ssh by default if the file isn't present + +BOOT_DIR="$1" + +function verify_file_exists () { + local file_name="$1" + local expected_path="$2" + + if [ ! -e "$expected_path/$file_name" ] + then + echo "STOP: Didn't find $file_name at $expected_path." + exit 1 + fi +} + +function verify_wifi_variables () { + if [ ! -n "${SSID+x}" ] || [ ! -n "${WIFIPASS+x}" ] + then + echo 'STOP: You need to specify your wifi name and password first. Run: ' + echo " " + echo ' export SSID=your_ssid' + echo ' export WIFIPASS=your_wifi_password' + echo " " + echo "Be sure to replace the values with your SSID (network name) and password." + exit 1 + fi +} + +verify_file_exists "cmdline.txt" "$BOOT_DIR" +verify_file_exists "config.txt" "$BOOT_DIR" + +verify_wifi_variables + +CMDLINE_TXT_PATH="$BOOT_DIR/cmdline.txt" +CONFIG_TXT_PATH="$BOOT_DIR/config.txt" + +echo "Updating $CONFIG_TXT_PATH ..." +echo "" >> "$CONFIG_TXT_PATH" +echo "dtoverlay=dwc2" >> "$CONFIG_TXT_PATH" + +echo "Updating $CMDLINE_TXT_PATH ..." +sed -i -e "s/rootwait/rootwait modules-load=dwc2,g_ether/" -e "s@ init=/usr/lib/raspi-config/init_resize.sh@@" "$CMDLINE_TXT_PATH" + +echo "Enabling SSH ..." +touch "$BOOT_DIR/ssh" + +# Sets up wifi credentials so wifi will be +# auto configured on first boot + +WPA_SUPPLICANT_CONF_PATH="$BOOT_DIR/wpa_supplicant.conf" + +echo "Adding Wifi setup file (wpa_supplicant.conf)." +if [ -r "$WPA_SUPPLICANT_CONF_PATH" ] +then + rm "$WPA_SUPPLICANT_CONF_PATH" +fi + +cat << EOF >> "$WPA_SUPPLICANT_CONF_PATH" +ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev +update_config=1 + +network={ + ssid="$SSID" + psk="$WIFIPASS" + key_mgmt=WPA-PSK +} +EOF + +echo "" +echo '-- Files updated and ready for Wifi and SSH over USB --' +echo "" diff --git a/mac_linux_archive/update-rpi-mac-linux.sh b/mac_linux_archive/update-rpi-mac-linux.sh deleted file mode 100755 index 570e48e..0000000 --- a/mac_linux_archive/update-rpi-mac-linux.sh +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/bash -#|| @license -#|| | This program is free software; you can redistribute it and/or -#|| | modify it under the terms of the GNU Lesser General Public -#|| | License as published by the Free Software Foundation; version -#|| | 2.1 of the License. -#|| | -#|| | This program is distributed in the hope that it will be useful, -#|| | but WITHOUT ANY WARRANTY; without even the implied warranty of -#|| | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -#|| | Lesser General Public License for more details. -#|| | -#|| | You should have received a copy of the GNU Lesser General Public -#|| | License along with this library; if not, write to the Free Software -#|| | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -#|| # - -# Script repurposed from https://github.com/BigNate1234/rpi-USBSSH -# -# This script will modify the cmdline.txt file on a freshly flashed Raspbian Stretch/Lite -# It readies it for SSH, USB OTG, USB networking, and Wifi -# -# Run it in a terminal in the "boot" directory of the flashed MicroSD card -# Ex: -# cd /Volumes/boot (or wherever the boot folder is mounted) -# chmod+x update-rpi-mac-linux.sh (if not executable already) -# ./update-rpi-mac-linux.sh -# -# Put the card in your Pi, and reboot! - -# Creates the ssh file if needed, since Raspbian now disables -# ssh by default if the file isn't present - -if [ ! -r "cmdline.txt" ]; then - echo 'STOP: Run this script in the "boot" directory where cmdline.txt is located.' - exit 1 -fi - -if [ ! -n "${SSID+x}" ] || [ ! -n "${WIFIPASS+x}" ] -then - echo 'STOP: You need to specify your wifi name and password first. Run: ' - echo " " - echo ' export SSID=your_ssid' - echo ' export WIFIPASS=your_wifi_password' - echo " " - echo "Be sure to replace the values with your SSID (network name) and password." - exit 1 -fi - -if [ ! -f ssh ]; then - touch ssh -fi - -# Append the dwc2 module if not set (USB OTG) -echo "Verifying dwc2 module is set in config.txt." -dt=$(cat config.txt | grep "dtoverlay=dwc2") -if [ "$dt" != "dtoverlay=dwc2" ]; then - echo "dtoverlay=dwc2" >> config.txt -fi - -# Append the g_ether module if not set (USB networking) -echo "Verifying the g_ether module (USB networking) is set in cmdline.txt." -mod=$(cat cmdline.txt | grep -o "modules-load=dwc2,g_ether") -if [ "$mod" != "modules-load=dwc2,g_ether" ]; then - sed -i '' '$ s/$/ modules-load=dwc2,g_ether/' cmdline.txt - # Only appends to end of line, not newline -fi - -# Remove the automatic filesystem expansion action -# This is specific to the teslausb project; normally the -# Raspbian image will automatically expand the filesystem to include the -# entire SD card. - -echo "Removing the command to auto-expand the root filesystem." -mod=$(cat cmdline.txt | grep -o "init=/usr/lib/raspi-config/init_resize.sh") -if [ "$mod" = "init=/usr/lib/raspi-config/init_resize.sh" ]; then - sed -i'.bak' -e 's/ init=\/usr\/lib\/raspi-config\/init_resize.sh//g' cmdline.txt -fi - -# Sets up wifi credentials so wifi will be -# auto configured on first boot - -echo "Adding Wifi setup file (wpa_supplicant.conf)." -if [ -r "wpa_supplicant.conf" ] -then - rm wpa_supplicant.conf -fi - -cat << EOF >> wpa_supplicant.conf -ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev -update_config=1 - -network={ - ssid="$SSID" - psk="$WIFIPASS" - key_mgmt=WPA-PSK -} -EOF - -echo "" -echo '-- Files updated and ready for Wifi and SSH over USB --' -echo ""