freedombone-image-make 6.5KB

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