freedombone-image-make 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #!/bin/sh
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Based upon bin/mk-freedombox-image from freedom-maker
  12. # With non-free stuff removed
  13. #
  14. # License
  15. # =======
  16. #
  17. # This program is free software: you can redistribute it and/or modify
  18. # it under the terms of the GNU General Public License as published by
  19. # the Free Software Foundation, either version 3 of the License, or
  20. # (at your option) any later version.
  21. #
  22. # This program is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU General Public License
  28. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. set -e # Exit on first error
  30. PROJECT_NAME='freedombone'
  31. export TEXTDOMAIN=${PROJECT_NAME}-image-make
  32. export TEXTDOMAINDIR="/usr/share/locale"
  33. #set -x # Enable debugging
  34. IMAGE=$1
  35. export ARCHITECTURE
  36. export MACHINE
  37. export SOURCE
  38. export SUITE
  39. export MY_USERNAME
  40. export MY_PASSWORD
  41. export ROUTER_IP_ADDRESS
  42. export BOX_IP_ADDRESS
  43. export NAMESERVER1
  44. export NAMESERVER2
  45. export PROJECT_NAME
  46. export CONFIG_FILENAME
  47. export SSH_PUBKEY
  48. export GENERIC_IMAGE
  49. export MINIMAL_INSTALL
  50. # Locate vmdebootstrap program fetched in Makefile
  51. basedir=`pwd`
  52. vendor_dir="${basedir}/vendor"
  53. vmdebootstrap_dir="${vendor_dir}/vmdebootstrap"
  54. if [ -z "$MIRROR" ] || [ -z "$SUITE" ] ; then
  55. echo $"error: Missing MIRROR and SUITE settings inherited from Makefile."
  56. exit 1
  57. fi
  58. # Packages to install in all Freedombone environments
  59. base_pkgs="apt base-files ifupdown initramfs-tools \
  60. logrotate module-init-tools netbase rsyslog udev debian-archive-keyring"
  61. # Packages needed on the beaglebone
  62. beaglebone_pkgs="linux-image-armmp u-boot-tools u-boot"
  63. # Packages needed on the Allwinner A20 devices:
  64. # - Cubieboard2
  65. a20_pkgs="linux-image-armmp-lpae u-boot-tools u-boot u-boot-sunxi"
  66. # Packages needed for self-hosted development
  67. dev_pkgs="build-essential devscripts make man-db emacs org-mode git mercurial"
  68. echo Building $MACHINE $PROJECT_NAME for $ARCHITECTURE.
  69. case "$MACHINE" in
  70. beaglebone)
  71. extra_pkgs="$beaglebone_pkgs"
  72. extra_opts="\
  73. --variant minbase \
  74. --bootoffset=2mib \
  75. --bootsize 128M \
  76. --boottype ext2 \
  77. --no-kernel \
  78. --no-extlinux \
  79. --foreign /usr/bin/qemu-arm-static \
  80. --roottype btrfs \
  81. "
  82. ;;
  83. cubietruck | a20-olinuxino-lime2 | cubieboard2)
  84. extra_pkgs="$a20_pkgs"
  85. extra_opts="\
  86. --variant minbase \
  87. --bootoffset=1mib \
  88. --bootsize 128M \
  89. --boottype vfat \
  90. --no-kernel \
  91. --no-extlinux \
  92. --foreign /usr/bin/qemu-arm-static \
  93. --roottype btrfs \
  94. "
  95. ;;
  96. virtualbox)
  97. extra_opts="\
  98. --grub \
  99. --roottype btrfs \
  100. " ;;
  101. qemu)
  102. extra_opts="\
  103. --grub \
  104. --roottype btrfs \
  105. " ;;
  106. all)
  107. extra_opts="\
  108. --grub \
  109. --roottype btrfs \
  110. " ;;
  111. esac
  112. # allow for lots of extra fun customization options.
  113. for customization in $CUSTOMIZATIONS
  114. do
  115. case "$customization" in
  116. development)
  117. extra_pkgs="$extra_pkgs $dev_pkgs"
  118. ;;
  119. esac
  120. done
  121. for p in $base_pkgs $extra_pkgs; do
  122. pkgopts="$pkgopts --package $p"
  123. done
  124. # Make sure file is owned by current user, not root
  125. touch $(dirname $IMAGE)/${PROJECT_NAME}.log
  126. if [ -x vendor/vmdebootstrap/vmdebootstrap ] ; then
  127. VMDEBOOTSTRAP=vendor/vmdebootstrap/vmdebootstrap
  128. else
  129. VMDEBOOTSTRAP=vmdebootstrap
  130. fi
  131. echo $'Making customised customisation script'
  132. TEMP_CUSTOMISE=/etc/${PROJECT_NAME}/image-customise
  133. if [ -f /usr/local/bin/${PROJECT_NAME}-image-customise ]; then
  134. sudo cp /usr/local/bin/${PROJECT_NAME}-image-customise $TEMP_CUSTOMISE
  135. else
  136. sudo cp /usr/bin/${PROJECT_NAME}-image-customise $TEMP_CUSTOMISE
  137. fi
  138. sudo sed -i "s|MY_USERNAME=.*|MY_USERNAME=${MY_USERNAME}|g" $TEMP_CUSTOMISE
  139. sudo sed -i "s|MY_PASSWORD=.*|MY_PASSWORD=${MY_PASSWORD}|g" $TEMP_CUSTOMISE
  140. sudo sed -i "s|ROUTER_IP_ADDRESS=.*|ROUTER_IP_ADDRESS=${ROUTER_IP_ADDRESS}|g" $TEMP_CUSTOMISE
  141. sudo sed -i "s|BOX_IP_ADDRESS=.*|BOX_IP_ADDRESS=${BOX_IP_ADDRESS}|g" $TEMP_CUSTOMISE
  142. sudo sed -i "s|NAMESERVER1=.*|NAMESERVER1=${NAMESERVER1}|g" $TEMP_CUSTOMISE
  143. sudo sed -i "s|NAMESERVER2=.*|NAMESERVER2=${NAMESERVER1}|g" $TEMP_CUSTOMISE
  144. sudo sed -i "s|PROJECT_NAME=.*|PROJECT_NAME=${PROJECT_NAME}|g" $TEMP_CUSTOMISE
  145. sudo sed -i "s|CONFIG_FILENAME=.*|CONFIG_FILENAME=${CONFIG_FILENAME}|g" $TEMP_CUSTOMISE
  146. sudo sed -i "s|SSH_PUBKEY=.*|SSH_PUBKEY=${SSH_PUBKEY}|g" $TEMP_CUSTOMISE
  147. sudo sed -i "s|GENERIC_IMAGE=.*|GENERIC_IMAGE=${GENERIC_IMAGE}|g" $TEMP_CUSTOMISE
  148. sudo sed -i "s|MINIMAL_INSTALL=.*|MINIMAL_INSTALL=\"${MINIMAL_INSTALL}\"|g" $TEMP_CUSTOMISE
  149. echo $"starting $VMDEBOOTSTRAP"
  150. # Run vmdebootstrap script to create image
  151. sudo -H \
  152. SUITE="$SUITE" \
  153. MIRROR="$MIRROR" \
  154. BUILD_MIRROR="$BUILD_MIRROR"\
  155. MACHINE="$MACHINE" \
  156. ARCHITECTURE="$ARCHITECTURE" \
  157. SOURCE="$SOURCE" \
  158. CUSTOM_SETUP="$CUSTOM_SETUP" \
  159. $VMDEBOOTSTRAP \
  160. --log $(dirname $IMAGE)/${PROJECT_NAME}.log \
  161. --log-level debug \
  162. --size $IMAGE_SIZE \
  163. --image $IMAGE.img \
  164. --hostname ${PROJECT_NAME} \
  165. --verbose \
  166. --mirror $BUILD_MIRROR \
  167. --customize "$TEMP_CUSTOMISE" \
  168. --lock-root-password \
  169. --arch $ARCHITECTURE \
  170. --distribution $SUITE \
  171. $extra_opts \
  172. $pkgopts
  173. echo $'Removing customised customisation script'
  174. sudo shred -zu $TEMP_CUSTOMISE