diff options
Diffstat (limited to 'install.sh')
-rw-r--r--[-rwxr-xr-x] | install.sh | 232 |
1 files changed, 129 insertions, 103 deletions
diff --git a/install.sh b/install.sh index 556d697..802a395 100755..100644 --- a/install.sh +++ b/install.sh @@ -23,10 +23,6 @@ echo "To finish the installation of the CLI" echo "====================================================" echo "" -# ============================================================================================ -# Functions to ease development -# ============================================================================================ - send_success_message() { echo -e $(printf "\e[32m$1\e[0m") } @@ -37,7 +33,7 @@ send_error_message() { } check_dependencides() { - if command -v $1 &> /dev/null; then + if command -v "$1" &> /dev/null; then send_success_message "$1 exists ✅ " else echo -e $(printf "\e[31m ⚠️ $1 not found! ⚠️\e[0m") @@ -54,20 +50,27 @@ check_dependencides() { running_services_location() { host_ip=$(hostname -I | awk '{ print $1 }') - echo "qBittorrent: http://$host_ip:8080/" - echo "Radarr: http://$host_ip:7878/" - echo "Sonarr: http://$host_ip:8989/" - echo "Lidarr: http://$host_ip:8686/" - echo "Readarr: http://$host_ip:8787/" - echo "Prowlarr: http://$host_ip:9696/" - echo "Bazarr: http://$host_ip:6767/" - echo "$media_service: http://$host_ip:$media_service_port/" - echo "Portainer: http://$host_ip:9000/" + + services=( + "qBittorrent:8080" + "Radarr:7878" + "Sonarr:8989" + "Lidarr:8686" + "Readarr:8787" + "Prowlarr:9696" + "Bazarr:6767" + "$media_service:$media_service_port" + "Portainer:9000" + ) + + echo -e "Service URLs:" + for service in "${services[@]}"; do + service_name="${service%%:*}" + service_port="${service##*:}" + echo "$service_name: http://$host_ip:$service_port/" + done } -# ============================================================================================ -# Check all the prerequisites are installed before continuing -# ============================================================================================ echo "Checking prerequisites..." @@ -78,22 +81,25 @@ if [[ "$EUID" = 0 ]]; then send_error_message "YAMS has to run without sudo! Please, run it again with regular permissions" fi -# ============================================================================================ +default_install_directory="/opt/yams" -# ============================================================================================ -# Gathering information -# ============================================================================================ -read -p "Where do you want to install the docker-compose file? [/opt/yams]: " install_location +read -p "Where do you want to install the docker-compose file? [$default_install_directory]: " install_directory +install_directory=${install_directory:-$default_install_directory} + +if [ ! -d "$install_directory" ]; then + echo "The directory \"$install_directory\" does not exists. Attempting to create..." + if mkdir -p "$install_directory"; then + send_success_message "Directory $install_directory created ✅" + else + send_error_message "There was an error creating the installation directory at \"$install_directory\". Make sure you have the necessary permissions ❌" + fi +fi -# Checking if the install_location exists -install_location=${install_location:-/opt/yams} -[[ -f "$install_location" ]] || mkdir -p "$install_location" || send_error_message "There was an error with your install location! Make sure the directory exists and the user \"$USER\" has permissions on it" -install_location=$(realpath "$install_location") -filename="$install_location/docker-compose.yaml" +filename="$install_directory/docker-compose.yaml" +custom_file_filename="$install_directory/docker-compose.custom.yaml" +env_file="$install_directory/.env" read -p "What's the user that is going to own the media server files? [$USER]: " username - -# Checking that the user exists username=${username:-$USER} if id -u "$username" &>/dev/null; then @@ -103,35 +109,35 @@ else send_error_message "The user \"$username\" doesn't exist!" fi -read -p "Please, input your media folder [/srv/media]: " media_folder -media_folder=${media_folder:-"/srv/media"} - -# Checking that the media folder exists +read -p "Please, input your media directory [/srv/media]: " media_directory +media_directory=${media_directory:-"/srv/media"} -realpath "$media_folder" &>/dev/null || send_error_message "There was an error with your media folder! The directory \"$media_folder\" does not exist!" +read -p "Are you sure your media directory is \"$media_directory\"? [y/N]: " media_directory_correct +media_directory_correct=${media_directory_correct:-"n"} -media_folder=$(realpath "$media_folder") - -read -p "Are you sure your media folder is \"$media_folder\"? [y/N]: " media_folder_correct -media_folder_correct=${media_folder_correct:-"n"} +if [ ! -d "$media_directory" ]; then + echo "The directory \"$media_directory\" does not exists. Attempting to create..." + if mkdir -p "$media_directory"; then + send_success_message "Directory $media_directory created ✅" + else + send_error_message "There was an error creating the installation directory at \"$media_directory\". Make sure you have the necessary permissions ❌" + fi +fi -if [ "$media_folder_correct" == "n" ]; then - send_error_message "Media folder is not correct. Please, fix it and run the script again" +if [ "$media_directory_correct" == "n" ]; then + send_error_message "Media directory is not correct. Please fix it and run the script again ❌" fi -# Setting the preferred media service -echo -echo -echo -echo "Time to choose your media service." -echo "Your media service is the one responsible for serving your files to your network." -echo "By default, YAMS support 3 media services:" +echo -e "\n\n\nTime to choose your media service." +echo "Your media service is responsible for serving your files to your network." +echo "By default, YAMS supports 3 media services:" echo "- jellyfin (recommended, easier)" echo "- emby" echo "- plex (advanced, always online)" + read -p "Choose your media service [jellyfin]: " media_service media_service=${media_service:-"jellyfin"} -media_service=$(echo "$media_service" | sed -e 's/\(.*\)/\L\1/') +media_service=$(echo "$media_service" | awk '{print tolower($0)}') media_service_port=8096 if [ "$media_service" == "plex" ]; then @@ -139,27 +145,24 @@ if [ "$media_service" == "plex" ]; then fi if echo "emby plex jellyfin" | grep -qw "$media_service"; then - echo "YAMS is going to install \"$media_service\" on port \"$media_service_port\"" + echo -e "\nYAMS is going to install \"$media_service\" on port \"$media_service_port\"" else send_error_message "\"$media_service\" is not supported by YAMS. Are you sure you chose the correct service?" fi -# Adding the VPN -echo -echo -echo -echo "Time to set up the VPN." +echo -e "\nTime to set up the VPN." echo "You can check the supported VPN list here: https://yams.media/advanced/vpn." + read -p "Do you want to configure a VPN? [Y/n]: " setup_vpn setup_vpn=${setup_vpn:-"y"} if [ "$setup_vpn" == "y" ]; then read -p "What's your VPN service? (with spaces) [mullvad]: " vpn_service vpn_service=${vpn_service:-"mullvad"} - echo - echo "You should read $vpn_service's documentation in case it has different configurations for username and password." + + echo -e "\nYou should read $vpn_service's documentation in case it has different configurations for username and password." echo "The documentation for $vpn_service is here: https://github.com/qdm12/gluetun-wiki/blob/main/setup/providers/${vpn_service// /-}.md" - echo + read -p "What's your VPN username? (without spaces): " vpn_user unset vpn_password @@ -188,52 +191,52 @@ if [ "$setup_vpn" == "y" ]; then echo fi -echo "Configuring the docker-compose file for the user \"$username\" on \"$install_location\"..." -# ============================================================================================ - -# ============================================================================================ -# Actually installing everything! -# ============================================================================================ - -# Copy the docker-compose file from the example to the real one -echo "" -echo "Copying $filename..." +echo "Configuring the docker-compose file for the user \"$username\" on \"$install_directory\"..." -cp docker-compose.example.yaml "$filename" || send_error_message "Your user ($USER) needs to have permissions on the installation folder!" +copy_files=( + "docker-compose.example.yaml:$filename" + ".env.example:$env_file" + "docker-compose.custom.yaml:$custom_file_filename" +) -# Set PUID -sed -i -e "s/<your_PUID>/$puid/g" "$filename" +for file_mapping in "${copy_files[@]}"; do + source_file="${file_mapping%%:*}" + destination_file="${file_mapping##*:}" -# Set PGID -sed -i -e "s/<your_PGID>/$pgid/g" "$filename" + echo -e "\nCopying $source_file to $destination_file..." + if cp "$source_file" "$destination_file"; then + send_success_message "$source_file was copied successfuly! ✅" + else + send_error_message "Failed to copy $source_file to $destination_file. Ensure your user ($USER) has the necessary permissions ❌" + fi +done -# Set media_folder -sed -i -e "s;<media_folder>;$media_folder;g" "$filename" +sed -i -e "s|<your_PUID>|$puid|g" "$env_file" \ + -e "s|<your_PGID>|$pgid|g" "$env_file" \ + -e "s|<media_directory>|$media_directory|g" "$env_file" \ + -e "s|<media_service>|$media_service|g" "$env_file" \ + -e "s|<media_service>|$media_service|g" "$filename" -# Set media_service -sed -i -e "s;<media_service>;$media_service;g" "$filename" if [ "$media_service" == "plex" ]; then - sed -i -e "s;#network_mode: host # plex;network_mode: host # plex;g" "$filename" + sed -i -e "s|#network_mode: host # plex|network_mode: host # plex|g" "$filename" fi -# Set config folder -sed -i -e "s;<install_location>;$install_location;g" "$filename" +sed -i -e "s|<install_directory>|$install_directory|g" "$env_file" -# Set VPN if [ "$setup_vpn" == "y" ]; then - sed -i -e "s;<vpn_service>;$vpn_service;g" "$filename" - sed -i -e "s;<vpn_user>;$vpn_user;g" "$filename" - sed -i -e "s;<vpn_password>;$vpn_password;g" "$filename" - sed -i -e "s;#network_mode: \"service:gluetun\";network_mode: \"service:gluetun\";g" "$filename" - sed -i -e "s;ports: # qbittorrent;#port: # qbittorrent;g" "$filename" - sed -i -e "s;- 8080:8080 # qbittorrent;#- 8080:8080 # qbittorrent;g" "$filename" - sed -i -e "s;#- 8080:8080/tcp # gluetun;- 8080:8080/tcp # gluetun;g" "$filename" + sed -i -e "s|<vpn_service>|$vpn_service|g" "$env_file" \ + -e "s|<vpn_user>|$vpn_user|g" "$env_file" \ + -e "s|<vpn_password>|$vpn_password|g" "$env_file" \ + -e "s|<vpn_enabled>|$setup_vpn|g" "$env_file" \ + -e "s|#network_mode: \"service:gluetun\"|network_mode: \"service:gluetun\"|g" "$filename" \ + -e "s|ports: # qbittorrent|#port: # qbittorrent|g" "$filename" \ + -e "s|- 8080:8080 # qbittorrent|#- 8080:8080 # qbittorrent|g" "$filename" \ + -e "s|#- 8080:8080/tcp # gluetun|- 8080:8080/tcp # gluetun|g" "$filename" fi -# Set yams script -sed -i -e "s;<filename>;$filename;g" yams -sed -i -e "s;<install_location>;$install_location;g" yams - +sed -i -e "s|<filename>|$filename|g" yams \ + -e "s|<custom_file_filename>|$custom_file_filename|g" yams \ + -e "s|<install_directory>|$install_directory|g" yams send_success_message "Everything installed correctly! 🎉" @@ -241,18 +244,42 @@ echo "Running the server..." echo "This is going to take a while..." docker-compose -f "$filename" up -d -# ============================================================================================ -# ============================================================================================ -# Cleaning up... -# ============================================================================================ +echo -e "\nWe need your sudo password to install the YAMS CLI and configure permissions..." + +if sudo cp yams /usr/local/bin/yams && sudo chmod +x /usr/local/bin/yams; then + send_success_message "YAMS CLI installed successfully ✅" +else + send_error_message "Failed to install YAMS CLI. Make sure you have the necessary permissions ❌" +fi -send_success_message "We need your sudo password to install the yams CLI and correct permissions..." -sudo cp yams /usr/local/bin/yams && sudo chmod +x /usr/local/bin/yams -[[ -f "$media_folder" ]] || sudo mkdir -p "$media_folder" || send_error_message "There was an error with your install location!" -sudo chown -R "$puid":"$pgid" "$media_folder" -[[ -f $install_location/config ]] || sudo mkdir -p "$install_location/config" -sudo chown -R "$puid":"$pgid" "$install_location" +if sudo chown -R "$puid":"$pgid" "$media_directory"; then + send_success_message "Media directory ownership and permissions set successfully ✅" +else + send_error_message "Failed to set ownership and permissions for the media directory. Check permissions ❌" +fi + +if sudo chown -R "$puid":"$pgid" "$install_directory"; then + send_success_message "Install directory ownership and permissions set successfully ✅" +else + send_error_message "Failed to set ownership and permissions for the install directory. Check permissions ❌" +fi + +if [[ -d "$install_directory/config" ]]; then + send_success_message "Configuration folder \"$install_directory/config\" exists ✅" +else + if sudo mkdir -p "$install_directory/config"; then + send_success_message "Configuration folder \"$install_directory/config\" created ✅" + else + send_error_message "Failed to create or access the configuration folder. Check permissions ❌" + fi +fi + +if sudo chown -R "$puid":"$pgid" "$install_directory/config"; then + send_success_message "Configuration folder ownership and permissions set successfully ✅" +else + send_error_message "Failed to set ownership and permissions for the configuration folder. Check permissions ❌" +fi printf "\033c" @@ -270,7 +297,7 @@ echo " \__\/ \ \::/ \ \:\ \ \::/ " echo " \__\/ \__\/ \__\/ " echo "========================================================" send_success_message "All done!✅ Enjoy YAMS!" -echo "You can check the installation on $install_location" +echo "You can check the installation on $install_directory" echo "========================================================" echo "Everything should be running now! To check everything running, go to:" echo @@ -288,4 +315,3 @@ echo "https://yams.media/config" echo echo "========================================================" exit 0 -# ============================================================================================ |