/packages/tools/installer/scripts/installer

http://github.com/OpenELEC/OpenELEC.tv · Shell · 654 lines · 432 code · 118 blank · 104 comment · 39 complexity · 7de8d5e6137cee149608bd870d408514 MD5 · raw file

  1. #!/bin/sh
  2. ################################################################################
  3. # This file is part of OpenELEC - http://www.openelec.tv
  4. # Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv)
  5. #
  6. # OpenELEC is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # OpenELEC is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with OpenELEC. If not, see <http://www.gnu.org/licenses/>.
  18. ################################################################################
  19. # some DOCs:
  20. # list devices:
  21. # cat /proc/partitions | sed -n "s/\ *[0-9][0-9]*\ *[0-9][0-9]*\ *[0-9][0-9]*\ \([a-z]*\)$/\1/p"
  22. # list all partitionnumbers from /dev/sda:
  23. # parted -m /dev/sda print |grep -v ^/dev |grep -v ^BYT | cut -f1 -d ":"
  24. # list device data from /dev/sda:
  25. # parted -m /dev/sda print |grep /dev/sda
  26. # list mounted partitions:
  27. # mount |grep ^/dev
  28. # list modelnumber:
  29. # parted -m /dev/sda print |grep /dev/sda | cut -f7 -d ":" | sed "s/;//"
  30. # list size:
  31. # parted -m /dev/sda print |grep /dev/sda | cut -f2 -d ":"
  32. # exclude mounted partitions
  33. # for i in `cat /proc/mounts | grep ^/dev/ | cut -f1 -d " " | sed "s/[0-9]//"`; do TEST="$TEST `echo "| grep -v $i"`"; done
  34. # Interpret embedded "\Z" sequences in the dialog text by the following
  35. # character, which tells dialog to set colors or video attributes: 0 through 7
  36. # are the ANSI used in curses: black, red, green, yellow, blue, magenta, cyan
  37. # and white respectively. Bold is set by 'b', reset by 'B'. Reverse is set
  38. # by 'r', reset by 'R'. Underline is set by 'u', reset by 'U'. The settings are
  39. # cumulative, e.g., "\Zb\Z1" makes the following text bold (perhaps bright)
  40. # red. Restore normal settings with "\Zn".
  41. # disable Ctrl+C - can be very dangerous
  42. trap '' 2
  43. [ -f /etc/installer.conf ] && . /etc/installer.conf || exit 0
  44. dbglg() {
  45. # Acts just like echo cmd, with automatic redirection
  46. echo "" >> $LOGFILE
  47. echo "###################################################################" >> $LOGFILE
  48. echo "# $@" >> $LOGFILE
  49. echo "###################################################################" >> $LOGFILE
  50. echo "" >> $LOGFILE
  51. }
  52. get_device_unmount() {
  53. # get all unmounted devices
  54. # usage: get_devices_unmount
  55. # uses: -
  56. # provides: DEVICES
  57. DEVICES=""
  58. DEVICES=$(parted -s -m -l 2>/dev/null | grep -E '^/dev/sd|^/dev/mmcblk|^/dev/nvme' | grep -E -v '.?rpmb|.?boot?' | cut -f1 -d ":")
  59. for i in $(cat /proc/mounts | grep -E '^/dev/sd' | cut -f1 -d " " | sed "s/[0-9].*$//"); do
  60. DEVICES=$(echo $DEVICES |sed -e "s|$i||")
  61. done
  62. for i in $(cat /proc/mounts | grep -E '^/dev/mmcblk' | cut -f1 -d " " | sed "s/p.*$//"); do
  63. DEVICES=$(echo $DEVICES |sed -e "s|$i||")
  64. done
  65. for i in $(cat /proc/mounts | grep -E '^/dev/nvme' | cut -f1 -d " " | sed "s/p.*$//"); do
  66. DEVICES=$(echo $DEVICES |sed -e "s|$i||")
  67. done
  68. }
  69. get_partition() {
  70. # get all partitions of a specifed device
  71. # usage: get_partitions /dev/sda
  72. # uses: -
  73. # provides: PARTITIONS
  74. PARTITIONS=$(parted -s -m $1 print |grep -v ^/dev |grep -v BYT | cut -f1 -d ":")
  75. }
  76. create_device_list() {
  77. # creates device list to use in menus
  78. # usage: create_devices_list
  79. # uses: get_device_unmount
  80. # provides: DEVICE_MODEL, DEVICE_SIZE, DEVICE_LIST, DEVICE_NAME,
  81. # DEVICES (get_device_unmount)
  82. DEVICE_MODEL=""
  83. DEVICE_SIZE=""
  84. DEVICE_LIST=""
  85. DEVICE_NAME=""
  86. get_device_unmount
  87. if [ "$DEVICES" = "" ]; then
  88. msg_no_device
  89. fi
  90. for i in $DEVICES; do
  91. DEVICE_MODEL=$(parted -s $i -m print | grep ^$i | cut -f7 -d ":" | sed "s/;//")
  92. DEVICE_SIZE=$(parted -s $i -m print | grep ^$i | cut -f2 -d ":")
  93. DEVICE_NAME=$(echo $DEVICE_MODEL ${DEVICE_SIZE} | sed 's/ /_/g')
  94. DEVICE_LIST="$DEVICE_LIST $i $DEVICE_NAME"
  95. done
  96. }
  97. create_partition_list() {
  98. # get an overview of all partitions of a specified device
  99. # usage: create_partition_list /dev/sda
  100. # uses: get_partition
  101. # provides: PARTITION_NUMBER, PARTITION_SIZE, PARTITION_FORMAT,
  102. # PARTITION_LIST, PARTITIONS (get_partition)
  103. PARTITION_NUMBER=""
  104. PARTITION_SIZE=""
  105. PARTITION_FORMAT=""
  106. PARTITION_LIST=""
  107. get_partition $1
  108. for partition in $PARTITIONS; do
  109. PARTITION_NUMBER=$(parted -s -m $1 print |grep -v ^/dev |grep -v BYT | cut -f1 -d ":")
  110. PARTITION_SIZE=$(parted -s -m $1 print |grep -v ^/dev |grep -v BYT | cut -f4 -d ":")
  111. PARTITION_FORMAT=$(parted -s -m $1 print |grep -v ^/dev |grep -v BYT | cut -f5 -d ":")
  112. PARTITION_LIST=" $PARTITION_LIST \n Partition $1$PARTITION_NUMBER Size: $PARTITION_SIZE Format: $PARTITION_FORMAT"
  113. done
  114. }
  115. do_install_mbr() {
  116. # show menu
  117. MSG_TITLE="\Z4[ (RE)INSTALL MBR ]\Zn"
  118. MSG_MENU="\n Please select where to install MBR.\n\n Please select a device:"
  119. MSG_CANCEL="Back"
  120. create_device_list
  121. dialog --colors --backtitle "$BACKTITLE" --cancel-label "$MSG_CANCEL" \
  122. --title "$MSG_TITLE" --menu "$MSG_MENU" 20 50 5 \
  123. $DEVICE_LIST 2> $TMPDIR/device_for_install
  124. # now we must do everything
  125. case $? in
  126. 0)
  127. INSTALL_DEVICE=$(cat "$TMPDIR/device_for_install")
  128. # installing mbr
  129. prompt_gpt
  130. if [ "$GPT" = "1" ]; then
  131. cat /usr/share/syslinux/gptmbr.bin > $INSTALL_DEVICE
  132. else
  133. cat /usr/share/syslinux/mbr.bin > $INSTALL_DEVICE
  134. fi
  135. msg_install_ready "Master Boot Record installed on $INSTALL_DEVICE"
  136. ;;
  137. 1)
  138. menu_main
  139. ;;
  140. 255)
  141. do_poweroff
  142. ;;
  143. esac
  144. }
  145. do_install_quick() {
  146. # show menu
  147. MSG_TITLE="\Z4[ QUICK INSTALL MENU ]\Zn"
  148. MSG_MENU="\nUse the up/down arrows to select the correct device.\n\n Please select a device:"
  149. MSG_CANCEL="Back"
  150. DIALOG_OPTIONS="--defaultno"
  151. create_device_list
  152. dialog --colors --backtitle "$BACKTITLE" --cancel-label "$MSG_CANCEL" \
  153. $DIALOG_OPTIONS --title "$MSG_TITLE" --menu "$MSG_MENU" 20 50 5 \
  154. $DEVICE_LIST 2> $TMPDIR/device_for_install
  155. # now we must do everything
  156. case $? in
  157. 0)
  158. INSTALL_DEVICE=$(cat "$TMPDIR/device_for_install")
  159. INSTALL_DEVICE_FULL=$(echo $DEVICE_LIST | sed "s|.*$INSTALL_DEVICE \([^ ]*\).*|$INSTALL_DEVICE \1|")
  160. case $INSTALL_DEVICE in
  161. "/dev/mmcblk"*|"/dev/nvme"*)
  162. PART1="p1"
  163. PART2="p2"
  164. ;;
  165. *)
  166. PART1="1"
  167. PART2="2"
  168. ;;
  169. esac
  170. prompt_gpt
  171. prompt_backup_unpack
  172. # check for confirmation (twice!)
  173. MSG_TITLE="\Z1[ Confirmation before installing ]\Zn"
  174. MSG_DETAIL="\nIf you continue the target disk will be wiped out:\n\n$INSTALL_DEVICE_FULL\n\n"
  175. DIALOG_OPTIONS="--defaultno"
  176. dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" \
  177. $DIALOG_OPTIONS --yesno "$MSG_DETAIL" 0 0
  178. if [ $? -ne 0 ]; then
  179. menu_main
  180. fi
  181. MSG_TITLE="\Z1[ Confirmation before installing ]\Zn"
  182. MSG_DETAIL="\nThis is last chance to abort the installation!\n\nIf you continue the target disk will be wiped out:\n\n$INSTALL_DEVICE_FULL\n\n\n"
  183. DIALOG_OPTIONS="--defaultno"
  184. dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" \
  185. $DIALOG_OPTIONS --yesno "$MSG_DETAIL" 0 0
  186. if [ $? -ne 0 ]; then
  187. menu_main
  188. fi
  189. # remove all partitions
  190. msg_progress_install "1" "get all partitions $INSTALL_DEVICE"
  191. get_partition $INSTALL_DEVICE
  192. msg_progress_install "5" "wiping disk $INSTALL_DEVICE"
  193. dd if=/dev/zero of=$INSTALL_DEVICE bs=4096 count=1024
  194. # create 2 new partitions (first $PARTSIZE_SYSTEM, second rest)
  195. msg_progress_install "7" "creating label on $INSTALL_DEVICE"
  196. if [ "$GPT" = "1" ]; then
  197. parted -s $INSTALL_DEVICE mklabel gpt >> $LOGFILE 2>&1
  198. else
  199. parted -s $INSTALL_DEVICE mklabel msdos >> $LOGFILE 2>&1
  200. fi
  201. msg_progress_install "9" "writing Master Boot Record on $INSTALL_DEVICE"
  202. if [ "$GPT" = "1" ]; then
  203. cat /usr/share/syslinux/gptmbr.bin > $INSTALL_DEVICE
  204. else
  205. cat /usr/share/syslinux/mbr.bin > $INSTALL_DEVICE
  206. fi
  207. msg_progress_install "10" "creating partition on $INSTALL_DEVICE"
  208. if [ "$UEFI" = "1" ]; then
  209. parted -s $INSTALL_DEVICE unit cyl mkpart primary fat32 -- 0 $PARTSIZE_SYSTEM >> $LOGFILE 2>&1
  210. else
  211. parted -s $INSTALL_DEVICE unit cyl mkpart primary ext2 -- 0 $PARTSIZE_SYSTEM >> $LOGFILE 2>&1
  212. fi
  213. msg_progress_install "13" "creating partition on $INSTALL_DEVICE"
  214. parted -s $INSTALL_DEVICE unit cyl mkpart primary ext2 -- $PARTSIZE_SYSTEM -2 >> $LOGFILE 2>&1
  215. msg_progress_install "16" "setup bootflag on partition 1 of $INSTALL_DEVICE"
  216. parted -s $INSTALL_DEVICE set 1 boot on >> $LOGFILE 2>&1
  217. if [ "$GPT" = "1" ]; then
  218. parted -s $INSTALL_DEVICE set 1 legacy_boot on >> $LOGFILE 2>&1
  219. fi
  220. msg_progress_install "20" "tell the kernel we have a new partitiontable on $INSTALL_DEVICE"
  221. partprobe $INSTALL_DEVICE >> $LOGFILE 2>&1
  222. # create filesystem
  223. msg_progress_install "23" "creating filesystem on ${INSTALL_DEVICE}1"
  224. if [ "$UEFI" = "1" ]; then
  225. mkfs.vfat ${INSTALL_DEVICE}${PART1} >> $LOGFILE 2>&1
  226. else
  227. mke2fs -t ext4 -m 0 ${INSTALL_DEVICE}${PART1} >> $LOGFILE 2>&1
  228. fi
  229. msg_progress_install "25" "set uuid and disklabel $DISKLABEL_SYSTEM on ${INSTALL_DEVICE}${PART1}"
  230. if [ "$UEFI" = "1" ]; then
  231. dosfslabel ${INSTALL_DEVICE}${PART1} $DISKLABEL_SYSTEM >> $LOGFILE 2>&1
  232. else
  233. tune2fs -U random -L $DISKLABEL_SYSTEM ${INSTALL_DEVICE}${PART1} >> $LOGFILE 2>&1
  234. fi
  235. msg_progress_install "28" "creating filesystem on ${INSTALL_DEVICE}${PART2}"
  236. mke2fs -t ext4 -m 0 ${INSTALL_DEVICE}${PART2} >> $LOGFILE 2>&1
  237. msg_progress_install "30" "set uuid and disklabel $DISKLABEL_STORAGE on ${INSTALL_DEVICE}${PART2}"
  238. tune2fs -U random -L $DISKLABEL_STORAGE ${INSTALL_DEVICE}${PART2} >> $LOGFILE 2>&1
  239. # mount system partition
  240. msg_progress_install "35" "creating $TMPDIR/part1"
  241. mkdir -p $TMPDIR/part1 >> $LOGFILE 2>&1
  242. msg_progress_install "40" "mounting ${INSTALL_DEVICE}${PART1} to $TMPDIR/part1"
  243. if [ "$UEFI" = "1" ]; then
  244. mount -t vfat ${INSTALL_DEVICE}${PART1} $TMPDIR/part1 >> $LOGFILE 2>&1
  245. else
  246. mount -t ext4 ${INSTALL_DEVICE}${PART1} $TMPDIR/part1 >> $LOGFILE 2>&1
  247. fi
  248. # installing extlinux
  249. msg_progress_install "50" "installing extlinux to $TMPDIR/part1"
  250. if [ "$UEFI" = "1" ]; then
  251. syslinux -i ${INSTALL_DEVICE}${PART1} >> $LOGFILE 2>&1
  252. else
  253. extlinux -i $TMPDIR/part1 >> $LOGFILE 2>&1
  254. fi
  255. # install system files
  256. msg_progress_install "60" "installing Kernel"
  257. cp /flash/KERNEL $TMPDIR/part1 >> $LOGFILE 2>&1
  258. msg_progress_install "65" "installing System"
  259. cp /flash/SYSTEM $TMPDIR/part1 >> $LOGFILE 2>&1
  260. sync
  261. # configuring bootloader
  262. msg_progress_install "80" "setup bootloader with boot label = $DISKLABEL_SYSTEM and disk label = $DISKLABEL_STORAGE"
  263. echo "DEFAULT linux" > $TMPDIR/part1/extlinux.conf
  264. echo "PROMPT 0" >> $TMPDIR/part1/extlinux.conf
  265. echo " " >> $TMPDIR/part1/extlinux.conf
  266. echo "LABEL linux" >> $TMPDIR/part1/extlinux.conf
  267. echo " KERNEL /KERNEL" >> $TMPDIR/part1/extlinux.conf
  268. echo " APPEND boot=LABEL=$DISKLABEL_SYSTEM disk=LABEL=$DISKLABEL_STORAGE $EXTLINUX_PARAMETERS quiet" >> $TMPDIR/part1/extlinux.conf
  269. # uefi boot / hybrid mode
  270. if [ "$UEFI" = "1" ]; then
  271. mv $TMPDIR/part1/extlinux.conf $TMPDIR/part1/syslinux.cfg
  272. mkdir -p $TMPDIR/part1/EFI/BOOT
  273. cp $TMPDIR/part1/syslinux.cfg $TMPDIR/part1/EFI/BOOT
  274. cp /usr/share/syslinux/bootx64.efi $TMPDIR/part1/EFI/BOOT
  275. cp /usr/share/syslinux/ldlinux.e64 $TMPDIR/part1/EFI/BOOT
  276. fi
  277. sync
  278. # umount system partition, remove mountpoint
  279. msg_progress_install "85" "unmount $TMPDIR/part1"
  280. umount $TMPDIR/part1 >> $LOGFILE 2>&1
  281. msg_progress_install "87" "remove $TMPDIR/part1"
  282. rmdir $TMPDIR/part1 >> $LOGFILE 2>&1
  283. if [ "$BACKUP_UNPACK" = "1" ]; then
  284. # mount storage partition
  285. msg_progress_install "89" "creating $TMPDIR/part2"
  286. mkdir -p $TMPDIR/part2 >> $LOGFILE 2>&1
  287. msg_progress_install "90" "mounting ${INSTALL_DEVICE}${PART2} to $TMPDIR/part2"
  288. mount -t ext4 ${INSTALL_DEVICE}${PART2} $TMPDIR/part2 >> $LOGFILE 2>&1
  289. msg_progress_install "92" "restoring backup"
  290. [ -f /flash/backup.tar.bz2 ] && tar -xjf /flash/backup.tar.bz2 -C $TMPDIR/part2 >> $LOGFILE 2>&1
  291. [ -f /flash/backup.zip ] && unzip -qq /flash/backup.zip -d $TMPDIR/part2 >> $LOGFILE 2>&1
  292. sync
  293. # umount system partition, remove mountpoint
  294. msg_progress_install "97" "unmount $TMPDIR/part2"
  295. umount $TMPDIR/part2 >> $LOGFILE 2>&1
  296. msg_progress_install "100" "remove $TMPDIR/part2"
  297. rmdir $TMPDIR/part2 >> $LOGFILE 2>&1
  298. fi
  299. # install complete
  300. MSG_TITLE="\Z1[ OpenELEC Install Complete ]\Zn"
  301. MSG_DETAIL="\nYou may now remove the install media and reboot\n"
  302. dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" --msgbox "$MSG_DETAIL" 6 52
  303. menu_main
  304. ;;
  305. 1)
  306. menu_main
  307. ;;
  308. 255)
  309. do_poweroff
  310. ;;
  311. esac
  312. }
  313. do_install_custom() {
  314. # show menu
  315. MSG_TITLE="\Z4[ REPAIR/UPGRADE MENU ]\Zn"
  316. MSG_MENU="\nUse the up/down arrows to select the correct partition where you want to overwrite KERNEL and SYSTEM files.\n\n Please select a partition:"
  317. MSG_CANCEL="Back"
  318. DIALOG_OPTIONS="--defaultno"
  319. get_device_unmount
  320. if [ "$DEVICES" = "" ]; then
  321. msg_no_device
  322. fi
  323. PARTITION_LIST=""
  324. for device in $DEVICES; do
  325. get_partition $device
  326. for partition in $PARTITIONS; do
  327. LABEL=$(tune2fs -l $device$partition | awk 'BEGIN {FS=":"} /Filesystem volume name/ {gsub(/ /,"",$2); print $2}')
  328. if [ "$LABEL" = "$DISKLABEL_SYSTEM" ]; then
  329. DEVICE_MODEL=$(parted -s $device -m print | grep ^$device | cut -f7 -d ":" | sed "s/;//")
  330. DEVICE_SIZE=$(parted -s $device -m print | grep ^$device | cut -f2 -d ":")
  331. DEVICE_NAME=$(echo $DEVICE_MODEL ${DEVICE_SIZE} | sed 's/ /_/g')
  332. PARTITION_LIST="$PARTITION_LIST $device$partition $DEVICE_NAME"
  333. fi
  334. done
  335. done
  336. if [ "$PARTITION_LIST" = "" ]; then
  337. msg_no_device
  338. fi
  339. dialog --colors --backtitle "$BACKTITLE" --cancel-label "$MSG_CANCEL" \
  340. $DIALOG_OPTIONS --title "$MSG_TITLE" --menu "$MSG_MENU" 20 50 5 \
  341. $PARTITION_LIST 2> $TMPDIR/device_for_install
  342. # now we must do everything
  343. case $? in
  344. 0)
  345. INSTALL_PARTITION=$(cat "$TMPDIR/device_for_install")
  346. INSTALL_PARTITION_FULL=$(echo $PARTITION_LIST | sed "s|.*$INSTALL_PARTITION \([^ ]*\).*|$INSTALL_PARTITION \1|")
  347. # check for confirmation (twice!)
  348. MSG_TITLE="\Z1[ Confirmation before copying ]\Zn"
  349. MSG_DETAIL="\nIf you continue the target partition will be\noverwritten with new KERNEL and SYSTEM files:\n\n$INSTALL_PARTITION_FULL\n\n"
  350. DIALOG_OPTIONS="--defaultno"
  351. dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" \
  352. $DIALOG_OPTIONS --yesno "$MSG_DETAIL" 0 0
  353. if [ $? -ne 0 ]; then
  354. menu_main
  355. fi
  356. MSG_TITLE="\Z1[ Confirmation before copying ]\Zn"
  357. MSG_DETAIL="\nThis is last chance to abort the copying!\n\nIf you continue the target partition will be\noverwritten with new KERNEL and SYSTEM files:\n\n$INSTALL_PARTITION_FULL\n\n\n"
  358. DIALOG_OPTIONS="--defaultno"
  359. dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" \
  360. $DIALOG_OPTIONS --yesno "$MSG_DETAIL" 0 0
  361. if [ $? -ne 0 ]; then
  362. menu_main
  363. fi
  364. # mount system partition
  365. msg_progress_install "5" "creating $TMPDIR/part1"
  366. mkdir -p $TMPDIR/part1 >> $LOGFILE 2>&1
  367. msg_progress_install "10" "mounting $INSTALL_PARTITION to $TMPDIR/part1"
  368. mount -t ext4 $INSTALL_PARTITION $TMPDIR/part1 >> $LOGFILE 2>&1
  369. # check for enough target space
  370. msg_progress_install "15" "checking for space on $INSTALL_PARTITION"
  371. KERNEL_SIZE=$(stat -t /flash/KERNEL | awk '{print $2}')
  372. SYSTEM_SIZE=$(stat -t /flash/SYSTEM | awk '{print $2}')
  373. SRC_SIZE=$(( $KERNEL_SIZE + $SYSTEM_SIZE ))
  374. DEST_SIZE=$(df $TMPDIR/part1 | awk '/[0-9]%/{print $4}')
  375. DEST_SIZE=$(( $DEST_SIZE * 1024 ))
  376. if [ -f $TMPDIR/part1/KERNEL ]; then
  377. KERNEL_SIZE=$(stat -t $TMPDIR/part1/KERNEL | awk '{print $2}')
  378. DEST_SIZE=$(( $DEST_SIZE + $KERNEL_SIZE ))
  379. fi
  380. if [ -f $TMPDIR/part1/SYSTEM ]; then
  381. SYSTEM_SIZE=$(stat -t $TMPDIR/part1/SYSTEM | awk '{print $2}')
  382. DEST_SIZE=$(( $DEST_SIZE + $SYSTEM_SIZE ))
  383. fi
  384. if [ $SRC_SIZE -ge $DEST_SIZE ]; then
  385. umount $TMPDIR/part1 >> $LOGFILE 2>&1
  386. rmdir $TMPDIR/part1 >> $LOGFILE 2>&1
  387. msg_target_space
  388. menu_main
  389. fi
  390. # install system files
  391. msg_progress_install "20" "installing Kernel"
  392. cp /flash/KERNEL $TMPDIR/part1 >> $LOGFILE 2>&1
  393. msg_progress_install "40" "installing System"
  394. cp /flash/SYSTEM $TMPDIR/part1 >> $LOGFILE 2>&1
  395. sync
  396. # umount system partition, remove mountpoint
  397. msg_progress_install "95" "unmount $TMPDIR/part1"
  398. umount $TMPDIR/part1 >> $LOGFILE 2>&1
  399. msg_progress_install "100" "remove $TMPDIR/part1"
  400. rmdir $TMPDIR/part1 >> $LOGFILE 2>&1
  401. # install complete
  402. MSG_TITLE="\Z1[ OpenELEC Install Complete ]\Zn"
  403. MSG_DETAIL="\nYou may now remove the install media and reboot\n"
  404. dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" --msgbox "$MSG_DETAIL" 6 52
  405. menu_main
  406. ;;
  407. 1)
  408. menu_main
  409. ;;
  410. 255)
  411. do_poweroff
  412. ;;
  413. esac
  414. }
  415. msg_no_device() {
  416. # show a warning dialog if we dont find not mounted devices for install and return to main menu
  417. MSG_TITLE="\Z1[ WARNING ]\Zn"
  418. MSG_INFOBOX=" No devices were found. "
  419. dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" --msgbox "$MSG_INFOBOX" 9 70
  420. menu_main
  421. }
  422. msg_target_space() {
  423. # show an error dialog for missing space
  424. MSG_TITLE="\Z1[ TARGET SPACE ]\Zn"
  425. MSG_INFOBOX="\nNot enough target space!\nCopying aborted.\n"
  426. dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" --msgbox "$MSG_INFOBOX" 8 70
  427. menu_main
  428. }
  429. msg_install_ready() {
  430. # show a dialog that we have installed
  431. MSG_TITLE="\Z1[ INFORMATION ]\Zn"
  432. dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" --msgbox " $1" 7 70
  433. menu_main
  434. }
  435. msg_progress_install() {
  436. # show the progress dialog
  437. MSG_TITLE="\Z1[ INSTALLING ]\Zn"
  438. dbglg "$2"
  439. dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" --gauge "$2 ..." 6 70 $1 &
  440. }
  441. prompt_gpt() {
  442. GPT="0"
  443. UEFI="0"
  444. # Get size in GB.
  445. INSTALL_DEVICE_SIZE=$(($(cat /sys/block/${INSTALL_DEVICE#/dev/}/size)*512/1000/1000/1000))
  446. if [ "$INSTALL_DEVICE_SIZE" -ge 2200 ] 2>/dev/null; then
  447. GPT="1"
  448. fi
  449. # force gpt + uefi in uefi boot mode
  450. if [ -d /sys/firmware/efi ]; then
  451. UEFI="1"
  452. GPT="1"
  453. fi
  454. }
  455. prompt_backup_unpack() {
  456. # Prompt for unpacking backup files to /storage
  457. # usage: prompt_backup_unpack
  458. # uses:
  459. # provides: BACKUP_UNPACK
  460. BACKUP_UNPACK="0"
  461. if [ -f /flash/backup.tar.bz2 -o -f /flash/backup.zip ]; then
  462. MSG_TITLE="\Z1[ Restore backup files ]\Zn"
  463. MSG_DETAIL="Restore backup files to storage partition.\nFile backup.tar.bz2 or/and backup.zip exist on\ninstallation USB stick."
  464. DIALOG_OPTIONS="--defaultno"
  465. if dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" $DIALOG_OPTIONS --yesno "$MSG_DETAIL" 0 0; then
  466. BACKUP_UNPACK="1"
  467. fi
  468. fi
  469. }
  470. menu_main() {
  471. # show the mainmenu
  472. MSG_TITLE="\Z4[ MAIN MENU ]\Zn"
  473. MSG_MENU="\n\ZbQuick Install:\Zn do a default installation on a specific device \
  474. \Z1\Zb(this will delete ALL data on this device!)\Zn \
  475. \n\ZbRepair / Upgrade:\Zn do repair / upgrade \
  476. \n\ZbShow logfile:\Zn show and save the logfile \
  477. \n \
  478. \nPlease select:"
  479. MSG_CANCEL="Reboot"
  480. dialog --colors --backtitle "$BACKTITLE" --cancel-label "$MSG_CANCEL" \
  481. --title "$MSG_TITLE" --menu "$MSG_MENU" 20 70 5 \
  482. 1 "Quick Install of OpenELEC" \
  483. 2 "Repair / Upgrade" \
  484. 3 "Show logfile" 2> $TMPDIR/mainmenu
  485. case $? in
  486. 0)
  487. ITEM_MAINMENU=$(cat "$TMPDIR/mainmenu")
  488. case $ITEM_MAINMENU in
  489. 1) do_install_quick; break;;
  490. 2) do_install_custom; break;;
  491. 3) logfile_show; break;;
  492. esac
  493. ;;
  494. 1)
  495. do_reboot
  496. ;;
  497. 255)
  498. do_poweroff
  499. ;;
  500. esac
  501. }
  502. logfile_show() {
  503. dialog --textbox "$LOGFILE" 20 70
  504. clear
  505. menu_main
  506. }
  507. do_reboot() {
  508. # reboot on request
  509. clear
  510. sync
  511. reboot -f
  512. }
  513. do_poweroff() {
  514. # powerdown on request
  515. clear
  516. sync
  517. poweroff -f
  518. }
  519. # setup needed variables
  520. INSTALLER_VERSION="0.2.7"
  521. OS_VERSION=$(lsb_release)
  522. BACKTITLE="OpenELEC Installer $INSTALLER_VERSION - $OS_VERSION"
  523. TMPDIR="/tmp/installer"
  524. LOGFILE="$TMPDIR/install.log"
  525. # prepare temporary directory
  526. rm -rf $TMPDIR
  527. mkdir -p $TMPDIR
  528. #create log file
  529. touch "$LOGFILE"
  530. # main
  531. while true; do
  532. clear
  533. menu_main
  534. done
  535. # exit cleanly
  536. exit 0