Added SodistoreHome Raspberry PI Setup Files
This commit is contained in:
parent
4197141162
commit
75ed68ed47
|
|
@ -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
|
||||
|
|
@ -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 <<EOF
|
||||
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
|
||||
update_config=1
|
||||
country=US
|
||||
|
||||
network={
|
||||
ssid="$SSID"
|
||||
psk="$WIFI_PASS"
|
||||
key_mgmt=WPA-PSK
|
||||
}
|
||||
EOF
|
||||
|
||||
sudo chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf
|
||||
|
||||
echo "OS customization complete. Device: $NEW_HOSTNAME"
|
||||
|
||||
######################### Cpoy Privates Keys of Gitea Server ###########################
|
||||
|
||||
SSH_DIR="$HOME/.ssh"
|
||||
KEY_SRC="./key"
|
||||
|
||||
echo "Creating $SSH_DIR if it doesn't exist..."
|
||||
mkdir -p "$SSH_DIR"
|
||||
chmod 700 "$SSH_DIR"
|
||||
|
||||
echo "Copying keys from $KEY_SRC to $SSH_DIR..."
|
||||
cp -r "$KEY_SRC/"* "$SSH_DIR/"
|
||||
|
||||
echo "Setting permissions for files in $SSH_DIR..."
|
||||
chmod 600 "$SSH_DIR/"*
|
||||
|
||||
echo "Private key copying complete."
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: $0 DEVICE_NUMBER"
|
||||
echo "Example: $0 3"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
######################### Set Up VPN ###########################
|
||||
DEVICENAME="sodistorehome${DEVICE_NUM}"
|
||||
PASSWORD="MwBRbQb3QaX7l9XIaakq"
|
||||
|
||||
echo "Using device name: $NEW_HOSTNAME"
|
||||
|
||||
echo "Updating system..."
|
||||
sudo apt update
|
||||
sudo apt install -y openvpn bridge-utils
|
||||
|
||||
echo "Enabling SSH..."
|
||||
sudo systemctl start ssh
|
||||
sudo systemctl enable ssh
|
||||
|
||||
echo "Downloading VPN certificate..."
|
||||
wget "https://salidomo.innovenergy.ch/get_cert?name=${NEW_HOSTNAME}&pw=${PASSWORD}" -O openvpn.tar
|
||||
|
||||
echo "Moving certificate to /etc/openvpn/client/..."
|
||||
sudo mkdir -p /etc/openvpn/client
|
||||
sudo mv openvpn.tar /etc/openvpn/client/
|
||||
|
||||
echo "Extracting certificate..."
|
||||
sudo tar -xvf /etc/openvpn/client/openvpn.tar -C /etc/openvpn/client/
|
||||
|
||||
echo "Enabling VPN service..."
|
||||
sudo systemctl start openvpn-client@innovenergy.service
|
||||
sudo systemctl enable openvpn-client@innovenergy.service
|
||||
|
||||
echo "VPN setup complete. Checking interface:"
|
||||
ip -br addr
|
||||
|
||||
######################### Copy and run install_release.sh ###########################
|
||||
HOME_DIR="$HOME"
|
||||
echo "Copying install_release.sh to $HOME_DIR"
|
||||
cp install_release.sh "$HOME_DIR"
|
||||
bash "$HOME_DIR/install_release.sh"
|
||||
|
||||
######################### End ###########################
|
||||
echo "🎉🎉🎉 Okay :) We made it!!! 🌟💪 Great Job, Team! 🚀🔥🏆🙌✨💫🎯"
|
||||
echo " Please document the following VPN address:"
|
||||
cat /etc/openvpn/client/installation-ip
|
||||
Loading…
Reference in New Issue