Skip to content

Instantly share code, notes, and snippets.

@lucndm
Forked from hjbotha/free_ports.sh
Created October 22, 2021 17:05
Show Gist options
  • Save lucndm/d4eef482128c13d759807329a917a3ac to your computer and use it in GitHub Desktop.
Save lucndm/d4eef482128c13d759807329a917a3ac to your computer and use it in GitHub Desktop.

Revisions

  1. @hjbotha hjbotha revised this gist Jul 25, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions free_ports.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    #! /bin/bash

    # NEWLY ADDED BACKUP FUNCTIONALITY IS NOT FULLY TESTED YET, USE WITH CARE, ESPECIALLY DELETION
    # Developed for DSM 6. Not tested on other versions.
    # Steps to install
    # Save this script in one of your shares
    # Backup /usr/syno/share/nginx/ as follows:
  2. @hjbotha hjbotha revised this gist Feb 6, 2021. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions free_ports.sh
    Original file line number Diff line number Diff line change
    @@ -19,12 +19,13 @@ BACKUP_FILES=true # change to false to disable backups
    BACKUP_DIR=/volume1/apps/free_ports/backup
    DELETE_OLD_BACKUPS=false # change to true to automatically delete old backups.
    KEEP_BACKUP_DAYS=30
    CURRENT_BACKUP_DIR="$BACKUP_DIR/$DATE"

    DATE=$(date +%Y-%m-%d-%H-%M-%S)

    if [ "$BACKUP_FILES" == "true" ]; then
    mkdir -p "$BACKUP_DIR/$DATE"
    cp /usr/syno/share/nginx/*.mustache "$BACKUP_DIR/$DATE"
    mkdir -p "$CURRENT_BACKUP_DIR"
    cp /usr/syno/share/nginx/*.mustache "$CURRENT_BACKUP_DIR"
    fi

    if [ "$DELETE_OLD_BACKUPS" == "true" ]; then
    @@ -33,3 +34,7 @@ fi

    sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)80\([^0-9]\)/\1$HTTP_PORT\2/" /usr/syno/share/nginx/*.mustache
    sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)443\([^0-9]\)/\1$HTTPS_PORT\2/" /usr/syno/share/nginx/*.mustache

    echo "Made these changes:"

    diff /usr/syno/share/nginx/ $CURRENT_BACKUP_DIR 2>&1 | tee $CURRENT_BACKUP_DIR/changes.log
  3. @hjbotha hjbotha revised this gist Dec 6, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions free_ports.sh
    Original file line number Diff line number Diff line change
    @@ -15,9 +15,9 @@
    HTTP_PORT=81
    HTTPS_PORT=444

    BACKUP_FILES=false
    BACKUP_FILES=true # change to false to disable backups
    BACKUP_DIR=/volume1/apps/free_ports/backup
    DELETE_OLD_BACKUPS=false
    DELETE_OLD_BACKUPS=false # change to true to automatically delete old backups.
    KEEP_BACKUP_DAYS=30

    DATE=$(date +%Y-%m-%d-%H-%M-%S)
  4. @hjbotha hjbotha revised this gist Dec 6, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion free_ports.sh
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ BACKUP_DIR=/volume1/apps/free_ports/backup
    DELETE_OLD_BACKUPS=false
    KEEP_BACKUP_DAYS=30

    DATE=$(date +%Y-%m-%d-%H-%m-%S)
    DATE=$(date +%Y-%m-%d-%H-%M-%S)

    if [ "$BACKUP_FILES" == "true" ]; then
    mkdir -p "$BACKUP_DIR/$DATE"
  5. @hjbotha hjbotha revised this gist Aug 4, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion free_ports.sh
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ if [ "$BACKUP_FILES" == "true" ]; then
    fi

    if [ "$DELETE_OLD_BACKUPS" == "true" ]; then
    find "/volume1/apps/traefik/backup_free_ports/" -type d -mtime +$KEEP_BACKUP_DAYS -exec rm -r {} \;
    find "$BACKUP_DIR/" -type d -mtime +$KEEP_BACKUP_DAYS -exec rm -r {} \;
    fi

    sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)80\([^0-9]\)/\1$HTTP_PORT\2/" /usr/syno/share/nginx/*.mustache
  6. @hjbotha hjbotha revised this gist Jun 2, 2020. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions free_ports.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    #! /bin/bash

    # NEWLY ADDED BACKUP FUNCTIONALITY IS NOT FULLY TESTED YET, USE WITH CARE, ESPECIALLY DELETION
    # Steps to install
    # Save this script in one of your shares
    # Backup /usr/syno/share/nginx/ as follows:
    @@ -14,5 +15,21 @@
    HTTP_PORT=81
    HTTPS_PORT=444

    BACKUP_FILES=false
    BACKUP_DIR=/volume1/apps/free_ports/backup
    DELETE_OLD_BACKUPS=false
    KEEP_BACKUP_DAYS=30

    DATE=$(date +%Y-%m-%d-%H-%m-%S)

    if [ "$BACKUP_FILES" == "true" ]; then
    mkdir -p "$BACKUP_DIR/$DATE"
    cp /usr/syno/share/nginx/*.mustache "$BACKUP_DIR/$DATE"
    fi

    if [ "$DELETE_OLD_BACKUPS" == "true" ]; then
    find "/volume1/apps/traefik/backup_free_ports/" -type d -mtime +$KEEP_BACKUP_DAYS -exec rm -r {} \;
    fi

    sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)80\([^0-9]\)/\1$HTTP_PORT\2/" /usr/syno/share/nginx/*.mustache
    sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)443\([^0-9]\)/\1$HTTPS_PORT\2/" /usr/syno/share/nginx/*.mustache
  7. @hjbotha hjbotha revised this gist Jul 18, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion free_ports.sh
    Original file line number Diff line number Diff line change
    @@ -14,5 +14,5 @@
    HTTP_PORT=81
    HTTPS_PORT=444

    sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)80\([^0-9]\)/\1$HTTP_PORT1\2/" /usr/syno/share/nginx/*.mustache
    sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)80\([^0-9]\)/\1$HTTP_PORT\2/" /usr/syno/share/nginx/*.mustache
    sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)443\([^0-9]\)/\1$HTTPS_PORT\2/" /usr/syno/share/nginx/*.mustache
  8. @hjbotha hjbotha revised this gist Jul 18, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions free_ports.sh
    Original file line number Diff line number Diff line change
    @@ -14,5 +14,5 @@
    HTTP_PORT=81
    HTTPS_PORT=444

    sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)80\([^0-9]\)/\181\2/" /usr/syno/share/nginx/*.mustache
    sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)443\([^0-9]\)/\1444\2/" /usr/syno/share/nginx/*.mustache
    sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)80\([^0-9]\)/\1$HTTP_PORT1\2/" /usr/syno/share/nginx/*.mustache
    sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)443\([^0-9]\)/\1$HTTPS_PORT\2/" /usr/syno/share/nginx/*.mustache
  9. @hjbotha hjbotha revised this gist Jul 18, 2019. 1 changed file with 11 additions and 6 deletions.
    17 changes: 11 additions & 6 deletions free_ports.sh
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,18 @@
    #! /bin/bash

    # Save this script in one of your shares and schedule it to run as root at boot
    # Steps to install
    # Save this script in one of your shares
    # Backup /usr/syno/share/nginx/ as follows:
    # # cd /usr/syno/share/
    # # tar cvf ~/nginx.tar nginx
    # Run this script as root
    # Reboot and ensure everything is still working
    # If not, restore the backup and post a comment on this script's gist page
    # If it did, schedule it to run at boot
    # through Control Panel -> Task Scheduler
    # DSM upgrades will reset these changes, which is why we schedule them to happen automatically
    # Set the variables below if you want to customise the ports which DSM will listen on instead
    # NOTE: These ports are used for some services, e.g. Photo Station

    HTTP_PORT=81
    HTTPS_PORT=444

    sed -i "s/^\( *listen .*\)80/\1$HTTP_PORT/" /usr/syno/share/nginx/*.mustache
    sed -i "s/^\( *listen .*\)443/\1$HTTPS_PORT/" /usr/syno/share/nginx/*.mustache
    sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)80\([^0-9]\)/\181\2/" /usr/syno/share/nginx/*.mustache
    sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)443\([^0-9]\)/\1444\2/" /usr/syno/share/nginx/*.mustache
  10. @hjbotha hjbotha revised this gist Apr 5, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions free_ports.sh
    Original file line number Diff line number Diff line change
    @@ -9,5 +9,5 @@
    HTTP_PORT=81
    HTTPS_PORT=444

    sed -i 's/^\( *listen .*\)80/\1$HTTP_PORT/' /usr/syno/share/nginx/*.mustache
    sed -i 's/^\( *listen .*\)443/\1$HTTPS_PORT/' /usr/syno/share/nginx/*.mustache
    sed -i "s/^\( *listen .*\)80/\1$HTTP_PORT/" /usr/syno/share/nginx/*.mustache
    sed -i "s/^\( *listen .*\)443/\1$HTTPS_PORT/" /usr/syno/share/nginx/*.mustache
  11. @hjbotha hjbotha revised this gist Mar 22, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion free_ports.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,8 @@
    #! /bin/bash

    # Save this script in one of your shares and schedule it to run at boot
    # Save this script in one of your shares and schedule it to run as root at boot
    # through Control Panel -> Task Scheduler
    # DSM upgrades will reset these changes, which is why we schedule them to happen automatically
    # Set the variables below if you want to customise the ports which DSM will listen on instead
    # NOTE: These ports are used for some services, e.g. Photo Station

  12. @hjbotha hjbotha revised this gist Mar 22, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions free_ports.sh
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@

    # Save this script in one of your shares and schedule it to run at boot
    # through Control Panel -> Task Scheduler
    # Set the variables below if you want to customise the ports which DSM will listen on instead
    # NOTE: These ports are used for some services, e.g. Photo Station

    HTTP_PORT=81
    HTTPS_PORT=444
  13. @hjbotha hjbotha created this gist Mar 22, 2018.
    10 changes: 10 additions & 0 deletions free_ports.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    #! /bin/bash

    # Save this script in one of your shares and schedule it to run at boot
    # through Control Panel -> Task Scheduler

    HTTP_PORT=81
    HTTPS_PORT=444

    sed -i 's/^\( *listen .*\)80/\1$HTTP_PORT/' /usr/syno/share/nginx/*.mustache
    sed -i 's/^\( *listen .*\)443/\1$HTTPS_PORT/' /usr/syno/share/nginx/*.mustache