Advertisement
eibgrad

merlin-installer.sh

May 26th, 2019 (edited)
1,872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.94 KB | None | 0 0
  1. #!/bin/sh
  2. # version: 1.0.0, 22-jul-2022, by eibgrad
  3.  
  4. # function usage()
  5. usage() {
  6.     echo 'Usage: merlin-installer.sh [options] pastebin-id [pastebin-id ...]'
  7.     echo
  8.     echo '  Download and install merlin script(s).'
  9.     echo
  10.     echo '  Options:'
  11.     echo '    --noexec   do NOT install script(s); only download to stdout'
  12.     echo '    --nocom    remove blank lines and pure/non-functional comments'
  13.     echo '    --comp     same as --nocom, plus remove leading whitespace'
  14.     echo '    --debug    install script(s) w/ debugging mode enabled'
  15.     echo '    -h,--help  this usage information'
  16.     echo
  17.     echo '  Note: use of --nocom or --comp implies --noexec'
  18.     echo
  19. }
  20.  
  21. # handle -h|--help option
  22. for opt; do case $opt in -h|--help) usage; exit 0;; esac; done
  23.  
  24. # process command line options
  25. while [ $# -gt 0 ]; do
  26.     case "$1" in
  27.         '--noexec') noexec=;;
  28.          '--nocom') nocom=; unset comp; noexec=;;
  29.           '--comp') comp=; unset nocom; noexec=;;
  30.          '--debug') debug=; export DEBUG=;;
  31.                  *) if echo "$1" | grep -q '^-'; then
  32.                         echo "error: unknown option: $1"; exit 1
  33.                     else
  34.                         break 2
  35.                     fi;;
  36.     esac
  37.     shift
  38. done
  39.  
  40. [ "$1" ] || { echo "info: nothing to do"; exit 0; }
  41.  
  42. # configure curl command
  43. CURL="curl -kLs -H 'Cache-Control: no-cache'"
  44.  
  45. # assume remaining command line arguments are pastebin ids
  46. while [ $# -gt 0 ]; do
  47.     # verify this is a known, supported merlin script
  48.     case "$1" in
  49.         'hvHHic1V') ;; # merlin-ac68u-add-networks.sh
  50.         'AGNF8cC8') ;; # merlin-dns-monitor.sh
  51.         'F2GmyrCC') ;; # merlin-ovpn-client-killswitch.sh
  52.         'wyKu0pww') ;; # merlin-ovpn-client-watchdog.sh
  53.         '9jHRA6DG') ;; # merlin-ovpn-lan2wan-by-domain.sh
  54.         'i8hpNGpq') ;; # merlin-ovpn-plex-pbr.sh
  55.         'SqReWZnB') ;; # merlin-ovpn-port-forward.sh
  56.         'MkKb9tia') ;; # merlin-ovpn-server-restart.sh
  57.         'kTThBV46') ;; # merlin-ovpn-sync-routes.sh
  58.         'MLtSBb6E') ;; # merlin-pptp-gw-override.sh
  59.         'b7p6f102') ;; # merlin-wol-port-forward.sh
  60.                  *) echo "error: file not found: $1"; shift; continue;;
  61.     esac
  62.  
  63.     # configure url for raw pull (obscure from hosting site)
  64.     url="$(echo wastebin | sed s/w/p/).com/raw/$1"
  65.  
  66.     if [ ${noexec+x} ]; then
  67.         # retrieve, clean, and dump script to stdout
  68.         if [ ${nocom+x} ]; then
  69.             # remove blank lines and pure/non-functional comments
  70.             $CURL $url | tr -d '\r' | sed -r '/^\s*($|#(\s|#|$))/d'; echo
  71.         elif [ ${comp+x} ]; then
  72.             # same as --nocom, plus remove leading whitespace
  73.             $CURL $url | tr -d '\r' | sed -r 's/^\s*//;/^($|#(\s|#|$))/d'; echo
  74.         else
  75.             $CURL $url | tr -d '\r'; echo
  76.         fi
  77.     else
  78.         # retrieve, clean, and execute the script
  79.         $CURL $url | tr -d '\r' | sh
  80.     fi
  81.  
  82.     shift
  83. done
  84.  
  85. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement