#!/bin/bash # Script to copy all files from /root/services to /etc/systemd/system/ # Requires root privileges SOURCE_DIR="/root/services" TARGET_DIR="/etc/systemd/system/" # Check if source directory exists if [ ! -d "$SOURCE_DIR" ]; then echo "Error: Source directory $SOURCE_DIR does not exist!" exit 1 fi # Check if target directory exists if [ ! -d "$TARGET_DIR" ]; then echo "Error: Target directory $TARGET_DIR does not exist!" exit 1 fi # Check if there are any files in the source directory if [ -z "$(ls -A "$SOURCE_DIR")" ]; then echo "No files found in $SOURCE_DIR" exit 0 fi # Copy all files from source to target echo "Copying files from $SOURCE_DIR to $TARGET_DIR..." cp -v "$SOURCE_DIR"/* "$TARGET_DIR"/ # Check if copy was successful if [ $? -eq 0 ]; then echo "Files copied successfully!" # Reload systemd daemon to recognize new services echo "Reloading systemd daemon..." systemctl daemon-reload echo "Systemd daemon reloaded." else echo "Error: Failed to copy files!" exit 1 fi