functions 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. #####################
  3. ##### DEFAULTS ######
  4. #####################
  5. declare -x _packages=(
  6. "luci" "luci-theme-material" "luci-app-ddns" \
  7. "wireguard" "luci-app-wireguard" "luci-app-vpn-policy-routing" \
  8. "-dnsmasq" "dnsmasq-full" \
  9. "luci-app-upnp" \
  10. "nano" "htop")
  11. declare -x _builddir
  12. _builddir="$(pwd)"
  13. declare -x _filesroot="$_builddir/files/"
  14. declare -x _ssh_backup="root@192.168.2.1"
  15. declare -x _backedup=(
  16. '/etc/config/*' \
  17. '/etc/dropbear/*')
  18. declare -x _debug="false"
  19. #####################
  20. ##### FUNCTIONS #####
  21. #####################
  22. runDebug () { [[ "$_debug" == "true" ]] && echo "Running: " "$@" ; }
  23. sshBackup () {
  24. runDebug "${FUNCNAME[0]}"
  25. for fd in "${_backedup[@]}"; do
  26. _dir="${fd%/*}/"
  27. [[ ! -d "$_filesroot$_dir" ]] && mkdir -p "$_filesroot/$_dir"
  28. if ! scp -rp "$_ssh_backup:$fd" "$_filesroot/$_dir"; then
  29. echo "Did not successfully backup files from --ssh-backup"
  30. echo "Exiting now to prevent data loss!"
  31. exit 1
  32. fi
  33. done
  34. }
  35. getOS () {
  36. runDebug "${FUNCNAME[0]}"
  37. if [[ -f /etc/os-release ]]; then
  38. source /etc/os-release
  39. else
  40. echo "Cannot detect OS!"
  41. exit 1
  42. fi
  43. }