diff --git a/headless-scripts/setup-piForHeadlessBuild.sh b/headless-scripts/setup-piForHeadlessBuild.sh deleted file mode 100755 index 3dcc0df..0000000 --- a/headless-scripts/setup-piForHeadlessBuild.sh +++ /dev/null @@ -1,252 +0,0 @@ -#/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" -RED='\033[0;31m' # Red for warning -NC='\033[0m' # No Color -GREEN='\033[0;32m' -scripts_downloaded=false -REPO=rtgoodwin -BRANCH=headless-patch - -function stop_message () { - echo -e "${RED}${1} ${NC}" -} - -function good_message () { - echo -e "${GREEN}${1} ${NC}" -} - -function show_setup_var_instructions () { - - stop_message 'STOP: You need to specify your setup variables first. Create the file "teslausb_setup_variables.conf" with: ' - echo "" - echo ' export archiveserver=Nautilus' - echo ' export sharename=SailfishCam' - echo ' export shareuser=sailfish' - echo ' export sharepassword=pa$$w0rd' - echo ' export campercent=100' - echo "" - echo "Be sure to replace the values with your relevant choices." - exit 1 - -} - -function verify_file_exists () { - local file_name="$1" - local expected_path="$2" - - if [ ! -e "$expected_path/$file_name" ] - then - stop_message "STOP: Didn't find $file_name at $expected_path." - exit 1 - fi -} - -function verify_setup_file_exists () { - local file_name="$1" - - if [ -e "$file_name" ] - then - good_message "Downloaded $file_name." - else - stop_message "STOP: Didn't find downloaded script $file_name. Try running the setup script again." - exit 1 - fi -} - -function verify_wifi_variables () { - if [ ! -n "${SSID+x}" ] || [ ! -n "${WIFIPASS+x}" ] - then - stop_message '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 -} - -function verify_setup_variables_file_exists () { - local file_name="$1" - local expected_path="$2" - - if [ ! -e "$expected_path/$file_name" ] - then - show_setup_var_instructions - exit 1 - fi -} - -function verify_setup_variables () { - if [ ! -n "${archiveserver+x}" ] - then - show_setup_var_instructions - fi -} - -function verify_pushover_variables () { - if [ ! -z "${pushover_enabled+x}" ] - then - if [ ! -n "${pushover_user_key+x}" ] || [ ! -n "${pushover_app_key+x}" ] - then - stop_message "STOP: You're trying to setup Pushover but didn't provide your User and/or App key." - echo 'Define the variables in "teslausb_setup_variables.conf" like this:' - echo "" - echo " export pushover_user_key=put_your_userkey_here" - echo " export pushover_app_key=put_your_appkey_here" - exit 1 - elif [ "${pushover_user_key}" = "put_your_userkey_here" ] || [ "${pushover_app_key}" = "put_your_appkey_here" ] - then - stop_message "STOP: You're trying to setup Pushover, but didn't replace the default User and App key values." - echo 'Replace the default values in "teslausb_setup_variables.conf".' - exit 1 - else - user_enabled_pushover=true - echo "export pushover_enabled=true" > $BOOT_DIR/.teslaCamPushoverCredentials - echo "export pushover_user_key=$pushover_user_key" >> $BOOT_DIR/.teslaCamPushoverCredentials - echo "export pushover_app_key=$pushover_app_key" >> $BOOT_DIR/.teslaCamPushoverCredentials - fi - fi -} - -function download_scripts () { - - if [ ! -d "${BOOT_DIR}/teslausb_setup_scripts" ] - then - mkdir "${BOOT_DIR}/teslausb_setup_scripts" - # stop_message "ERROR: Failed to make teslausb_setup_scripts and download setup scripts. Ensure you have internet access and run this script again." - fi - cd "${BOOT_DIR}/teslausb_setup_scripts" - curl -s -o setup-teslausb-headless https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/headless-scripts/setup-teslausb-headless - verify_setup_file_exists "setup-teslausb-headless" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x setup-teslausb-headless - good_message "Downloaded main setup script." - - curl -s -o archiveloop https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archiveloop - # sed s/ARCHIVE_HOST_NAME=archiveserver/ARCHIVE_HOST_NAME=$archiveserver/ ~/archiveloop > /root/bin/archiveloop - sed -i'.bak' -e "s/ARCHIVE_HOST_NAME=archiveserver/ARCHIVE_HOST_NAME=$archiveserver/" archiveloop - verify_setup_file_exists "archiveloop" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x archiveloop - - curl -s -o archive-teslacam-clips https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-teslacam-clips - verify_setup_file_exists "archive-teslacam-clips" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x archive-teslacam-clips - good_message "Configured the archive scripts." - - curl -s -o remountfs_rw https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/remountfs_rw - verify_setup_file_exists "remountfs_rw" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x remountfs_rw - good_message "Downloaded script to remount filesystems read/write if needed (/root/bin/remountfs_rw)." - - if [ ${user_enabled_pushover} = "true" ] - then - curl -s -o send-pushover https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/send-pushover - verify_setup_file_exists "remountfs_rw" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x send-pushover - good_message "Downloaded Pushover notification script." - fi - - good_message "Downloading ancillary setup scripts." - curl -s -o create-backingfiles-partition.sh https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh - verify_setup_file_exists "create-backingfiles-partition.sh" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x create-backingfiles-partition.sh - curl -s -o create-backingfiles.sh https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh - verify_setup_file_exists "create-backingfiles.sh" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x create-backingfiles.sh - curl -s -o make-root-fs-readonly.sh https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/make-root-fs-readonly.sh - verify_setup_file_exists "make-root-fs-readonly.sh" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x make-root-fs-readonly.sh - cd - - good_message "All scripts downloaded and configured." - -} - -verify_file_exists "cmdline.txt" "$BOOT_DIR" -verify_file_exists "config.txt" "$BOOT_DIR" -verify_setup_variables_file_exists "teslausb_setup_variables.conf" "$BOOT_DIR" - -source "$BOOT_DIR"/teslausb_setup_variables.conf - -verify_wifi_variables -verify_setup_variables -verify_pushover_variables - -CMDLINE_TXT_PATH="$BOOT_DIR/cmdline.txt" -CONFIG_TXT_PATH="$BOOT_DIR/config.txt" - -if ! grep -q "dtoverlay=dwc2" $CONFIG_TXT_PATH -then - good_message "Updating $CONFIG_TXT_PATH ..." - echo "" >> "$CONFIG_TXT_PATH" - echo "dtoverlay=dwc2" >> "$CONFIG_TXT_PATH" -else - good_message "config.txt already contains the required dwc2 module" -fi - -if ! grep -q "dwc2,g_ether" $CMDLINE_TXT_PATH -then - echo "Updating $CMDLINE_TXT_PATH ..." - sed -i'.bak' -e "s/rootwait/rootwait modules-load=dwc2,g_ether/" -e "s@ init=/usr/lib/raspi-config/init_resize.sh@@" "$CMDLINE_TXT_PATH" -else - good_message "cmdline.txt already updated with modules and removed initial resize script." -fi - -if [ ! -e "$BOOT_DIR/ssh" ] -then - good_message "Ensuring SSH is setup..." - touch "$BOOT_DIR/ssh" -fi - -# Sets up wifi credentials so wifi will be -# auto configured on first boot - -WPA_SUPPLICANT_CONF_PATH="$BOOT_DIR/wpa_supplicant.conf" - -good_message "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 - -good_message "Downloading setup scripts. They will be downloaded to ${BOOT_DIR}/teslausb_setup_scripts," -good_message "and moved to /root/teslausb_setup_scripts during first boot and install." - -download_scripts - -echo "" -good_message '-- Files updated and ready for headless setup --' -echo '' -echo 'You can now insert your SD card into the Pi for headless setup. Plug in power to the Pi and it will boot and run.' -echo "When done (this may take a vew minutes), the Pi should be available over SSH as pi@teslausb.local." -echo "It's recommended you have your Pi plugged into a PC USB port for power, and connected to the port labeled USB on the Pi." -echo "That way, when setup is complete, you should see your CAM and/or MUSIC drives appear as confirmation." -echo "" diff --git a/headless-scripts/setup-teslausb-headless b/headless-scripts/setup-teslausb-headless deleted file mode 100644 index 8c8112f..0000000 --- a/headless-scripts/setup-teslausb-headless +++ /dev/null @@ -1,284 +0,0 @@ -#!/bin/bash -eu - -REPO=rtgoodwin -BRANCH="headless-patch" -user_enabled_pushover=false -SETUP_LOGFILE=/boot/teslausb-headless-setup.log -setup_complete=false - -# if ! [ $(id -u) = 0 ] -# then -# echo "STOP: Run sudo -i." -# exit 1 -# fi - -function setup_progress () { - echo "$( date ) : $1" >> "$LOGFILE" -} - -if [ ! -e /boot/TESLAUSB_SETUP_FINISHED ] -then - setup_log "Setting up teslausb functionality" - touch /boot/TESLAUSB_SETUP_STARTED -fi - -function mark_setup_failed () { - setup_log "ERROR: Setup Failed." - touch /boot/TESLAUSB_SETUP_FAILED -} - -function mark_setup_success () { - if [ -e /boot/TESLAUSB_SETUP_FAILED ] - then - rm /boot/TESLAUSB_SETUP_FAILED - fi - rm /boot/TESLAUSB_SETUP_STARTED - touch /boot/TESLAUSB_SETUP_FINISHED - setup_log "Main setup completed. Remounting file systems read only." -} - -function check_variable () { - local var_name="$1" - if [ -z "${!var_name+x}" ] - then - echo "STOP: Define the variable $var_name like this: export $var_name=value" - setup_log "SETUP FAILED: Define the variable $var_name as export $var_name=value in /boot/teslausb_setup_variables.conf" - /etc/stage_flash 10 - exit 1 - fi -} - -function check_pushover_enabled () { - if [ ! -z "${pushover_enabled+x}" ] - then - setup_log "Adding Pushover variables into /root/.teslaCamPushoverCredentials" - echo "export pushover_enabled=true" > /root/.teslaCamPushoverCredentials - echo "export pushover_user_key=$pushover_user_key" >> /root/.teslaCamPushoverCredentials - echo "export pushover_app_key=$pushover_app_key" >> /root/.teslaCamPushoverCredentials - fi -} - -function check_archive_server_reachable () { - setup_log "Verifying that the archive server $archiveserver is reachable..." - local serverunreachable=false - ping -c 1 -w 1 "$archiveserver" 1>/dev/null 2>&1 || serverunreachable=true - - if [ "$serverunreachable" = true ] - then - setup_log "WARNING: The archive server $archiveserver is unreachable. Try specifying its IP address instead." - setup_log "Continuing setup, but you may need to edit /etc/fstab to verify your archive mount entry is correct" - fi - - # echo "The archive server is reachable." -} - -function check_available_space () { - setup_log "Verifying that there is sufficient space available on the MicroSD card..." - - local available_space="$( parted -m /dev/mmcblk0 u b print free | tail -1 | cut -d ":" -f 4 | sed 's/B//g' )" - - if [ "$available_space" -lt 4294967296 ] - then - setup_log "ERROR: The MicroSD card is too small. Stopping setup." - /etc/stage_flash 10 - exit 1 - fi - - setup_log "There is sufficient space available." -} - -# function get_ancillary_setup_scripts () { -# pushd -# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh -# chmod +x ./create-backingfiles-partition.sh -# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh -# chmod +x ./create-backingfiles.sh -# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/make-root-fs-readonly.sh -# chmod +x ./make-root-fs-readonly.sh -# popd -# } - -function fix_cmdline_txt_modules_load () -{ - setup_log "Fixing the modules-load parameter in /boot/cmdline.txt..." - cp /boot/cmdline.txt ~ - cat ~/cmdline.txt | sed 's/[[:space:]]\+modules-load=[^ [:space:]]\+//' | sed 's/rootwait/rootwait modules-load=dwc2/' > /boot/cmdline.txt - rm ~/cmdline.txt - setup_log "Fixed cmdline.txt." -} - -BACKINGFILES_MOUNTPOINT=/backingfiles - -function create_usb_drive_backing_files () { - mkdir "$BACKINGFILES_MOUNTPOINT" - /root/bin/tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT" - - setup_log "Mounting the partition for the backing files..." - mount /backingfiles - setup_log "Mounted the partition for the backing files." - - /root/bin/tmp/create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT" -} - -function configure_archive () { - setup_log "Configuring the archive..." - mkdir /mnt/archive - local archive_server_ip_address="$(ping -c 1 -w 1 $archiveserver 2>/dev/null | head -n 1 | grep -o -e "(\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\})" | tr -d '()')" - echo "//$archive_server_ip_address/$sharename /mnt/archive cifs credentials=/root/.teslaCamArchiveCredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0" >> /etc/fstab - - echo "username=$shareuser" > /root/.teslaCamArchiveCredentials - echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials - setup_log "Configured the archive." -} - -# function configure_archive_scripts () { -# echo "Configuring the archive scripts..." -# mkdir /root/bin - -# pushd ~ -# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archiveloop -# sed s/ARCHIVE_HOST_NAME=archiveserver/ARCHIVE_HOST_NAME=$archiveserver/ ~/archiveloop > /root/bin/archiveloop -# rm ~/archiveloop -# chmod +x /root/bin/archiveloop -# popd - -# pushd /root/bin -# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-teslacam-clips -# chmod +x archive-teslacam-clips -# popd -# echo "Configured the archive scripts." - -# pushd /root -# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/remountfs_rw -# chmod +x remountfs_rw -# popd -# echo "Downloaded script to remount filesystems read/write if needed (/root/remountfs_rw)." -# } - - -# function configure_pushover_scripts() { -# if [ ${user_enabled_pushover} = "true" ] -# then -# pushd /root/bin -# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/send-pushover -# chmod +x send-pushover -# popd -# fi -# } - -function configure_rc_local () { - setup_log "Configuring /etc/rc.local to run the archive scripts at startup..." - echo "#!/bin/bash -eu" > ~/rc.local - tail -n +2 /etc/rc.local | sed '$d' >> ~/rc.local -cat << 'EOF' >> ~/rc.local -LOGFILE=/tmp/rc.local.log - -function log () { - echo "$( date )" >> "$LOGFILE" - echo "$1" >> "$LOGFILE" -} - -log "Launching archival script..." -/root/bin/archiveloop & -log "All done" -exit 0 -EOF - - cat ~/rc.local > /etc/rc.local - rm ~/rc.local - setup_log "Configured rc.local." -} - -# function configure_hostname () { -# setup_log "Configuring the hostname..." - -# local new_host_name="teslausb" -# cp /etc/hosts ~ -# sed "s/raspberrypi/$new_host_name/g" ~/hosts > /etc/hosts - -# cp /etc/hostname ~ -# sed "s/raspberrypi/$new_host_name/g" ~/hostname > /etc/hostname -# setup_log "Configured the hostname." -# } - -function make_root_fs_readonly () { - /root/bin/tmp/make-root-fs-readonly.sh -} - -# TURN OFF LED so we can start watching progress -echo 1 | sudo tee /sys/class/leds/led0/brightness - -sleep 5 - -# SETUP STAGE 1 - Check variables file - -/etc/stage_flash 1 - -# setup_log "SETUP STAGE 1: Check variables file." -# if [ ! -e /boot/teslausb_setup_variables.conf ] -# then -# setup_log "ERROR: teslausb_setup_variables.conf file not found. Can't continue setup." -# /etc/stage_flash 10 -# exit 1 -# fi - -source /boot/teslausb_setup_variables.conf - -# SETUP STAGE 2 - Validate variables. This should never fail but just in case. -/etc/stage_flash 2 - -setup_log "SETUP STAGE 2: Verifying environment variables..." - -check_variable "archiveserver" -check_variable "sharename" -check_variable "shareuser" -check_variable "sharepassword" -check_variable "campercent" - -check_pushover_enabled - -check_archive_server_reachable - -# SETUP STAGE 3 - -setup_log "SETUP STAGE 3: Check available space." -/etc/stage_flash 3 -check_available_space - -# get_ancillary_setup_scripts - -# pushd ~ - -# configure_archive_scripts - -# configure_pushover_scripts - -fix_cmdline_txt_modules_load - -echo "" >> /etc/fstab - -# SETUP STAGE 4 -setup_log "SETUP STAGE 4: Create backing files and final config changes." -/etc/stage_flash 4 - -create_usb_drive_backing_files - -configure_archive - -configure_rc_local - -# configure_hostname - -# SETUP STAGE 5 and reboot -# If you see 5 flashes we are probably good! - -setup_log "SETUP STAGE 5: Marking successful and making filesystem readonly." -/etc/stage_flash 5 -mark_setup_success - -make_root_fs_readonly -# echo 0 | sudo tee /sys/class/leds/led0/brightness -setup_log "Filesystems made read-only. Rebooting." - -reboot - diff --git a/headless-scripts/teslausb_setup_variables.conf.sample b/headless-scripts/teslausb_setup_variables.conf.sample index aae9f34..5340683 100644 --- a/headless-scripts/teslausb_setup_variables.conf.sample +++ b/headless-scripts/teslausb_setup_variables.conf.sample @@ -5,6 +5,9 @@ export sharepassword=password export campercent=100 export SSID=your_ssid export WIFIPASS=your_pass +export HEADLESS_SETUP=true +# export REPO=cimryan +# export BRANCH=master # export pushover_enabled=false # export pushover_user_key=user_key # export pushover_app_key=app_key \ No newline at end of file