2024-08-27, 07:25 PM
It works so beautiful well! Thank you for everything!!
As for Synology users; I wrote the following script that should be put in the task scheduler (have it run at boot as root)
As for Synology users; I wrote the following script that should be put in the task scheduler (have it run at boot as root)
Code:
# Define the search term for grep and the words for modification
search_word_1="jellyfin.MYHOSTNAME.com"
search_word_2="location \/ {"
insert_text="\n if (\$arg_searchTerm) { \n proxy_pass http:\/\/localhost:MYJELLYSEARCHPORT;\n break;\n }\n"
# Search for the first file containing the string in grep_term in the specified directory
file=$(grep -Rnw '/usr/local/etc/nginx/sites-available/' -e "$search_word_1" | awk -F: 'NR==1{print $1}')
# Check if a file was found
if [ -z "$file" ]; then
echo "No file containing '$grep_term' found."
exit 1
fi
# Verify that both search_word_1 and search_word_2 exist in the file
if grep -q "$search_word_1" "$file" && grep -q "$search_word_2" "$file"; then
# Use sed with variables to find the first occurrence of search_word_2 after search_word_1 and insert insert_text after search_word_2
sed -i "/$search_word_1/,/$search_word_2/{s/\($search_word_2\)/\1 $insert_text/;}" "$file"
echo "Modification applied to $file"
nginx -s reload
else
echo "The file $file does not contain both '$search_word_1' and '$search_word_2'"
fi