freedombone-image-make 4.8KB

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