debian-config-functions 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  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. # Functions:
  9. # main
  10. # check_desktop
  11. # exceptions
  12. # check_if_installed
  13. # is_package_manager_running
  14. # display_qr_code
  15. # beta_disclaimer
  16. # show_box
  17. # description
  18. # generic_select
  19. # reload_bsp
  20. # other_kernel_version
  21. # aval_dtbs
  22. # get_a20modes
  23. # get_h3modes
  24. # add_choose_user
  25. # google_token_allusers
  26. # configure_desktop
  27. #
  28. # gather info about the board and start with loading menu
  29. #
  30. function main(){
  31. DIALOG_CANCEL=1
  32. DIALOG_ESC=255
  33. # we have our own lsb_release which does not use Python. Others shell install it here
  34. if [[ ! -f /usr/bin/lsb_release ]]; then
  35. if is_package_manager_running; then
  36. sleep 3
  37. fi
  38. debconf-apt-progress -- apt-get update
  39. debconf-apt-progress -- apt -y -qq --allow-downgrades --no-install-recommends install lsb-release
  40. fi
  41. [[ -f /etc/orangepi-release ]] && source /etc/orangepi-release && ORANGEPI="Orange Pi $VERSION $IMAGE_TYPE";
  42. DISTRO=$(lsb_release -is)
  43. DISTROID=$(lsb_release -sc)
  44. KERNELID=$(uname -r)
  45. [[ -z "${ORANGEPI// }" ]] && ORANGEPI="$DISTRO $DISTROID"
  46. DEFAULT_ADAPTER=$(ip -4 route ls | grep default | tail -1 | grep -Po '(?<=dev )(\S+)')
  47. LOCALIPADD=$(ip -4 addr show dev $DEFAULT_ADAPTER | awk '/inet/ {print $2}' | cut -d'/' -f1)
  48. BACKTITLE="Configuration utility, $ORANGEPI"
  49. [[ -n "$LOCALIPADD" ]] && BACKTITLE=$BACKTITLE", "$LOCALIPADD
  50. TITLE="$BOARD_NAME "
  51. [[ -z "${DEFAULT_ADAPTER// }" ]] && DEFAULT_ADAPTER="lo"
  52. OVERLAYDIR="/boot/dtb/overlay";
  53. [[ "$LINUXFAMILY" == "sunxi64" ]] && OVERLAYDIR="/boot/dtb/allwinner/overlay";
  54. [[ "$LINUXFAMILY" == "meson64" ]] && OVERLAYDIR="/boot/dtb/amlogic/overlay";
  55. [[ "$LINUXFAMILY" == "rockchip64" ]] && OVERLAYDIR="/boot/dtb/rockchip/overlay";
  56. [[ "$LINUXFAMILY" == "rockchip-rk3588" ]] && OVERLAYDIR="/boot/dtb/rockchip/overlay";
  57. [[ "$LINUXFAMILY" == "sun50iw9" && "$BRANCH" == "current" ]] && OVERLAYDIR="/boot/dtb/sunxi/overlay";
  58. [[ "$LINUXFAMILY" == "sun50iw9" && "$BRANCH" == "next" ]] && OVERLAYDIR="/boot/dtb/allwinner/overlay";
  59. [[ "$LINUXFAMILY" == "rockchip-rk356x" ]] && OVERLAYDIR="/boot/dtb/rockchip/overlay";
  60. [[ "$LINUXFAMILY" == "ky" ]] && OVERLAYDIR="/boot/dtb/ky/overlay";
  61. # detect desktop
  62. check_desktop
  63. dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nLoading Orange Pi configuration utility ... " 5 45
  64. sleep 1
  65. }
  66. #
  67. # compare two strings in dot separated version format
  68. #
  69. vercomp () {
  70. if [[ $1 == $2 ]]
  71. then
  72. return 0
  73. fi
  74. local IFS=.
  75. local i ver1=($1) ver2=($2)
  76. # fill empty fields in ver1 with zeros
  77. for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
  78. do
  79. ver1[i]=0
  80. done
  81. for ((i=0; i<${#ver1[@]}; i++))
  82. do
  83. if [[ -z ${ver2[i]} ]]
  84. then
  85. # fill empty fields in ver2 with zeros
  86. ver2[i]=0
  87. fi
  88. if ((10#${ver1[i]} > 10#${ver2[i]}))
  89. then
  90. return 1
  91. fi
  92. if ((10#${ver1[i]} < 10#${ver2[i]}))
  93. then
  94. return 2
  95. fi
  96. done
  97. return 0
  98. }
  99. #
  100. # test compare two strings $1="3.4.12" $2="5.4.2" $3="<" returns 0 if relation is correct
  101. #
  102. testvercomp () {
  103. vercomp $1 $2
  104. case $? in
  105. 0) op='=';;
  106. 1) op='>';;
  107. 2) op='<';;
  108. esac
  109. if [[ $op != $3 ]]
  110. then
  111. return 1
  112. else
  113. return 0
  114. fi
  115. }
  116. #
  117. # read desktop parameters
  118. #
  119. function check_desktop()
  120. {
  121. DISPLAY_MANAGER=""; DESKTOP_INSTALLED=""
  122. check_if_installed nodm && DESKTOP_INSTALLED="nodm";
  123. check_if_installed lightdm && DESKTOP_INSTALLED="lightdm";
  124. check_if_installed gdm && DESKTOP_INSTALLED="gdm";
  125. [[ -n $(service lightdm status 2> /dev/null | grep -w active) ]] && DISPLAY_MANAGER="lightdm"
  126. [[ -n $(service nodm status 2> /dev/null | grep -w active) ]] && DISPLAY_MANAGER="nodm"
  127. [[ -n $(service gdm status 2> /dev/null | grep -w active) ]] && DISPLAY_MANAGER="gdm"
  128. }
  129. #
  130. # naming exceptions for packages
  131. #
  132. function exceptions ()
  133. {
  134. TARGET_FAMILY=$LINUXFAMILY
  135. UBOOT_BRANCH=$TARGET_BRANCH # uboot naming is different
  136. if [[ $TARGET_BRANCH == "default" ]]; then TARGET_BRANCH=""; else TARGET_BRANCH="-"$TARGET_BRANCH; fi
  137. # pine64
  138. if [[ $TARGET_FAMILY == pine64 ]]; then
  139. TARGET_FAMILY="sunxi64"
  140. fi
  141. # allwinner legacy kernels
  142. if [[ $TARGET_FAMILY == sun*i ]]; then
  143. TARGET_FAMILY="sunxi"
  144. if [[ $UBOOT_BRANCH == "default" ]]; then
  145. TARGET_FAMILY=$(cat /proc/cpuinfo | grep "Hardware" | sed 's/^.*Allwinner //' | awk '{print $1;}')
  146. fi
  147. fi
  148. }
  149. #
  150. # check dpkg status of $1 -- currently only 'not installed at all' case caught
  151. #
  152. check_if_installed (){
  153. local DPKG_Status="$(dpkg -s "$1" 2>/dev/null | awk -F": " '/^Status/ {print $2}')"
  154. if [[ "X${DPKG_Status}" = "X" || "${DPKG_Status}" = *deinstall* ]]; then
  155. return 1
  156. else
  157. return 0
  158. fi
  159. }
  160. #
  161. # check if package manager is doing something
  162. #
  163. function is_package_manager_running() {
  164. if ps -C apt-get,apt,dpkg >/dev/null ; then
  165. [[ -z $scripted ]] && dialog --colors --title " \Z1Error\Z0 " --backtitle "$BACKTITLE" --no-collapse --msgbox \
  166. "\n\Z0Package manager is running in the background. \n\nCan't install dependencies. Try again later." 9 53
  167. return 0
  168. else
  169. return 1
  170. fi
  171. }
  172. #
  173. # wget with dialog progress bar $1=URL $2=parameters
  174. #
  175. function fancy_wget()
  176. {
  177. LANG=C wget $2 --progress=bar:force:noscroll $1 2>&1 | stdbuf -i0 -o0 -e0 tr '>' '\n' | \
  178. stdbuf -i0 -o0 -e0 sed -rn 's/^.*\<([0-9]+)%\[.*$/\1/p' | dialog --backtitle "$BACKTITLE" --title " Downloading " \
  179. --gauge "Please wait" 7 70 0
  180. }
  181. #
  182. # display qr code for authentication method
  183. #
  184. function display_qr_code()
  185. {
  186. clear
  187. SECRET=$(head -1 /root/.google_authenticator)
  188. qrencode -m 2 -d 9 -8 -t ANSI256 "otpauth://totp/test?secret=$SECRET"
  189. echo -e "\nHow to setup your one type password generator?\n"
  190. echo -e "\nInstall a one-time password authenticator on your mobile device (e.g. FreeOTP) from the Android \
  191. market or F-Droid. \n\nIn the application menu, click the corresponding button to create a new account and either \
  192. scan the QR code or enter the secret key manually:\\n\n$SECRET \n\nYou should now see a new passcode token being \
  193. generated every 60 seconds on your phone.\n" | fold -sw 60
  194. read -n 1 -s -r -p "Press any key to continue"
  195. }
  196. #
  197. # show disclaimer
  198. #
  199. function beta_disclaimer ()
  200. {
  201. exec 3>&1
  202. ACKNOWLEDGEMENT=$(dialog --colors --nocancel --backtitle "$BACKTITLE" --no-collapse --title " Warning " \
  203. --clear \--radiolist "\n$1\n \n" 0 56 5 "Yes, I understand" "" off 2>&1 1>&3)
  204. exec 3>&-
  205. }
  206. #
  207. # show box
  208. #
  209. function show_box ()
  210. {
  211. dialog --colors --backtitle "$BACKTITLE" --no-collapse --title " $1 " --clear --msgbox "\n$2\n \n" $3 56
  212. }
  213. #
  214. # show description for MOTD files
  215. #
  216. function description
  217. {
  218. case $1 in
  219. *header*)
  220. echo "Big board logo and kernel info"
  221. ;;
  222. *sysinfo*)
  223. echo "Sysinfo - load, ip, memory, uptime, ..."
  224. ;;
  225. *tips*)
  226. echo "Shows tip of the day"
  227. ;;
  228. *updates*)
  229. echo "Display number of available updates"
  230. ;;
  231. *orangepi-config*)
  232. echo "Show command for system configuration"
  233. ;;
  234. *autoreboot-warn*)
  235. echo "Show warning when reboot is needed"
  236. ;;
  237. *uk.armbian.com*)
  238. echo "United Kingdom"
  239. ;;
  240. *mirrors.tuna.tsinghua.edu.cn/armbian/*)
  241. echo "China"
  242. ;;
  243. *mirrors.netix.net/armbian/apt/*)
  244. echo "Bulgarija"
  245. ;;
  246. *mirrors.dotsrc.org/armbian-apt/*)
  247. echo "Denmark"
  248. ;;
  249. *.armbian.com*)
  250. echo "Estonia"
  251. ;;
  252. *)
  253. echo ""
  254. ;;
  255. esac
  256. }
  257. #
  258. # Generic select box
  259. #
  260. function generic_select()
  261. {
  262. IFS=$' '
  263. PARAMETER=($1)
  264. local LIST=()
  265. for i in "${PARAMETER[@]}"
  266. do
  267. if [[ -n $3 ]]; then
  268. [[ ${i[0]} -ge $3 ]] && \
  269. LIST+=( "${i[0]//[[:blank:]]/}" "" )
  270. else
  271. LIST+=( "${i[0]//[[:blank:]]/}" "" )
  272. fi
  273. done
  274. LIST_LENGTH=$((${#LIST[@]}/2));
  275. if [ "$LIST_LENGTH" -eq 1 ]; then
  276. PARAMETER=${PARAMETER[0]}
  277. else
  278. exec 3>&1
  279. PARAMETER=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
  280. --title "$2" --clear --menu "" $((6+${LIST_LENGTH})) 0 $((1+${LIST_LENGTH})) "${LIST[@]}" 2>&1 1>&3)
  281. exec 3>&-
  282. fi
  283. }
  284. #
  285. # reload kernel, bsp and orangepi-config
  286. #
  287. function reload_bsp(){
  288. # switch to defined branch
  289. [[ -n "$1" ]] && BRANCH=$1
  290. # deal with exceptions
  291. if [[ $BRANCH == current || $BRANCH == dev ]]; then
  292. [[ ${LINUXFAMILY} == rk3399 ]] && LINUXFAMILY=rockchip64
  293. fi
  294. clear
  295. debconf-apt-progress -- apt-get update
  296. # must exits
  297. PACKAGE_INSTALL="linux-image-${BRANCH}-${LINUXFAMILY} linux-dtb-${BRANCH}-${LINUXFAMILY}"
  298. PACKAGE_PURGE="linux-image* linux-dtb*"
  299. # create install and remove logic
  300. command=$(LC_ALL=C apt-get --download-only --simulate --allow-downgrades -y --no-install-recommends install linux-${DISTROID}-root-${BRANCH}-${BOARD} 2>/dev/null)
  301. if [[ $? -eq 0 && -z $(echo $command | grep "not possible") ]]; then
  302. PACKAGE_INSTALL+=" linux-${DISTROID}-root-${BRANCH}-${BOARD}"
  303. PACKAGE_PURGE+=" linux-${DISTROID}-root*"
  304. fi
  305. command=$(LC_ALL=C apt-get --download-only --simulate --reinstall --allow-downgrades -y --no-install-recommends install linux-u-boot-${BOARD}-${BRANCH} 2>/dev/null)
  306. if [[ $? -eq 0 && -z $(echo $command | grep "not possible") ]]; then
  307. PACKAGE_INSTALL+=" linux-u-boot-${BOARD}-${BRANCH}"
  308. PACKAGE_PURGE+=" linux-u-boot-${BOARD}-*"
  309. fi
  310. if check_if_installed orangepi-${DISTROID}-desktop ; then
  311. PACKAGE_INSTALL+=" orangepi-${DISTROID}-desktop"
  312. PACKAGE_PURGE+=" orangepi-${DISTROID}-desktop*"
  313. fi
  314. if check_if_installed linux-headers-${BRANCH}-${FAMILY} ; then
  315. PACKAGE_INSTALL+=" linux-headers-${BRANCH}-${FAMILY}"
  316. PACKAGE_PURGE+=" linux-headers*"
  317. fi
  318. debconf-apt-progress -- apt-get -o Dpkg::Options::="--force-confold" --force-yes --download-only --allow-downgrades -y --no-install-recommends install $PACKAGE_INSTALL
  319. # if download is ok, remove old packages
  320. if [[ $? = 0 ]]; then
  321. debconf-apt-progress -- apt-get -y -qq purge $PACKAGE_PURGE
  322. find "/boot/" -name "System.map*" -type f -delete
  323. find "/boot/" -name "config*" -type f -delete
  324. find "/boot/" -name "vmlinuz*" -type f -delete
  325. find "/boot/" -name "*nitrd*" -type f -delete
  326. find "/boot/" -name "*Image" -type l -delete
  327. # install packages
  328. echo $PACKAGE_INSTALL >> /var/log/upgrade.log
  329. debconf-apt-progress -- apt-get -y -qq --allow-downgrades --no-install-recommends --reinstall \
  330. -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install $PACKAGE_INSTALL
  331. if [[ $? -eq 1 ]]; then
  332. echo "Something went wrong ... check logs."; exit;
  333. else
  334. apt clean
  335. fi
  336. fi
  337. }
  338. function other_kernel_version ()
  339. {
  340. IFS=$'\r\n'
  341. GLOBIGNORE='*'
  342. local HIDDEN='hidden'
  343. # get current kernel information
  344. CURRENT_VERSION_TEMP=$(dpkg -l | grep '^ii' | grep linux-image)
  345. CURRENT_VERSION=$(echo $CURRENT_VERSION_TEMP | awk '{print $2}')"="$(echo $CURRENT_VERSION_TEMP | awk '{print $3}')
  346. # Merge families and handle exceptions
  347. [[ ${LINUXFAMILY} == sun*i ]] && LINUXFAMILY=sunxi
  348. [[ ${LINUXFAMILY} == pine64 ]] && LINUXFAMILY=sunxi64
  349. [[ ${LINUXFAMILY} == sun*iw* ]] && LINUXFAMILY=sunxi64
  350. [[ ${LINUXFAMILY} == cubox || ${LINUXFAMILY} == udoo ]] && LINUXFAMILY=imx6
  351. [[ ${BOARD} == odroidc2 || ${BOARD} == kvim1 || ${BOARD} == lafrite || ${BOARD} == lepotato || ${BOARD} == nanopik2-s905 ]] && HIDDEN="legacy"
  352. [[ ${LINUXFAMILY} == odroidn2 ]] && LINUXFAMILY=meson64
  353. # check what is available from the repository
  354. debconf-apt-progress -- apt-get update
  355. LIST=($(apt-cache show linux-image*${LINUXFAMILY} | grep -E "Package:|Version:|version:" \
  356. | grep -v "Config-Version" | sed -n -e 's/^.*: //p' | sed 's/\.$//g'))
  357. new_list=()
  358. # create a human readable menu
  359. for ((n=0;n<$((${#LIST[@]}));n++));
  360. do
  361. m=$(( $n + 1 ))
  362. prvi=$((3*$m - 3))
  363. drugi=$((3*$m - 2))
  364. tretji=$((3*$m - 1))
  365. [[ -z ${LIST[$prvi]} ]] && break
  366. if [[ $CURRENT_VERSION != "${LIST[$prvi]}=${LIST[$drugi]}" && ${LIST[$prvi]} != *${HIDDEN}* ]]; then
  367. new_list+=( "${LIST[$prvi]}=${LIST[$drugi]}" )
  368. new_list+=( ${LIST[$tretji]} )
  369. fi
  370. local tmp="${LIST[$prvi]}=${LIST[$drugi]}${LIST[$tretji]}"
  371. [[ ${#tmp} -gt $chrlen ]] && local chrlen=${#tmp}
  372. done
  373. # copy back to main array
  374. LIST=("${new_list[@]}")
  375. LIST_LENGTH=$((${#LIST[@]}/2));
  376. if [ "$LIST_LENGTH" -eq 0 ]; then
  377. dialog --backtitle "$BACKTITLE" --title " Warning " --msgbox "\nNo other kernels available!" 7 32
  378. else
  379. beta_disclaimer "Switching between kernels might change functionality of your board or it might fail to boot. \
  380. \n\n\Z1In case of troubles expect no help!\Z0"
  381. if [[ -n $ACKNOWLEDGEMENT ]]; then
  382. exec 3>&1
  383. TARGET_VERSION=$(dialog --ok-label "Reboot" --cancel-label "Cancel" --backtitle "$BACKTITLE" --no-collapse \
  384. --title "Select kernel and reboot" --clear --menu "" $((6+${LIST_LENGTH})) $((7+${chrlen})) 25 "${LIST[@]}" 2>&1 1>&3)
  385. exitstatus=$?;
  386. exec 3>&-
  387. if [[ $exitstatus = 0 ]]; then
  388. IFS=" "
  389. # determine upgrade packages
  390. UPGRADE_ROOT="default"
  391. UPGRADE_UBOOT=""
  392. [[ $TARGET_VERSION == *legacy* ]] && UPGRADE_ROOT="-legacy" && UPGRADE_UBOOT="legacy"
  393. [[ $TARGET_VERSION == *next* ]] && UPGRADE_ROOT="-next" && UPGRADE_UBOOT="next"
  394. [[ $TARGET_VERSION == *current* ]] && UPGRADE_ROOT="-current" && UPGRADE_UBOOT="current"
  395. [[ $TARGET_VERSION == *dev* ]] && UPGRADE_ROOT="-dev" && UPGRADE_UBOOT="dev"
  396. # install packages
  397. PACKAGE_LIST="$TARGET_VERSION"
  398. TARGET_VERSION_DTB=${TARGET_VERSION/image/dtb}
  399. TARGET_VERSION_PRE=$(echo $TARGET_VERSION_DTB | cut -f1 -d"=")
  400. TARGET_VERSION_SUB=$(echo $TARGET_VERSION_DTB | cut -f2 -d"=")
  401. [[ -n $(apt-cache madison "$TARGET_VERSION_PRE" | grep $TARGET_VERSION_SUB ) ]] && \
  402. # installs u-boot only if exits
  403. apt-cache show linux-u-boot-${BOARD}-${UPGRADE_UBOOT} 2> /dev/null
  404. [[ $? -eq 0 ]] && PACKAGE_LIST=$PACKAGE_LIST" linux-u-boot-${BOARD}-${UPGRADE_UBOOT}"
  405. PACKAGE_LIST=$PACKAGE_LIST" $TARGET_VERSION_DTB"
  406. echo $PACKAGE_LIST > /tmp/switch_kernel.log 2>&1
  407. debconf-apt-progress -- apt -o Dpkg::Options::="--force-confold" --force-yes --download-only --allow-downgrades -y --no-install-recommends install $PACKAGE_LIST
  408. if [[ $? = 0 ]]; then
  409. dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nRemoving current kernel ..." 5 36
  410. # remove old kernel
  411. debconf-apt-progress -- apt -y -qq purge linux-u-boot* linux-image* linux-dtb* linux-headers* linux-${DISTROID}-root*
  412. # cleanup
  413. find "/boot/" -name "System.map*" -type f -delete; find "/boot/" -name "config*" -type f -delete
  414. find "/boot/" -name "vmlinuz*" -type f -delete; find "/boot/" -name "*nitrd*" -type f -delete
  415. apt clean
  416. # BSP must be installed separate otherwise it won't work
  417. debconf-apt-progress -- apt -o Dpkg::Options::="--force-confold" --force-yes -y -qq --allow-downgrades --no-install-recommends install linux-${DISTROID}-root${UPGRADE_ROOT}-${BOARD}
  418. debconf-apt-progress -- apt -o Dpkg::Options::="--force-confold" --force-yes -y -qq --allow-downgrades --no-install-recommends install $PACKAGE_LIST
  419. if [[ $? = 0 ]]; then
  420. # update boot loader
  421. [[ -f /usr/lib/u-boot/platform_install.sh ]] && source /usr/lib/u-boot/platform_install.sh
  422. #recognize_root
  423. root_uuid=$(sed -e 's/^.*root=//' -e 's/ .*$//' < /proc/cmdline)
  424. root_partition=$(blkid | tr -d '":' | grep "${root_uuid}" | awk '{print $1}')
  425. root_partition_device="${root_partition::-2}"
  426. write_uboot_platform "$DIR" "${root_partition_device}"
  427. reboot
  428. fi
  429. else
  430. dialog --backtitle "$BACKTITLE" --title "Warning" --msgbox \
  431. "\nTest install failed. Can't change firmware \n\nCheck /tmp/switch_kernel.log" 9 48
  432. fi
  433. fi
  434. fi
  435. fi
  436. }
  437. #
  438. # check if board has alternative kernels
  439. #
  440. function aval_dtbs ()
  441. {
  442. if [[ $LINUXFAMILY == cubox ]]; then
  443. local width=80
  444. LIST=("imx6dl-hummingboard.dtb" "HB Solo/DualLite" "imx6dl-hummingboard-emmc-som-v15.dtb" "HB Solo/DualLite v1.5 with eMMC" "imx6dl-hummingboard-som-v15.dtb" "HB Solo/DualLite v1.5" \
  445. "imx6dl-hummingboard2.dtb" "HB2 Solo/DualLite" "imx6dl-hummingboard2-emmc-som-v15.dtb" "HB2 Solo/DualLite v1.5 with eMMC" "imx6dl-hummingboard2-som-v15.dtb" "HB2 Solo/DualLite v1.5" \
  446. "imx6q-hummingboard.dtb" "HB Dual/Quad" "imx6q-hummingboard-emmc-som-v15.dtb" "HB Dual/Quad v1.5 with eMMC" "imx6q-hummingboard-som-v15.dtb" "HB Dual/Quad v1.5" \
  447. "imx6q-hummingboard2.dtb" "HB2 Dual/Quad" "imx6q-hummingboard2-emmc-som-v15.dtb" "HB2 Dual/Quad v1.5 with eMMC" "imx6q-hummingboard2-som-v15.dtb" "HB2 Dual/Quad v1.5" \
  448. "imx6dl-cubox-i.dtb" "Cubox-i Solo/DualLite" "imx6dl-cubox-i-emmc-som-v15.dtb" "Cubox-i Solo/DualLite v1.5 with eMMC" "imx6dl-cubox-i-som-v15.dtb" "Cubox-i Solo/DualLite v1.5" \
  449. "imx6q-cubox-i.dtb" "Cubox-i Dual/Quad" "imx6q-cubox-i-emmc-som-v15.dtb" "Cubox-i Dual/Quad v1.5 with eMMC" "imx6q-cubox-i-som-v15.dtb" "Cubox-i Dual/Quad v1.5")
  450. else
  451. local width=52
  452. LIST=("xu4" "Odroid XU4" "xu3" "Odroid XU3" "xu3l" "Odroid XU3 Lite" "hc1" "Odroid HC1/HC2")
  453. fi
  454. LIST_LENGTH=$((${#LIST[@]}/2));
  455. if [ "$LIST_LENGTH" -eq 1 ]; then
  456. TARGET_BOARD=${AVAL_KERNEL[0]}
  457. else
  458. exec 3>&1
  459. TARGET_BOARD=$(dialog --cancel-label "Cancel" --backtitle "$BACKTITLE" --no-collapse \
  460. --title "Select optimised board configuration" --clear --menu \
  461. "" $((6+${LIST_LENGTH})) ${width} 25 "${LIST[@]}" 2>&1 1>&3)
  462. exitstatus=$?;
  463. exec 3>&-
  464. fi
  465. }
  466. #
  467. # select video modes for a10 and a20
  468. #
  469. function get_a20modes ()
  470. {
  471. IFS=$'\r'
  472. GLOBIGNORE='*'
  473. SCREEN_RESOLUTION=("1920x1080p60" "1280x720p60" "1920x1080p50" "1280x1024p60" "1024x768p60" "800x600p60" "640x480p60" "1360x768p60" "1440x900p60" "1680x1050p60")
  474. local LIST=()
  475. for i in "${SCREEN_RESOLUTION[@]}"
  476. do
  477. LIST+=( "${i[0]//[[:blank:]]/}" "" )
  478. done
  479. LIST_LENGTH=$((${#LIST[@]}/2));
  480. #echo $LIST_LENGTH
  481. #exit
  482. if [ "$LIST_LENGTH" -eq 1 ]; then
  483. SCREEN_RESOLUTION=${SCREEN_RESOLUTION[0]}
  484. else
  485. exec 3>&1
  486. SCREEN_RESOLUTION=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
  487. --title "Select video mode" --clear --menu \
  488. "" $((6+${LIST_LENGTH})) 25 $((1+${LIST_LENGTH})) "${LIST[@]}" 2>&1 1>&3)
  489. exec 3>&-
  490. fi
  491. }
  492. #
  493. # select video modes for odroid c1/c2
  494. #
  495. function get_odroidmodes ()
  496. {
  497. IFS=$'\r\n'
  498. GLOBIGNORE='*'
  499. SCREEN_RESOLUTION=($(cat /boot/boot.ini | grep -w "# setenv" | grep "hz" | cut -d'"' -f 2))
  500. SCREEN_RESOLUTION=($(cat /boot/boot.ini | grep "Progressive" | grep -v "setenv" | cut -d'"' -f 2))
  501. local LIST=()
  502. for i in "${SCREEN_RESOLUTION[@]}"
  503. do
  504. LIST+=( "${i[0]//[[:blank:]]/}" "" )
  505. done
  506. LIST_LENGTH=$((${#LIST[@]}/2));
  507. #echo $LIST_LENGTH
  508. #exit
  509. if [ "$LIST_LENGTH" -eq 1 ]; then
  510. SCREEN_RESOLUTION=${SCREEN_RESOLUTION[0]}
  511. else
  512. exec 3>&1
  513. SCREEN_RESOLUTION=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
  514. --title "Select video mode" --clear --menu \
  515. "" $((6+${LIST_LENGTH})) 25 $((1+${LIST_LENGTH})) "${LIST[@]}" 2>&1 1>&3)
  516. exec 3>&-
  517. fi
  518. }
  519. #
  520. # select video modes for h3
  521. #
  522. function get_h3modes ()
  523. {
  524. IFS=$'\r\n'
  525. GLOBIGNORE='*'
  526. SCREEN_RESOLUTION=($(h3disp -i clean))
  527. local LIST=()
  528. for i in "${SCREEN_RESOLUTION[@]}"
  529. do
  530. LIST+=( "${i[0]//[[:blank:]]/}" "" )
  531. done
  532. LIST_LENGTH=$((${#LIST[@]}/2));
  533. #echo $LIST_LENGTH
  534. #exit
  535. if [ "$LIST_LENGTH" -eq 1 ]; then
  536. SCREEN_RESOLUTION=${SCREEN_RESOLUTION[0]}
  537. else
  538. exec 3>&1
  539. SCREEN_RESOLUTION=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
  540. --title "Select video mode" --clear --menu \
  541. "" $((6+${LIST_LENGTH})) 25 $((1+${LIST_LENGTH})) "${LIST[@]}" 2>&1 1>&3)
  542. exec 3>&-
  543. fi
  544. }
  545. #
  546. # create or pick unprivileged user
  547. #
  548. function add_choose_user ()
  549. {
  550. IFS=$'\r\n'
  551. GLOBIGNORE='*'
  552. local USERS=($(awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534) print $1}' /etc/passwd))
  553. local LIST=()
  554. for i in "${USERS[@]}"
  555. do
  556. LIST+=( "${i[0]//[[:blank:]]/}" "" )
  557. done
  558. LIST_LENGTH=$((${#LIST[@]}/2));
  559. if [ "$LIST_LENGTH" -eq 0 ]; then
  560. dialog --backtitle "$BACKTITLE" --title " Notice " --msgbox \
  561. "\nWe didn't find any unprivileged user with sudo rights which is required to run this service.\
  562. \n\nPress enter to create one!" 10 48
  563. read -t 0 temp
  564. echo -e "\nPlease provide a username (eg. your forename) or leave blank for canceling user creation: \c"
  565. read -e username
  566. CHOSEN_USER="$(echo "$username" | tr '[:upper:]' '[:lower:]' | tr -d -c '[:alnum:]')"
  567. [ -z "$CHOSEN_USER" ] && return
  568. echo "Trying to add user $CHOSEN_USER"
  569. adduser $CHOSEN_USER || return
  570. elif [ "$LIST_LENGTH" -eq 1 ]; then
  571. CHOSEN_USER=${USERS[0]}
  572. else
  573. exec 3>&1
  574. CHOSEN_USER=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
  575. --title "Select unprivileged user" --clear --menu "" $((6+${LIST_LENGTH})) 40 15 "${LIST[@]}" 2>&1 1>&3)
  576. exec 3>&-
  577. fi
  578. }
  579. #
  580. # Copy Google token to all local users.
  581. #
  582. function google_token_allusers ()
  583. {
  584. if [[ -f /root/.google_authenticator ]]; then
  585. local USERS=($(awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534) print $1}' /etc/passwd))
  586. for i in "${USERS[@]}"
  587. do
  588. USER=${i[0]//[[:blank:]]/}
  589. if [[ -d /home/$USER ]]; then
  590. cp /root/.google_authenticator /home/$USER/
  591. chown ${USER}:${USER} /home/${USER}/.google_authenticator
  592. fi
  593. done
  594. fi
  595. }
  596. #
  597. # configure orangepi desktop
  598. #
  599. function configure_desktop ()
  600. {
  601. add_choose_user
  602. if [ -n "$CHOSEN_USER" ]; then
  603. # update packages
  604. debconf-apt-progress -- apt-get update
  605. # install new package if exists
  606. unset PACKAGE_SUFIX
  607. [[ -n $(apt-cache search --names-only "^orangepi-${DISTROID}-desktop-xfce$") ]] && PACKAGE_SUFIX="-xfce"
  608. # remove desktop package to secure proper install
  609. if check_if_installed orangepi-${DISTROID}-desktop ; then
  610. debconf-apt-progress -- apt-get -y \
  611. remove orangepi-${DISTROID}-desktop${PACKAGE_SUFIX} lightdm lightdm-gtk-greeter
  612. fi
  613. # install desktop package
  614. debconf-apt-progress -- apt-get --reinstall -o Dpkg::Options::="--force-confdef" \
  615. -o Dpkg::Options::="--force-confold" -y \
  616. install $1 orangepi-${DISTROID}-desktop${PACKAGE_SUFIX} lightdm lightdm-gtk-greeter
  617. # in case previous install was interrupted
  618. [[ $? -eq 130 ]] && dpkg --configure -a
  619. # clean apt cache
  620. apt clean
  621. # add user to groups
  622. for additionalgroup in sudo netdev audio video dialout plugdev input bluetooth systemd-journal ssh; do
  623. usermod -aG ${additionalgroup} ${CHOSEN_USER} 2>/dev/null
  624. done
  625. # Prevent loading paralel printer port drivers which we don't need here.
  626. # suppress boot error if kernel modules are absent
  627. if [[ -f /etc/modules-load.d/cups-filters.conf ]]; then
  628. sed "s/^lp/#lp/" -i /etc/modules-load.d/cups-filters.conf
  629. sed "s/^ppdev/#ppdev/" -i /etc/modules-load.d/cups-filters.conf
  630. sed "s/^parport_pc/#parport_pc/" -i /etc/modules-load.d/cups-filters.conf
  631. fi
  632. # enable show windows content on stronger boards
  633. cpu_cores=$(grep -c '^processor' /proc/cpuinfo | sed 's/^0$/1/')
  634. if [[ ${cpu_cores} -gt 2 && -f /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml ]]; then
  635. sed -i 's/<property name="box_move" type="bool" value=".*/<property name="box_move" type="bool" value="false"\/>/g' \
  636. /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml
  637. fi
  638. # fix for gksu in Xenial
  639. touch /home/${CHOSEN_USER}/.Xauthority
  640. cp -R /etc/skel/. /home/${CHOSEN_USER}
  641. # set up profile sync daemon on desktop systems
  642. which psd >/dev/null 2>&1
  643. if [[ $? -eq 0 && -z $(grep overlay-helper /etc/sudoers) ]]; then
  644. echo "${CHOSEN_USER} ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper" >> /etc/sudoers
  645. touch /home/${CHOSEN_USER}/.activate_psd
  646. fi
  647. mkdir -p /etc/lightdm/lightdm.conf.d
  648. echo "[Seat:*]" > /etc/lightdm/lightdm.conf.d/22-orangepi-autologin.conf
  649. echo "autologin-user=$CHOSEN_USER" >> /etc/lightdm/lightdm.conf.d/22-orangepi-autologin.conf
  650. echo "autologin-user-timeout=0" >> /etc/lightdm/lightdm.conf.d/22-orangepi-autologin.conf
  651. echo "user-session=xfce" >> /etc/lightdm/lightdm.conf.d/22-orangepi-autologin.conf
  652. ln -s /lib/systemd/system/lightdm.service /etc/systemd/system/display-manager.service >/dev/null 2>&1
  653. # fix permissions
  654. chown -R ${CHOSEN_USER}:${CHOSEN_USER} /home/${CHOSEN_USER}/.
  655. service lightdm start >/dev/null 2>&1
  656. fi
  657. }