freedombone-image-make 5.4KB

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