Advertisement
Guest User

Untitled

a guest
Feb 24th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.58 KB | None | 0 0
  1. usage()
  2. {
  3. cat << EOF
  4. usage: $0 options
  5.  
  6. ChrUbuntu installation script.
  7.  
  8. OPTIONS:
  9. -h show help.
  10. -m Ubuntu metapackage to install such as xubuntu-desktop, kubuntu-desktop or ubuntu-minimal. Default is ubuntu-desktop
  11. -a Architecture to install (i386, amd64). Default is amd64 (64-bit).
  12. -t Target drive to install to (/dev/mmcblk1, /dev/sdb, etc). Default is the builtin SSD.
  13. -u Ubuntu version to install (lts, dev, 10.10, etc). Default is latest stable release.
  14. EOF
  15. }
  16.  
  17. echo_red()
  18. {
  19. echo -e "\E[1;31m$1"
  20. echo -e '\e[0m'
  21. }
  22.  
  23. echo_green()
  24. {
  25. echo -e "\E[1;32m$1"
  26. echo -e '\e[0m'
  27. }
  28.  
  29. echo_yellow()
  30. {
  31. echo -e "\E[1;33m$1"
  32. echo -e '\e[0m'
  33. }
  34.  
  35. target_disk=""
  36. ubuntu_arch="amd64"
  37. ubuntu_metapackage="ubuntu-desktop"
  38. ubuntu_version="latest"
  39. while getopts "hm:a:t:u:" OPTION
  40. do
  41. case $OPTION in
  42. h)
  43. usage
  44. exit
  45. ;;
  46. m)
  47. ubuntu_metapackage=$OPTARG
  48. ;;
  49. a)
  50. ubuntu_arch=$OPTARG
  51. ;;
  52. t)
  53. target_disk=$OPTARG
  54. ;;
  55. u)
  56. ubuntu_version=$OPTARG
  57. ;;
  58. ?)
  59. usage
  60. exit
  61. ;;
  62. esac
  63. done
  64.  
  65. echo_green "Determining support for legacy boot..."
  66. LEGACY_LOCATION="`mosys -k eeprom map | grep RW_LEGACY`"
  67. if [ "$LEGACY_LOCATION" = "" ]; then
  68. echo_red "Error: this Chrome device does not seem to support CTRL+L Legacy SeaBIOS booting. Use the old ChrUbuntu script please..."
  69. exit 1
  70. fi
  71. echo_green "This system supports legacy boot. Good."
  72.  
  73. powerd_status="`initctl status powerd`"
  74. if [ ! "$powerd_status" = "powerd stop/waiting" ]
  75. then
  76. echo_green "Stopping powerd to keep display from timing out..."
  77. initctl stop powerd
  78. fi
  79.  
  80. setterm -blank 0
  81.  
  82. if [ "$target_disk" != "" ]; then
  83. echo_green "Got ${target_disk} as target drive"
  84. echo ""
  85. echo_yellow "WARNING! All data on this device will be wiped out! Continue at your own risk!"
  86. echo ""
  87. read -p "Press [Enter] to install ChrUbuntu on ${target_disk} or CTRL+C to quit"
  88.  
  89. ext_size="`blockdev --getsz ${target_disk}`"
  90. aroot_size=$((ext_size - 65600 - 33))
  91. parted --script ${target_disk} "mktable gpt"
  92. cgpt create ${target_disk}
  93. cgpt add -i 6 -b 64 -s 32768 -S 1 -P 5 -l GRUB-BOOT -t "reserved" ${target_disk}
  94. cgpt add -i 7 -b 65600 -s $aroot_size -l ROOT-A -t "rootfs" ${target_disk}
  95. sync
  96. blockdev --rereadpt ${target_disk}
  97. partprobe ${target_disk}
  98. crossystem dev_boot_usb=1
  99. parted ${target_disk} set 6 bios_grub on
  100. else
  101. target_disk="`rootdev -d -s`"
  102. # Do partitioning (if we haven't already)
  103. ckern_size="`cgpt show -i 6 -n -s -q ${target_disk}`"
  104. croot_size="`cgpt show -i 7 -n -s -q ${target_disk}`"
  105. state_size="`cgpt show -i 1 -n -s -q ${target_disk}`"
  106.  
  107. max_ubuntu_size=$(($state_size/1024/1024/2))
  108. rec_ubuntu_size=$(($max_ubuntu_size - 1))
  109. # If KERN-C and ROOT-C are one, we partition, otherwise assume they're what they need to be...
  110. if [ "$ckern_size" = "1" -o "$croot_size" = "1" ]
  111. then
  112. while :
  113. do
  114. read -p "Enter the size in gigabytes you want to reserve for Ubuntu. Acceptable range is 5 to $max_ubuntu_size but $rec_ubuntu_size is the recommended maximum: " ubuntu_size
  115. if [ ! $ubuntu_size -ne 0 2>/dev/null ]
  116. then
  117. echo_red "\n\nNumbers only please...\n\n"
  118. continue
  119. fi
  120. if [ $ubuntu_size -lt 5 -o $ubuntu_size -gt $max_ubuntu_size ]
  121. then
  122. echo_red "\n\nThat number is out of range. Enter a number 5 through $max_ubuntu_size\n\n"
  123. continue
  124. fi
  125. break
  126. done
  127. # We've got our size in GB for ROOT-C so do the math...
  128.  
  129. #calculate sector size for rootc
  130. rootc_size=$(($ubuntu_size*1024*1024*2))
  131.  
  132. #kernc is always 16mb
  133. kernc_size=32768
  134.  
  135. #new stateful size with rootc and kernc subtracted from original
  136. stateful_size=$(($state_size - $rootc_size - $kernc_size))
  137.  
  138. #start stateful at the same spot it currently starts at
  139. stateful_start="`cgpt show -i 1 -n -b -q ${target_disk}`"
  140.  
  141. #start kernc at stateful start plus stateful size
  142. kernc_start=$(($stateful_start + $stateful_size))
  143.  
  144. #start rootc at kernc start plus kernc size
  145. rootc_start=$(($kernc_start + $kernc_size))
  146.  
  147. #Do the real work
  148.  
  149. echo_green "\n\nModifying partition table to make room for Ubuntu."
  150. echo_green "Your Chromebook will reboot, wipe your data and then"
  151. echo_green "you should re-run this script..."
  152. umount -f /mnt/stateful_partition
  153.  
  154. # stateful first
  155. cgpt add -i 1 -b $stateful_start -s $stateful_size -l STATE ${target_disk}
  156.  
  157. # now kernc
  158. cgpt add -i 6 -b $kernc_start -s $kernc_size -l KERN-C -t "kernel" ${target_disk}
  159.  
  160. # finally rootc
  161. cgpt add -i 7 -b $rootc_start -s $rootc_size -l ROOT-C ${target_disk}
  162.  
  163. reboot
  164. exit
  165. fi
  166. fi
  167.  
  168. if [ "$ubuntu_version" = "lts" ]
  169. then
  170. ubuntu_version=`curl -s -O - http://changelogs.ubuntu.com/meta-release | grep "^Version:" | grep "LTS" | tail -1 | sed -r 's/^Version: ([^ ]+)( LTS)?$/\1/'`
  171. tar_file="http://cdimage.ubuntu.com/ubuntu-core/releases/$ubuntu_version/release/ubuntu-core-$ubuntu_version-core-$ubuntu_arch.tar.gz"
  172. elif [ "$ubuntu_version" = "latest" ]
  173. then
  174. ubuntu_version=`curl -s -O - http://changelogs.ubuntu.com/meta-release | grep "^Version: " | tail -1 | sed -r 's/^Version: ([^ ]+)( LTS)?$/\1/'`
  175. tar_file="http://cdimage.ubuntu.com/ubuntu-core/releases/$ubuntu_version/release/ubuntu-core-$ubuntu_version-core-$ubuntu_arch.tar.gz"
  176. elif [ $ubuntu_version = "dev" ]
  177. then
  178. ubuntu_version=`curl -s -O - http://changelogs.ubuntu.com/meta-release-development | grep "^Version: " | tail -1 | sed -r 's/^Version: ([^ ]+)( LTS)?$/\1/'`
  179. ubuntu_animal=`curl -s -O - http://changelogs.ubuntu.com/meta-release-development | grep "^Dist: " | tail -1 | sed -r 's/^Dist: (.*)$/\1/'`
  180. tar_file="http://cdimage.ubuntu.com/ubuntu-core/daily/current/$ubuntu_animal-core-$ubuntu_arch.tar.gz"
  181. else
  182. tar_file="http://cdimage.ubuntu.com/ubuntu-core/releases/$ubuntu_version/release/ubuntu-core-$ubuntu_version-core-$ubuntu_arch.tar.gz"
  183. fi
  184.  
  185. echo_green "Installing Ubuntu ${ubuntu_version} with metapackage ${ubuntu_metapackage}\n"
  186. echo_green "Installing Ubuntu Arch: $ubuntu_arch\n"
  187.  
  188. read -p "Press [Enter] to continue..."
  189.  
  190. if [[ "${target_disk}" =~ "mmcblk" ]]
  191. then
  192. target_rootfs="${target_disk}p7"
  193. target_kern="${target_disk}p6"
  194. else
  195. target_rootfs="${target_disk}7"
  196. target_kern="${target_disk}6"
  197. fi
  198.  
  199. echo_green "Target Kernel Partition: $target_kern Target Root FS: ${target_rootfs}"
  200.  
  201. if mount|grep ${target_rootfs}
  202. then
  203. echo_red "Refusing to continue since ${target_rootfs} is formatted and mounted. Try rebooting"
  204. exit
  205. fi
  206.  
  207. mkfs.ext4 ${target_rootfs}
  208.  
  209. if [ ! -d /tmp/urfs ]
  210. then
  211. mkdir /tmp/urfs
  212. fi
  213. mount -t ext4 ${target_rootfs} /tmp/urfs
  214.  
  215. curl -O - $tar_file | tar xzvvp -C /tmp/urfs/
  216.  
  217. mount -o bind /proc /tmp/urfs/proc
  218. mount -o bind /dev /tmp/urfs/dev
  219. mount -o bind /dev/pts /tmp/urfs/dev/pts
  220. mount -o bind /sys /tmp/urfs/sys
  221.  
  222. if [ -f /usr/bin/old_bins/cgpt ]
  223. then
  224. cp /usr/bin/old_bins/cgpt /tmp/urfs/usr/bin/
  225. else
  226. cp /usr/bin/cgpt /tmp/urfs/usr/bin/
  227. fi
  228.  
  229. chmod a+rx /tmp/urfs/usr/bin/cgpt
  230. cp /etc/resolv.conf /tmp/urfs/etc/
  231. echo chrubuntu > /tmp/urfs/etc/hostname
  232. echo -e "\n127.0.1.1 chrubuntu" >> /tmp/urfs/etc/hosts
  233.  
  234. cr_install="curl -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
  235. add-apt-repository \"deb http://dl.google.com/linux/chrome/deb/ stable main\"
  236. apt-get update
  237. apt-get -y install google-chrome-stable"
  238.  
  239. echo -e "export DEBIAN_FRONTEND=noninteractive
  240. apt-get -y update
  241. apt-get -y dist-upgrade
  242. apt-get -y install ubuntu-minimal
  243. apt-get -y install wget
  244. apt-get -y install software-properties-common
  245. add-apt-repository main
  246. add-apt-repository universe
  247. add-apt-repository restricted
  248. add-apt-repository multiverse
  249. apt-get update
  250. apt-get -y install $ubuntu_metapackage
  251. $cr_install
  252. apt-get -y install linux-generic
  253. apt-get -y install grub-pc
  254. grub-mkconfig -o /boot/grub/grub.cfg
  255. grub-install ${target_disk} --force
  256. mykern=\`ls /boot/vmlinuz-* | grep -oP \"[0-9].*\" | sort -rV | head -1\`
  257. wget http://goo.gl/kz917j
  258. bash kz917j \$mykern
  259. rm kz917j
  260. useradd -m user -s /bin/bash
  261. echo user | echo user:user | chpasswd
  262. adduser user adm
  263. adduser user sudo
  264. if [ -f /usr/lib/lightdm/lightdm-set-defaults ]
  265. then
  266. /usr/lib/lightdm/lightdm-set-defaults --autologin user
  267. fi" > /tmp/urfs/install-ubuntu.sh
  268.  
  269. chmod a+x /tmp/urfs/install-ubuntu.sh
  270. chroot /tmp/urfs /bin/bash -c /install-ubuntu.sh
  271. #rm /tmp/urfs/install-ubuntu.sh
  272.  
  273. echo -e "Section \"InputClass\"
  274. Identifier \"touchpad peppy cyapa\"
  275. MatchIsTouchpad \"on\"
  276. MatchDevicePath \"/dev/input/event*\"
  277. MatchProduct \"cyapa\"
  278. Option \"FingerLow\" \"10\"
  279. Option \"FingerHigh\" \"10\"
  280. EndSection" > /tmp/urfs/usr/share/X11/xorg.conf.d/50-cros-touchpad.conf
  281.  
  282. if echo `crossystem hwid` | grep -q "^PANTHER "; then
  283. echo_green "Fixing SeaBIOS on ASUS Chromebox"
  284. echo_green "Thanks to John Lewis"
  285. echo_green "http://johnlewis.ie/asus-chromebox-owners-rejoice/"
  286. wget http://johnlewis.ie/asus-chromebox-SeaBIOS-new.bin
  287. flashrom -w -i RW_LEGACY:asus-chromebox-SeaBIOS-new.bin
  288. fi
  289.  
  290. crossystem dev_boot_legacy=1 dev_boot_signed_only=1
  291.  
  292. echo -e "
  293.  
  294. Installation is complete! On reboot at the dev mode screen, you can press
  295. CTRL+L to boot ChrUbuntu or CTRL+D to boot Chrome OS. The ChrUbuntu login is:
  296.  
  297. Username: user
  298. Password: user
  299.  
  300. We're now ready to start ChrUbuntu!
  301. "
  302.  
  303. read -p "Press [Enter] to reboot..."
  304.  
  305. reboot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement