mirror of
https://github.com/cimryan/teslausb.git
synced 2026-03-01 04:30:33 +00:00
@@ -83,6 +83,7 @@ Follow the instructions corresponding to the technology you'd like to use to hos
|
|||||||
wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup/pi/setup-teslausb
|
wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup/pi/setup-teslausb
|
||||||
chmod +x setup-teslausb
|
chmod +x setup-teslausb
|
||||||
./setup-teslausb
|
./setup-teslausb
|
||||||
|
/root/configure.sh
|
||||||
```
|
```
|
||||||
1. Run this command:
|
1. Run this command:
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ function configure_archive () {
|
|||||||
mkdir "$archive_path"
|
mkdir "$archive_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local cifs_version="${cifs_version:-3.0}"
|
||||||
|
|
||||||
local credentials_file_path="/root/.teslaCamArchiveCredentials"
|
local credentials_file_path="/root/.teslaCamArchiveCredentials"
|
||||||
echo "username=$shareuser" > "$credentials_file_path"
|
echo "username=$shareuser" > "$credentials_file_path"
|
||||||
echo "password=$sharepassword" >> "$credentials_file_path"
|
echo "password=$sharepassword" >> "$credentials_file_path"
|
||||||
@@ -21,6 +23,6 @@ function configure_archive () {
|
|||||||
echo "Configured the archive."
|
echo "Configured the archive."
|
||||||
}
|
}
|
||||||
|
|
||||||
ARCHIVE_SERVER_IP_ADDRESS="$( /root/bin/get-archiveserver-ip-address.sh )"
|
ARCHIVE_SERVER_IP_ADDRESS="$( $INSTALL_DIR/lookup-ip-address.sh "$archiveserver" )"
|
||||||
|
|
||||||
configure_archive "$ARCHIVE_SERVER_IP_ADDRESS"
|
configure_archive "$ARCHIVE_SERVER_IP_ADDRESS"
|
||||||
@@ -24,7 +24,11 @@ function check_archive_mountable () {
|
|||||||
mkdir "$test_mount_location"
|
mkdir "$test_mount_location"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local tmp_credentials_file_path="/root/.teslaCamArchiveCredentials"
|
local cifs_version="${cifs_version:-3.0}"
|
||||||
|
|
||||||
|
local tmp_credentials_file_path="/tmp/.teslaCamArchiveCredentials"
|
||||||
|
echo "username=$shareuser" > "$tmp_credentials_file_path"
|
||||||
|
echo "password=$sharepassword" >> "$tmp_credentials_file_path"
|
||||||
|
|
||||||
local mount_failed=false
|
local mount_failed=false
|
||||||
mount -t cifs "//$archive_server_ip_address/$sharename" "$test_mount_location" -o "vers=${cifs_version},credentials=${tmp_credentials_file_path},iocharset=utf8,file_mode=0777,dir_mode=0777" || mount_failed=true
|
mount -t cifs "//$archive_server_ip_address/$sharename" "$test_mount_location" -o "vers=${cifs_version},credentials=${tmp_credentials_file_path},iocharset=utf8,file_mode=0777,dir_mode=0777" || mount_failed=true
|
||||||
@@ -40,8 +44,7 @@ function check_archive_mountable () {
|
|||||||
umount "$test_mount_location"
|
umount "$test_mount_location"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ARCHIVE_SERVER_IP_ADDRESS="$( $INSTALL_DIR/lookup-ip-address.sh "$archiveserver" )"
|
||||||
|
|
||||||
check_archive_server_reachable
|
check_archive_server_reachable
|
||||||
|
|
||||||
ARCHIVE_SERVER_IP_ADDRESS="$( /root/bin/get-archiveserver-ip-address.sh )"
|
|
||||||
|
|
||||||
check_archive_mountable "$ARCHIVE_SERVER_IP_ADDRESS"
|
check_archive_mountable "$ARCHIVE_SERVER_IP_ADDRESS"
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash -eu
|
|
||||||
|
|
||||||
echo "$(ping -c 1 -w 1 $archiveserver 2>/dev/null | head -n 1 | grep -o -e "(\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\})" | tr -d '()')"
|
|
||||||
3
run/lookup-ip-address.sh
Normal file
3
run/lookup-ip-address.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash -eu
|
||||||
|
|
||||||
|
echo "$(ping -c 1 -w 1 $1 2>/dev/null | head -n 1 | grep -o -e "(\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\})" | tr -d '()')"
|
||||||
@@ -1,10 +1,19 @@
|
|||||||
#!/bin/bash -eu
|
#!/bin/bash -eu
|
||||||
|
|
||||||
function configure_archive () {
|
function configure_archive () {
|
||||||
echo "Configuring the archive for Rclone..."
|
echo "Configuring rclone archive..."
|
||||||
|
|
||||||
echo "drive=$RCLONE_DRIVE" > /root/.teslaCamRcloneConfig
|
echo "drive=$RCLONE_DRIVE" > /root/.teslaCamRcloneConfig
|
||||||
echo "path=$RCLONE_PATH" >> /root/.teslaCamRcloneConfig
|
echo "path=$RCLONE_PATH" >> /root/.teslaCamRcloneConfig
|
||||||
|
|
||||||
|
if [ ! -L "/root/.config/rclone" ] && [ -e "/root/.config/rclone" ]
|
||||||
|
then
|
||||||
|
echo "Moving rclone configs into /mutable"
|
||||||
|
mv /root/.config/rclone /mutable/configs
|
||||||
|
ln -s /mutable/configs/rclone /root/.config/rclone
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Done"
|
||||||
}
|
}
|
||||||
|
|
||||||
configure_archive
|
configure_archive
|
||||||
@@ -1 +1,18 @@
|
|||||||
#!/bin/bash -eu
|
#!/bin/bash -eu
|
||||||
|
|
||||||
|
function verify_configuration () {
|
||||||
|
echo "Verifying rlcone configuration..."
|
||||||
|
if ! [ -e "/root/.config/rclone/rclone.conf" ]
|
||||||
|
then
|
||||||
|
echo "STOP: rclone config was not found. did you configure rclone correctly?"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! rclone lsd "$RCLONE_DRIVE": | grep -q "$RCLONE_PATH"
|
||||||
|
then
|
||||||
|
echo "STOP: Could not find the $RCLONE_DRIVE:$RCLONE_PATH"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
verify_configuration
|
||||||
@@ -1,16 +1,11 @@
|
|||||||
#!/bin/bash -eu
|
#!/bin/bash -eu
|
||||||
|
|
||||||
function configure_archive () {
|
function configure_archive () {
|
||||||
local archive_server_ip_address="$1"
|
echo "Configuring the rsync archive..."
|
||||||
|
|
||||||
echo "Configuring the archive..."
|
|
||||||
|
|
||||||
echo "Configuring for Rsync..."
|
|
||||||
echo "user=$RSYNC_USER" > /root/.teslaCamRsyncConfig
|
echo "user=$RSYNC_USER" > /root/.teslaCamRsyncConfig
|
||||||
echo "server=$RSYNC_SERVER" >> /root/.teslaCamRsyncConfig
|
echo "server=$RSYNC_SERVER" >> /root/.teslaCamRsyncConfig
|
||||||
echo "path=$RSYNC_PATH" >> /root/.teslaCamRsyncConfig
|
echo "path=$RSYNC_PATH" >> /root/.teslaCamRsyncConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
ARCHIVE_SERVER_IP_ADDRESS="$( /root/bin/get-archiveserver-ip-address.sh )"
|
configure_archive
|
||||||
|
|
||||||
configure_archive "$ARCHIVE_SERVER_IP_ADDRESS"
|
|
||||||
216
setup/pi/configure.sh
Normal file
216
setup/pi/configure.sh
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
#!/bin/bash -eu
|
||||||
|
|
||||||
|
REPO=${REPO:-cimryan}
|
||||||
|
BRANCH=${BRANCH:-master}
|
||||||
|
INSTALL_DIR=${INSTALL_DIR:-/root/bin}
|
||||||
|
|
||||||
|
upgrade=false #TODO: create an option to just refresh the scripts
|
||||||
|
debug_on=false
|
||||||
|
|
||||||
|
function debug() {
|
||||||
|
$debug_on && echo "$1"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
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"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_script () {
|
||||||
|
local local_path="$1"
|
||||||
|
local name="$2"
|
||||||
|
local remote_path="${3:-}"
|
||||||
|
|
||||||
|
echo "Starting download for $local_path/$name"
|
||||||
|
curl -o "$local_path/$name" https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/"$remote_path"/"$name"
|
||||||
|
chmod +x "$local_path/$name"
|
||||||
|
echo "Done"
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_command_line() {
|
||||||
|
echo -n "Parsing command line: "
|
||||||
|
|
||||||
|
local OPTIND=1 # Reset in case getopts has been used previously in the shell.
|
||||||
|
while getopts "du" opt; do
|
||||||
|
case "$opt" in
|
||||||
|
d) debug_on=true
|
||||||
|
;;
|
||||||
|
u) upgrade=true
|
||||||
|
#TODO: just upgrade all the scripts instead building new configs
|
||||||
|
echo "STOP: this option is not yet implemented"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
[ "${1:-}" = "--" ] && shift
|
||||||
|
|
||||||
|
echo "done"
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_rc_local () {
|
||||||
|
local install_home="$1"
|
||||||
|
|
||||||
|
if grep -q archiveloop /etc/rc.local
|
||||||
|
then
|
||||||
|
echo "Skipping rc.local installation"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Configuring /etc/rc.local to run the archive scripts at startup..."
|
||||||
|
echo "#!/bin/bash -eu" > ~/rc.local
|
||||||
|
echo "archiveserver=\"${archiveserver}\"" >> ~/rc.local
|
||||||
|
echo "install_home=\"${install_home}\"" >> ~/rc.local
|
||||||
|
cat << 'EOF' >> ~/rc.local
|
||||||
|
LOGFILE=/tmp/rc.local.log
|
||||||
|
|
||||||
|
function log () {
|
||||||
|
echo "$( date )" >> "$LOGFILE"
|
||||||
|
echo "$1" >> "$LOGFILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
log "Launching archival script..."
|
||||||
|
"$install_home"/archiveloop "$archiveserver" &
|
||||||
|
log "All done"
|
||||||
|
exit 0
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat ~/rc.local > /etc/rc.local
|
||||||
|
rm ~/rc.local
|
||||||
|
echo "Installed rc.local."
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_archive_configs () {
|
||||||
|
echo -n "Checking archive configs: "
|
||||||
|
|
||||||
|
RSYNC_ENABLE="${RSYNC_ENABLE:-false}"
|
||||||
|
RCLONE_ENABLE="${RCLONE_ENABLE:-false}"
|
||||||
|
if [ "$RSYNC_ENABLE" = true ] && [ "$RCLONE_ENABLE" = true ]
|
||||||
|
then
|
||||||
|
echo "STOP: Can't enable rsync and rclone at the same time"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$RSYNC_ENABLE" = true ]
|
||||||
|
then
|
||||||
|
check_variable "RSYNC_USER"
|
||||||
|
check_variable "RSYNC_SERVER"
|
||||||
|
check_variable "RSYNC_PATH"
|
||||||
|
export archiveserver="$RSYNC_SERVER"
|
||||||
|
|
||||||
|
elif [ "$RCLONE_ENABLE" = true ]
|
||||||
|
then
|
||||||
|
check_variable "RCLONE_DRIVE"
|
||||||
|
check_variable "RCLONE_PATH"
|
||||||
|
export archiveserver="8.8.8.8" # since it's a cloud hosted drive we'll just set this to google dns
|
||||||
|
else
|
||||||
|
# default to cifs
|
||||||
|
check_variable "sharename"
|
||||||
|
check_variable "shareuser"
|
||||||
|
check_variable "sharepassword"
|
||||||
|
check_variable "archiveserver"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "done"
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_archive_module () {
|
||||||
|
|
||||||
|
if [ "$RSYNC_ENABLE" = true ]
|
||||||
|
then
|
||||||
|
archive_module="run/rsync_archive"
|
||||||
|
elif [ "$RCLONE_ENABLE" = true ]
|
||||||
|
then
|
||||||
|
archive_module="run/rclone_archive"
|
||||||
|
else
|
||||||
|
archive_module="run/cifs_archive"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $archive_module
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_archive_scripts () {
|
||||||
|
local install_path="$1"
|
||||||
|
local archive_module="$2"
|
||||||
|
|
||||||
|
echo "Installing base archive scripts into $install_path"
|
||||||
|
get_script $install_path archiveloop run
|
||||||
|
get_script $install_path remountfs_rw run
|
||||||
|
get_script $install_path lookup-ip-address.sh run
|
||||||
|
|
||||||
|
echo "Installing archive module scripts ($archive_module)"
|
||||||
|
|
||||||
|
get_script $install_path verify-archive-configuration.sh $archive_module
|
||||||
|
get_script $install_path configure-archive.sh $archive_module
|
||||||
|
get_script $install_path archive-clips.sh $archive_module
|
||||||
|
get_script $install_path connect-archive.sh $archive_module
|
||||||
|
get_script $install_path disconnect-archive.sh $archive_module
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_and_configure_pushover () {
|
||||||
|
if [ ! -z "${pushover_enabled+x}" ]
|
||||||
|
then
|
||||||
|
if [ ! -n "${pushover_user_key+x}" ] || [ ! -n "${pushover_app_key+x}" ]
|
||||||
|
then
|
||||||
|
echo "STOP: You're trying to setup Pushover but didn't provide your User and/or App key."
|
||||||
|
echo "Define the variables like this:"
|
||||||
|
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
|
||||||
|
echo "STOP: You're trying to setup Pushover, but didn't replace the default User and App key values."
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Enabling pushover"
|
||||||
|
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
|
||||||
|
else
|
||||||
|
echo "Pushover not configured."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_pushover_scripts() {
|
||||||
|
local install_path="$1"
|
||||||
|
get_script $install_path send-pushover run
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! [ $(id -u) = 0 ]
|
||||||
|
then
|
||||||
|
echo "STOP: Run sudo -i."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -e "$INSTALL_DIR" ]
|
||||||
|
then
|
||||||
|
mkdir "$INSTALL_DIR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
parse_command_line "$@"
|
||||||
|
debug "Getting files from $REPO:$BRANCH"
|
||||||
|
debug "- debug mode = $debug_on"
|
||||||
|
debug "- upgrade only = $upgrade"
|
||||||
|
|
||||||
|
check_and_configure_pushover
|
||||||
|
install_pushover_scripts "$INSTALL_DIR"
|
||||||
|
|
||||||
|
check_archive_configs
|
||||||
|
|
||||||
|
archive_module="$( get_archive_module )"
|
||||||
|
debug "Archive module: $archive_module"
|
||||||
|
|
||||||
|
install_archive_scripts $INSTALL_DIR $archive_module
|
||||||
|
"$INSTALL_DIR"/verify-archive-configuration.sh
|
||||||
|
"$INSTALL_DIR"/configure-archive.sh
|
||||||
|
|
||||||
|
install_rc_local "$INSTALL_DIR"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,8 +1,19 @@
|
|||||||
#!/bin/bash -eu
|
#!/bin/bash -eu
|
||||||
|
|
||||||
|
function setup_progress () {
|
||||||
|
local setup_logfile=/boot/teslausb-headless-setup.log
|
||||||
|
local headless_setup=${HEADLESS_SETUP:-false}
|
||||||
|
if [ $headless_setup = "true" ]
|
||||||
|
then
|
||||||
|
echo "$( date ) : $1" >> "$setup_logfile"
|
||||||
|
fi
|
||||||
|
echo $1
|
||||||
|
}
|
||||||
|
|
||||||
BACKINGFILES_MOUNTPOINT="$1"
|
BACKINGFILES_MOUNTPOINT="$1"
|
||||||
MUTABLE_MOUNTPOINT="$2"
|
MUTABLE_MOUNTPOINT="$2"
|
||||||
|
|
||||||
|
setup_progress "Checking existing partitions..."
|
||||||
PARTITION_TABLE=$(parted -m /dev/mmcblk0 unit B print)
|
PARTITION_TABLE=$(parted -m /dev/mmcblk0 unit B print)
|
||||||
DISK_LINE=$(echo "$PARTITION_TABLE" | grep -e "^/dev/mmcblk0:")
|
DISK_LINE=$(echo "$PARTITION_TABLE" | grep -e "^/dev/mmcblk0:")
|
||||||
DISK_SIZE=$(echo "$DISK_LINE" | cut -d ":" -f 2 | sed 's/B//' )
|
DISK_SIZE=$(echo "$DISK_LINE" | cut -d ":" -f 2 | sed 's/B//' )
|
||||||
@@ -15,19 +26,21 @@ LAST_BACKINGFILES_PARTITION_DESIRED_BYTE="$(( $DISK_SIZE - (100 * (2 ** 20)) - 1
|
|||||||
|
|
||||||
ORIGINAL_DISK_IDENTIFIER=$( fdisk -l /dev/mmcblk0 | grep -e "^Disk identifier" | sed "s/Disk identifier: 0x//" )
|
ORIGINAL_DISK_IDENTIFIER=$( fdisk -l /dev/mmcblk0 | grep -e "^Disk identifier" | sed "s/Disk identifier: 0x//" )
|
||||||
|
|
||||||
|
setup_progress "Modifying partition table for backing files partition..."
|
||||||
BACKINGFILES_PARTITION_END_SPEC="$(( $LAST_BACKINGFILES_PARTITION_DESIRED_BYTE / 1000000 ))M"
|
BACKINGFILES_PARTITION_END_SPEC="$(( $LAST_BACKINGFILES_PARTITION_DESIRED_BYTE / 1000000 ))M"
|
||||||
parted -a optimal -m /dev/mmcblk0 unit B mkpart primary ext4 "$FIRST_BACKINGFILES_PARTITION_BYTE" "$BACKINGFILES_PARTITION_END_SPEC"
|
parted -a optimal -m /dev/mmcblk0 unit B mkpart primary ext4 "$FIRST_BACKINGFILES_PARTITION_BYTE" "$BACKINGFILES_PARTITION_END_SPEC"
|
||||||
|
|
||||||
LAST_BACKINGFILES_PARTITION_BYTE=$(parted -m /dev/mmcblk0 unit B print | grep -e "^3:" | cut -d ":" -f 3 | sed 's/B//g' )
|
setup_progress "Modifying partition table for mutable (writable) partition for script usage..."
|
||||||
|
MUTABLE_PARTITION_START_SPEC="$BACKINGFILES_PARTITION_END_SPEC"
|
||||||
MUTABLE_PARTITION_START_SPEC="$(( $LAST_BACKINGFILES_PARTITION_BYTE / 1000000 ))M"
|
parted -a optimal -m /dev/mmcblk0 unit B mkpart primary ext4 "$MUTABLE_PARTITION_START_SPEC" 100%
|
||||||
parted -a optimal -m /dev/mmcblk0 unit B mkpart primary ext4 "$MUTABLE_PARTITION_START_SPEC" 100%
|
|
||||||
|
|
||||||
NEW_DISK_IDENTIFIER=$( fdisk -l /dev/mmcblk0 | grep -e "^Disk identifier" | sed "s/Disk identifier: 0x//" )
|
NEW_DISK_IDENTIFIER=$( fdisk -l /dev/mmcblk0 | grep -e "^Disk identifier" | sed "s/Disk identifier: 0x//" )
|
||||||
|
|
||||||
|
setup_progress "Writing updated partitions to fstab and /boot/cmdline.txt"
|
||||||
sed -i "s/${ORIGINAL_DISK_IDENTIFIER}/${NEW_DISK_IDENTIFIER}/g" /etc/fstab
|
sed -i "s/${ORIGINAL_DISK_IDENTIFIER}/${NEW_DISK_IDENTIFIER}/g" /etc/fstab
|
||||||
sed -i "s/${ORIGINAL_DISK_IDENTIFIER}/${NEW_DISK_IDENTIFIER}/" /boot/cmdline.txt
|
sed -i "s/${ORIGINAL_DISK_IDENTIFIER}/${NEW_DISK_IDENTIFIER}/" /boot/cmdline.txt
|
||||||
|
|
||||||
|
setup_progress "Formatting new partitions..."
|
||||||
mkfs.ext4 -F /dev/mmcblk0p3
|
mkfs.ext4 -F /dev/mmcblk0p3
|
||||||
mkfs.ext4 -F /dev/mmcblk0p4
|
mkfs.ext4 -F /dev/mmcblk0p4
|
||||||
|
|
||||||
|
|||||||
@@ -33,25 +33,19 @@ if [ ! -e "/mutable/etc" ]
|
|||||||
then
|
then
|
||||||
mkdir -p /mutable/etc
|
mkdir -p /mutable/etc
|
||||||
fi
|
fi
|
||||||
if [ -e "/etc/fake-hwclock.data" ]
|
|
||||||
|
if [ ! -L "/etc/fake-hwclock.data" ] && [ -e "/etc/fake-hwclock.data" ]
|
||||||
then
|
then
|
||||||
echo "Moving fake-hwclock data"
|
echo "Moving fake-hwclock data"
|
||||||
cp /etc/fake-hwclock.data /mutable/etc/fake-hwclock.data
|
mv /etc/fake-hwclock.data /mutable/etc/fake-hwclock.data
|
||||||
rm /etc/fake-hwclock.data
|
|
||||||
ln -s /mutable/etc/fake-hwclock.data /etc/fake-hwclock.data
|
ln -s /mutable/etc/fake-hwclock.data /etc/fake-hwclock.data
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Move rclone configs if it exists so we can write to it
|
# Create a configs directory for others to use
|
||||||
if [ ! -e "/mutable/configs" ]
|
if [ ! -e "/mutable/configs" ]
|
||||||
then
|
then
|
||||||
mkdir -p /mutable/configs
|
mkdir -p /mutable/configs
|
||||||
fi
|
fi
|
||||||
if [ -e "/root/.config/rclone/rclone.conf" ]
|
|
||||||
then
|
|
||||||
echo "Moving rclone configs"
|
|
||||||
mv /root/.config/rclone /mutable/configs
|
|
||||||
ln -s /mutable/configs/rclone /root/.config/rclone
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Move /var/spool to /tmp
|
# Move /var/spool to /tmp
|
||||||
rm -rf /var/spool
|
rm -rf /var/spool
|
||||||
@@ -61,8 +55,7 @@ ln -s /tmp /var/spool
|
|||||||
sed -i "s/spool\s*0755/spool 1777/g" /usr/lib/tmpfiles.d/var.conf >/dev/null
|
sed -i "s/spool\s*0755/spool 1777/g" /usr/lib/tmpfiles.d/var.conf >/dev/null
|
||||||
|
|
||||||
# Move dhcpd.resolv.conf to tmpfs
|
# Move dhcpd.resolv.conf to tmpfs
|
||||||
touch /tmp/dhcpcd.resolv.conf
|
mv /etc/resolv.conf /tmp/dhcpcd.resolv.conf
|
||||||
rm /etc/resolv.conf
|
|
||||||
ln -s /tmp/dhcpcd.resolv.conf /etc/resolv.conf
|
ln -s /tmp/dhcpcd.resolv.conf /etc/resolv.conf
|
||||||
|
|
||||||
# Update /etc/fstab
|
# Update /etc/fstab
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
#!/bin/bash -eu
|
#!/bin/bash -eu
|
||||||
|
|
||||||
USER_ENABLED_PUSHOVER=${USER_ENABLED_PUSHOVER:-false}
|
|
||||||
SETUP_LOGFILE=/boot/teslausb-headless-setup.log
|
|
||||||
REPO=${REPO:-cimryan}
|
REPO=${REPO:-cimryan}
|
||||||
BRANCH=${BRANCH:-master}
|
BRANCH=${BRANCH:-master}
|
||||||
HEADLESS_SETUP=${HEADLESS_SETUP:-false}
|
HEADLESS_SETUP=${HEADLESS_SETUP:-false}
|
||||||
USE_LED_FOR_SETUP_PROGRESS=true
|
USE_LED_FOR_SETUP_PROGRESS=true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ! [ $(id -u) = 0 ]
|
if ! [ $(id -u) = 0 ]
|
||||||
then
|
then
|
||||||
setup_progress "STOP: Run sudo -i."
|
setup_progress "STOP: Run sudo -i."
|
||||||
@@ -16,9 +13,10 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
function setup_progress () {
|
function setup_progress () {
|
||||||
|
local setup_logfile=/boot/teslausb-headless-setup.log
|
||||||
if [ $HEADLESS_SETUP = "true" ]
|
if [ $HEADLESS_SETUP = "true" ]
|
||||||
then
|
then
|
||||||
echo "$( date ) : $1" >> "$SETUP_LOGFILE"
|
echo "$( date ) : $1" >> "$setup_logfile"
|
||||||
fi
|
fi
|
||||||
echo $1
|
echo $1
|
||||||
}
|
}
|
||||||
@@ -90,66 +88,6 @@ function check_variable () {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_pushover_enabled () {
|
|
||||||
if [ ! -z "${pushover_enabled+x}" ]
|
|
||||||
then
|
|
||||||
if [ ! -n "${pushover_user_key+x}" ] || [ ! -n "${pushover_app_key+x}" ]
|
|
||||||
then
|
|
||||||
setup_progress "STOP: You're trying to setup Pushover but didn't provide your User and/or App key."
|
|
||||||
setup_progress "Define the variables like this:"
|
|
||||||
setup_progress "export pushover_user_key=put_your_userkey_here"
|
|
||||||
setup_progress "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
|
|
||||||
setup_progress "STOP: You're trying to setup Pushover, but didn't replace the default User and App key values."
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
USER_ENABLED_PUSHOVER=true
|
|
||||||
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
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_archive_configs () {
|
|
||||||
|
|
||||||
RSYNC_ENABLE="${RSYNC_ENABLE:-false}"
|
|
||||||
RCLONE_ENABLE="${RCLONE_ENABLE:-false}"
|
|
||||||
|
|
||||||
if [ "$RSYNC_ENABLE" = true ] && [ "$RCLONE_ENABLE" = true ]
|
|
||||||
then
|
|
||||||
setup_progress "STOP: Cannot enable rsync and rclone at the same time"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$RSYNC_ENABLE" = true ]
|
|
||||||
then
|
|
||||||
check_variable "RSYNC_USER"
|
|
||||||
check_variable "RSYNC_SERVER"
|
|
||||||
export archiveserver="$RSYNC_SERVER"
|
|
||||||
check_variable "RSYNC_PATH"
|
|
||||||
export archive_module="run/rsync_archive"
|
|
||||||
elif [ "$RCLONE_ENABLE" = true ]
|
|
||||||
then
|
|
||||||
check_variable "RCLONE_DRIVE"
|
|
||||||
check_variable "RCLONE_PATH"
|
|
||||||
# since it's a cloud hosted drive we'll just set this to google dns
|
|
||||||
export archiveserver="8.8.8.8"
|
|
||||||
export archive_module="run/rclone_archive"
|
|
||||||
else # Else for now, TODO allow both for more redundancy?
|
|
||||||
check_variable "sharename"
|
|
||||||
check_variable "shareuser"
|
|
||||||
check_variable "sharepassword"
|
|
||||||
|
|
||||||
export cifs_version="${cifs_version:-3.0}"
|
|
||||||
export archive_module="run/cifs_archive"
|
|
||||||
fi
|
|
||||||
|
|
||||||
check_variable "archiveserver"
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_available_space () {
|
function check_available_space () {
|
||||||
setup_progress "Verifying that there is sufficient space available on the MicroSD card..."
|
setup_progress "Verifying that there is sufficient space available on the MicroSD card..."
|
||||||
|
|
||||||
@@ -179,6 +117,7 @@ function get_ancillary_setup_scripts () {
|
|||||||
get_script /tmp create-backingfiles-partition.sh setup/pi
|
get_script /tmp create-backingfiles-partition.sh setup/pi
|
||||||
get_script /tmp create-backingfiles.sh setup/pi
|
get_script /tmp create-backingfiles.sh setup/pi
|
||||||
get_script /tmp make-root-fs-readonly.sh setup/pi
|
get_script /tmp make-root-fs-readonly.sh setup/pi
|
||||||
|
get_script /root configure.sh setup/pi
|
||||||
}
|
}
|
||||||
|
|
||||||
function fix_cmdline_txt_modules_load ()
|
function fix_cmdline_txt_modules_load ()
|
||||||
@@ -206,6 +145,7 @@ function create_usb_drive_backing_files () {
|
|||||||
|
|
||||||
if [ ! -e /dev/mmcblk0p3 ]
|
if [ ! -e /dev/mmcblk0p3 ]
|
||||||
then
|
then
|
||||||
|
setup_progress "Starting to create backing files partition..."
|
||||||
/tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT" "$MUTABLE_MOUNTPOINT"
|
/tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT" "$MUTABLE_MOUNTPOINT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -223,59 +163,6 @@ function create_usb_drive_backing_files () {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function configure_archive_scripts () {
|
|
||||||
setup_progress "Configuring the archive scripts..."
|
|
||||||
|
|
||||||
get_script /root/bin archiveloop run
|
|
||||||
get_script /root/bin remountfs_rw run
|
|
||||||
|
|
||||||
setup_progress "Configured the archive scripts."
|
|
||||||
}
|
|
||||||
|
|
||||||
function install_archive_scripts () {
|
|
||||||
check_variable "archive_module"
|
|
||||||
setup_progress "Installing scripts for archive module: $archive_module"
|
|
||||||
|
|
||||||
local install_path="/root/bin"
|
|
||||||
get_script $install_path verify-archive-configuration.sh $archive_module
|
|
||||||
get_script $install_path configure-archive.sh $archive_module
|
|
||||||
get_script $install_path archive-clips.sh $archive_module
|
|
||||||
get_script $install_path connect-archive.sh $archive_module
|
|
||||||
get_script $install_path disconnect-archive.sh $archive_module
|
|
||||||
}
|
|
||||||
|
|
||||||
function configure_pushover_scripts() {
|
|
||||||
get_script /root/bin send-pushover run
|
|
||||||
}
|
|
||||||
|
|
||||||
function configure_rc_local () {
|
|
||||||
if grep -q archiveloop /etc/rc.local
|
|
||||||
then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
setup_progress "Configuring /etc/rc.local to run the archive scripts at startup..."
|
|
||||||
echo "#!/bin/bash -eu" > ~/rc.local
|
|
||||||
echo "archiveserver=\"${archiveserver}\"" >> ~/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 "$archiveserver" &
|
|
||||||
log "All done"
|
|
||||||
exit 0
|
|
||||||
EOF
|
|
||||||
|
|
||||||
cat ~/rc.local > /etc/rc.local
|
|
||||||
rm ~/rc.local
|
|
||||||
setup_progress "Configured rc.local."
|
|
||||||
}
|
|
||||||
|
|
||||||
function configure_hostname () {
|
function configure_hostname () {
|
||||||
# Headless image already has hostname set
|
# Headless image already has hostname set
|
||||||
if [ ! $HEADLESS_SETUP = "true" ]
|
if [ ! $HEADLESS_SETUP = "true" ]
|
||||||
@@ -285,10 +172,12 @@ function configure_hostname () {
|
|||||||
local new_host_name="teslausb"
|
local new_host_name="teslausb"
|
||||||
cp /etc/hosts ~
|
cp /etc/hosts ~
|
||||||
sed "s/raspberrypi/$new_host_name/g" ~/hosts > /etc/hosts
|
sed "s/raspberrypi/$new_host_name/g" ~/hosts > /etc/hosts
|
||||||
|
rm ~/hosts
|
||||||
|
|
||||||
cp /etc/hostname ~
|
cp /etc/hostname ~
|
||||||
sed "s/raspberrypi/$new_host_name/g" ~/hostname > /etc/hostname
|
sed "s/raspberrypi/$new_host_name/g" ~/hostname > /etc/hostname
|
||||||
setup_progress "Configured the hostname."
|
setup_progress "Configured the hostname."
|
||||||
|
rm ~/hostname
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,35 +196,18 @@ headless_setup_progress_flash 1
|
|||||||
setup_progress "Verifying environment variables..."
|
setup_progress "Verifying environment variables..."
|
||||||
|
|
||||||
check_variable "campercent"
|
check_variable "campercent"
|
||||||
check_archive_configs
|
|
||||||
check_pushover_enabled
|
|
||||||
|
|
||||||
# Flash for Stage 3 headless (grab scripts)
|
# Flash for Stage 3 headless (grab scripts)
|
||||||
headless_setup_progress_flash 2
|
headless_setup_progress_flash 2
|
||||||
|
|
||||||
setup_progress "Downloading additional setup scripts."
|
setup_progress "Downloading additional setup scripts."
|
||||||
|
|
||||||
if [ ! -e /root/bin ]
|
|
||||||
then
|
|
||||||
mkdir /root/bin
|
|
||||||
fi
|
|
||||||
|
|
||||||
get_script /root/bin get-archiveserver-ip-address.sh run
|
|
||||||
|
|
||||||
install_archive_scripts
|
|
||||||
/root/bin/configure-archive.sh
|
|
||||||
/root/bin/verify-archive-configuration.sh
|
|
||||||
|
|
||||||
check_available_space
|
check_available_space
|
||||||
|
|
||||||
get_ancillary_setup_scripts
|
get_ancillary_setup_scripts
|
||||||
|
|
||||||
pushd ~
|
pushd ~
|
||||||
|
|
||||||
configure_archive_scripts
|
|
||||||
|
|
||||||
configure_pushover_scripts
|
|
||||||
|
|
||||||
fix_cmdline_txt_modules_load
|
fix_cmdline_txt_modules_load
|
||||||
|
|
||||||
echo "" >> /etc/fstab
|
echo "" >> /etc/fstab
|
||||||
@@ -345,8 +217,6 @@ headless_setup_progress_flash 3
|
|||||||
|
|
||||||
create_usb_drive_backing_files
|
create_usb_drive_backing_files
|
||||||
|
|
||||||
configure_rc_local
|
|
||||||
|
|
||||||
configure_hostname
|
configure_hostname
|
||||||
|
|
||||||
# Flash for stage 5 headless (Mark success, FS readonly)
|
# Flash for stage 5 headless (Mark success, FS readonly)
|
||||||
|
|||||||
Reference in New Issue
Block a user