134 lines
4.3 KiB
Bash
134 lines
4.3 KiB
Bash
#!/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"
|
|
RUN_APP_FILE="$DEFAULT_INSTALL_DIR/run_app.sh"
|
|
|
|
# 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."
|
|
read -p "Press any key to close the terminal..." -n 1 -s
|
|
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 || {
|
|
echo "Error: Failed to update system packages."
|
|
read -p "Press any key to close the terminal..." -n 1 -s
|
|
exit 1
|
|
}
|
|
echo "Installation directory is set to: $INSTALL_DIR and is starting the installation process."
|
|
# Install required system packages
|
|
echo "Installing required system packages..."
|
|
sudo apt install -y python3 python3-pip git || {
|
|
echo "Error: Failed to install required system packages."
|
|
read -p "Press any key to close the terminal..." -n 1 -s
|
|
exit 1
|
|
}
|
|
|
|
# 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" || {
|
|
echo "Error: Failed to clone the repository."
|
|
read -p "Press any key to close the terminal..." -n 1 -s
|
|
exit 1
|
|
}
|
|
|
|
# Navigate to the cloned repository
|
|
cd "$INSTALL_DIR" || {
|
|
echo "Error: Failed to navigate to the cloned repository."
|
|
read -p "Press any key to close the terminal..." -n 1 -s
|
|
exit 1
|
|
}
|
|
|
|
# Install Python dependencies
|
|
echo "Installing Python dependencies..."
|
|
pip3 install -r requirements.txt --break-system-packages || {
|
|
echo "Error: Failed to install Python dependencies."
|
|
read -p "Press any key to close the terminal..." -n 1 -s
|
|
exit 1
|
|
}
|
|
|
|
# Set permissions for the run_app.sh script
|
|
echo "Setting permissions for run_app.sh..."
|
|
chmod +x "$INSTALL_DIR/run_app.sh" || {
|
|
echo "Error: Failed to set permissions for run_app.sh."
|
|
read -p "Press any key to close the terminal..." -n 1 -s
|
|
exit 1
|
|
}
|
|
|
|
# Create the signage_player.service file in the installation folder
|
|
SERVICE_TEMPLATE="$INSTALL_DIR/signage_player.service"
|
|
echo "Creating signage_player.service file in the installation folder..."
|
|
cat <<EOF > "$SERVICE_TEMPLATE"
|
|
[Unit]
|
|
Description=Signage Player Service
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
WorkingDirectory=$INSTALL_DIR
|
|
ExecStart=$INSTALL_DIR/run_app.sh
|
|
Restart=always
|
|
RestartSec=5
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
# Copy the service file to the systemd service directory
|
|
echo "Copying signage_player.service file to $SERVICE_FILE..."
|
|
sudo cp "$SERVICE_TEMPLATE" "$SERVICE_FILE" || {
|
|
echo "Error: Failed to copy signage_player.service file."
|
|
read -p "Press any key to close the terminal..." -n 1 -s
|
|
exit 1
|
|
}
|
|
|
|
# Reload systemd daemon
|
|
echo "Reloading systemd daemon..."
|
|
sudo systemctl daemon-reload || {
|
|
echo "Error: Failed to reload systemd daemon."
|
|
read -p "Press any key to close the terminal..." -n 1 -s
|
|
exit 1
|
|
}
|
|
|
|
# Enable the service
|
|
echo "Enabling signage_player.service..."
|
|
sudo systemctl enable signage_player.service || {
|
|
echo "Error: Failed to enable signage_player.service."
|
|
read -p "Press any key to close the terminal..." -n 1 -s
|
|
exit 1
|
|
}
|
|
|
|
echo "signage_player.service file created, copied, and enabled successfully."
|
|
|
|
# Restart the system to check if the service starts
|
|
echo "Restarting the system to check if the service starts..."
|
|
sudo reboot || {
|
|
echo "Error: Failed to restart the system."
|
|
read -p "Press any key to close the terminal..." -n 1 -s
|
|
exit 1
|
|
} |