From 63a453951ef703a0408876889fae469ab41472e2 Mon Sep 17 00:00:00 2001 From: Roger Gonzalez Date: Sat, 21 Oct 2023 17:25:19 -0300 Subject: Refactored the "Installing YAMS" portion --- docs.org | 65 ++++++++++++++++++++++++++++++++++++-------------------------- install.sh | 58 +++++++++++++++++++++++++++++++------------------------ 2 files changed, 71 insertions(+), 52 deletions(-) diff --git a/docs.org b/docs.org index c69eee8..73d6f78 100644 --- a/docs.org +++ b/docs.org @@ -20,7 +20,7 @@ - [[#setting-the-vpn][Setting the VPN]] - [[#installing-yams][Installing YAMS]] - [[#copy-the-docker-compose-file-to-the-install-location][Copy the docker-compose file to the install location]] - - [[#set-puid-pgid-media-folder-media-service-config-folder-and-vpn][Set PUID, PGID, Media Folder, Media Service, Config folder and VPN]] + - [[#set-puid-pgid-media-folder-media-service-config-folder-and-vpn-on-the-yams-scripts][Set PUID, PGID, Media Folder, Media Service, Config folder and VPN on the YAMS scripts]] - [[#set-the-configuration-for-the-yams-binary][Set the configuration for the YAMS binary]] - [[#success-message][Success message!]] - [[#final-steps][Final steps]] @@ -311,42 +311,53 @@ echo "Configuring the docker-compose file for the user \"$username\" on \"$insta :END: #+begin_src bash -echo "" -echo "Copying $filename..." - -cp docker-compose.example.yaml "$filename" || send_error_message "Your user ($USER) needs to have permissions on the installation folder!" -cp .env.example "$env_file" || send_error_message "Your user ($USER) needs to have permissions on the installation folder!" -cp docker-compose.custom.yaml "$custom_file_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" +) + +for file_mapping in "${copy_files[@]}"; do + source_file="${file_mapping%%:*}" + destination_file="${file_mapping##*:}" + + echo -e "\nCopying $source_file to $destination_file..." + if ! cp "$source_file" "$destination_file"; then + send_error_message "Failed to copy $source_file to $destination_file. Ensure your user ($USER) has the necessary permissions." + fi +done #+end_src -** Set PUID, PGID, Media Folder, Media Service, Config folder and VPN +** Set PUID, PGID, Media Folder, Media Service, Config folder and VPN on the YAMS scripts :PROPERTIES: :ID: 3d169001-f0f7-477f-a954-0460484f4b43 :END: +This steps prepares all the files with the correct information that was collected on the "[[#gather-all-the-required-information][Gather all the +required information]]" step. + #+begin_src bash -sed -i -e "s//$puid/g" "$env_file" \ - -e "s//$pgid/g" "$env_file" \ - -e "s;;$media_folder;g" "$env_file" \ - -e "s;;$media_service;g" "$env_file" \ - -e "s;;$media_service;g" "$filename" +sed -i -e "s||$puid|g" "$env_file" \ + -e "s||$pgid|g" "$env_file" \ + -e "s||$media_folder|g" "$env_file" \ + -e "s||$media_service|g" "$env_file" \ + -e "s||$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 -sed -i -e "s;;$install_location;g" "$env_file" +sed -i -e "s||$install_location|g" "$env_file" -# Set VPN if [ "$setup_vpn" == "y" ]; then - sed -i -e "s;;$vpn_service;g" "$env_file" \ - -e "s;;$vpn_user;g" "$env_file" \ - -e "s;;$vpn_password;g" "$env_file" \ - -e "s;;$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" + sed -i -e "s||$vpn_service|g" "$env_file" \ + -e "s||$vpn_user|g" "$env_file" \ + -e "s||$vpn_password|g" "$env_file" \ + -e "s||$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 #+end_src @@ -356,9 +367,9 @@ fi :END: #+begin_src bash -sed -i -e "s;;$filename;g" yams \ - -e "s;;$custom_file_filename;g" yams \ - -e "s;;$install_location;g" yams +sed -i -e "s||$filename|g" yams \ + -e "s||$custom_file_filename|g" yams \ + -e "s||$install_location|g" yams #+end_src ** Success message! diff --git a/install.sh b/install.sh index 5eff501..5ec03b4 100644 --- a/install.sh +++ b/install.sh @@ -174,40 +174,48 @@ fi echo "Configuring the docker-compose file for the user \"$username\" on \"$install_location\"..." -echo "" -echo "Copying $filename..." - -cp docker-compose.example.yaml "$filename" || send_error_message "Your user ($USER) needs to have permissions on the installation folder!" -cp .env.example "$env_file" || send_error_message "Your user ($USER) needs to have permissions on the installation folder!" -cp docker-compose.custom.yaml "$custom_file_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" +) + +for file_mapping in "${copy_files[@]}"; do + source_file="${file_mapping%%:*}" + destination_file="${file_mapping##*:}" + + echo -e "\nCopying $source_file to $destination_file..." + if ! cp "$source_file" "$destination_file"; then + send_error_message "Failed to copy $source_file to $destination_file. Ensure your user ($USER) has the necessary permissions." + fi +done -sed -i -e "s//$puid/g" "$env_file" \ - -e "s//$pgid/g" "$env_file" \ - -e "s;;$media_folder;g" "$env_file" \ - -e "s;;$media_service;g" "$env_file" \ - -e "s;;$media_service;g" "$filename" +sed -i -e "s||$puid|g" "$env_file" \ + -e "s||$pgid|g" "$env_file" \ + -e "s||$media_folder|g" "$env_file" \ + -e "s||$media_service|g" "$env_file" \ + -e "s||$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 -sed -i -e "s;;$install_location;g" "$env_file" +sed -i -e "s||$install_location|g" "$env_file" -# Set VPN if [ "$setup_vpn" == "y" ]; then - sed -i -e "s;;$vpn_service;g" "$env_file" \ - -e "s;;$vpn_user;g" "$env_file" \ - -e "s;;$vpn_password;g" "$env_file" \ - -e "s;;$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" + sed -i -e "s||$vpn_service|g" "$env_file" \ + -e "s||$vpn_user|g" "$env_file" \ + -e "s||$vpn_password|g" "$env_file" \ + -e "s||$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 -sed -i -e "s;;$filename;g" yams \ - -e "s;;$custom_file_filename;g" yams \ - -e "s;;$install_location;g" yams +sed -i -e "s||$filename|g" yams \ + -e "s||$custom_file_filename|g" yams \ + -e "s||$install_location|g" yams send_success_message "Everything installed correctly! 🎉" -- cgit v1.2.3