From 75ed68ed47d02d7f4c39200371405877821313ad Mon Sep 17 00:00:00 2001 From: Yinyin Liu Date: Wed, 12 Nov 2025 10:16:49 +0100 Subject: [PATCH] Added SodistoreHome Raspberry PI Setup Files --- .../SodistoreHomeSetup/install_release.sh | 131 ++++++++++++++++++ .../setup_OS_Customization_and_VPN.sh | 125 +++++++++++++++++ 2 files changed, 256 insertions(+) create mode 100755 firmware/SodistoreHome/SodistoreHomeSetup/install_release.sh create mode 100644 firmware/SodistoreHome/SodistoreHomeSetup/setup_OS_Customization_and_VPN.sh diff --git a/firmware/SodistoreHome/SodistoreHomeSetup/install_release.sh b/firmware/SodistoreHome/SodistoreHomeSetup/install_release.sh new file mode 100755 index 000000000..683a0a4cf --- /dev/null +++ b/firmware/SodistoreHome/SodistoreHomeSetup/install_release.sh @@ -0,0 +1,131 @@ +#!/bin/bash +set -euo pipefail + +# === Settings === +SERVER="91.92.155.224" +REMOTE_PATH="/home/ubuntu/Sodistorehome/release-package.tar.gz" + +TARGET_DIR="$HOME/SodiStoreHome" +SCRIPT_DIR="$TARGET_DIR/scripts" +MODPOLL_DIR="$TARGET_DIR/ModpollDir" + +# Change this if your config file has a different name (e.g., config.json, config.yaml, etc.) +CONFIG_FILE="config.json" + +SERVICE_NAME="SodiStoreHome.service" +SERVICE_PATH="/etc/systemd/system/$SERVICE_NAME" + +echo "📦 Downloading release package from server..." +mkdir -p "$TARGET_DIR" +scp -i ~/.ssh/InnovEnergy.pem.priv "ubuntu@$SERVER:$REMOTE_PATH" "$TARGET_DIR/release-package.tar.gz" + +echo "📂 Extracting package..." +tar -xzf "$TARGET_DIR/release-package.tar.gz" -C "$TARGET_DIR" + +echo "📁 Ensuring directories exist..." +mkdir -p "$SCRIPT_DIR" "$MODPOLL_DIR" \ + "$TARGET_DIR/csvFile" "$TARGET_DIR/FailedUploads" "$TARGET_DIR/JsonLogDirectory" + +echo "📥 Placing files (no bin/; put under $TARGET_DIR)" +# Stuff that used to go to bin/ now goes directly under $TARGET_DIR +if [ -f "$TARGET_DIR/libSystem.IO.Ports.Native.so" ]; then + echo " - libSystem.IO.Ports.Native.so -> $TARGET_DIR/" + # already in place after extract; nothing to do +fi + +if [ -f "$TARGET_DIR/GrowattCommunication" ]; then + echo " - Setting executable on GrowattCommunication" + chmod +x "$TARGET_DIR/GrowattCommunication" +fi + +# modpoll stays in ModpollDir +if [ -f "$TARGET_DIR/modpoll" ]; then + echo " - Moving modpoll -> $MODPOLL_DIR/" + mv -f "$TARGET_DIR/modpoll" "$MODPOLL_DIR/" + chmod +x "$MODPOLL_DIR/modpoll" +fi + +# Move Python files to scripts/ (unchanged behavior) +shopt -s nullglob +PY_FILES=( "$TARGET_DIR"/*.py ) +if [ ${#PY_FILES[@]} -gt 0 ]; then + echo " - Moving Python files -> $SCRIPT_DIR/" + mv -f "${PY_FILES[@]}" "$SCRIPT_DIR/" +fi +shopt -u nullglob + +# 2) Place systemd service under /etc/systemd/system/ +if [ -f "$TARGET_DIR/$SERVICE_NAME" ]; then + echo "🛠️ Installing systemd service to $SERVICE_PATH (requires sudo)..." + sudo install -m 0644 "$TARGET_DIR/$SERVICE_NAME" "$SERVICE_PATH" + echo " - Reloading systemd daemon..." + sudo systemctl daemon-reload + # Enable but don't start automatically; comment out if you don't want this: + if ! systemctl is-enabled --quiet "$SERVICE_NAME"; then + echo " - Enabling service $SERVICE_NAME" + sudo systemctl enable "$SERVICE_NAME" + fi +else + echo "⚠️ WARNING: $SERVICE_NAME not found in $TARGET_DIR. Skipping service install." +fi + +# 3) Place the config file under $TARGET_DIR +if [ -f "$TARGET_DIR/$CONFIG_FILE" ]; then + echo "📝 Config file already in $TARGET_DIR: $CONFIG_FILE" +elif [ -f "$TARGET_DIR/config" ]; then + echo " - Moving 'config' -> $TARGET_DIR/$CONFIG_FILE" + mv -f "$TARGET_DIR/config" "$TARGET_DIR/$CONFIG_FILE" +else + echo "⚠️ WARNING: Config file '$CONFIG_FILE' not found in extracted package." + echo " If the filename differs, set CONFIG_FILE accordingly at the top of this script." +fi + +# 4) csvFile/, FailedUploads/, JsonLogDirectory/ were created earlier. + +# 5) Place log, start, stop, restart under $TARGET_DIR and make them executable +for f in log start stop restart; do + if [ -f "$TARGET_DIR/$f" ]; then + echo " - Ensuring $f is in $TARGET_DIR and executable" + chmod +x "$TARGET_DIR/$f" + elif [ -f "$TARGET_DIR/$f.sh" ]; then + echo " - Moving $f.sh -> $TARGET_DIR/$f and making executable" + mv -f "$TARGET_DIR/$f.sh" "$TARGET_DIR/$f" + chmod +x "$TARGET_DIR/$f" + else + echo "⚠️ NOTE: '$f' script not found in extracted package." + fi +done + +# --- ModbusTCP Integration --- +echo "Installing systemd Modbus TCP service..." +MODBUS_TARGET_DIR="$TARGET_DIR/ModbusTCP" +sudo cp "$MODBUS_TARGET_DIR/ModbusTCP.service" /etc/systemd/system/ + +echo "Preparing Python virtual environment..." +cd "$TARGET_DIR" +python3 -m venv venv +source venv/bin/activate +pip install watchdog +pip install pymodbus==2.5.3 +pip install pyinstaller +deactivate + +echo "Granting permission to bind port 502..." +sudo setcap 'cap_net_bind_service=+ep' "$MODBUS_TARGET_DIR/dist/modbus_tcp_server" + +# echo "Enabling ModbusTCP systemd service..." +sudo systemctl daemon-reload +sudo systemctl enable --now ModbusTCP.service + +# Remove existing timezone link (if it exists) +if [ -L /etc/localtime ]; then + echo "Removing existing timezone link..." + sudo rm /etc/localtime +fi + +# Create a symbolic link to the desired timezone +echo "Creating symbolic link to timezone..." +sudo ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime + +# Starting the SodistoreHome service +sudo systemctl restart SodiStoreHome.service diff --git a/firmware/SodistoreHome/SodistoreHomeSetup/setup_OS_Customization_and_VPN.sh b/firmware/SodistoreHome/SodistoreHomeSetup/setup_OS_Customization_and_VPN.sh new file mode 100644 index 000000000..44f3c50ea --- /dev/null +++ b/firmware/SodistoreHome/SodistoreHomeSetup/setup_OS_Customization_and_VPN.sh @@ -0,0 +1,125 @@ +#!/bin/bash +# Raspberry Pi OS Customization Setup Script +set -e + +############################### Change Raspberry Pi Hostname ################################## + +if [ -z "$1" ]; then + echo "Usage: $0 DEVICE_NUMBER" + exit 1 +fi + +DEVICE_NUM=$(printf "%04d" "$1") +NEW_HOSTNAME="sodistorehome${DEVICE_NUM}" +NEW_USER="inesco" +NEW_PASS="Sodistore0918425" +SSID="inesco" +WIFI_PASS="inesco25" + +echo "Creating user $NEW_USER..." +if id "$NEW_USER" &>/dev/null; then + echo "User $NEW_USER already exists" +else + sudo useradd -m -s /bin/bash "$NEW_USER" + echo "${NEW_USER}:${NEW_PASS}" | sudo chpasswd + sudo usermod -aG sudo "$NEW_USER" +fi + +echo "Setting static hostname to $NEW_HOSTNAME..." +sudo hostnamectl --static set-hostname "$NEW_HOSTNAME" + +# Update /etc/hosts for hostname resolution +if grep -q "^127.0.1.1" /etc/hosts; then + sudo sed -i "s/^127.0.1.1.*/127.0.1.1\t$NEW_HOSTNAME/" /etc/hosts +else + echo "127.0.1.1 $NEW_HOSTNAME" | sudo tee -a /etc/hosts +fi + +echo "Disabling default 'pi' user (if exists)..." +if id pi &>/dev/null; then + sudo passwd -l pi +else + echo "User 'pi' does not exist, skipping disabling." +fi + +echo "Configuring Wi-Fi..." +sudo tee /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null <