code.fastix.org

Dateiansicht:

Datei:Projekte -> Linux:ubuntu-for-raspberry-installer -> rpi2-build-system.sh
md5:68be77ec0c2f93ec36da2547d4530dd8
sha1:311f46c83fa11fcd8493c7452c52c585d40dc8ff
Download-Link:Download
  1. #!/usr/bin/sudo /bin/sh
  2.  
  3. if [ -z "${BUILD_HOSTNAME}" ]; then
  4. . ./rpi2-settings.sh
  5. fi
  6.  
  7. set +x
  8.  
  9. if [ "{${UBUNTU_FIRST_USER}_PASS}" = '#EDIT THIS#' ]; then
  10.     echo "Sorry. You have not set a Password in rpi2-settings.sh"
  11.     echo "This is verry unsafe. Exit."
  12.     exit 2
  13. fi
  14.  
  15.  
  16. if [ ${WriteTo} = 'mmcblk0' ]; then
  17.  
  18.   clear
  19.  
  20.   echo    "        #==========================================================#"
  21.   echo    "        #                                                          #"
  22.   echo    "        #  AVE                                                     #"
  23.   echo    "        #                                                          #"
  24.   echo    "        #  This will brutal delete your files on mmcblk0!          #"
  25.   echo    "        #                                                          #"
  26.   echo    "        #==========================================================#"
  27.   echo    ""
  28.   echo -n "           Yout want this really? Type YES: ___\b\b\b"
  29.   read answer
  30.   echo  ""
  31.   if [ "${answer}" = "YES" ]; then
  32.     echo  ""
  33.     echo  "           Ok. So you want ..."
  34.     echo  ""
  35.   else
  36.     echo ""
  37.     echo  "           Ok. Exit."
  38.     echo ""
  39.     exit
  40.   fi
  41.  
  42. elif [ ${WriteTo} = 'image' ]; then
  43.  
  44.   clear
  45.  
  46.   echo    "        #=============================================================#"
  47.   echo    "        #                                                             #"
  48.   echo    "        #  Hint:                                                      #"
  49.   echo    "        #                                                             #"
  50.   echo    "        #  Generate $BASEDIR/${DATE}-ubuntu-${RELEASE}.img"
  51.   echo    "        #                                                             #"
  52.   echo    "        #=============================================================#"
  53.   echo    ""
  54.  
  55. else
  56.  
  57.   clear
  58.  
  59.   echo    "        #=============================================================#"
  60.   echo    "        #                                                             #"
  61.   echo    "        #  Hint:                                                      #"
  62.   echo    "        #                                                             #"
  63.   echo    "        #  Generate Ubuntu-installation in ${BUILDDIR}"
  64.   echo    "        #                                                             #"
  65.   echo    "        #=============================================================#"
  66.   echo    ""
  67.  
  68. fi
  69.  
  70. # Don't clobber an old build
  71. if [ -e "${BUILDDIR}" ]; then
  72.   echo "${BUILDDIR} exists, not proceeding"
  73.   exit 1
  74. fi
  75.  
  76. set -x
  77.  
  78.  
  79. # Install needed software
  80. apt-get update
  81. if ! which debootstrap; then
  82.   apt-get install debootstrap qemu-debootstrap
  83. fi
  84.  
  85. if ! which qemu-debootstrap; then
  86.   apt-get install qemu-debootstrap
  87. fi
  88.  
  89. if ! which bmaptool; then
  90.   apt-get install bmap-tools
  91. fi
  92.  
  93. # Set up environment
  94. export TZ=UTC
  95. mkdir -p ${R}
  96.  
  97. # Base debootstrap
  98. apt-get -y install ubuntu-keyring
  99. qemu-debootstrap --arch armhf ${RELEASE} ${R} http://ports.ubuntu.com/
  100.  
  101. # Mount required filesystems
  102. mount -t proc none ${R}/proc
  103. mount -t sysfs none ${R}/sys
  104.  
  105. # Set up initial sources.list
  106. cat <<EOM >${R}/etc/apt/sources.list
  107. deb http://ports.ubuntu.com/ ${RELEASE} main restricted universe multiverse
  108. # deb-src http://ports.ubuntu.com/ ${RELEASE} main restricted universe multiverse
  109.  
  110. deb http://ports.ubuntu.com/ ${RELEASE}-updates main restricted universe multiverse
  111. # deb-src http://ports.ubuntu.com/ ${RELEASE}-updates main restricted universe multiverse
  112.  
  113. deb http://ports.ubuntu.com/ ${RELEASE}-security main restricted universe multiverse
  114. # deb-src http://ports.ubuntu.com/ ${RELEASE}-security main restricted universe multiverse
  115.  
  116. deb http://ports.ubuntu.com/ ${RELEASE}-backports main restricted universe multiverse
  117. # deb-src http://ports.ubuntu.com/ ${RELEASE}-backports main restricted universe multiverse
  118. EOM
  119.  
  120. chroot ${R} apt-get update
  121. chroot ${R} apt-get -y -u dist-upgrade
  122.  
  123. # Install the RPi PPA
  124. cat <<"EOM" >${R}/etc/apt/preferences.d/rpi2-ppa
  125. Package: *
  126. Pin: release o=LP-PPA-fo0bar-rpi2
  127. Pin-Priority: 990
  128.  
  129. Package: *
  130. Pin: release o=LP-PPA-fo0bar-rpi2-staging
  131. Pin-Priority: 990
  132. EOM
  133.  
  134. chroot ${R} apt-get -y --force-yes install software-properties-common ubuntu-keyring
  135. chroot ${R} apt-add-repository -y ppa:fo0bar/rpi2
  136. chroot ${R} apt-get update
  137.  
  138. # Standard packages
  139. chroot ${R} apt-get -y --force-yes install ubuntu-minimal initramfs-tools raspberrypi-bootloader-nokernel rpi2-ubuntu-errata language-pack-en
  140.  
  141. # Kernel installation
  142. # Install flash-kernel last so it doesn't try (and fail) to detect the
  143. # platform in the chroot.
  144. chroot ${R} apt-get -y --force-yes --no-install-recommends install linux-image-rpi2
  145. chroot ${R} apt-get -y --force-yes install flash-kernel
  146.  
  147. ############################ Jörg Reinholz: Software
  148.  
  149. if [ -n ${EXTRA_SOFTWARE} ]; then
  150.     for w in ${EXTRA_SOFTWARE}; do
  151.     chroot ${R} apt-get -y --force-yes install ${w};
  152.     done;
  153. fi
  154.  
  155. if [ -n ${REMOVE_SOFTWARE} ]; then
  156.     for w in ${REMOVE_SOFTWARE}; do
  157.     chroot ${R} apt-get -y purge ${w};
  158.     done;
  159. fi
  160.  
  161.  
  162. #chroot ${R} apt-get -y install linux-firmware libraspberrypi-bin libraspberrypi-dev libraspberrypi-bin-nonfree
  163. #chroot ${R} apt-get -y install dphys-swapfile
  164. ############################
  165.  
  166. VMLINUZ="$(ls -1 ${R}/boot/vmlinuz-* | sort | tail -n 1)"
  167. [ -z "${VMLINUZ}" ] && exit 1
  168. cp ${VMLINUZ} ${R}/boot/firmware/kernel7.img
  169. INITRD="$(ls -1 ${R}/boot/initrd.img-* | sort | tail -n 1)"
  170. [ -z "${INITRD}" ] && exit 1
  171. cp ${INITRD} ${R}/boot/firmware/initrd7.img
  172.  
  173. # Set up fstab
  174. cat <<EOM >${R}/etc/fstab
  175. proc            /proc           proc    defaults          0       0
  176. /dev/mmcblk0p3  /               ext4    defaults,noatime  0       1
  177. /dev/mmcblk0p1  /boot/firmware  vfat    defaults,ro       0       2
  178. /dev/mmcblk0p2  none            swap    sw                0       0
  179.  
  180. EOM
  181.  
  182. #setting up extra files
  183. . ./rpi2-extra-files.sh
  184.  
  185. # Set up default user
  186. chroot ${R} adduser --disabled-login --gecos "${UBUNTU_FIRST_USER}" --add_extra_groups ${UBUNTU_FIRST_USER}
  187. UBUNTU_FIRST_USER_PASS=`echo "ttt:${UBUNTU_FIRST_USER}_PASS" | chpasswd -S -c SHA512 | sed s/ttt://`
  188. chroot ${R} usermod -a -G sudo,adm -p ${UBUNTU_FIRST_USER}_PASS ${UBUNTU_FIRST_USER}
  189. unset UBUNTU_FIRST_USER_PASS;
  190.  
  191. # install the firmware-updater:
  192. chroot ${R} curl -L --output /usr/bin/rpi-update https://raw.githubusercontent.com/Hexxeh/rpi-update/master/rpi-update
  193. chroot ${R} chmod +x /usr/bin/rpi-update
  194.  
  195. # update the firmware:
  196. if [ -n ${UPDATE_FIRMWARE_USB_SAVE} ]; then
  197.     chroot ${R} /usr/bin/rpi-update e3e89868ece21abe525dc181c431c8a8b5de58b8
  198.     export UPDATE_FIRMWARE=''
  199. fi
  200. if [ -n ${UPDATE_FIRMWARE} ]; then
  201.     chroot ${R} /usr/bin/rpi-update
  202. fi
  203.  
  204. if [ -n Activate1_2AmpPowerOverUSB ]; then
  205.     echo "# sets the available current over USB to 1.2A (default is 0 [600mA])" >> ${R}/boot/config.txt
  206.     echo "max_usb_current=1" >> ${R}/boot/config.txt
  207. fi
  208.  
  209. chroot ${R} apt-get autoremove
  210.  
  211. # Clean cached downloads
  212. chroot ${R} apt-get clean
  213.  
  214. # Unmount mounted filesystems
  215. umount ${R}/proc
  216. umount ${R}/sys
  217.  
  218. # Clean up files
  219. rm -f ${R}/etc/apt/sources.list.save
  220. rm -f ${R}/etc/resolvconf/resolv.conf.d/original
  221. rm -rf ${R}/run
  222. mkdir -p ${R}/run
  223. rm -f ${R}/etc/*-
  224. rm -f ${R}/root/.bash_history
  225. rm -rf ${R}/tmp/*
  226. rm -f ${R}/var/lib/urandom/random-seed
  227. [ -L ${R}/var/lib/dbus/machine-id ] || rm -f ${R}/var/lib/dbus/machine-id
  228. rm -f ${R}/etc/machine-id
  229.  
  230. set +x
  231. echo ""
  232. echo "Installation (virtual filesystem) written to: ${R}"
  233. echo ""
  234.  
  235. if [ "${WriteTo}" = "mmcblk0" ]; then
  236. . ./rpi2-create-mmcblk0.sh
  237. elif [ "${WriteTo}" = "image" ]; then
  238. . ./rpi2-create-image.sh
  239. fi
  240.  
  241. echo ""
  242. echo "        #=========================================#"
  243. echo "        #                                         #"
  244. echo "        #                 Ready!                  #"
  245. echo "        #                                         #"
  246. echo "        #=========================================#"
  247. echo ""
  248. exit
  249.