diff --git a/skier233_nsfw_ai_model_server/daemonize.sh b/skier233_nsfw_ai_model_server/daemonize.sh new file mode 100644 index 0000000..757a132 --- /dev/null +++ b/skier233_nsfw_ai_model_server/daemonize.sh @@ -0,0 +1,120 @@ +#!/bin/bash +# daemonize.sh +# Installs Skier233's NSFW AI Model Server as a daemon on systemd-based systems +# https://github.com/skier233/nsfw_ai_model_server +# +# Author: voidf1sh (Skylar Grant) +# This script is unofficial and not endorsed, developed, or supported by Skier233 +# +# Usage: source daemonize.sh + +# Check if the script is being run as root +if [ "$EUID" -eq 0 ]; then + echo "Please run as yourself, not root, we need environment variables from your user session." + exit +fi + +# Check if the script is being run on a systemd-based system +if [ ! -d "/etc/systemd" ]; then + echo "This script only works on systemd-based systems" + exit +fi + +# Variables +activate_name="ai_model_server" +miniconda_dir="$HOME/miniconda3" +ai_server_dir="$HOME/nsfw_ai_model_server" +service_name="nsfw_ai_model_server" + +# Activate the Conda environment +conda activate $activate_name +if [ $? -ne 0 ]; then + echo "Error activating the Conda environment, please activate it manually." + exit +fi + + +# Print env vars for debugging, user, group, conda +echo "This script installs Skier233's NSFW AI Model Server as a daemon on systemd-based systems." +echo "https://github.com/skier233/nsfw_ai_model_server" +echo "Author: voidf1sh (Skylar Grant)" +echo "This script is unofficial and not endorsed, developed, or supported by Skier233" +echo +# DEBUG: +# echo "Environment Variables:" +# echo "USER: $USER" +# echo "Conda Environment: $CONDA_DEFAULT_ENV" +# echo "Miniconda Directory: $miniconda_dir" +# echo "AI Server Directory: $ai_server_dir" +# echo "Service Name: $service_name" +# echo + +# Check if the MiniConda directory actually exists +if [ ! -d "$miniconda_dir" ]; then + echo "Miniconda directory not found, please install Miniconda first or modify the script to point to the correct directory (\$miniconda_dir)." + exit +fi + +# Check if the Conda environment matches the expected environment +if [ "$CONDA_DEFAULT_ENV" != "$activate_name" ]; then + echo "Conda environment $activate_name not found, please activate the correct environment or modify the script to point to the correct environment (\$activate_name)." + exit +fi + +# Check if the server.py file exists +if [ ! -f "$ai_server_dir/server.py" ]; then + echo "server.py not found, please install Skier233's NSFW AI Model Server first or modify the script to point to the correct directory (\$ai_server_dir)." + exit +fi + +# Let the user know why we need sudo +echo "Creating systemd file at /etc/systemd/system/$service_name.service..." + +# Create the systemd service file +cat <