From e19903bb980aeac8be1cedce4bde19c03532911f Mon Sep 17 00:00:00 2001 From: Satu Koskinen Date: Sat, 22 Oct 2022 15:54:50 +0300 Subject: [PATCH] Reorganize config & script files, set HOME_PATH and SCRIPT_PATH in setup-raspberry-pi.sh --- configuration/setup-raspberry-pi.sh | 68 ---------------- ...tor-config.txt => hydrophonitor-config.txt | 5 +- {configuration => pi-config}/ssh.txt | 0 {configuration => pi-config}/userconf.txt | 0 .../wpa_supplicant.conf | 0 scripts/setup-audio.sh | 2 +- scripts/setup-gps.sh | 2 +- scripts/setup-pressure-depth.sh | 2 +- scripts/setup-raspberry-pi.sh | 81 +++++++++++++++++++ scripts/start-all.sh | 2 +- scripts/start-audio.sh | 5 +- scripts/start-gps.sh | 5 +- scripts/start-pressure-depth.sh | 5 +- 13 files changed, 97 insertions(+), 80 deletions(-) delete mode 100644 configuration/setup-raspberry-pi.sh rename configuration/hydrophonitor-config.txt => hydrophonitor-config.txt (65%) rename {configuration => pi-config}/ssh.txt (100%) rename {configuration => pi-config}/userconf.txt (100%) rename {configuration => pi-config}/wpa_supplicant.conf (100%) create mode 100644 scripts/setup-raspberry-pi.sh diff --git a/configuration/setup-raspberry-pi.sh b/configuration/setup-raspberry-pi.sh deleted file mode 100644 index d9c0867..0000000 --- a/configuration/setup-raspberry-pi.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash - -set -ex - -DIR_PATH=$HOME -BOOT_DIR_PATH=/boot/hydrophonitor - -# Copy the files to DIR_PATH -echo -echo "### Copy files to $DIR_PATH" -echo - -mkdir -p "$DIR_PATH" -cd "$DIR_PATH" -cp -R $BOOT_DIR_PATH/ . - -# Install the Rust toolchain -echo -echo "### Install the Rust toolchain" -echo - -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y -source "$HOME/.cargo/env" - -# Install some developer tools -echo -echo "### Install some developer tools" -echo - -sudo apt-get update && sudo apt-get install -y build-essential python3-pip - -# Setup audio -echo -echo "### Setup audio" -echo - -cd "$DIR_PATH" && sh hydrophonitor/scripts/setup-audio.sh - -# Setup GPS -echo -echo "### Setup GPS" -echo - -cd "$DIR_PATH" && sh hydrophonitor/scripts/setup-gps.sh - -# Setup depth sensor -echo -echo "### Setup depth recording" -echo - -cd "$DIR_PATH" && sh hydrophonitor/scripts/setup-pressure-depth.sh - -# Set up cron job to start the recordings at boot -echo -echo "### Set up a cron job to start the recordings at boot" -echo - -# USER=$(whoami) -CRON_FILE=/etc/crontab -CRON_COMMAND="@reboot root $DIR_PATH/hydrophonitor/scripts/start-all.sh 2>&1 >> $BOOT_DIR_PATH/log.txt" - -# Append command to cron file only if it's not there yet -sudo grep -qxF "$CRON_COMMAND" $CRON_FILE || echo "$CRON_COMMAND" | sudo tee -a $CRON_FILE - -# Reboot -echo -echo "### Setup ready, run 'sudo reboot' to apply all changes" -echo diff --git a/configuration/hydrophonitor-config.txt b/hydrophonitor-config.txt similarity index 65% rename from configuration/hydrophonitor-config.txt rename to hydrophonitor-config.txt index 96eba0f..4628bbd 100644 --- a/configuration/hydrophonitor-config.txt +++ b/hydrophonitor-config.txt @@ -17,5 +17,6 @@ DEPTH_INTERVAL=5 TRY_MOUNT_SSD=true -DEFAULT_BASE_DIR_PATH=/home/pi/recordings -BASE_DIR_PATH=/home/pi/data +HOME_PATH=/home/pi +DEFAULT_OUTPUT_PATH=$HOME_PATH/recordings +OUTPUT_PATH=$HOME_PATH/data diff --git a/configuration/ssh.txt b/pi-config/ssh.txt similarity index 100% rename from configuration/ssh.txt rename to pi-config/ssh.txt diff --git a/configuration/userconf.txt b/pi-config/userconf.txt similarity index 100% rename from configuration/userconf.txt rename to pi-config/userconf.txt diff --git a/configuration/wpa_supplicant.conf b/pi-config/wpa_supplicant.conf similarity index 100% rename from configuration/wpa_supplicant.conf rename to pi-config/wpa_supplicant.conf diff --git a/scripts/setup-audio.sh b/scripts/setup-audio.sh index 99d41f1..48fa92a 100755 --- a/scripts/setup-audio.sh +++ b/scripts/setup-audio.sh @@ -27,4 +27,4 @@ ctl.!default { } EOF -cd hydrophonitor/audio-logger && cargo build --release +cd $HOME/hydrophonitor/audio-logger && cargo build --release diff --git a/scripts/setup-gps.sh b/scripts/setup-gps.sh index af7bff2..f544018 100755 --- a/scripts/setup-gps.sh +++ b/scripts/setup-gps.sh @@ -6,7 +6,7 @@ echo "Setting up GPS recording" sudo apt-get update && sudo apt-get install -y gpsd gpsd-clients -sudo pip install -r /home/pi/hydrophonitor/gps-logger/requirements.txt +sudo pip install -r $HOME/hydrophonitor/gps-logger/requirements.txt sudo systemctl stop gpsd.socket sudo systemctl disable gpsd.socket diff --git a/scripts/setup-pressure-depth.sh b/scripts/setup-pressure-depth.sh index fb71a78..1ffaf04 100644 --- a/scripts/setup-pressure-depth.sh +++ b/scripts/setup-pressure-depth.sh @@ -10,4 +10,4 @@ sudo raspi-config nonint do_i2c 0 # Install packages sudo apt-get update && sudo apt-get install -y i2c-tools python3-pip -sudo pip install -r /home/pi/hydrophonitor/depth-logger/requirements.txt +sudo pip install -r $HOME/hydrophonitor/depth-logger/requirements.txt diff --git a/scripts/setup-raspberry-pi.sh b/scripts/setup-raspberry-pi.sh new file mode 100644 index 0000000..e9ee41e --- /dev/null +++ b/scripts/setup-raspberry-pi.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +set -ex + +DIR_PATH=$HOME +BOOT_DIR_PATH=/boot/hydrophonitor + +echo +echo "### Update file paths in config and start script files" +echo + +# Update hydrophonitor-config.txt HOME_PATH to the current user's home +sudo sed -i "s|^HOME_PATH=.*$|HOME_PATH=$HOME|" $BOOT_DIR_PATH/hydrophonitor_config.txt + +# Update script path in start scripts to the current user's home +sudo sed -i "s|^SCRIPT_PATH=.*$|SCRIPT_PATH=$HOME/hydrophonitor/scripts|" $BOOT_DIR_PATH/scripts/start-all.sh +sudo sed -i "s|^SCRIPT_PATH=.*$|SCRIPT_PATH=$HOME/hydrophonitor/scripts|" $BOOT_DIR_PATH/scripts/start-audio.sh +sudo sed -i "s|^SCRIPT_PATH=.*$|SCRIPT_PATH=$HOME/hydrophonitor/scripts|" $BOOT_DIR_PATH/scripts/start-gps.sh +sudo sed -i "s|^SCRIPT_PATH=.*$|SCRIPT_PATH=$HOME/hydrophonitor/scripts|" $BOOT_DIR_PATH/scripts/start-pressure-depth.sh + +# Copy the files to DIR_PATH +echo +echo "### Copy files to $DIR_PATH" +echo + +mkdir -p "$DIR_PATH" +cd "$DIR_PATH" +cp -R $BOOT_DIR_PATH/ . + +# Install some development tools +echo +echo "### Install some development tools" +echo + +sudo apt-get update && sudo apt-get install -y build-essential python3-pip + +# Install the Rust programming language toolchain +echo +echo "### Install the Rust toolchain" +echo + +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +source "$HOME/.cargo/env" + +# Setup audio +echo +echo "### Setup audio" +echo + +cd "$DIR_PATH" && ./hydrophonitor/scripts/setup-audio.sh + +# Setup GPS +echo +echo "### Setup GPS" +echo + +cd "$DIR_PATH" && ./hydrophonitor/scripts/setup-gps.sh + +# Setup depth sensor +echo +echo "### Setup depth recording" +echo + +cd "$DIR_PATH" && ./hydrophonitor/scripts/setup-pressure-depth.sh + +# Set up cron job to start the recordings at boot +echo +echo "### Set up a cron job to start the recordings at boot" +echo + +# USER=$(whoami) +CRON_FILE=/etc/crontab +CRON_COMMAND="@reboot root $DIR_PATH/hydrophonitor/scripts/start-all.sh 2>&1 > $BOOT_DIR_PATH/$(date +"%Y-%m-%dT%H-%M-%S")-log.txt" + +# Append command to cron file only if it's not there yet +sudo grep -qxF "$CRON_COMMAND" $CRON_FILE || echo "$CRON_COMMAND" | sudo tee -a $CRON_FILE + +# Reboot +echo +echo "### Setup ready, run 'sudo reboot' to apply all changes" +echo diff --git a/scripts/start-all.sh b/scripts/start-all.sh index d6c4c21..cf15194 100755 --- a/scripts/start-all.sh +++ b/scripts/start-all.sh @@ -9,7 +9,7 @@ SCRIPT_PATH=/home/pi/hydrophonitor/scripts $SCRIPT_PATH/export-config-values.sh # Create output directory -OUTPUT_DIR=$BASE_DIR_PATH/$(date +"%Y-%m-%d_%H-%M-%S_output") +OUTPUT_DIR=$OUTPUT_PATH/$(date +"%Y-%m-%d_%H-%M-%S_output") echo "Create output directory $OUTPUT_DIR" mkdir -p "$OUTPUT_DIR"/audio diff --git a/scripts/start-audio.sh b/scripts/start-audio.sh index 8484151..a400bfd 100755 --- a/scripts/start-audio.sh +++ b/scripts/start-audio.sh @@ -3,7 +3,8 @@ set -x # Export the configuration values -/home/pi/hydrophonitor/scripts/export-config-values.sh +SCRIPT_PATH=/home/pi/hydrophonitor/scripts +$SCRIPT_PATH/export-config-values.sh AUDIO_TARGET_EXECUTABLE="audio" @@ -16,4 +17,4 @@ OPTIONS="rec \ --buffer-size 1024 \ alsa" -cd /home/pi/hydrophonitor/audio-logger/target/release && ./$AUDIO_TARGET_EXECUTABLE $OPTIONS +cd $HOME_PATH/hydrophonitor/audio-logger/target/release && ./$AUDIO_TARGET_EXECUTABLE $OPTIONS diff --git a/scripts/start-gps.sh b/scripts/start-gps.sh index 34c4ec0..23f1af8 100755 --- a/scripts/start-gps.sh +++ b/scripts/start-gps.sh @@ -3,8 +3,9 @@ set -x # Export the configuration values -/home/pi/hydrophonitor/scripts/export-config-values.sh +SCRIPT_PATH=/home/pi/hydrophonitor/scripts +$SCRIPT_PATH/export-config-values.sh OPTIONS="--output $OUTPUT_DIR --interval $GPS_INTERVAL" -cd /home/pi/hydrophonitor/gps-logger && python record-gps.py $OPTIONS +cd $HOME_PATH/hydrophonitor/gps-logger && python record-gps.py $OPTIONS diff --git a/scripts/start-pressure-depth.sh b/scripts/start-pressure-depth.sh index 72feb75..44ca6d7 100644 --- a/scripts/start-pressure-depth.sh +++ b/scripts/start-pressure-depth.sh @@ -3,8 +3,9 @@ set -x # Export the configuration values -/home/pi/hydrophonitor/scripts/export-config-values.sh +SCRIPT_PATH=/home/pi/hydrophonitor/scripts +$SCRIPT_PATH/export-config-values.sh OPTIONS="--output $OUTPUT_DIR --interval $DEPTH_INTERVAL" -cd /home/pi/hydrophonitor/depth-logger && python record-depth.py $OPTIONS +cd $HOME_PATH/hydrophonitor/depth-logger && python record-depth.py $OPTIONS