debian-config 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #!/bin/bash
  2. #
  3. # Copyright (c) Authors: http://www.armbian.com/authors, info@armbian.com
  4. #
  5. # This file is licensed under the terms of the GNU General Public
  6. # License version 2. This program is licensed "as is" without any
  7. # warranty of any kind, whether express or implied.
  8. #
  9. # check for root privileges
  10. #
  11. if [[ $EUID != 0 ]]; then
  12. echo "This tool requires root privileges. Try again with \"sudo \" please ..." >&2
  13. sleep 2
  14. exit 1
  15. fi
  16. #
  17. # check for internet connection to install dependencies
  18. #
  19. wget -q --spider www.baidu.com
  20. if [[ $? -ne 0 ]]; then
  21. read -n 1 -s -p "Warning: Configuration cannot work properly without a working internet connection. \
  22. Press CTRL C to stop or any key to ignore and continue."
  23. fi
  24. #
  25. # load functions, local first
  26. #
  27. if [[ -f ${BASH_SOURCE}-jobs ]]; then source ${BASH_SOURCE}-jobs;
  28. elif [[ -f /usr/lib/orangepi-config/jobs.sh ]]; then source /usr/lib/orangepi-config/jobs.sh;
  29. else exit 1;
  30. fi
  31. if [[ -f ${BASH_SOURCE}-submenu ]]; then source ${BASH_SOURCE}-submenu;
  32. elif [[ -f /usr/lib/orangepi-config/submenu.sh ]]; then source /usr/lib/orangepi-config/submenu.sh;
  33. else exit 1;
  34. fi
  35. if [[ -f ${BASH_SOURCE}-functions ]]; then source ${BASH_SOURCE}-functions;
  36. elif [[ -f /usr/lib/orangepi-config/functions.sh ]]; then source /usr/lib/orangepi-config/functions.sh;
  37. else exit 1;
  38. fi
  39. if [[ -f ${BASH_SOURCE}-functions-network ]]; then source ${BASH_SOURCE}-functions-network;
  40. elif [[ -f /usr/lib/orangepi-config/functions-network.sh ]]; then source /usr/lib/orangepi-config/functions-network.sh;
  41. else exit 1;
  42. fi
  43. # Script parameters handling
  44. while [[ $1 == *=* ]]; do
  45. parameter=${1%%=*}
  46. value=${1##*=}
  47. shift
  48. echo "Command line: setting $parameter to ${value:-(empty)}"
  49. eval "$parameter=\"$value\""
  50. scripted=true
  51. done
  52. # Display help
  53. if [[ $1 == "--help" ]]; then
  54. echo "Orange Pi config options:"
  55. echo ""
  56. echo "Examples:"
  57. echo ""
  58. echo "Install headers: ${BASH_SOURCE[0]} main=Sytem selection=Headers"
  59. echo "Update, upgrade and reboot: ${BASH_SOURCE[0]} main=System selection=Firmware"
  60. echo "Switch to nightly builds: ${BASH_SOURCE[0]} main=System selection=Nightly"
  61. echo "Switch to stable builds: ${BASH_SOURCE[0]} main=System selection=Stable"
  62. echo "Install default desktop: ${BASH_SOURCE[0]} main=System selection=Default"
  63. echo "Change to ZSH: ${BASH_SOURCE[0]} main=System selection=ZSH"
  64. echo "Change to BASH: ${BASH_SOURCE[0]} main=System selection=BASH"
  65. echo "Change to stable repository [branch=dev]: ${BASH_SOURCE[0]} main=System selection=Stable"
  66. echo "Change to nightly repository [branch=dev]: ${BASH_SOURCE[0]} main=System selection=Nightly"
  67. echo "Install headers: ${BASH_SOURCE[0]} main=Software selection=Headers_install"
  68. echo "Remove headers: ${BASH_SOURCE[0]} main=Software selection=Headers_remove"
  69. echo "Install kernel source: ${BASH_SOURCE[0]} main=Software selection=Source_install"
  70. echo "Remove kernel source: ${BASH_SOURCE[0]} main=Software selection=Source_remove"
  71. echo "Install Avahi mDNS/DNS-SD daemon: ${BASH_SOURCE[0]} main=Software selection=Avahi"
  72. exit
  73. fi
  74. # collect info
  75. main "$@"
  76. #
  77. # Main menu
  78. #
  79. while true
  80. do
  81. LIST=()
  82. LIST+=( "System" "System and security settings" )
  83. LIST+=( "Network" "Wired, wireless, Bluetooth, access point" )
  84. LIST+=( "Personal" "Timezone, language, hostname" )
  85. LIST+=( "Software" "System and 3rd party software install" )
  86. LIST+=( "Help" "Documentation, support, sources" )
  87. # count number of menu items to adjust window size
  88. LISTLENGTH="$((11+${#LIST[@]}/2))"
  89. BOXLENGTH=${#LIST[@]}
  90. MENUTITLE="Configure \Z1$DISTRO $DISTROID\Z0"
  91. # read cpu speed
  92. POLICY="policy0"
  93. [[ $(grep -c '^processor' /proc/cpuinfo) -gt 4 ]] && POLICY="policy4"
  94. [[ ! -d /sys/devices/system/cpu/cpufreq/policy4 ]] && POLICY="policy0"
  95. num=$(cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_min_freq 2> /dev/null)
  96. if [[ -f /etc/default/cpufrequtils && ! -z "${num##*[!0-9]*}" ]]; then
  97. LISTLENGTH=$((LISTLENGTH + 2))
  98. MIN_CPU=$(($(cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_min_freq) / 1000))
  99. MAX_CPU=$(($(cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_max_freq) / 1000))
  100. GOVERNOR_CPU=$(cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_governor)
  101. FREQENCIES="\nSoC runs between \Z1${MIN_CPU}\Z0 and \Z1${MAX_CPU} MHz\Z0 using \Z1${GOVERNOR_CPU}\Z0 governor.\n"
  102. fi
  103. [[ -n "${BOARD_NAME/ /}" ]] && MENUTITLE=$MENUTITLE" based \Z1OrangePi\Z0 for the \Z1${BOARD_NAME}\Z0 "
  104. # main dialog routine
  105. DIALOG_CANCEL=1
  106. DIALOG_ESC=255
  107. TITLELENGTH=${#MENUTITLE}
  108. [[ "$TITLELENGTH" -lt 60 ]] && TITLELENGTH="60"
  109. if [[ -z $main ]]; then
  110. exec 3>&1
  111. main=$(dialog --colors --backtitle "$BACKTITLE" --title " orangepi-config " --clear \
  112. --cancel-label "Exit" --menu "\n$MENUTITLE \n$FREQENCIES\nSupport: \Z1http://www.orangepi.org\Z0\n " \
  113. $LISTLENGTH ${TITLELENGTH} $BOXLENGTH "${LIST[@]}" 2>&1 1>&3)
  114. exit_status=$?
  115. exec 3>&-
  116. [[ $exit_status == $DIALOG_CANCEL || $exit_status == $DIALOG_ESC ]] && clear && exit
  117. dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox \
  118. "\nLoading ${main,,} submodule ... " 5 $((26+${#main}))
  119. fi
  120. case $main in
  121. "System" )
  122. submenu_settings
  123. ;;
  124. "Network" )
  125. submenu_networking
  126. ;;
  127. "Personal" )
  128. submenu_personal
  129. ;;
  130. "Software" )
  131. submenu_software
  132. ;;
  133. "Help" )
  134. unset main
  135. t="This tool provides a straightforward way of configuring."
  136. t=$t"\n \nAlthough it can be run at any time, some of the"
  137. t=$t" options may have difficulties if you alter system settings manually.\n"
  138. t=$t"\n\Z1Documentation:\Z0 http://www.orangepi.org"
  139. t=$t"\n\n\Z1Support:\Z0 http://www.orangepi.org\n"
  140. t=$t"\n\Z1Sources:\Z0 https://github.com/orangepi-xunlong"
  141. show_box "Info" "$t" "18"
  142. ;;
  143. esac
  144. done