2015-12-30 14:31:33 +03:00
|
|
|
# Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com
|
|
|
|
#
|
|
|
|
# This file is licensed under the terms of the GNU General Public
|
|
|
|
# License version 2. This program is licensed "as is" without any
|
|
|
|
# warranty of any kind, whether express or implied.
|
|
|
|
#
|
|
|
|
# This file is a part of tool chain https://github.com/igorpecovnik/lib
|
|
|
|
#
|
|
|
|
|
|
|
|
# Functions:
|
|
|
|
# debootstrap_ng
|
|
|
|
# create_rootfs_cache
|
|
|
|
# prepare_partitions
|
|
|
|
# create_image
|
2016-05-28 13:44:57 +03:00
|
|
|
# install_dummy_initctl
|
2016-03-09 12:18:40 +03:00
|
|
|
# mount_chroot
|
|
|
|
# umount_chroot
|
2015-12-30 14:31:33 +03:00
|
|
|
# unmount_on_exit
|
|
|
|
|
|
|
|
# custom_debootstrap_ng
|
|
|
|
#
|
|
|
|
# main debootstrap function
|
|
|
|
#
|
|
|
|
debootstrap_ng()
|
|
|
|
{
|
|
|
|
display_alert "Starting build process for" "$BOARD $RELEASE" "info"
|
|
|
|
|
2016-08-30 19:25:32 +03:00
|
|
|
[[ "ext4 f2fs btrfs nfs fel" != *$ROOTFS_TYPE* ]] && exit_with_error "Unknown rootfs type" "$ROOTFS_TYPE"
|
2016-03-05 15:54:44 +03:00
|
|
|
|
|
|
|
# Fixed image size is in 1M dd blocks (MiB)
|
|
|
|
# to get size of block device /dev/sdX execute as root:
|
|
|
|
# echo $(( $(blockdev --getsize64 /dev/sdX) / 1024 / 1024 ))
|
2016-05-08 16:10:11 +03:00
|
|
|
[[ "btrfs f2fs" == *"$ROOTFS_TYPE"* && -z $FIXED_IMAGE_SIZE ]] && exit_with_error "Please define FIXED_IMAGE_SIZE"
|
2016-03-05 15:54:44 +03:00
|
|
|
|
2016-03-14 21:54:03 +03:00
|
|
|
[[ $ROOTFS_TYPE != ext4 ]] && display_alert "Assuming $BOARD $BRANCH kernel supports $ROOTFS_TYPE" "" "wrn"
|
2016-03-05 15:54:44 +03:00
|
|
|
|
|
|
|
# small SD card with kernel, boot scritpt and .dtb/.bin files
|
2016-03-09 12:18:40 +03:00
|
|
|
[[ $ROOTFS_TYPE == nfs ]] && FIXED_IMAGE_SIZE=64
|
2016-03-05 15:54:44 +03:00
|
|
|
|
2015-12-30 14:31:33 +03:00
|
|
|
# trap to unmount stuff in case of error/manual interruption
|
|
|
|
trap unmount_on_exit INT TERM EXIT
|
|
|
|
|
|
|
|
# stage: clean and create directories
|
2016-08-30 19:25:32 +03:00
|
|
|
rm -rf $CACHEDIR/{sdcard,mount}
|
|
|
|
mkdir -p $CACHEDIR/{sdcard,mount,rootfs} $DEST/images
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# stage: verify tmpfs configuration and mount
|
|
|
|
# default maximum size for tmpfs mount is 1/2 of available RAM
|
2016-03-08 21:22:35 +03:00
|
|
|
# CLI needs ~1.2GiB+ (Xenial CLI), Desktop - ~2.2GiB+ (Xenial Desktop w/o HW acceleration)
|
2015-12-30 14:31:33 +03:00
|
|
|
# calculate and set tmpfs mount to use 2/3 of available RAM
|
2016-03-08 21:22:35 +03:00
|
|
|
local phymem=$(( $(awk '/MemTotal/ {print $2}' /proc/meminfo) / 1024 * 2 / 3 )) # MiB
|
|
|
|
if [[ $BUILD_DESKTOP == yes ]]; then local tmpfs_max_size=2500; else local tmpfs_max_size=1500; fi # MiB
|
2016-05-08 16:10:11 +03:00
|
|
|
if [[ $FORCE_USE_RAMDISK == no ]]; then local use_tmpfs=no
|
2015-12-30 14:31:33 +03:00
|
|
|
elif [[ $FORCE_USE_RAMDISK == yes || $phymem -gt $tmpfs_max_size ]]; then
|
|
|
|
local use_tmpfs=yes
|
|
|
|
fi
|
|
|
|
|
2016-05-01 17:49:29 +03:00
|
|
|
[[ $use_tmpfs == yes ]] && mount -t tmpfs -o size=${tmpfs_max_size}M tmpfs $CACHEDIR/sdcard
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# stage: prepare basic rootfs: unpack cache or create from scratch
|
|
|
|
create_rootfs_cache
|
|
|
|
|
|
|
|
# stage: install kernel and u-boot packages
|
2016-03-09 12:18:40 +03:00
|
|
|
# install distribution and board specific applications
|
2016-06-15 19:44:14 +03:00
|
|
|
|
2016-08-30 19:25:32 +03:00
|
|
|
mkdir -p $CACHEDIR/sdcard/tmp/debs
|
|
|
|
mount --bind $DEST/debs/ $CACHEDIR/sdcard/tmp/debs
|
2016-06-15 19:44:14 +03:00
|
|
|
|
2016-03-09 12:18:40 +03:00
|
|
|
install_distribution_specific
|
2016-06-24 17:30:39 +03:00
|
|
|
install_common
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# install additional applications
|
2016-04-08 16:36:56 +03:00
|
|
|
[[ $EXTERNAL == yes ]] && install_external_applications
|
2015-12-30 14:31:33 +03:00
|
|
|
|
2016-06-17 15:06:41 +03:00
|
|
|
# install desktop files
|
|
|
|
[[ $BUILD_DESKTOP == yes ]] && install_desktop
|
|
|
|
|
2016-08-19 19:16:03 +03:00
|
|
|
if [[ $RELEASE == jessie || $RELEASE == xenial ]]; then
|
|
|
|
# install locally built packages
|
2016-09-03 16:42:03 +03:00
|
|
|
[[ $EXTERNAL_NEW == compile ]] && chroot_installpackages_local
|
2016-08-19 19:16:03 +03:00
|
|
|
# install from apt.armbian.com
|
2016-09-03 16:42:03 +03:00
|
|
|
[[ $EXTERNAL_NEW == prebuilt ]] && chroot_installpackages "yes"
|
2016-08-19 19:16:03 +03:00
|
|
|
fi
|
2016-07-11 21:20:34 +03:00
|
|
|
|
2016-06-15 19:44:14 +03:00
|
|
|
# cleanup for install_kernel and install_board_specific
|
2016-08-30 19:25:32 +03:00
|
|
|
umount $CACHEDIR/sdcard/tmp/debs && rm -rf $CACHEDIR/sdcard/tmp/debs
|
2016-06-15 19:44:14 +03:00
|
|
|
|
2015-12-30 14:31:33 +03:00
|
|
|
# stage: user customization script
|
|
|
|
# NOTE: installing too many packages may fill tmpfs mount
|
2016-03-19 17:26:15 +03:00
|
|
|
customize_image
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# stage: cleanup
|
2016-03-17 20:16:26 +01:00
|
|
|
rm -f $CACHEDIR/sdcard/usr/sbin/policy-rc.d
|
2016-04-18 19:20:15 +03:00
|
|
|
rm -f $CACHEDIR/sdcard/usr/bin/$QEMU_BINARY
|
2016-05-01 17:49:29 +03:00
|
|
|
[[ -x $CACHEDIR/sdcard/sbin/initctl.REAL ]] && mv -f $CACHEDIR/sdcard/sbin/initctl.REAL $CACHEDIR/sdcard/sbin/initctl
|
|
|
|
[[ -x $CACHEDIR/sdcard/sbin/start-stop-daemon.REAL ]] && mv -f $CACHEDIR/sdcard/sbin/start-stop-daemon.REAL $CACHEDIR/sdcard/sbin/start-stop-daemon
|
2015-12-30 14:31:33 +03:00
|
|
|
|
2016-06-18 17:57:17 +03:00
|
|
|
umount_chroot "$CACHEDIR/sdcard"
|
2015-12-30 14:31:33 +03:00
|
|
|
|
2016-05-01 17:49:29 +03:00
|
|
|
# to prevent creating swap file on NFS (needs specific kernel options)
|
|
|
|
# and f2fs/btrfs (not recommended or needs specific kernel options)
|
|
|
|
[[ $ROOTFS_TYPE != ext4 ]] && touch $CACHEDIR/sdcard/var/swap
|
2016-03-14 18:29:47 +03:00
|
|
|
|
2016-03-05 15:54:44 +03:00
|
|
|
if [[ $ROOTFS_TYPE == fel ]]; then
|
2016-03-17 20:16:26 +01:00
|
|
|
FEL_ROOTFS=$CACHEDIR/sdcard/
|
2016-03-05 15:54:44 +03:00
|
|
|
display_alert "Starting FEL boot" "$BOARD" "info"
|
|
|
|
source $SRC/lib/fel-load.sh
|
|
|
|
else
|
|
|
|
prepare_partitions
|
|
|
|
create_image
|
|
|
|
fi
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# stage: unmount tmpfs
|
2016-05-01 17:49:29 +03:00
|
|
|
[[ $use_tmpfs = yes ]] && umount $CACHEDIR/sdcard
|
2015-12-30 14:31:33 +03:00
|
|
|
|
2016-03-17 20:16:26 +01:00
|
|
|
rm -rf $CACHEDIR/sdcard
|
2016-03-07 19:34:56 +03:00
|
|
|
|
2015-12-30 14:31:33 +03:00
|
|
|
# remove exit trap
|
|
|
|
trap - INT TERM EXIT
|
|
|
|
} #############################################################################
|
|
|
|
|
|
|
|
# create_rootfs_cache
|
|
|
|
#
|
|
|
|
# unpacks cached rootfs for $RELEASE or creates one
|
|
|
|
#
|
|
|
|
create_rootfs_cache()
|
|
|
|
{
|
2016-03-04 00:00:37 +03:00
|
|
|
local packages_hash=$(get_package_list_hash $PACKAGE_LIST)
|
2016-05-01 14:24:40 +03:00
|
|
|
local cache_fname=$CACHEDIR/rootfs/${RELEASE}-ng-$ARCH.$packages_hash.tgz
|
|
|
|
local display_name=${RELEASE}-ng-$ARCH.${packages_hash:0:3}...${packages_hash:29}.tgz
|
2015-12-30 14:31:33 +03:00
|
|
|
if [[ -f $cache_fname ]]; then
|
2016-04-18 19:20:15 +03:00
|
|
|
local date_diff=$(( ($(date +%s) - $(stat -c %Y $cache_fname)) / 86400 ))
|
|
|
|
display_alert "Extracting $display_name" "$date_diff days old" "info"
|
2016-06-05 13:12:47 +03:00
|
|
|
pv -p -b -r -c -N "$display_name" "$cache_fname" | pigz -dc | tar xp --xattrs -C $CACHEDIR/sdcard/
|
2015-12-30 14:31:33 +03:00
|
|
|
else
|
|
|
|
display_alert "Creating new rootfs for" "$RELEASE" "info"
|
|
|
|
|
|
|
|
# stage: debootstrap base system
|
2016-05-04 17:16:39 +03:00
|
|
|
if [[ $NO_APT_CACHER != yes ]]; then
|
|
|
|
# apt-cacher-ng apt-get proxy parameter
|
2016-05-28 15:10:29 +03:00
|
|
|
local apt_extra="-o Acquire::http::Proxy=\"http://${APT_PROXY_ADDR:-localhost:3142}\""
|
|
|
|
local apt_mirror="http://${APT_PROXY_ADDR:-localhost:3142}/$APT_MIRROR"
|
2015-12-30 14:31:33 +03:00
|
|
|
else
|
2016-05-27 13:14:16 +03:00
|
|
|
local apt_mirror="http://$APT_MIRROR"
|
2015-12-30 14:31:33 +03:00
|
|
|
fi
|
2016-05-04 17:16:39 +03:00
|
|
|
|
2016-03-10 17:14:34 +03:00
|
|
|
# fancy progress bars (except for Wheezy target)
|
|
|
|
[[ -z $OUTPUT_DIALOG && $RELEASE != wheezy ]] && local apt_extra_progress="--show-progress -o DPKG::Progress-Fancy=1"
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
display_alert "Installing base system" "Stage 1/2" "info"
|
2016-04-18 19:20:15 +03:00
|
|
|
eval 'debootstrap --include=locales ${PACKAGE_LIST_EXCLUDE:+ --exclude=${PACKAGE_LIST_EXCLUDE// /,}} \
|
|
|
|
--arch=$ARCH --foreign $RELEASE $CACHEDIR/sdcard/ $apt_mirror' \
|
2015-12-30 14:31:33 +03:00
|
|
|
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/debootstrap.log'} \
|
2016-03-07 18:29:48 +01:00
|
|
|
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Debootstrap (stage 1/2)..." $TTY_Y $TTY_X'} \
|
2015-12-30 14:31:33 +03:00
|
|
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
|
|
|
|
2016-08-30 19:25:32 +03:00
|
|
|
[[ ${PIPESTATUS[0]} -ne 0 || ! -f $CACHEDIR/sdcard/debootstrap/debootstrap ]] && exit_with_error "Debootstrap base system first stage failed"
|
2016-03-10 16:24:28 +03:00
|
|
|
|
2016-04-18 19:20:15 +03:00
|
|
|
cp /usr/bin/$QEMU_BINARY $CACHEDIR/sdcard/usr/bin/
|
2016-05-26 18:42:14 +03:00
|
|
|
|
2016-03-17 20:16:26 +01:00
|
|
|
mkdir -p $CACHEDIR/sdcard/usr/share/keyrings/
|
|
|
|
cp /usr/share/keyrings/debian-archive-keyring.gpg $CACHEDIR/sdcard/usr/share/keyrings/
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
display_alert "Installing base system" "Stage 2/2" "info"
|
2016-03-17 20:16:26 +01:00
|
|
|
eval 'chroot $CACHEDIR/sdcard /bin/bash -c "/debootstrap/debootstrap --second-stage"' \
|
2015-12-30 14:31:33 +03:00
|
|
|
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/debootstrap.log'} \
|
2016-03-07 18:29:48 +01:00
|
|
|
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Debootstrap (stage 2/2)..." $TTY_Y $TTY_X'} \
|
2015-12-30 14:31:33 +03:00
|
|
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
|
|
|
|
2016-05-26 18:42:14 +03:00
|
|
|
[[ ${PIPESTATUS[0]} -ne 0 || ! -f $CACHEDIR/sdcard/bin/bash ]] && exit_with_error "Debootstrap base system second stage failed"
|
2016-03-10 16:24:28 +03:00
|
|
|
|
2016-06-18 17:57:17 +03:00
|
|
|
mount_chroot "$CACHEDIR/sdcard"
|
2015-12-30 14:31:33 +03:00
|
|
|
|
2016-05-01 17:49:29 +03:00
|
|
|
# policy-rc.d script prevents starting or reloading services during image creation
|
2016-04-18 19:20:15 +03:00
|
|
|
printf '#!/bin/sh\nexit 101' > $CACHEDIR/sdcard/usr/sbin/policy-rc.d
|
2016-03-17 20:16:26 +01:00
|
|
|
chmod 755 $CACHEDIR/sdcard/usr/sbin/policy-rc.d
|
2016-05-28 13:44:57 +03:00
|
|
|
install_dummy_initctl
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# stage: configure language and locales
|
|
|
|
display_alert "Configuring locales" "$DEST_LANG" "info"
|
|
|
|
|
2016-06-18 17:57:17 +03:00
|
|
|
[[ -f $CACHEDIR/sdcard/etc/locale.gen ]] && sed -i "s/^# $DEST_LANG/$DEST_LANG/" $CACHEDIR/sdcard/etc/locale.gen
|
2016-03-17 20:16:26 +01:00
|
|
|
eval 'LC_ALL=C LANG=C chroot $CACHEDIR/sdcard /bin/bash -c "locale-gen $DEST_LANG"' ${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
2016-05-08 16:10:11 +03:00
|
|
|
eval 'LC_ALL=C LANG=C chroot $CACHEDIR/sdcard /bin/bash -c "update-locale LANG=$DEST_LANG LANGUAGE=$DEST_LANG LC_MESSAGES=$DEST_LANG"' \
|
2015-12-30 14:31:33 +03:00
|
|
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
2016-05-08 16:10:11 +03:00
|
|
|
|
|
|
|
if [[ -f $CACHEDIR/sdcard/etc/default/console-setup ]]; then
|
|
|
|
sed -e 's/CHARMAP=.*/CHARMAP="UTF-8"/' -e 's/FONTSIZE=.*/FONTSIZE="8x16"/' \
|
|
|
|
-e 's/CODESET=.*/CODESET="guess"/' -i $CACHEDIR/sdcard/etc/default/console-setup
|
2016-08-08 17:13:43 +02:00
|
|
|
eval 'LC_ALL=C LANG=C chroot $CACHEDIR/sdcard /bin/bash -c "setupcon --save"'
|
2016-05-08 16:10:11 +03:00
|
|
|
fi
|
2015-12-30 14:31:33 +03:00
|
|
|
|
2016-08-25 00:51:12 +03:00
|
|
|
# stage: create apt sources list
|
2016-09-06 17:55:26 +03:00
|
|
|
create_sources_list "$RELEASE" "$CACHEDIR/sdcard/"
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# stage: add armbian repository and install key
|
2016-08-25 22:54:46 +03:00
|
|
|
case $RELEASE in
|
|
|
|
wheezy|trusty)
|
|
|
|
echo "deb http://apt.armbian.com $RELEASE main" > $CACHEDIR/sdcard/etc/apt/sources.list.d/armbian.list
|
|
|
|
;;
|
|
|
|
jessie|xenial)
|
|
|
|
echo "deb http://apt.armbian.com $RELEASE main utils ${RELEASE}-desktop" > $CACHEDIR/sdcard/etc/apt/sources.list.d/armbian.list
|
|
|
|
;;
|
|
|
|
esac
|
2016-03-17 20:16:26 +01:00
|
|
|
cp $SRC/lib/bin/armbian.key $CACHEDIR/sdcard
|
|
|
|
eval 'chroot $CACHEDIR/sdcard /bin/bash -c "cat armbian.key | apt-key add -"' \
|
2015-12-30 14:31:33 +03:00
|
|
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
2016-03-17 20:16:26 +01:00
|
|
|
rm $CACHEDIR/sdcard/armbian.key
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# stage: update packages list
|
|
|
|
display_alert "Updating package list" "$RELEASE" "info"
|
2016-05-28 15:10:29 +03:00
|
|
|
eval 'LC_ALL=C LANG=C chroot $CACHEDIR/sdcard /bin/bash -c "apt-get -q -y $apt_extra update"' \
|
2015-12-30 14:31:33 +03:00
|
|
|
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/debootstrap.log'} \
|
2016-03-07 18:29:48 +01:00
|
|
|
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Updating package lists..." $TTY_Y $TTY_X'} \
|
2015-12-30 14:31:33 +03:00
|
|
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
|
|
|
|
2016-05-04 17:16:39 +03:00
|
|
|
#[[ ${PIPESTATUS[0]} -ne 0 ]] && exit_with_error "Updating package lists failed"
|
|
|
|
|
2016-03-22 17:15:10 +03:00
|
|
|
# stage: upgrade base packages from xxx-updates and xxx-backports repository branches
|
2016-05-01 14:24:40 +03:00
|
|
|
display_alert "Upgrading base packages" "Armbian" "info"
|
2016-03-22 17:15:10 +03:00
|
|
|
eval 'LC_ALL=C LANG=C chroot $CACHEDIR/sdcard /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get -y -q \
|
|
|
|
$apt_extra $apt_extra_progress upgrade"' \
|
|
|
|
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/debootstrap.log'} \
|
|
|
|
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Upgrading base packages..." $TTY_Y $TTY_X'} \
|
|
|
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
|
|
|
|
2016-05-04 17:16:39 +03:00
|
|
|
#[[ ${PIPESTATUS[0]} -ne 0 ]] && exit_with_error "Upgrading base packages failed"
|
|
|
|
|
2016-05-27 12:42:44 +03:00
|
|
|
# new initctl and start-stop-daemon may be installed after upgrading base packages
|
2016-05-28 13:44:57 +03:00
|
|
|
install_dummy_initctl
|
2016-05-27 12:42:44 +03:00
|
|
|
|
2015-12-30 14:31:33 +03:00
|
|
|
# stage: install additional packages
|
|
|
|
display_alert "Installing packages for" "Armbian" "info"
|
2016-03-17 20:16:26 +01:00
|
|
|
eval 'LC_ALL=C LANG=C chroot $CACHEDIR/sdcard /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get -y -q \
|
2016-03-10 17:14:34 +03:00
|
|
|
$apt_extra $apt_extra_progress --no-install-recommends install $PACKAGE_LIST"' \
|
2015-12-30 14:31:33 +03:00
|
|
|
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/debootstrap.log'} \
|
2016-03-07 18:29:48 +01:00
|
|
|
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Installing Armbian system..." $TTY_Y $TTY_X'} \
|
2015-12-30 14:31:33 +03:00
|
|
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
|
|
|
|
2016-03-10 16:24:28 +03:00
|
|
|
[[ ${PIPESTATUS[0]} -ne 0 ]] && exit_with_error "Installation of Armbian packages failed"
|
|
|
|
|
2015-12-30 14:31:33 +03:00
|
|
|
# DEBUG: print free space
|
2016-04-18 19:20:15 +03:00
|
|
|
echo -e "\nFree space:"
|
2016-09-05 12:22:56 +03:00
|
|
|
eval 'df -h | grep "$CACHEDIR/"' ${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/debootstrap.log'}
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# stage: remove downloaded packages
|
2016-03-17 20:16:26 +01:00
|
|
|
chroot $CACHEDIR/sdcard /bin/bash -c "apt-get clean"
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# stage: make rootfs cache archive
|
|
|
|
display_alert "Ending debootstrap process and preparing cache" "$RELEASE" "info"
|
|
|
|
sync
|
|
|
|
# the only reason to unmount here is compression progress display
|
|
|
|
# based on rootfs size calculation
|
2016-06-18 17:57:17 +03:00
|
|
|
umount_chroot "$CACHEDIR/sdcard"
|
2015-12-30 14:31:33 +03:00
|
|
|
|
2016-06-05 13:12:47 +03:00
|
|
|
tar cp --xattrs --directory=$CACHEDIR/sdcard/ --exclude='./dev/*' --exclude='./proc/*' --exclude='./run/*' --exclude='./tmp/*' \
|
2016-09-02 11:07:39 +02:00
|
|
|
--exclude='./sys/*' . | pv -p -b -r -s $(du -sb $CACHEDIR/sdcard/ | cut -f1) -N "$display_name" | pigz --fast > $cache_fname
|
2015-12-30 14:31:33 +03:00
|
|
|
fi
|
2016-06-18 17:57:17 +03:00
|
|
|
mount_chroot "$CACHEDIR/sdcard"
|
2015-12-30 14:31:33 +03:00
|
|
|
} #############################################################################
|
|
|
|
|
|
|
|
# prepare_partitions
|
|
|
|
#
|
|
|
|
# creates image file, partitions and fs
|
|
|
|
# and mounts it to local dir
|
|
|
|
# FS-dependent stuff (boot and root fs partition types) happens here
|
|
|
|
#
|
|
|
|
prepare_partitions()
|
|
|
|
{
|
|
|
|
display_alert "Preparing image file for rootfs" "$BOARD $RELEASE" "info"
|
|
|
|
|
|
|
|
# possible partition combinations
|
2016-03-05 15:54:44 +03:00
|
|
|
# ext4 root only (BOOTSIZE == 0 && ROOTFS_TYPE == ext4)
|
|
|
|
# ext4 boot + non-ext4 local root (BOOTSIZE == 0; ROOTFS_TYPE != ext4 or nfs)
|
|
|
|
# fat32 boot + ext4 root (BOOTSIZE > 0 && ROOTFS_TYPE == ext4)
|
|
|
|
# fat32 boot + non-ext4 local root (BOOTSIZE > 0; ROOTFS_TYPE != ext4 or nfs)
|
|
|
|
# ext4 boot + NFS root (BOOTSIZE == 0; ROOTFS_TYPE == nfs)
|
|
|
|
# fat32 boot + NFS root (BOOTSIZE > 0; ROOTFS_TYPE == nfs)
|
|
|
|
|
|
|
|
# declare makes local variables by default if used inside a function
|
2015-12-30 14:31:33 +03:00
|
|
|
# NOTE: mountopts string should always start with comma if not empty
|
|
|
|
|
|
|
|
# array copying in old bash versions is tricky, so having filesystems as arrays
|
|
|
|
# with attributes as keys is not a good idea
|
|
|
|
declare -A parttype mkopts mkfs mountopts
|
|
|
|
|
|
|
|
parttype[ext4]=ext4
|
|
|
|
parttype[fat]=fat16
|
|
|
|
parttype[f2fs]=ext4 # not a copy-paste error
|
2016-03-05 15:54:44 +03:00
|
|
|
parttype[btrfs]=btrfs
|
|
|
|
# parttype[nfs] is empty
|
2016-05-28 13:44:57 +03:00
|
|
|
|
|
|
|
# metadata_csum is supported since e2fsprogs 1.43
|
2016-05-27 19:38:40 +02:00
|
|
|
local codename=$(lsb_release -sc)
|
2016-05-28 13:44:57 +03:00
|
|
|
if [[ $codename == sid || $codename == stretch ]]; then
|
2016-05-27 19:38:40 +02:00
|
|
|
mkopts[ext4]='-O ^64bit,^metadata_csum,uninit_bg -q -m 2'
|
2016-05-28 06:25:10 +02:00
|
|
|
else
|
2016-05-28 13:44:57 +03:00
|
|
|
mkopts[ext4]='-q -m 2'
|
2016-05-27 19:38:40 +02:00
|
|
|
fi
|
2016-05-28 13:44:57 +03:00
|
|
|
|
2016-04-08 13:58:57 +02:00
|
|
|
mkopts[fat]='-n BOOT'
|
2016-03-05 15:54:44 +03:00
|
|
|
# mkopts[f2fs] is empty
|
|
|
|
# mkopts[btrfs] is empty
|
|
|
|
# mkopts[nfs] is empty
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
mkfs[ext4]=ext4
|
|
|
|
mkfs[fat]=vfat
|
|
|
|
mkfs[f2fs]=f2fs
|
2016-03-05 15:54:44 +03:00
|
|
|
mkfs[btrfs]=btrfs
|
|
|
|
# mkfs[nfs] is empty
|
2015-12-30 14:31:33 +03:00
|
|
|
|
2016-02-04 19:47:40 +03:00
|
|
|
mountopts[ext4]=',commit=600,errors=remount-ro'
|
2016-03-05 15:54:44 +03:00
|
|
|
# mountopts[fat] is empty
|
|
|
|
# mountopts[f2fs] is empty
|
|
|
|
# mountopts[btrfs] is empty
|
|
|
|
# mountopts[nfs] is empty
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# stage: calculate rootfs size
|
2016-03-17 20:16:26 +01:00
|
|
|
local rootfs_size=$(du -sm $CACHEDIR/sdcard/ | cut -f1) # MiB
|
2015-12-30 14:31:33 +03:00
|
|
|
display_alert "Current rootfs size" "$rootfs_size MiB" "info"
|
|
|
|
if [[ -n $FIXED_IMAGE_SIZE && $FIXED_IMAGE_SIZE =~ ^[0-9]+$ ]]; then
|
|
|
|
display_alert "Using user-defined image size" "$FIXED_IMAGE_SIZE MiB" "info"
|
|
|
|
local sdsize=$FIXED_IMAGE_SIZE
|
|
|
|
# basic sanity check
|
2016-03-05 15:54:44 +03:00
|
|
|
if [[ $ROOTFS_TYPE != nfs && $sdsize -lt $rootfs_size ]]; then
|
2016-03-06 13:01:05 +03:00
|
|
|
exit_with_error "User defined image size is too small" "$sdsize <= $rootfs_size"
|
2015-12-30 14:31:33 +03:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
local imagesize=$(( $rootfs_size + $OFFSET + $BOOTSIZE )) # MiB
|
2016-09-01 13:10:31 +03:00
|
|
|
# Hardcoded overhead +40% and +128MB for ext4 is needed for desktop images, for CLI it can be lower
|
2015-12-30 14:31:33 +03:00
|
|
|
# extra 128 MiB for emergency swap file
|
2016-09-01 13:10:31 +03:00
|
|
|
local sdsize=$(bc -l <<< "scale=0; ($imagesize * 1.4) / 1 + 128")
|
2015-12-30 14:31:33 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# stage: create blank image
|
|
|
|
display_alert "Creating blank image for rootfs" "$sdsize MiB" "info"
|
2016-03-17 20:16:26 +01:00
|
|
|
dd if=/dev/zero bs=1M status=none count=$sdsize | pv -p -b -r -s $(( $sdsize * 1024 * 1024 )) | dd status=none of=$CACHEDIR/tmprootfs.raw
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# stage: determine partition configuration
|
2016-03-05 15:54:44 +03:00
|
|
|
if [[ $ROOTFS_TYPE != ext4 && $BOOTSIZE == 0 ]]; then
|
2015-12-30 14:31:33 +03:00
|
|
|
local bootfs=ext4
|
2016-02-04 19:47:40 +03:00
|
|
|
BOOTSIZE=32 # MiB
|
2015-12-30 14:31:33 +03:00
|
|
|
elif [[ $BOOTSIZE != 0 ]]; then
|
|
|
|
local bootfs=fat
|
|
|
|
fi
|
|
|
|
|
|
|
|
# stage: calculate boot partition size
|
|
|
|
BOOTSTART=$(($OFFSET * 2048))
|
|
|
|
ROOTSTART=$(($BOOTSTART + ($BOOTSIZE * 2048)))
|
|
|
|
BOOTEND=$(($ROOTSTART - 1))
|
|
|
|
|
|
|
|
# stage: create partition table
|
2016-03-05 15:54:44 +03:00
|
|
|
display_alert "Creating partitions" "${bootfs:+/boot: $bootfs }root: $ROOTFS_TYPE" "info"
|
2016-03-17 20:16:26 +01:00
|
|
|
parted -s $CACHEDIR/tmprootfs.raw -- mklabel msdos
|
2016-03-05 15:54:44 +03:00
|
|
|
if [[ $ROOTFS_TYPE == nfs ]]; then
|
2016-03-17 20:16:26 +01:00
|
|
|
parted -s $CACHEDIR/tmprootfs.raw -- mkpart primary ${parttype[$bootfs]} ${BOOTSTART}s -1s
|
2016-03-05 15:54:44 +03:00
|
|
|
elif [[ $BOOTSIZE == 0 ]]; then
|
2016-03-17 20:16:26 +01:00
|
|
|
parted -s $CACHEDIR/tmprootfs.raw -- mkpart primary ${parttype[$ROOTFS_TYPE]} ${ROOTSTART}s -1s
|
2015-12-30 14:31:33 +03:00
|
|
|
else
|
2016-03-17 20:16:26 +01:00
|
|
|
parted -s $CACHEDIR/tmprootfs.raw -- mkpart primary ${parttype[$bootfs]} ${BOOTSTART}s ${BOOTEND}s
|
|
|
|
parted -s $CACHEDIR/tmprootfs.raw -- mkpart primary ${parttype[$ROOTFS_TYPE]} ${ROOTSTART}s -1s
|
2015-12-30 14:31:33 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# stage: mount image
|
|
|
|
LOOP=$(losetup -f)
|
2016-05-01 17:49:29 +03:00
|
|
|
[[ -z $LOOP ]] && exit_with_error "Unable to find free loop device"
|
2016-01-10 18:55:02 +03:00
|
|
|
|
|
|
|
# NOTE: losetup -P option is not available in Trusty
|
2016-03-17 20:16:26 +01:00
|
|
|
losetup $LOOP $CACHEDIR/tmprootfs.raw
|
2016-01-10 18:55:02 +03:00
|
|
|
partprobe $LOOP
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# stage: create fs
|
|
|
|
if [[ $BOOTSIZE == 0 ]]; then
|
2016-03-05 15:54:44 +03:00
|
|
|
eval mkfs.${mkfs[$ROOTFS_TYPE]} ${mkopts[$ROOTFS_TYPE]} ${LOOP}p1 ${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
2016-04-17 14:08:38 +03:00
|
|
|
[[ $ROOTFS_TYPE == ext4 ]] && tune2fs -o journal_data_writeback ${LOOP}p1 > /dev/null
|
2015-12-30 14:31:33 +03:00
|
|
|
else
|
2016-03-05 15:54:44 +03:00
|
|
|
if [[ $ROOTFS_TYPE != nfs ]]; then
|
|
|
|
eval mkfs.${mkfs[$ROOTFS_TYPE]} ${mkopts[$ROOTFS_TYPE]} ${LOOP}p2 ${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
2016-04-17 14:08:38 +03:00
|
|
|
[[ $ROOTFS_TYPE == ext4 ]] && tune2fs -o journal_data_writeback ${LOOP}p2 > /dev/null
|
2016-03-05 15:54:44 +03:00
|
|
|
fi
|
2015-12-30 14:31:33 +03:00
|
|
|
eval mkfs.${mkfs[$bootfs]} ${mkopts[$bootfs]} ${LOOP}p1 ${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# stage: mount partitions and create proper fstab
|
2016-03-17 20:16:26 +01:00
|
|
|
rm -f $CACHEDIR/sdcard/etc/fstab
|
2015-12-30 14:31:33 +03:00
|
|
|
if [[ $BOOTSIZE == 0 ]]; then
|
2016-03-17 20:16:26 +01:00
|
|
|
mount ${LOOP}p1 $CACHEDIR/mount/
|
2016-03-20 17:51:44 +03:00
|
|
|
echo "/dev/mmcblk0p1 / ${mkfs[$ROOTFS_TYPE]} defaults,noatime,nodiratime${mountopts[$ROOTFS_TYPE]} 0 1" >> $CACHEDIR/sdcard/etc/fstab
|
2015-12-30 14:31:33 +03:00
|
|
|
else
|
2016-03-05 15:54:44 +03:00
|
|
|
if [[ $ROOTFS_TYPE != nfs ]]; then
|
2016-03-17 20:16:26 +01:00
|
|
|
mount ${LOOP}p2 $CACHEDIR/mount/
|
2016-03-20 17:51:44 +03:00
|
|
|
echo "/dev/mmcblk0p2 / ${mkfs[$ROOTFS_TYPE]} defaults,noatime,nodiratime${mountopts[$ROOTFS_TYPE]} 0 1" >> $CACHEDIR/sdcard/etc/fstab
|
2016-04-29 14:06:00 +03:00
|
|
|
else
|
|
|
|
echo "/dev/nfs / nfs defaults 0 0" >> $CACHEDIR/sdcard/etc/fstab
|
2016-03-05 15:54:44 +03:00
|
|
|
fi
|
2015-12-30 14:31:33 +03:00
|
|
|
# create /boot on rootfs after it is mounted
|
2016-03-17 20:16:26 +01:00
|
|
|
mkdir -p $CACHEDIR/mount/boot/
|
|
|
|
mount ${LOOP}p1 $CACHEDIR/mount/boot/
|
2016-03-20 17:51:44 +03:00
|
|
|
echo "/dev/mmcblk0p1 /boot ${mkfs[$bootfs]} defaults${mountopts[$bootfs]} 0 2" >> $CACHEDIR/sdcard/etc/fstab
|
2015-12-30 14:31:33 +03:00
|
|
|
fi
|
2016-05-01 14:24:40 +03:00
|
|
|
echo "tmpfs /tmp tmpfs defaults,nosuid 0 0" >> $CACHEDIR/sdcard/etc/fstab
|
2016-03-05 15:54:44 +03:00
|
|
|
|
|
|
|
# stage: create boot script
|
|
|
|
if [[ $ROOTFS_TYPE == nfs ]]; then
|
|
|
|
# copy script provided by user if exists
|
|
|
|
if [[ -f $SRC/userpatches/nfs-boot.cmd ]]; then
|
|
|
|
display_alert "Using custom NFS boot script" "userpatches/nfs-boot.cmd" "info"
|
2016-03-17 20:16:26 +01:00
|
|
|
cp $SRC/userpatches/nfs-boot.cmd $CACHEDIR/sdcard/boot/boot.cmd
|
2016-03-05 15:54:44 +03:00
|
|
|
else
|
2016-03-17 20:16:26 +01:00
|
|
|
cp $SRC/lib/scripts/nfs-boot.cmd.template $CACHEDIR/sdcard/boot/boot.cmd
|
2016-03-05 15:54:44 +03:00
|
|
|
fi
|
2016-05-04 17:16:39 +03:00
|
|
|
elif [[ $BOOTSIZE != 0 && -f $CACHEDIR/sdcard/boot/boot.cmd ]]; then
|
2016-03-17 20:16:26 +01:00
|
|
|
sed -i 's/mmcblk0p1/mmcblk0p2/' $CACHEDIR/sdcard/boot/boot.cmd
|
|
|
|
sed -i "s/rootfstype=ext4/rootfstype=$ROOTFS_TYPE/" $CACHEDIR/sdcard/boot/boot.cmd
|
2016-03-05 15:54:44 +03:00
|
|
|
fi
|
2016-05-04 17:16:39 +03:00
|
|
|
[[ -f $CACHEDIR/sdcard/boot/boot.cmd ]] && \
|
|
|
|
mkimage -C none -A arm -T script -d $CACHEDIR/sdcard/boot/boot.cmd $CACHEDIR/sdcard/boot/boot.scr > /dev/null 2>&1
|
2016-01-04 18:20:53 +03:00
|
|
|
|
|
|
|
} #############################################################################
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# create_image
|
|
|
|
#
|
|
|
|
# finishes creation of image from cached rootfs
|
|
|
|
#
|
|
|
|
create_image()
|
|
|
|
{
|
2016-03-05 15:54:44 +03:00
|
|
|
# stage: create file name
|
2016-08-30 19:25:32 +03:00
|
|
|
local version="Armbian_${REVISION}_${BOARD^}_${DISTRIBUTION}_${RELEASE}_${VER/-$LINUXFAMILY/}"
|
|
|
|
[[ $BUILD_DESKTOP == yes ]] && version=${version}_desktop
|
|
|
|
[[ $ROOTFS_TYPE == nfs ]] && version=${version}_nfsboot
|
2016-03-05 15:54:44 +03:00
|
|
|
|
|
|
|
if [[ $ROOTFS_TYPE != nfs ]]; then
|
|
|
|
display_alert "Copying files to image" "tmprootfs.raw" "info"
|
2016-06-05 13:12:47 +03:00
|
|
|
rsync -aHWXh --exclude="/boot/*" --exclude="/dev/*" --exclude="/proc/*" --exclude="/run/*" --exclude="/tmp/*" \
|
2016-05-08 16:10:11 +03:00
|
|
|
--exclude="/sys/*" --info=progress2,stats1 $CACHEDIR/sdcard/ $CACHEDIR/mount/
|
2016-03-05 15:54:44 +03:00
|
|
|
else
|
|
|
|
display_alert "Creating rootfs archive" "rootfs.tgz" "info"
|
2016-06-05 13:12:47 +03:00
|
|
|
tar cp --xattrs --directory=$CACHEDIR/sdcard/ --exclude='./boot/*' --exclude='./dev/*' --exclude='./proc/*' --exclude='./run/*' --exclude='./tmp/*' \
|
2016-08-30 19:25:32 +03:00
|
|
|
--exclude='./sys/*' . | pv -p -b -r -s $(du -sb $CACHEDIR/sdcard/ | cut -f1) -N "rootfs.tgz" | pigz > $DEST/images/${version}-rootfs.tgz
|
2016-03-05 15:54:44 +03:00
|
|
|
fi
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# stage: rsync /boot
|
2016-03-05 15:54:44 +03:00
|
|
|
display_alert "Copying files to /boot partition" "tmprootfs.raw" "info"
|
2016-03-17 20:16:26 +01:00
|
|
|
if [[ $(findmnt --target $CACHEDIR/mount/boot -o FSTYPE -n) == vfat ]]; then
|
2016-03-05 15:54:44 +03:00
|
|
|
# fat32
|
2016-03-17 20:16:26 +01:00
|
|
|
rsync -rLtWh --info=progress2,stats1 $CACHEDIR/sdcard/boot $CACHEDIR/mount
|
2016-03-05 15:54:44 +03:00
|
|
|
else
|
|
|
|
# ext4
|
2016-06-05 13:12:47 +03:00
|
|
|
rsync -aHWXh --info=progress2,stats1 $CACHEDIR/sdcard/boot $CACHEDIR/mount
|
2016-01-09 21:31:33 +03:00
|
|
|
fi
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# DEBUG: print free space
|
2016-04-17 14:08:38 +03:00
|
|
|
display_alert "Free space:" "SD card" "info"
|
2016-09-05 12:22:56 +03:00
|
|
|
eval 'df -h | grep "$CACHEDIR/"' ${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/debootstrap.log'}
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# stage: write u-boot
|
|
|
|
write_uboot $LOOP
|
|
|
|
|
2016-03-17 20:16:26 +01:00
|
|
|
cp $CACHEDIR/sdcard/etc/armbian.txt $CACHEDIR/
|
2016-02-04 19:47:40 +03:00
|
|
|
|
2015-12-30 14:31:33 +03:00
|
|
|
# unmount /boot first, rootfs second, image file last
|
2016-05-26 18:42:14 +03:00
|
|
|
sync
|
2016-05-01 17:49:29 +03:00
|
|
|
[[ $BOOTSIZE != 0 ]] && umount -l $CACHEDIR/mount/boot
|
|
|
|
[[ $ROOTFS_TYPE != nfs ]] && umount -l $CACHEDIR/mount
|
2015-12-30 14:31:33 +03:00
|
|
|
losetup -d $LOOP
|
|
|
|
|
2016-08-30 19:25:32 +03:00
|
|
|
mv $CACHEDIR/tmprootfs.raw $CACHEDIR/${version}.raw
|
2016-03-17 20:16:26 +01:00
|
|
|
cd $CACHEDIR/
|
2015-12-30 14:31:33 +03:00
|
|
|
|
|
|
|
# stage: compressing or copying image file
|
2016-04-26 21:29:37 +03:00
|
|
|
if [[ $COMPRESS_OUTPUTIMAGE != yes ]]; then
|
2016-08-30 19:25:32 +03:00
|
|
|
mv -f $CACHEDIR/${version}.raw $DEST/images/${version}.raw
|
|
|
|
display_alert "Done building" "$DEST/images/${version}.raw" "info"
|
2015-12-30 14:31:33 +03:00
|
|
|
else
|
2016-03-22 20:56:55 +01:00
|
|
|
display_alert "Signing and compressing" "Please wait!" "info"
|
2016-08-30 19:25:32 +03:00
|
|
|
# stage: generate sha256sum
|
|
|
|
sha256sum -b ${version}.raw > sha256sum
|
2015-12-30 14:31:33 +03:00
|
|
|
# stage: sign with PGP
|
2016-03-05 15:54:44 +03:00
|
|
|
if [[ -n $GPG_PASS ]]; then
|
2016-08-30 19:25:32 +03:00
|
|
|
echo $GPG_PASS | gpg --passphrase-fd 0 --armor --detach-sign --batch --yes ${version}.raw
|
2015-12-30 14:31:33 +03:00
|
|
|
echo $GPG_PASS | gpg --passphrase-fd 0 --armor --detach-sign --batch --yes armbian.txt
|
|
|
|
fi
|
2016-03-22 20:56:55 +01:00
|
|
|
if [[ $SEVENZIP == yes ]]; then
|
2016-08-30 19:25:32 +03:00
|
|
|
local filename=$DEST/images/${version}.7z
|
2016-09-02 11:07:39 +02:00
|
|
|
7za a -t7z -bd -m0=lzma2 -mx=3 -mfb=64 -md=32m -ms=on $filename ${version}.raw armbian.txt *.asc sha256sum >/dev/null 2>&1
|
2016-03-22 20:56:55 +01:00
|
|
|
else
|
2016-08-30 19:25:32 +03:00
|
|
|
local filename=$DEST/images/${version}.zip
|
|
|
|
zip -FSq $filename ${version}.raw armbian.txt *.asc sha256sum
|
2016-03-22 20:56:55 +01:00
|
|
|
fi
|
2016-08-30 19:25:32 +03:00
|
|
|
rm -f ${version}.raw *.asc armbian.txt sha256sum
|
|
|
|
local filesize=$(ls -l --b=M $filename | cut -d " " -f5)
|
|
|
|
display_alert "Done building" "$filename [$filesize]" "info"
|
2015-12-30 14:31:33 +03:00
|
|
|
fi
|
2016-03-09 12:18:40 +03:00
|
|
|
} #############################################################################
|
2015-12-30 14:31:33 +03:00
|
|
|
|
2016-05-28 13:44:57 +03:00
|
|
|
# install_dummy_initctl
|
|
|
|
#
|
|
|
|
# helper to reduce code duplication
|
|
|
|
#
|
|
|
|
install_dummy_initctl()
|
|
|
|
{
|
2016-05-29 23:08:54 +03:00
|
|
|
if [[ -x $CACHEDIR/sdcard/sbin/start-stop-daemon ]] && ! cmp -s $CACHEDIR/sdcard/sbin/start-stop-daemon <(printf '#!/bin/sh\necho "Warning: Fake start-stop-daemon called, doing nothing"'); then
|
2016-05-28 13:44:57 +03:00
|
|
|
mv $CACHEDIR/sdcard/sbin/start-stop-daemon $CACHEDIR/sdcard/sbin/start-stop-daemon.REAL
|
|
|
|
printf '#!/bin/sh\necho "Warning: Fake start-stop-daemon called, doing nothing"' > $CACHEDIR/sdcard/sbin/start-stop-daemon
|
|
|
|
chmod 755 $CACHEDIR/sdcard/sbin/start-stop-daemon
|
|
|
|
fi
|
2016-05-29 23:08:54 +03:00
|
|
|
if [[ -x $CACHEDIR/sdcard/sbin/initctl ]] && ! cmp -s $CACHEDIR/sdcard/sbin/initctl <(printf '#!/bin/sh\necho "Warning: Fake initctl called, doing nothing"'); then
|
2016-05-28 13:44:57 +03:00
|
|
|
mv $CACHEDIR/sdcard/sbin/initctl $CACHEDIR/sdcard/sbin/initctl.REAL
|
|
|
|
printf '#!/bin/sh\necho "Warning: Fake initctl called, doing nothing"' $CACHEDIR/sdcard/sbin/initctl
|
|
|
|
chmod 755 $CACHEDIR/sdcard/sbin/initctl
|
|
|
|
fi
|
|
|
|
} #############################################################################
|
|
|
|
|
2016-06-18 17:57:17 +03:00
|
|
|
# mount_chroot <target>
|
2016-03-09 12:18:40 +03:00
|
|
|
#
|
|
|
|
# helper to reduce code duplication
|
|
|
|
#
|
|
|
|
mount_chroot()
|
|
|
|
{
|
2016-06-18 17:57:17 +03:00
|
|
|
local target=$1
|
|
|
|
mount -t proc chproc $target/proc
|
|
|
|
mount -t sysfs chsys $target/sys
|
|
|
|
mount -t devtmpfs chdev $target/dev || mount --bind /dev $target/dev
|
|
|
|
mount -t devpts chpts $target/dev/pts
|
2016-03-09 12:18:40 +03:00
|
|
|
} #############################################################################
|
|
|
|
|
2016-06-18 17:57:17 +03:00
|
|
|
# umount_chroot <target>
|
2016-03-09 12:18:40 +03:00
|
|
|
#
|
|
|
|
# helper to reduce code duplication
|
|
|
|
#
|
|
|
|
umount_chroot()
|
|
|
|
{
|
2016-06-19 08:53:31 +02:00
|
|
|
local target=$1
|
2016-06-18 17:57:17 +03:00
|
|
|
umount -l $target/dev/pts >/dev/null 2>&1
|
|
|
|
umount -l $target/dev >/dev/null 2>&1
|
|
|
|
umount -l $target/proc >/dev/null 2>&1
|
|
|
|
umount -l $target/sys >/dev/null 2>&1
|
2015-12-30 14:31:33 +03:00
|
|
|
} #############################################################################
|
|
|
|
|
|
|
|
# unmount_on_exit
|
|
|
|
#
|
|
|
|
unmount_on_exit()
|
|
|
|
{
|
2016-04-16 18:12:34 +03:00
|
|
|
trap - INT TERM EXIT
|
2016-06-18 17:57:17 +03:00
|
|
|
umount_chroot "$CACHEDIR/sdcard/"
|
2016-06-15 19:44:14 +03:00
|
|
|
umount -l $CACHEDIR/sdcard/tmp >/dev/null 2>&1
|
2016-03-17 20:16:26 +01:00
|
|
|
umount -l $CACHEDIR/sdcard >/dev/null 2>&1
|
|
|
|
umount -l $CACHEDIR/mount/boot >/dev/null 2>&1
|
|
|
|
umount -l $CACHEDIR/mount >/dev/null 2>&1
|
2016-03-05 15:54:44 +03:00
|
|
|
losetup -d $LOOP >/dev/null 2>&1
|
2016-03-17 20:16:26 +01:00
|
|
|
rm -rf $CACHEDIR/sdcard
|
2016-03-05 21:26:01 +03:00
|
|
|
exit_with_error "debootstrap-ng was interrupted"
|
|
|
|
} #############################################################################
|