137 lines
4.6 KiB
Bash
137 lines
4.6 KiB
Bash
#!/bin/bash
|
|
# Configuration module for Transmission RSS Manager Installation
|
|
|
|
# Configuration variables with defaults
|
|
INSTALL_DIR="/opt/transmission-rss-manager"
|
|
SERVICE_NAME="transmission-rss-manager"
|
|
USER=$(logname || echo $SUDO_USER)
|
|
PORT=3000
|
|
|
|
# Transmission configuration variables
|
|
TRANSMISSION_REMOTE=false
|
|
TRANSMISSION_HOST="localhost"
|
|
TRANSMISSION_PORT=9091
|
|
TRANSMISSION_USER=""
|
|
TRANSMISSION_PASS=""
|
|
TRANSMISSION_RPC_PATH="/transmission/rpc"
|
|
TRANSMISSION_DOWNLOAD_DIR="/var/lib/transmission-daemon/downloads"
|
|
TRANSMISSION_DIR_MAPPING="{}"
|
|
|
|
# Media path defaults
|
|
MEDIA_DIR="/mnt/media"
|
|
ENABLE_BOOK_SORTING=true
|
|
|
|
function gather_configuration() {
|
|
echo -e "${BOLD}Installation Configuration:${NC}"
|
|
echo -e "Please provide the following configuration parameters:"
|
|
echo
|
|
|
|
read -p "Installation directory [$INSTALL_DIR]: " input_install_dir
|
|
INSTALL_DIR=${input_install_dir:-$INSTALL_DIR}
|
|
|
|
read -p "Web interface port [$PORT]: " input_port
|
|
PORT=${input_port:-$PORT}
|
|
|
|
read -p "Run as user [$USER]: " input_user
|
|
USER=${input_user:-$USER}
|
|
|
|
echo
|
|
echo -e "${BOLD}Transmission Configuration:${NC}"
|
|
echo -e "Configure connection to your Transmission client:"
|
|
echo
|
|
|
|
read -p "Is Transmission running on a remote server? (y/n) [n]: " input_remote
|
|
if [[ $input_remote =~ ^[Yy]$ ]]; then
|
|
TRANSMISSION_REMOTE=true
|
|
|
|
read -p "Remote Transmission host [localhost]: " input_trans_host
|
|
TRANSMISSION_HOST=${input_trans_host:-$TRANSMISSION_HOST}
|
|
|
|
read -p "Remote Transmission port [9091]: " input_trans_port
|
|
TRANSMISSION_PORT=${input_trans_port:-$TRANSMISSION_PORT}
|
|
|
|
read -p "Remote Transmission username []: " input_trans_user
|
|
TRANSMISSION_USER=${input_trans_user:-$TRANSMISSION_USER}
|
|
|
|
read -p "Remote Transmission password []: " input_trans_pass
|
|
TRANSMISSION_PASS=${input_trans_pass:-$TRANSMISSION_PASS}
|
|
|
|
read -p "Remote Transmission RPC path [/transmission/rpc]: " input_trans_path
|
|
TRANSMISSION_RPC_PATH=${input_trans_path:-$TRANSMISSION_RPC_PATH}
|
|
|
|
# Configure directory mapping for remote setup
|
|
echo
|
|
echo -e "${YELLOW}Directory Mapping Configuration${NC}"
|
|
echo -e "When using a remote Transmission server, you need to map paths between servers."
|
|
echo -e "For each directory on the remote server, specify the corresponding local directory."
|
|
echo
|
|
|
|
# Get remote download directory
|
|
read -p "Remote Transmission download directory: " REMOTE_DOWNLOAD_DIR
|
|
REMOTE_DOWNLOAD_DIR=${REMOTE_DOWNLOAD_DIR:-"/var/lib/transmission-daemon/downloads"}
|
|
|
|
# Get local directory that corresponds to remote download directory
|
|
read -p "Local directory that corresponds to the remote download directory: " LOCAL_DOWNLOAD_DIR
|
|
LOCAL_DOWNLOAD_DIR=${LOCAL_DOWNLOAD_DIR:-"/mnt/transmission-downloads"}
|
|
|
|
# Create mapping JSON
|
|
TRANSMISSION_DIR_MAPPING=$(cat <<EOF
|
|
{
|
|
"$REMOTE_DOWNLOAD_DIR": "$LOCAL_DOWNLOAD_DIR"
|
|
}
|
|
EOF
|
|
)
|
|
|
|
# Create the local directory
|
|
mkdir -p "$LOCAL_DOWNLOAD_DIR"
|
|
chown -R $USER:$USER "$LOCAL_DOWNLOAD_DIR"
|
|
|
|
# Ask if want to add more mappings
|
|
while true; do
|
|
read -p "Add another directory mapping? (y/n) [n]: " add_another
|
|
if [[ ! $add_another =~ ^[Yy]$ ]]; then
|
|
break
|
|
fi
|
|
|
|
read -p "Remote directory path: " remote_dir
|
|
read -p "Corresponding local directory path: " local_dir
|
|
|
|
if [ -n "$remote_dir" ] && [ -n "$local_dir" ]; then
|
|
# Update mapping JSON (remove the last "}" and add the new mapping)
|
|
TRANSMISSION_DIR_MAPPING="${TRANSMISSION_DIR_MAPPING%\}}, \"$remote_dir\": \"$local_dir\" }"
|
|
|
|
# Create the local directory
|
|
mkdir -p "$local_dir"
|
|
chown -R $USER:$USER "$local_dir"
|
|
|
|
echo -e "${GREEN}Mapping added: $remote_dir → $local_dir${NC}"
|
|
fi
|
|
done
|
|
|
|
# Set Transmission download dir for configuration
|
|
TRANSMISSION_DOWNLOAD_DIR=$REMOTE_DOWNLOAD_DIR
|
|
else
|
|
read -p "Transmission download directory [/var/lib/transmission-daemon/downloads]: " input_trans_dir
|
|
TRANSMISSION_DOWNLOAD_DIR=${input_trans_dir:-$TRANSMISSION_DOWNLOAD_DIR}
|
|
fi
|
|
|
|
echo
|
|
echo -e "${BOLD}Media Destination Configuration:${NC}"
|
|
|
|
read -p "Media destination base directory [/mnt/media]: " input_media_dir
|
|
MEDIA_DIR=${input_media_dir:-$MEDIA_DIR}
|
|
|
|
# Ask about enabling book/magazine sorting
|
|
echo
|
|
echo -e "${BOLD}Content Type Configuration:${NC}"
|
|
read -p "Enable book and magazine sorting? (y/n) [y]: " input_book_sorting
|
|
ENABLE_BOOK_SORTING=true
|
|
if [[ $input_book_sorting =~ ^[Nn]$ ]]; then
|
|
ENABLE_BOOK_SORTING=false
|
|
fi
|
|
|
|
echo
|
|
echo -e "${GREEN}Configuration complete!${NC}"
|
|
echo
|
|
}
|