From d3745aafde214b8999a6f712eed8fb5ddc503d03 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Wed, 31 Oct 2018 07:53:41 -0500 Subject: [PATCH] Adding pi-gen sources as of v9-beta3 --- pi-gen-sources/00-packages | 1 + .../00-patches/01-cmdline-update.diff | 5 + .../00-patches/02-config-update.diff | 7 + .../00-patches/03-hosts-update.diff | 9 ++ .../00-patches/04-hostname-update.diff | 5 + pi-gen-sources/00-patches/series | 4 + pi-gen-sources/00-run.sh | 52 ++++++ pi-gen-sources/files/enable_wifi.sh | 49 ++++++ pi-gen-sources/files/hosts | 6 + pi-gen-sources/files/rc.local | 153 ++++++++++++++++++ pi-gen-sources/files/ssh | 0 pi-gen-sources/files/stage_flash | 34 ++++ .../teslausb_setup_variables.conf.sample | 43 +++++ .../files/wpa_supplicant.conf.sample | 8 + 14 files changed, 376 insertions(+) create mode 100644 pi-gen-sources/00-packages create mode 100644 pi-gen-sources/00-patches/01-cmdline-update.diff create mode 100644 pi-gen-sources/00-patches/02-config-update.diff create mode 100644 pi-gen-sources/00-patches/03-hosts-update.diff create mode 100644 pi-gen-sources/00-patches/04-hostname-update.diff create mode 100644 pi-gen-sources/00-patches/series create mode 100755 pi-gen-sources/00-run.sh create mode 100644 pi-gen-sources/files/enable_wifi.sh create mode 100644 pi-gen-sources/files/hosts create mode 100755 pi-gen-sources/files/rc.local create mode 100644 pi-gen-sources/files/ssh create mode 100644 pi-gen-sources/files/stage_flash create mode 100644 pi-gen-sources/files/teslausb_setup_variables.conf.sample create mode 100644 pi-gen-sources/files/wpa_supplicant.conf.sample diff --git a/pi-gen-sources/00-packages b/pi-gen-sources/00-packages new file mode 100644 index 0000000..700b896 --- /dev/null +++ b/pi-gen-sources/00-packages @@ -0,0 +1 @@ +dos2unix \ No newline at end of file diff --git a/pi-gen-sources/00-patches/01-cmdline-update.diff b/pi-gen-sources/00-patches/01-cmdline-update.diff new file mode 100644 index 0000000..493533c --- /dev/null +++ b/pi-gen-sources/00-patches/01-cmdline-update.diff @@ -0,0 +1,5 @@ +--- stage7/rootfs/boot/cmdline.txt ++++ stage7/rootfs/boot/cmdline.txt +@@ -1 +1 @@ +-dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh ++dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait modules-load=dwc2,g_ether quiet diff --git a/pi-gen-sources/00-patches/02-config-update.diff b/pi-gen-sources/00-patches/02-config-update.diff new file mode 100644 index 0000000..3edb7da --- /dev/null +++ b/pi-gen-sources/00-patches/02-config-update.diff @@ -0,0 +1,7 @@ +--- stage7/rootfs/boot/config.txt ++++ stage7/rootfs/boot/config.txt +@@ -54,3 +54,4 @@ + + # Enable audio (loads snd_bcm2835) + dtparam=audio=on ++dtoverlay=dwc2 diff --git a/pi-gen-sources/00-patches/03-hosts-update.diff b/pi-gen-sources/00-patches/03-hosts-update.diff new file mode 100644 index 0000000..e2896de --- /dev/null +++ b/pi-gen-sources/00-patches/03-hosts-update.diff @@ -0,0 +1,9 @@ +--- stage7/rootfs/etc/hosts ++++ stage7/rootfs/etc/hosts +@@ -3,4 +3,5 @@ + ff02::1 ip6-allnodes + ff02::2 ip6-allrouters + +-127.0.1.1 raspberrypi ++127.0.0.1 teslausb ++ diff --git a/pi-gen-sources/00-patches/04-hostname-update.diff b/pi-gen-sources/00-patches/04-hostname-update.diff new file mode 100644 index 0000000..d051108 --- /dev/null +++ b/pi-gen-sources/00-patches/04-hostname-update.diff @@ -0,0 +1,5 @@ +--- stage7/rootfs/etc/hostname ++++ stage7/rootfs/etc/hostname +@@ -1 +1 @@ +-raspberrypi ++teslausb diff --git a/pi-gen-sources/00-patches/series b/pi-gen-sources/00-patches/series new file mode 100644 index 0000000..7d6a2ab --- /dev/null +++ b/pi-gen-sources/00-patches/series @@ -0,0 +1,4 @@ +01-cmdline-update.diff +02-config-update.diff +03-hosts-update.diff +04-hostname-update.diff diff --git a/pi-gen-sources/00-run.sh b/pi-gen-sources/00-run.sh new file mode 100755 index 0000000..c60ff02 --- /dev/null +++ b/pi-gen-sources/00-run.sh @@ -0,0 +1,52 @@ +#!/bin/bash -e +touch "${ROOTFS_DIR}/boot/ssh" +install -m 755 files/rc.local "${ROOTFS_DIR}/etc/" +install -m 755 files/stage_flash "${ROOTFS_DIR}/etc/" +install -m 666 files/teslausb_setup_variables.conf.sample "${ROOTFS_DIR}/boot/" +install -m 666 files/wpa_supplicant.conf.sample "${ROOTFS_DIR}/boot/" +install -d "${ROOTFS_DIR}/root/bin" +install -m 755 files/enable_wifi.sh "${ROOTFS_DIR}/root/bin" + +# install -m 755 files/teslausb_setup_scripts/bin/* "${ROOTFS_DIR}/root/bin/" +# install -d "${ROOTFS_DIR}/root/bin/tmp" +# install -m 755 files/teslausb_setup_scripts/tmp/* "${ROOTFS_DIR}/root/bin/tmp/" + +# on_chroot << EOF +# systemctl disable hwclock.sh +# systemctl disable nfs-common +# systemctl disable rpcbind +# systemctl disable ssh +# systemctl enable regenerate_ssh_host_keys +# EOF + +# if [ "${USE_QEMU}" = "1" ]; then +# echo "enter QEMU mode" +# install -m 644 files/90-qemu.rules "${ROOTFS_DIR}/etc/udev/rules.d/" +# on_chroot << EOF +# systemctl disable resize2fs_once +# EOF +# echo "leaving QEMU mode" +# else +# on_chroot << EOF +# systemctl enable resize2fs_once +# EOF +# fi + +# on_chroot << \EOF +# for GRP in input spi i2c gpio; do +# groupadd -f -r "$GRP" +# done +# for GRP in adm dialout cdrom audio users sudo video games plugdev input gpio spi i2c netdev; do +# adduser pi $GRP +# done +# EOF + +# on_chroot << EOF +# setupcon --force --save-only -v +# EOF + +# on_chroot << EOF +# usermod --pass='*' root +# EOF + +# rm -f "${ROOTFS_DIR}/etc/ssh/"ssh_host_*_key* diff --git a/pi-gen-sources/files/enable_wifi.sh b/pi-gen-sources/files/enable_wifi.sh new file mode 100644 index 0000000..b87e410 --- /dev/null +++ b/pi-gen-sources/files/enable_wifi.sh @@ -0,0 +1,49 @@ +#! /bin/bash -eu + +HEADLESS_SETUP=false + +if [ -e "/boot/teslausb-headless-setup.log" ] +then + HEADLESS_SETUP=true +fi + + +function setup_progress () { + if [ $HEADLESS_SETUP = "true" ] + then + SETUP_LOGFILE=/boot/teslausb-headless-setup.log + echo "$( date ) : $1" >> "$SETUP_LOGFILE" + fi + echo $1 +} + +function enable_wifi () { + setup_progress "Detecting whether to update wpa_supplicant.conf" + if [ ! -z ${SSID+x} ] && [ ! -z ${WIFIPASS+x} ] + then + if [ ! -e /boot/WIFI_ENABLED ] + then + if [ -e /root/bin/remountfs_rw ] + then + /root/bin/remountfs_rw + fi + setup_progress "Wifi variables specified, and no /boot/WIFI_ENABLED. Building wpa_supplicant.conf." + cp /boot/wpa_supplicant.conf.sample /boot/wpa_supplicant.conf + sed -i'.bak' -e "s/TEMPSSID/${SSID}/g" /boot/wpa_supplicant.conf + sed -i'.bak' -e "s/TEMPPASS/${WIFIPASS}/g" /boot/wpa_supplicant.conf + cp /boot/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf + touch /boot/WIFI_ENABLED + setup_progress "Rebooting..." + reboot + fi + else + echo "You need to export your desired SSID and WIFI pass like:" + echo " export SSID=your_ssid" + echo " export WIFIPASS=your_wifi_pass" + echo "" + echo "Then re-run enable_wifi.sh" + + fi +} + +enable_wifi \ No newline at end of file diff --git a/pi-gen-sources/files/hosts b/pi-gen-sources/files/hosts new file mode 100644 index 0000000..89f1b56 --- /dev/null +++ b/pi-gen-sources/files/hosts @@ -0,0 +1,6 @@ +127.0.0.1 localhost +::1 localhost ip6-localhost ip6-loopback +ff02::1 ip6-allnodes +ff02::2 ip6-allrouters + +127.0.0.1 raspberrypi diff --git a/pi-gen-sources/files/rc.local b/pi-gen-sources/files/rc.local new file mode 100755 index 0000000..744e3ce --- /dev/null +++ b/pi-gen-sources/files/rc.local @@ -0,0 +1,153 @@ +#!/bin/bash -e +# +# rc.local +# +# This script is executed at the end of each multiuser runlevel. +# Make sure that the script will "exit 0" on success or any other +# value on error. +# +# In order to enable or disable this script just change the execution +# bits. +# +# By default this script does nothing. + +# Print the IP address +_IP=$(hostname -I) || true +if [ "$_IP" ]; then + printf "My IP address is %s\n" "$_IP" +fi + + +SETUP_LOGFILE=/boot/teslausb-headless-setup.log + +function setup_progress () { + echo "$( date ) : $1" >> "$SETUP_LOGFILE" + echo $1 +} + +function get_script () { + local local_path="$1" + local name="$2" + local remote_path="${3:-}" + + curl -o "$local_path/$name" https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/"$remote_path"/"$name" + # wget -O "$local_path/$name" https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/"$remote_path"/"$name" + chmod +x "$local_path/$name" +} + +function enable_wifi () { + setup_progress "Detecting whether to update wpa_supplicant.conf" + if [[ ! -z $SSID ]] && [[ ! -z $WIFIPASS ]] + then + if [ ! -e /boot/WIFI_ENABLED ] + then + if [ -e /root/bin/remountfs_rw ] + then + /root/bin/remountfs_rw + fi + setup_progress "Wifi variables specified, and no /boot/WIFI_ENABLED. Building wpa_supplicant.conf." + cp /boot/wpa_supplicant.conf.sample /boot/wpa_supplicant.conf + sed -i'.bak' -e "s/TEMPSSID/${SSID}/g" /boot/wpa_supplicant.conf + sed -i'.bak' -e "s/TEMPPASS/${WIFIPASS}/g" /boot/wpa_supplicant.conf + cp /boot/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf + touch /boot/WIFI_ENABLED + setup_progress "Rebooting..." + reboot + fi + fi +} + + +if [ -e "/boot/teslausb_setup_variables.conf" ] + then + if [ -e /root/bin/remountfs_rw ] + then + /root/bin/remountfs_rw + fi + cp /boot/teslausb_setup_variables.conf /root/ + dos2unix /root/teslausb_setup_variables.conf + source "/root/teslausb_setup_variables.conf" + fi + +# Check for headless setup +if [ -z "${HEADLESS_SETUP+x}" ] +then + HEADLESS_SETUP=false +fi + + +# check if we previously marked wifi as enabled +enable_wifi +# Good to start setup at this point + +# This begins the Headless Setup loop +# If the FINISHED file does not exist then we start setup. Otherwise passes on to normal loop +if [ ! -e "/boot/TESLAUSB_SETUP_FINISHED" ] && [ $HEADLESS_SETUP = "true" ] +then + if [ -e /root/bin/remountfs_rw ] + then + /root/bin/remountfs_rw + fi + touch "/boot/TESLAUSB_SETUP_STARTED" + + # Grab the setup variables. Should still be there since setup isn't finished. + # This is a double check to cover various scenarios of mixed headless/not headless setup attempts + if [ -e "/boot/teslausb_setup_variables.conf" ] + then + cp /boot/teslausb_setup_variables.conf /root/ + dos2unix /root/teslausb_setup_variables.conf + source "/root/teslausb_setup_variables.conf" + else + # No conf file found, can't complete setup + setup_progress "Setup appears not to have completed, but you didn't provide a teslausb_setup_variables.conf." + fi + + + + # Make the bin dir if needed to grab the setup script into it and persist + if [ ! -d "/root/bin" ] + then + mkdir "/root/bin" + fi + + if [ ! -e "/root/bin/setup-teslausb" ] + then + REPO=${REPO:-cimryan} + BRANCH=${BRANCH:-master} + # Script doesn't exist, grab it. + setup_progress "Grabbing main setup file." + get_script /root/bin setup-teslausb setup/pi + fi + + setup_progress "Starting setup." + + # Update the archiveserver value if needed in script on disk + sed -i'.bak' -e "s/TEMPARCHIVESERVER/$archiveserver/g" /etc/rc.local + + # Start setup. This should take us all the way through to reboot + /root/bin/setup-teslausb + + # reboot for good measure, also restarts the rc.local script + reboot +fi + +LOGFILE=/tmp/rc.local.log + +function log () { + echo "$( date ) ${1}" >> "$LOGFILE" +} +if [ -e "/root/bin/archiveloop" ] +then + log "Launching archival script..." + /root/bin/archiveloop TEMPARCHIVESERVER & + log "All done" +else + echo "Setup doesn't seem to have completed, there is no /root/bin/archiveloop." + echo "Try re-running /root/bin/setup-teslausb (re-downloading if needed)," + echo "or export HEADLESS=true and run /etc/rc.local if you want to run automatic setup." +fi +exit 0 + + + + diff --git a/pi-gen-sources/files/ssh b/pi-gen-sources/files/ssh new file mode 100644 index 0000000..e69de29 diff --git a/pi-gen-sources/files/stage_flash b/pi-gen-sources/files/stage_flash new file mode 100644 index 0000000..2bd2e2c --- /dev/null +++ b/pi-gen-sources/files/stage_flash @@ -0,0 +1,34 @@ +#!/bin/bash + +i=$1 +flash_count=0 +flash_count=$((i + 1 )) + +function led_off () { +echo 1 | sudo tee /sys/class/leds/led0/brightness > /dev/null +} + +function led_on () { +echo 0 | sudo tee /sys/class/leds/led0/brightness > /dev/null +} + +function led_flash () { + led_on + sleep .2 + led_off +} + +function flash () { + local COUNTER=0 + sleep 2 + while [ ${COUNTER} -lt ${flash_count} ] + do + led_flash + let COUNTER=COUNTER+1 + done +} + +flash +sleep 5 + +exit 0 diff --git a/pi-gen-sources/files/teslausb_setup_variables.conf.sample b/pi-gen-sources/files/teslausb_setup_variables.conf.sample new file mode 100644 index 0000000..5c0b859 --- /dev/null +++ b/pi-gen-sources/files/teslausb_setup_variables.conf.sample @@ -0,0 +1,43 @@ +##################################################################### +# SAMPLE CONFIGURATION FILE FOR TESLAUSB Pi Setup +# +# Example config file for teslausb_setup. Lines with "#" are comments/ignored. +# Remove the "#" before "export" to activate a line. Be sure to rename this file +# to "teslausb_setup_variables.conf" and place it in the "boot" folder of your +# SD card. +# +###################################################################### + +# Default variables for CIFS (Windows/Mac file sharing) setup +export archiveserver=your_archive_name_or_ip +export sharename=your_archive_share_name +export shareuser=username +export sharepassword=password +export campercent=100 + +# Wifi setup information +export SSID=your_ssid +export WIFIPASS=your_pass + +# If doing a headless (i.e. automatic) setup +export HEADLESS_SETUP=true + +# Uncomment if setting up Pushover push notifications +# export pushover_enabled=false +# export pushover_user_key=user_key +# export pushover_app_key=app_key + +# Uncomment and change if you want setup scripts to be pulled +# from a different repo than the "main" github.com/cimryan/teslausb +# export REPO=cimryan + +# Uncomment and change if you want a different branch than master +# export BRANCH=master + +# Uncomment if you're using rsync/ssh for the archive. +# Note: RSYNC_ENABLE=true is going to disable the default archive server. +# +# export RSYNC_ENABLE=true +# export RSYNC_USER= +# export RSYNC_SERVER= +# export RSYNC_PATH= \ No newline at end of file diff --git a/pi-gen-sources/files/wpa_supplicant.conf.sample b/pi-gen-sources/files/wpa_supplicant.conf.sample new file mode 100644 index 0000000..6d8faca --- /dev/null +++ b/pi-gen-sources/files/wpa_supplicant.conf.sample @@ -0,0 +1,8 @@ +ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev +update_config=1 + +network={ + ssid="TEMPSSID" + psk="TEMPPASS" + key_mgmt=WPA-PSK +}