Advertisement
Guest User

Untitled

a guest
Aug 5th, 2015
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.38 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. ########################################################################
  4. #
  5. # Copyright (C) 2015 Ryan Finnie <ryan@finnie.org>
  6. # Copyright (C) 2015 Rohith Madhavan <rohithmadhavan@gmail.com>
  7. # Copyright (C) 2015 Martin Wimpress <code@ubuntu-mate.org>
  8. #
  9. # This program is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU General Public License
  11. # as published by the Free Software Foundation; either version 2
  12. # of the License, or (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. ########################################################################
  23.  
  24. set -ex
  25.  
  26. RELEASE=vivid
  27. BASEDIR=/var/local/build/${RELEASE}
  28. BUILDDIR=${BASEDIR}/ubuntu-mate
  29. BASE_R=${BUILDDIR}/base
  30. MATE_R=${BUILDDIR}/mate
  31. DEVICE_R=${BUILDDIR}/device
  32. export TZ=UTC
  33.  
  34. if [ $(id -u) -ne 0 ]; then
  35. echo "ERROR! Must be root."
  36. exit 1
  37. fi
  38.  
  39. # Don't clobber an old build
  40. if [ -d "${BUILDDIR}" ]; then
  41. echo "WARNING! ${BUILDDIR} exists. Press any key to continue or CTRL + C to exit."
  42. read
  43. fi
  44.  
  45. # Mount host system
  46. function mount_system() {
  47. mount -t proc none $R/proc
  48. mount -t sysfs none $R/sys
  49. mount -o bind /dev $R/dev
  50. mount -o bind /dev/pts $R/dev/pts
  51. }
  52.  
  53. # Unmount host system
  54. function umount_system() {
  55. umount -f $R/dev/pts
  56. umount -f $R/proc
  57. umount -f $R/sys
  58. umount -r $R/dev
  59. }
  60.  
  61. function sync_to() {
  62. local TARGET="${1}"
  63. rsync -a --progress --delete ${R}/ ${TARGET}/
  64. }
  65.  
  66. # Base debootstrap
  67. function bootstrap() {
  68. # Required tools
  69. apt-get -y install f2fs-tools qemu-user-static rsync ubuntu-keyring wget
  70. qemu-debootstrap --verbose --arch=armhf $RELEASE $R http://ports.ubuntu.com/
  71. }
  72.  
  73. # Set up initial sources.list
  74. function apt_sources() {
  75. cat <<EOM >$R/etc/apt/sources.list
  76. deb http://ports.ubuntu.com/ ${RELEASE} main restricted universe multiverse
  77. # deb-src http://ports.ubuntu.com/ ${RELEASE} main restricted universe multiverse
  78.  
  79. deb http://ports.ubuntu.com/ ${RELEASE}-updates main restricted universe multiverse
  80. # deb-src http://ports.ubuntu.com/ ${RELEASE}-updates main restricted universe multiverse
  81.  
  82. deb http://ports.ubuntu.com/ ${RELEASE}-security main restricted universe multiverse
  83. # deb-src http://ports.ubuntu.com/ ${RELEASE}-security main restricted universe multiverse
  84.  
  85. deb http://ports.ubuntu.com/ ${RELEASE}-backports main restricted universe multiverse
  86. # deb-src http://ports.ubuntu.com/ ${RELEASE}-backports main restricted universe multiverse
  87. EOM
  88. }
  89.  
  90. function apt_upgrade() {
  91. chroot $R apt-get update
  92. chroot $R apt-get -y -u dist-upgrade
  93. }
  94.  
  95. function apt_clean() {
  96. # Clean cached downloads
  97. chroot $R apt-get clean
  98. }
  99.  
  100. # Install Ubuntu standard
  101. function ubuntu_standard() {
  102. chroot $R apt-get -y install f2fs-tools gdebi-core language-pack-en linux-firmware \
  103. software-properties-common tasksel
  104. #chroot $R apt-get -y install minimal^
  105. #chroot $R apt-get -y install standard^
  106. tasksel --new-install install minimal
  107. tasksel --new-install install standard
  108. }
  109.  
  110. # Install Ubuntu MATE
  111. function ubuntu_mate() {
  112. # chroot $R dpkg --configure -a
  113. # Prevent errors encountered while configuring modemmanager
  114. touch $R/etc/init.d/modemmanager
  115. #echo 'APT::Install-Recommends "false";' > $R/etc/apt/apt.conf.d/99noinstallrecommends
  116. #chroot $R apt-get -y install --no-install-recommends ubuntu-mate-core^
  117. #chroot $R apt-get -y install --no-install-recommends ubuntu-mate-desktop^
  118. #rm $R/etc/apt/apt.conf.d/99noinstallrecommends
  119.  
  120. # tasksel install the task
  121. echo 'APT::Install-Recommends "false";' > $R/etc/apt/apt.conf.d/99noinstallrecommends
  122. chroot $R tasksel --new-install install ubuntu-mate-core
  123. chroot $R tasksel --new-install install ubuntu-mate-desktop
  124. rm $R/etc/apt/apt.conf.d/99noinstallrecommends
  125. }
  126.  
  127. # Create the 'oem' user
  128. function create_oem_user() {
  129. # mkpasswd -m sha-512 ubuntu-mate `date +%m%H%M%S`
  130. chroot $R addgroup --gid 29999 oem
  131. chroot $R adduser --gecos "OEM Configuration (temporary user)" --add_extra_groups --disabled-password --gid 29999 --uid 29999 oem
  132. chroot $R usermod -a -G sudo,adm -p '$6$04121227$8mCHpKLFGjDdMgBCn5QjzlXZpx5o9HxOLoEt.Aea1HQzvly3M1yXWuEloW0a3mqWCrcddrWqwye7DzQZ.3Cfh/' oem
  133. }
  134.  
  135. # Prepare oem-config for first boot.
  136. function prepare_oem_config() {
  137. chroot $R apt-get -y install oem-config-gtk ubiquity-frontend-gtk ubiquity-ubuntu-artwork
  138. chroot $R /bin/systemctl set-default oem-config.target
  139. }
  140.  
  141. function configure_ssh() {
  142. # OpenSSH - Do not enable until one-time hostkey re-generation on first
  143. # boot is in place using either:
  144. # - ssh-keygen -A
  145. # - /usr/sbin/dpkg-reconfigure openssh-server
  146. chroot $R apt-get -y install openssh-server
  147. rm $R/etc/ssh/ssh_host_*
  148. }
  149.  
  150. function configure_network() {
  151. # Set up hosts
  152. echo ubuntu-mate >$R/etc/hostname
  153. cat <<EOM >$R/etc/hosts
  154. 127.0.0.1 localhost
  155. ::1 localhost ip6-localhost ip6-loopback
  156. ff02::1 ip6-allnodes
  157. ff02::2 ip6-allrouters
  158.  
  159. 127.0.1.1 ubuntu-mate
  160. EOM
  161.  
  162. # Set up interfaces
  163. cat <<EOM >$R/etc/network/interfaces
  164. # interfaces(5) file used by ifup(8) and ifdown(8)
  165. # Include files from /etc/network/interfaces.d:
  166. source-directory /etc/network/interfaces.d
  167.  
  168. # The loopback network interface
  169. auto lo
  170. iface lo inet loopback
  171. EOM
  172. }
  173.  
  174. function configure_raspi2() {
  175. local FS="${1}"
  176. if [ "${FS}" != "ext4" ] && [ "${FS}" != 'f2fs' ]; then
  177. echo "ERROR! Unsupport filesystem requested. Exitting."
  178. exit 1
  179. fi
  180.  
  181. local OMX="http://omxplayer.sconde.net/builds/omxplayer_0.3.6~git20150402~74aac37_armhf.deb"
  182.  
  183. # Install the RPi PPA
  184. cat <<"EOM" >$R/etc/apt/preferences.d/rpi2-ppa
  185. Package: *
  186. Pin: release o=LP-PPA-fo0bar-rpi2
  187. Pin-Priority: 990
  188.  
  189. Package: *
  190. Pin: release o=LP-PPA-fo0bar-rpi2-staging
  191. Pin-Priority: 990
  192. EOM
  193.  
  194. # Install the RPi PPA
  195. chroot $R apt-add-repository -y ppa:fo0bar/rpi2
  196. chroot $R apt-get update
  197. chroot $R apt-get -y install rpi2-ubuntu-errata
  198.  
  199. # Kernel installation
  200. # Install flash-kernel last so it doesn't try (and fail) to detect the
  201. # platform in the chroot.
  202. chroot $R apt-get -y install raspberrypi-bootloader-nokernel
  203. chroot $R apt-get -y --no-install-recommends install linux-image-rpi2
  204. chroot $R apt-get -y install flash-kernel
  205. VMLINUZ="$(ls -1 $R/boot/vmlinuz-* | sort | tail -n 1)"
  206. [ -z "$VMLINUZ" ] && exit 1
  207. cp $VMLINUZ $R/boot/firmware/kernel7.img
  208. INITRD="$(ls -1 $R/boot/initrd.img-* | sort | tail -n 1)"
  209. [ -z "$INITRD" ] && exit 1
  210. cp $INITRD $R/boot/firmware/initrd7.img
  211.  
  212. # Install video drivers
  213. chroot $R apt-get -y install libraspberrypi0 libraspberrypi-bin \
  214. libraspberrypi-bin-nonfree
  215.  
  216. chroot $R apt-get -y install xserver-xorg-video-fbturbo
  217. cat <<EOM >$R/etc/X11/xorg.conf
  218. Section "Device"
  219. Identifier "Raspberry Pi FBDEV"
  220. Driver "fbturbo"
  221. Option "fbdev" "/dev/fb0"
  222. Option "SwapbuffersWait" "true"
  223. EndSection
  224. EOM
  225.  
  226. # Create sym-links to VideoCore utilities for 3rd party script
  227. # compatibility.
  228. mkdir -p ${R}/opt/vc/{bin,sbin}
  229. for FILE in containers_check_frame_int \
  230. containers_datagram_receiver \
  231. containers_datagram_sender \
  232. containers_dump_pktfile \
  233. containers_rtp_decoder \
  234. containers_stream_client \
  235. containers_stream_server \
  236. containers_test \
  237. containers_test_bits \
  238. containers_test_uri \
  239. containers_uri_pipe \
  240. edidparser \
  241. mmal_vc_diag \
  242. raspistill \
  243. raspivid \
  244. raspividyuv \
  245. raspiyuv \
  246. tvservice \
  247. vcdbg \
  248. vcgencmd \
  249. vchiq_test \
  250. vcsmem; do
  251. chroot $R ln -s /usr/bin/${FILE} /opt/vc/bin/
  252. done
  253. chroot $R ln -s /usr/sbin/vcfiled /opt/vc/sbin/
  254.  
  255. # omxplayer
  256. # - Requires: libpcre3 libfreetype6 fonts-freefont-ttf dbus libssl1.0.0 libsmbclient libssh-4
  257. wget -c "${OMX}" -O $R/tmp/omxplayer.deb
  258. chroot $R gdebi -n /tmp/omxplayer.deb
  259.  
  260. # copies-and-fills
  261. wget -c http://archive.raspberrypi.org/debian/pool/main/r/raspi-copies-and-fills/raspi-copies-and-fills_0.4-1_armhf.deb -O $R/tmp/cofi.deb
  262. chroot $R gdebi -n /tmp/cofi.deb
  263.  
  264. # raspi-config - Needs forking/modifying to support Ubuntu 15.04
  265. # - Requires: whiptail parted lua5.1 triggerhappy
  266. #wget -c http://archive.raspberrypi.org/debian/pool/main/r/raspi-config/raspi-config_20150131-1_all.deb -O $R/tmp/rasp-config.deb
  267. #chroot $R gdebi -n /tmp/rasp-config.deb
  268.  
  269. # Set up fstab
  270. cat <<EOM >$R/etc/fstab
  271. proc /proc proc defaults 0 0
  272. /dev/mmcblk0p2 / ${FS} defaults,noatime 0 1
  273. /dev/mmcblk0p1 /boot/firmware vfat defaults 0 2
  274. EOM
  275.  
  276. # Set up firmware config
  277. cat <<EOM >$R/boot/firmware/config.txt
  278. # For more options and information see
  279. # http://www.raspberrypi.org/documentation/configuration/config-txt.md
  280. # Some settings may impact device functionality. See link above for details
  281.  
  282. # uncomment if you get no picture on HDMI for a default "safe" mode
  283. #hdmi_safe=1
  284.  
  285. # uncomment this if your display has a black border of unused pixels visible
  286. # and your display can output without overscan
  287. #disable_overscan=1
  288.  
  289. # uncomment the following to adjust overscan. Use positive numbers if console
  290. # goes off screen, and negative if there is too much border
  291. #overscan_left=16
  292. #overscan_right=16
  293. #overscan_top=16
  294. #overscan_bottom=16
  295.  
  296. # uncomment to force a console size. By default it will be display's size minus
  297. # overscan.
  298. #framebuffer_width=1280
  299. #framebuffer_height=720
  300.  
  301. # uncomment if hdmi display is not detected and composite is being output
  302. #hdmi_force_hotplug=1
  303.  
  304. # uncomment to force a specific HDMI mode (this will force VGA)
  305. #hdmi_group=1
  306. #hdmi_mode=1
  307.  
  308. # uncomment to force a HDMI mode rather than DVI. This can make audio work in
  309. # DMT (computer monitor) modes
  310. #hdmi_drive=2
  311.  
  312. # uncomment to increase signal to HDMI, if you have interference, blanking, or
  313. # no display
  314. #config_hdmi_boost=4
  315.  
  316. # uncomment for composite PAL
  317. #sdtv_mode=2
  318.  
  319. #uncomment to overclock the arm. 700 MHz is the default.
  320. #arm_freq=800
  321. EOM
  322.  
  323. ln -sf firmware/config.txt $R/boot/config.txt
  324. echo 'dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 elevator=deadline rootwait' > $R/boot/firmware/cmdline.txt
  325. ln -sf firmware/cmdline.txt $R/boot/cmdline.txt
  326.  
  327. # Load sound module on boot
  328. cat <<EOM >$R/lib/modules-load.d/rpi2.conf
  329. snd_bcm2835
  330. bcm2708_rng
  331. EOM
  332.  
  333. # Blacklist platform modules not applicable to the RPi2
  334. cat <<EOM >$R/etc/modprobe.d/rpi2.conf
  335. blacklist snd_soc_pcm512x_i2c
  336. blacklist snd_soc_pcm512x
  337. blacklist snd_soc_tas5713
  338. blacklist snd_soc_wm8804
  339. EOM
  340. }
  341.  
  342. function clean_up() {
  343. rm -f $R/etc/apt/sources.list.save
  344. rm -f $R/etc/resolvconf/resolv.conf.d/original
  345. rm -rf $R/run
  346. mkdir -p $R/run/resolvconf
  347. rm -f $R/etc/*-
  348. rm -rf $R/tmp/*
  349. rm -f $R/var/crash/*
  350. rm -f $R/var/lib/urandom/random-seed
  351.  
  352. # Potentially sensitive.
  353. rm -f $R/root/.bash_history
  354. rm -f $R/root/.ssh/known_hosts
  355.  
  356. # Machine-specific, so remove in case this system is going to be
  357. # cloned. These will be regenerated on the first boot.
  358. rm -f $R/etc/udev/rules.d/70-persistent-cd.rules
  359. rm -f $R/etc/udev/rules.d/70-persistent-net.rules
  360. [ -L $R/var/lib/dbus/machine-id ] || rm -f $R/var/lib/dbus/machine-id
  361. rm -f $R/etc/machine-id
  362. }
  363.  
  364. function make_raspi2_image() {
  365. # Build the image file
  366. DATE="$(date +%y.%j.%H%M)"
  367. IMAGE="ubuntu-mate-${RELEASE}-${DATE}.img"
  368.  
  369. local FS="${1}"
  370. local GB=${2}
  371.  
  372. if [ "${FS}" != "ext4" ] && [ "${FS}" != 'f2fs' ]; then
  373. echo "ERROR! Unsupport filesystem requested. Exitting."
  374. exit 1
  375. fi
  376.  
  377. if [ ${GB} -ne 4 ] && [ ${GB} -ne 8 ]; then
  378. echo "ERROR! Unsupport card image size requested. Exitting."
  379. exit 1
  380. fi
  381.  
  382. if [ ${GB} -eq 4 ]; then
  383. SEEK=3750
  384. SIZE=7546880
  385. SIZE_LIMIT=3685
  386. elif [ ${GB} -eq 8 ]; then
  387. SEEK=7680
  388. SIZE=15728639
  389. SIZE_LIMIT=7615
  390. fi
  391.  
  392. dd if=/dev/zero of="${BASEDIR}/${IMAGE}" bs=1M count=1
  393. dd if=/dev/zero of="${BASEDIR}/${IMAGE}" bs=1M count=0 seek=${SEEK}
  394.  
  395. sfdisk -f "$BASEDIR/${IMAGE}" <<EOM
  396. unit: sectors
  397.  
  398. 1 : start= 2048, size= 131072, Id= c, bootable
  399. 2 : start= 133120, size= ${SIZE}, Id=83
  400. 3 : start= 0, size= 0, Id= 0
  401. 4 : start= 0, size= 0, Id= 0
  402. EOM
  403.  
  404. BOOT_LOOP="$(losetup -o 1M --sizelimit 64M -f --show ${BASEDIR}/${IMAGE})"
  405. ROOT_LOOP="$(losetup -o 65M --sizelimit ${SIZE_LIMIT}M -f --show ${BASEDIR}/${IMAGE})"
  406. mkfs.vfat -n PI_BOOT -S 512 -s 16 -v "${BOOT_LOOP}"
  407. if [ "${FS}" == "ext4" ]; then
  408. mkfs.ext4 -L PI_ROOT -m 0 "${ROOT_LOOP}"
  409. else
  410. mkfs.f2fs -l PI_ROOT -o 1 "${ROOT_LOOP}"
  411. fi
  412. MOUNTDIR="${BUILDDIR}/mount"
  413. mkdir -p "${MOUNTDIR}"
  414. mount "${ROOT_LOOP}" "${MOUNTDIR}"
  415. mkdir -p "${MOUNTDIR}/boot/firmware"
  416. mount "${BOOT_LOOP}" "${MOUNTDIR}/boot/firmware"
  417. rsync -a --progress "$R/" "${MOUNTDIR}/"
  418. umount "${MOUNTDIR}/boot/firmware"
  419. umount "${MOUNTDIR}"
  420. losetup -d "${ROOT_LOOP}"
  421. losetup -d "${BOOT_LOOP}"
  422. }
  423.  
  424. function publish_img() {
  425. local IMAGE="ubuntu-mate-15.04-desktop-armhf-raspberry-pi-2.img"
  426. local DEST=$(echo "cmVtaXhfODgsdWJ1bnR1LW1hdGVAZnJzLnNvdXJjZWZvcmdlLm5ldAo=" | base64 --decode)
  427. if [ ! -e "${BASEDIR}/${IMAGE}.bz2" ]; then
  428. echo "ERROR! Could not find a bzip2 archive of ${IMAGE}/ Exitting."
  429. exit 1
  430. fi
  431. echo ${DEST}
  432. rsync -rvl -e 'ssh -c arcfour128' --progress "${BASEDIR}/${IMAGE}.bz2" ${DEST}:/home/frs/project/u/ub/ubuntu-mate/15.04/armhf/
  433. }
  434.  
  435. function stage_01_base() {
  436. R=${BASE_R}
  437. bootstrap
  438. mount_system
  439. apt_sources
  440. ubuntu_standard
  441. apt_upgrade
  442. apt_clean
  443. umount_system
  444. sync_to ${MATE_R}
  445. }
  446.  
  447. function stage_02_mate() {
  448. R=${MATE_R}
  449. mount_system
  450. ubuntu_mate
  451. create_oem_user
  452. prepare_oem_config
  453.  
  454. # NOT READY
  455. # configure_ssh
  456.  
  457. configure_network
  458. apt_upgrade
  459. apt_clean
  460. umount_system
  461. clean_up
  462. sync_to ${DEVICE_R}
  463. }
  464.  
  465. function stage_03_raspi2() {
  466. R=${DEVICE_R}
  467. local FS="ext4"
  468. mount_system
  469. configure_raspi2 ${FS}
  470. apt_upgrade
  471. apt_clean
  472. clean_up
  473. umount_system
  474. make_raspi2_image ${FS} 4
  475. }
  476.  
  477. function stage_03_odroid_c1() {
  478. # This is just an example as to how other target devices could be added.
  479. return
  480. R=${DEVICE_R}
  481. local FS="ext4"
  482. mount_system
  483. #configure_odroidc1 ${FS}
  484. apt_upgrade
  485. apt_clean
  486. clean_up
  487. umount_system
  488. #make_odriodc1_image ${FS} 4
  489. }
  490.  
  491. stage_01_base
  492. stage_02_mate
  493. stage_03_raspi2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement