freedombone-image-make 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. #set -x # Enable debugging
  31. IMAGE=$1
  32. export ARCHITECTURE
  33. export MACHINE
  34. export SOURCE
  35. export SUITE
  36. export MY_USERNAME
  37. export MY_PASSWORD
  38. export ROUTER_IP_ADDRESS
  39. export BOX_IP_ADDRESS
  40. export NAMESERVER1
  41. export NAMESERVER2
  42. export PROJECT_NAME
  43. export CONFIG_FILENAME
  44. export SSH_PUBKEY
  45. export GENERIC_IMAGE
  46. # Locate vmdebootstrap program fetched in Makefile
  47. basedir=`pwd`
  48. vendor_dir="${basedir}/vendor"
  49. vmdebootstrap_dir="${vendor_dir}/vmdebootstrap"
  50. if [ -z "$MIRROR" ] || [ -z "$SUITE" ] ; then
  51. echo error: Missing MIRROR and SUITE settings inherited from Makefile.
  52. exit 1
  53. fi
  54. # Packages to install in all Freedombone environments
  55. base_pkgs="apt base-files ifupdown initramfs-tools \
  56. logrotate module-init-tools netbase rsyslog udev debian-archive-keyring"
  57. # Packages needed on the beaglebone
  58. beaglebone_pkgs="linux-image-armmp u-boot-tools u-boot"
  59. # Packages needed on the Allwinner A20 devices:
  60. # - Cubieboard2
  61. a20_pkgs="linux-image-armmp-lpae u-boot-tools u-boot u-boot-sunxi"
  62. # Packages needed for self-hosted development
  63. dev_pkgs="build-essential devscripts make man-db emacs org-mode git mercurial"
  64. echo Building $MACHINE $PROJECT_NAME for $ARCHITECTURE.
  65. case "$MACHINE" in
  66. beaglebone)
  67. extra_pkgs="$beaglebone_pkgs"
  68. extra_opts="\
  69. --variant minbase \
  70. --bootoffset=2mib \
  71. --bootsize 128M \
  72. --boottype ext2 \
  73. --no-kernel \
  74. --no-extlinux \
  75. --foreign /usr/bin/qemu-arm-static \
  76. --roottype btrfs \
  77. "
  78. ;;
  79. cubieboard2)
  80. extra_pkgs="$a20_pkgs"
  81. extra_opts="\
  82. --variant minbase \
  83. --bootoffset=1mib \
  84. --bootsize 128M \
  85. --boottype vfat \
  86. --no-kernel \
  87. --no-extlinux \
  88. --foreign /usr/bin/qemu-arm-static \
  89. --roottype btrfs \
  90. "
  91. ;;
  92. virtualbox)
  93. extra_opts="\
  94. --grub \
  95. --roottype btrfs \
  96. " ;;
  97. qemu)
  98. extra_opts="\
  99. --grub \
  100. --roottype btrfs \
  101. " ;;
  102. all)
  103. extra_opts="\
  104. --grub \
  105. --roottype btrfs \
  106. " ;;
  107. esac
  108. # allow for lots of extra fun customization options.
  109. for customization in $CUSTOMIZATIONS
  110. do
  111. case "$customization" in
  112. development)
  113. extra_pkgs="$extra_pkgs $dev_pkgs"
  114. ;;
  115. esac
  116. done
  117. for p in $base_pkgs $extra_pkgs; do
  118. pkgopts="$pkgopts --package $p"
  119. done
  120. # Make sure file is owned by current user, not root
  121. touch $(dirname $IMAGE)/${PROJECT_NAME}.log
  122. if [ -x vendor/vmdebootstrap/vmdebootstrap ] ; then
  123. VMDEBOOTSTRAP=vendor/vmdebootstrap/vmdebootstrap
  124. else
  125. VMDEBOOTSTRAP=vmdebootstrap
  126. fi
  127. echo 'Making customised customisation script'
  128. TEMP_CUSTOMISE=/etc/${PROJECT_NAME}/image-customise
  129. if [ -f /usr/local/bin/${PROJECT_NAME}-image-customise ]; then
  130. sudo cp /usr/local/bin/${PROJECT_NAME}-image-customise $TEMP_CUSTOMISE
  131. else
  132. sudo cp /usr/bin/${PROJECT_NAME}-image-customise $TEMP_CUSTOMISE
  133. fi
  134. sudo sed -i "s|MY_USERNAME=.*|MY_USERNAME=${MY_USERNAME}|g" $TEMP_CUSTOMISE
  135. sudo sed -i "s|MY_PASSWORD=.*|MY_PASSWORD=${MY_PASSWORD}|g" $TEMP_CUSTOMISE
  136. sudo sed -i "s|ROUTER_IP_ADDRESS=.*|ROUTER_IP_ADDRESS=${ROUTER_IP_ADDRESS}|g" $TEMP_CUSTOMISE
  137. sudo sed -i "s|BOX_IP_ADDRESS=.*|BOX_IP_ADDRESS=${BOX_IP_ADDRESS}|g" $TEMP_CUSTOMISE
  138. sudo sed -i "s|NAMESERVER1=.*|NAMESERVER1=${NAMESERVER1}|g" $TEMP_CUSTOMISE
  139. sudo sed -i "s|NAMESERVER2=.*|NAMESERVER2=${NAMESERVER1}|g" $TEMP_CUSTOMISE
  140. sudo sed -i "s|PROJECT_NAME=.*|PROJECT_NAME=${PROJECT_NAME}|g" $TEMP_CUSTOMISE
  141. sudo sed -i "s|CONFIG_FILENAME=.*|CONFIG_FILENAME=${CONFIG_FILENAME}|g" $TEMP_CUSTOMISE
  142. sudo sed -i "s|SSH_PUBKEY=.*|SSH_PUBKEY=${SSH_PUBKEY}|g" $TEMP_CUSTOMISE
  143. sudo sed -i "s|GENERIC_IMAGE=.*|GENERIC_IMAGE=${GENERIC_IMAGE}|g" $TEMP_CUSTOMISE
  144. echo "starting $VMDEBOOTSTRAP"
  145. # Run vmdebootstrap script to create image
  146. sudo -H \
  147. SUITE="$SUITE" \
  148. MIRROR="$MIRROR" \
  149. BUILD_MIRROR="$BUILD_MIRROR"\
  150. MACHINE="$MACHINE" \
  151. ARCHITECTURE="$ARCHITECTURE" \
  152. SOURCE="$SOURCE" \
  153. CUSTOM_SETUP="$CUSTOM_SETUP" \
  154. $VMDEBOOTSTRAP \
  155. --log $(dirname $IMAGE)/${PROJECT_NAME}.log \
  156. --log-level debug \
  157. --size $IMAGE_SIZE \
  158. --image $IMAGE.img \
  159. --hostname ${PROJECT_NAME} \
  160. --verbose \
  161. --mirror $BUILD_MIRROR \
  162. --customize "$TEMP_CUSTOMISE" \
  163. --lock-root-password \
  164. --arch $ARCHITECTURE \
  165. --distribution $SUITE \
  166. $extra_opts \
  167. $pkgopts
  168. echo 'Removing customised customisation script'
  169. sudo shred -zu $TEMP_CUSTOMISE