anki-sync-server/install.sh
2023-09-06 17:09:19 +00:00

60 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# Set variables
SERVICE_FILE="service/anki-sync-server.service"
SYSTEMD_DIR="/etc/systemd/system"
ENV_SAMPLE="sample.env"
ENV_TARGET=".env"
# Check if root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root."
exit 1
fi
# Copy service file to systemd directory
if [ -e "$SERVICE_FILE" ]; then
cp -n "$SERVICE_FILE" "$SYSTEMD_DIR"
if [ $? -eq 0 ]; then
echo "Service file copied successfully."
systemctl daemon-reload
if [ $? -eq 0 ]; then
echo "Daemon reloaded successfully."
else
echo "Failed to reload the daemon."
exit 1
fi
else
echo "Failed to copy the service file."
exit 1
fi
else
echo "Service file $SERVICE_FILE does not exist."
exit 1
fi
# Copy sample.env to .env if it does not already exist
if [ ! -e "$ENV_TARGET" ]; then
if [ -e "$ENV_SAMPLE" ]; then
cp "$ENV_SAMPLE" "$ENV_TARGET"
if [ $? -eq 0 ]; then
echo ".env file created successfully."
else
echo "Failed to create .env file."
exit 1
fi
else
echo "Sample env file $ENV_SAMPLE does not exist."
exit 1
fi
else
echo ".env file already exists, skipping."
fi
# Remind user to create data directory
echo "Remember to create the data directory on your local machine."
# Script completed successfully
exit 0