Reorganize config & script files, set HOME_PATH and SCRIPT_PATH in setup-raspberry-pi.sh

This commit is contained in:
Satu Koskinen 2022-10-22 15:54:50 +03:00
parent 81b83f2a14
commit e19903bb98
13 changed files with 97 additions and 80 deletions

View File

@ -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

View File

@ -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

View File

@ -27,4 +27,4 @@ ctl.!default {
}
EOF
cd hydrophonitor/audio-logger && cargo build --release
cd $HOME/hydrophonitor/audio-logger && cargo build --release

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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