freedombone-image-make 6.9KB

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