freedombone-image-make 5.7KB

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