2015-11-20 17:09:21 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2015-11-21 12:25:32 +01:00
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
2015-11-20 17:09:21 +01:00
|
|
|
# Based upon bin/mk-freedombox-image from freedom-maker
|
|
|
|
# With non-free stuff removed
|
|
|
|
#
|
2015-11-21 12:25:32 +01:00
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
2015-11-20 17:09:21 +01:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
set -e # Exit on first error
|
|
|
|
|
2015-11-27 12:42:16 +01:00
|
|
|
PROJECT_NAME='freedombone'
|
|
|
|
|
|
|
|
export TEXTDOMAIN=$PROJECT_NAME
|
|
|
|
export TEXTDOMAINDIR="/usr/share/locale"
|
|
|
|
|
2015-11-20 17:09:21 +01:00
|
|
|
#set -x # Enable debugging
|
|
|
|
|
|
|
|
IMAGE=$1
|
|
|
|
export ARCHITECTURE
|
|
|
|
export MACHINE
|
|
|
|
export SOURCE
|
|
|
|
export SUITE
|
2015-11-20 22:43:03 +01:00
|
|
|
export MY_USERNAME
|
|
|
|
export MY_PASSWORD
|
|
|
|
export ROUTER_IP_ADDRESS
|
|
|
|
export BOX_IP_ADDRESS
|
|
|
|
export NAMESERVER1
|
|
|
|
export NAMESERVER2
|
2015-11-21 12:21:56 +01:00
|
|
|
export PROJECT_NAME
|
2015-11-21 12:56:40 +01:00
|
|
|
export CONFIG_FILENAME
|
2015-11-21 15:33:39 +01:00
|
|
|
export SSH_PUBKEY
|
2015-11-23 11:33:45 +01:00
|
|
|
export GENERIC_IMAGE
|
2015-11-20 17:09:21 +01:00
|
|
|
|
|
|
|
# Locate vmdebootstrap program fetched in Makefile
|
|
|
|
basedir=`pwd`
|
|
|
|
vendor_dir="${basedir}/vendor"
|
|
|
|
vmdebootstrap_dir="${vendor_dir}/vmdebootstrap"
|
|
|
|
|
|
|
|
if [ -z "$MIRROR" ] || [ -z "$SUITE" ] ; then
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $"error: Missing MIRROR and SUITE settings inherited from Makefile."
|
2015-11-20 17:09:21 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Packages to install in all Freedombone environments
|
|
|
|
base_pkgs="apt base-files ifupdown initramfs-tools \
|
|
|
|
logrotate module-init-tools netbase rsyslog udev debian-archive-keyring"
|
|
|
|
|
|
|
|
# Packages needed on the beaglebone
|
|
|
|
beaglebone_pkgs="linux-image-armmp u-boot-tools u-boot"
|
|
|
|
|
2015-11-26 18:35:54 +01:00
|
|
|
# Packages needed on the Allwinner A20 devices:
|
2015-11-26 18:40:37 +01:00
|
|
|
# - Cubieboard2
|
|
|
|
a20_pkgs="linux-image-armmp-lpae u-boot-tools u-boot u-boot-sunxi"
|
2015-11-26 18:35:54 +01:00
|
|
|
|
2015-11-20 17:09:21 +01:00
|
|
|
# Packages needed for self-hosted development
|
|
|
|
dev_pkgs="build-essential devscripts make man-db emacs org-mode git mercurial"
|
|
|
|
|
2015-11-21 12:21:56 +01:00
|
|
|
echo Building $MACHINE $PROJECT_NAME for $ARCHITECTURE.
|
2015-11-20 17:09:21 +01:00
|
|
|
|
|
|
|
case "$MACHINE" in
|
|
|
|
beaglebone)
|
2015-11-20 22:50:54 +01:00
|
|
|
extra_pkgs="$beaglebone_pkgs"
|
|
|
|
extra_opts="\
|
2015-11-20 17:09:21 +01:00
|
|
|
--variant minbase \
|
|
|
|
--bootoffset=2mib \
|
|
|
|
--bootsize 128M \
|
|
|
|
--boottype ext2 \
|
|
|
|
--no-kernel \
|
|
|
|
--no-extlinux \
|
|
|
|
--foreign /usr/bin/qemu-arm-static \
|
|
|
|
--roottype btrfs \
|
|
|
|
"
|
2015-11-20 22:50:54 +01:00
|
|
|
;;
|
2015-11-26 18:40:37 +01:00
|
|
|
cubieboard2)
|
2015-11-26 17:36:10 +01:00
|
|
|
extra_pkgs="$a20_pkgs"
|
|
|
|
extra_opts="\
|
|
|
|
--variant minbase \
|
|
|
|
--bootoffset=1mib \
|
|
|
|
--bootsize 128M \
|
|
|
|
--boottype vfat \
|
|
|
|
--no-kernel \
|
|
|
|
--no-extlinux \
|
|
|
|
--foreign /usr/bin/qemu-arm-static \
|
|
|
|
--roottype btrfs \
|
|
|
|
"
|
|
|
|
;;
|
2015-11-20 17:09:21 +01:00
|
|
|
virtualbox)
|
2015-11-20 22:50:54 +01:00
|
|
|
extra_opts="\
|
2015-11-20 17:09:21 +01:00
|
|
|
--grub \
|
|
|
|
--roottype btrfs \
|
2015-11-22 23:52:59 +01:00
|
|
|
" ;;
|
|
|
|
qemu)
|
|
|
|
extra_opts="\
|
|
|
|
--grub \
|
|
|
|
--roottype btrfs \
|
2015-11-20 22:50:54 +01:00
|
|
|
" ;;
|
2015-11-20 17:09:21 +01:00
|
|
|
all)
|
2015-11-20 22:50:54 +01:00
|
|
|
extra_opts="\
|
2015-11-20 17:09:21 +01:00
|
|
|
--grub \
|
|
|
|
--roottype btrfs \
|
2015-11-20 22:50:54 +01:00
|
|
|
" ;;
|
2015-11-20 17:09:21 +01:00
|
|
|
esac
|
|
|
|
|
|
|
|
# allow for lots of extra fun customization options.
|
|
|
|
for customization in $CUSTOMIZATIONS
|
|
|
|
do
|
|
|
|
case "$customization" in
|
|
|
|
development)
|
|
|
|
extra_pkgs="$extra_pkgs $dev_pkgs"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
for p in $base_pkgs $extra_pkgs; do
|
|
|
|
pkgopts="$pkgopts --package $p"
|
|
|
|
done
|
|
|
|
|
|
|
|
# Make sure file is owned by current user, not root
|
2015-11-21 12:21:56 +01:00
|
|
|
touch $(dirname $IMAGE)/${PROJECT_NAME}.log
|
2015-11-20 17:09:21 +01:00
|
|
|
|
|
|
|
if [ -x vendor/vmdebootstrap/vmdebootstrap ] ; then
|
|
|
|
VMDEBOOTSTRAP=vendor/vmdebootstrap/vmdebootstrap
|
|
|
|
else
|
|
|
|
VMDEBOOTSTRAP=vmdebootstrap
|
|
|
|
fi
|
|
|
|
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $'Making customised customisation script'
|
2015-11-21 12:21:56 +01:00
|
|
|
TEMP_CUSTOMISE=/etc/${PROJECT_NAME}/image-customise
|
|
|
|
if [ -f /usr/local/bin/${PROJECT_NAME}-image-customise ]; then
|
|
|
|
sudo cp /usr/local/bin/${PROJECT_NAME}-image-customise $TEMP_CUSTOMISE
|
2015-11-20 22:50:54 +01:00
|
|
|
else
|
2015-11-21 12:21:56 +01:00
|
|
|
sudo cp /usr/bin/${PROJECT_NAME}-image-customise $TEMP_CUSTOMISE
|
2015-11-20 22:50:54 +01:00
|
|
|
fi
|
2015-11-20 22:43:03 +01:00
|
|
|
sudo sed -i "s|MY_USERNAME=.*|MY_USERNAME=${MY_USERNAME}|g" $TEMP_CUSTOMISE
|
|
|
|
sudo sed -i "s|MY_PASSWORD=.*|MY_PASSWORD=${MY_PASSWORD}|g" $TEMP_CUSTOMISE
|
|
|
|
sudo sed -i "s|ROUTER_IP_ADDRESS=.*|ROUTER_IP_ADDRESS=${ROUTER_IP_ADDRESS}|g" $TEMP_CUSTOMISE
|
|
|
|
sudo sed -i "s|BOX_IP_ADDRESS=.*|BOX_IP_ADDRESS=${BOX_IP_ADDRESS}|g" $TEMP_CUSTOMISE
|
|
|
|
sudo sed -i "s|NAMESERVER1=.*|NAMESERVER1=${NAMESERVER1}|g" $TEMP_CUSTOMISE
|
|
|
|
sudo sed -i "s|NAMESERVER2=.*|NAMESERVER2=${NAMESERVER1}|g" $TEMP_CUSTOMISE
|
2015-11-21 12:56:40 +01:00
|
|
|
sudo sed -i "s|PROJECT_NAME=.*|PROJECT_NAME=${PROJECT_NAME}|g" $TEMP_CUSTOMISE
|
2015-11-21 13:59:19 +01:00
|
|
|
sudo sed -i "s|CONFIG_FILENAME=.*|CONFIG_FILENAME=${CONFIG_FILENAME}|g" $TEMP_CUSTOMISE
|
2015-11-21 15:33:39 +01:00
|
|
|
sudo sed -i "s|SSH_PUBKEY=.*|SSH_PUBKEY=${SSH_PUBKEY}|g" $TEMP_CUSTOMISE
|
2015-11-23 11:33:45 +01:00
|
|
|
sudo sed -i "s|GENERIC_IMAGE=.*|GENERIC_IMAGE=${GENERIC_IMAGE}|g" $TEMP_CUSTOMISE
|
2015-11-20 22:43:03 +01:00
|
|
|
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $"starting $VMDEBOOTSTRAP"
|
2015-11-20 17:09:21 +01:00
|
|
|
# Run vmdebootstrap script to create image
|
|
|
|
sudo -H \
|
|
|
|
SUITE="$SUITE" \
|
|
|
|
MIRROR="$MIRROR" \
|
|
|
|
BUILD_MIRROR="$BUILD_MIRROR"\
|
|
|
|
MACHINE="$MACHINE" \
|
|
|
|
ARCHITECTURE="$ARCHITECTURE" \
|
|
|
|
SOURCE="$SOURCE" \
|
|
|
|
CUSTOM_SETUP="$CUSTOM_SETUP" \
|
|
|
|
$VMDEBOOTSTRAP \
|
2015-11-21 12:21:56 +01:00
|
|
|
--log $(dirname $IMAGE)/${PROJECT_NAME}.log \
|
2015-11-20 17:09:21 +01:00
|
|
|
--log-level debug \
|
|
|
|
--size $IMAGE_SIZE \
|
|
|
|
--image $IMAGE.img \
|
2015-11-21 12:21:56 +01:00
|
|
|
--hostname ${PROJECT_NAME} \
|
2015-11-20 17:09:21 +01:00
|
|
|
--verbose \
|
|
|
|
--mirror $BUILD_MIRROR \
|
2015-11-20 22:43:03 +01:00
|
|
|
--customize "$TEMP_CUSTOMISE" \
|
2015-11-20 17:09:21 +01:00
|
|
|
--lock-root-password \
|
|
|
|
--arch $ARCHITECTURE \
|
|
|
|
--distribution $SUITE \
|
|
|
|
$extra_opts \
|
|
|
|
$pkgopts
|
2015-11-20 22:43:03 +01:00
|
|
|
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $'Removing customised customisation script'
|
2015-11-20 22:43:03 +01:00
|
|
|
sudo shred -zu $TEMP_CUSTOMISE
|