install Sh
This commit is contained in:
91
Install.sh
Normal file
91
Install.sh
Normal file
@@ -0,0 +1,91 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Define variables
|
||||
REPO_URL="https://gitea.moto-adv.com/ske087/signage-player.git"
|
||||
DEFAULT_INSTALL_DIR="/home/pi/signage-player"
|
||||
SERVICE_FILE="/etc/systemd/system/signage_player.service"
|
||||
|
||||
# Ask the user whether to use the default installation directory
|
||||
echo "The default installation directory is: $DEFAULT_INSTALL_DIR"
|
||||
read -p "Do you want to use the default installation directory? (y/n): " response
|
||||
|
||||
# Handle the user's response
|
||||
if [[ "$response" == "y" || "$response" == "Y" ]]; then
|
||||
INSTALL_DIR="$DEFAULT_INSTALL_DIR"
|
||||
echo "Using default installation directory: $INSTALL_DIR"
|
||||
else
|
||||
read -p "Enter the custom installation directory: " CUSTOM_INSTALL_DIR
|
||||
INSTALL_DIR="$CUSTOM_INSTALL_DIR"
|
||||
if [[ ! -d "$INSTALL_DIR" ]]; then
|
||||
echo "Directory $INSTALL_DIR does not exist. Creating it..."
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "Error: Failed to create directory $INSTALL_DIR."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
echo "Using custom installation directory: $INSTALL_DIR"
|
||||
fi
|
||||
|
||||
# Update system packages
|
||||
echo "Updating system packages..."
|
||||
sudo apt update && sudo apt upgrade -y
|
||||
|
||||
# Install required system packages
|
||||
echo "Installing required system packages..."
|
||||
sudo apt install -y python3 python3-pip git
|
||||
|
||||
# Clone the repository
|
||||
echo "Cloning the repository..."
|
||||
if [ -d "$INSTALL_DIR" ]; then
|
||||
echo "Directory $INSTALL_DIR already exists. Removing it..."
|
||||
sudo rm -rf "$INSTALL_DIR"
|
||||
fi
|
||||
git clone "$REPO_URL" "$INSTALL_DIR"
|
||||
|
||||
# Navigate to the cloned repository
|
||||
cd "$INSTALL_DIR" || exit
|
||||
|
||||
# Install Python dependencies
|
||||
echo "Installing Python dependencies..."
|
||||
pip3 install -r requirements.txt --break-system-packages
|
||||
|
||||
# Set permissions for the run_app.sh script
|
||||
echo "Setting permissions for run_app.sh..."
|
||||
chmod +x "$INSTALL_DIR/run_app.sh"
|
||||
|
||||
# Check and update the signage_player.service file
|
||||
if [[ -f "$SERVICE_FILE" ]]; then
|
||||
echo "Checking signage_player.service file..."
|
||||
WORKING_DIR=$(grep -oP '(?<=^WorkingDirectory=).*' "$SERVICE_FILE")
|
||||
EXEC_START=$(grep -oP '(?<=^ExecStart=).*' "$SERVICE_FILE")
|
||||
|
||||
EXPECTED_WORKING_DIR="$INSTALL_DIR"
|
||||
EXPECTED_EXEC_START="$INSTALL_DIR/run_app.sh"
|
||||
|
||||
if [[ "$WORKING_DIR" != "$EXPECTED_WORKING_DIR" || "$EXEC_START" != "$EXPECTED_EXEC_START" ]]; then
|
||||
echo "Updating signage_player.service file..."
|
||||
sudo cp "$INSTALL_DIR/signage_player.service" "$SERVICE_FILE"
|
||||
sudo sed -i "s|^WorkingDirectory=.*|WorkingDirectory=$INSTALL_DIR|" "$SERVICE_FILE"
|
||||
sudo sed -i "s|^ExecStart=.*|ExecStart=$INSTALL_DIR/run_app.sh|" "$SERVICE_FILE"
|
||||
sudo systemctl daemon-reload
|
||||
echo "signage_player.service file updated successfully."
|
||||
else
|
||||
echo "signage_player.service file is already configured correctly."
|
||||
fi
|
||||
else
|
||||
echo "signage_player.service file not found. Copying and configuring it..."
|
||||
sudo cp "$INSTALL_DIR/signage_player.service" "$SERVICE_FILE"
|
||||
sudo sed -i "s|^WorkingDirectory=.*|WorkingDirectory=$INSTALL_DIR|" "$SERVICE_FILE"
|
||||
sudo sed -i "s|^ExecStart=.*|ExecStart=$INSTALL_DIR/run_app.sh|" "$SERVICE_FILE"
|
||||
sudo systemctl daemon-reload
|
||||
echo "signage_player.service file created and configured successfully."
|
||||
fi
|
||||
|
||||
# Enable the service
|
||||
echo "Enabling signage_player.service..."
|
||||
sudo systemctl enable signage_player.service
|
||||
|
||||
# Restart the system to check if the service starts
|
||||
echo "Restarting the system to check if the service starts..."
|
||||
sudo reboot
|
||||
Reference in New Issue
Block a user