mirror of
https://github.com/Fishwaldo/build.git
synced 2025-07-07 13:38:57 +00:00
Shellcheck fix4 (#2061)
* compilation.sh: Lint with shellcheck * configuration.sh: Lint with shellcheck * debootstrap.sh: Lint via shellcheck * Update configuration.sh * Update compilation.sh Co-authored-by: Igor Pečovnik <igorpecovnik@users.noreply.github.com>
This commit is contained in:
parent
cc3b7d1b0e
commit
4555a7aed5
3 changed files with 320 additions and 285 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
# Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com
|
# Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com
|
||||||
#
|
#
|
||||||
# This file is licensed under the terms of the GNU General Public
|
# This file is licensed under the terms of the GNU General Public
|
||||||
|
@ -26,45 +28,49 @@ compile_atf()
|
||||||
{
|
{
|
||||||
if [[ $CLEAN_LEVEL == *make* ]]; then
|
if [[ $CLEAN_LEVEL == *make* ]]; then
|
||||||
display_alert "Cleaning" "$ATFSOURCEDIR" "info"
|
display_alert "Cleaning" "$ATFSOURCEDIR" "info"
|
||||||
(cd $SRC/cache/sources/$ATFSOURCEDIR; make distclean > /dev/null 2>&1)
|
(cd "${SRC}/cache/sources/${ATFSOURCEDIR}"; make distclean > /dev/null 2>&1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $USE_OVERLAYFS == yes ]]; then
|
if [[ $USE_OVERLAYFS == yes ]]; then
|
||||||
local atfdir=$(overlayfs_wrapper "wrap" "$SRC/cache/sources/$ATFSOURCEDIR" "atf_${LINUXFAMILY}_${BRANCH}")
|
local atfdir
|
||||||
|
atfdir=$(overlayfs_wrapper "wrap" "$SRC/cache/sources/$ATFSOURCEDIR" "atf_${LINUXFAMILY}_${BRANCH}")
|
||||||
else
|
else
|
||||||
local atfdir="$SRC/cache/sources/$ATFSOURCEDIR"
|
local atfdir="$SRC/cache/sources/$ATFSOURCEDIR"
|
||||||
fi
|
fi
|
||||||
cd "$atfdir"
|
cd "$atfdir" || exit
|
||||||
|
|
||||||
display_alert "Compiling ATF" "" "info"
|
display_alert "Compiling ATF" "" "info"
|
||||||
|
|
||||||
local toolchain=$(find_toolchain "$ATF_COMPILER" "$ATF_USE_GCC")
|
local toolchain
|
||||||
|
toolchain=$(find_toolchain "$ATF_COMPILER" "$ATF_USE_GCC")
|
||||||
[[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${ATF_COMPILER}gcc $ATF_USE_GCC"
|
[[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${ATF_COMPILER}gcc $ATF_USE_GCC"
|
||||||
|
|
||||||
if [[ -n $ATF_TOOLCHAIN2 ]]; then
|
if [[ -n $ATF_TOOLCHAIN2 ]]; then
|
||||||
local toolchain2_type=$(cut -d':' -f1 <<< $ATF_TOOLCHAIN2)
|
local toolchain2_type toolchain2_ver toolchain2
|
||||||
local toolchain2_ver=$(cut -d':' -f2 <<< $ATF_TOOLCHAIN2)
|
toolchain2_type=$(cut -d':' -f1 <<< "${ATF_TOOLCHAIN2}")
|
||||||
local toolchain2=$(find_toolchain "$toolchain2_type" "$toolchain2_ver")
|
toolchain2_ver=$(cut -d':' -f2 <<< "${ATF_TOOLCHAIN2}")
|
||||||
|
toolchain2=$(find_toolchain "$toolchain2_type" "$toolchain2_ver")
|
||||||
[[ -z $toolchain2 ]] && exit_with_error "Could not find required toolchain" "${toolchain2_type}gcc $toolchain2_ver"
|
[[ -z $toolchain2 ]] && exit_with_error "Could not find required toolchain" "${toolchain2_type}gcc $toolchain2_ver"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
display_alert "Compiler version" "${ATF_COMPILER}gcc $(eval env PATH=$toolchain:$PATH ${ATF_COMPILER}gcc -dumpversion)" "info"
|
display_alert "Compiler version" "${ATF_COMPILER}gcc $(eval env PATH="${toolchain}:${PATH}" "${ATF_COMPILER}gcc" -dumpversion)" "info"
|
||||||
|
|
||||||
local target_make=$(cut -d';' -f1 <<< $ATF_TARGET_MAP)
|
local target_make target_patchdir target_files
|
||||||
local target_patchdir=$(cut -d';' -f2 <<< $ATF_TARGET_MAP)
|
target_make=$(cut -d';' -f1 <<< "${ATF_TARGET_MAP}")
|
||||||
local target_files=$(cut -d';' -f3 <<< $ATF_TARGET_MAP)
|
target_patchdir=$(cut -d';' -f2 <<< "${ATF_TARGET_MAP}")
|
||||||
|
target_files=$(cut -d';' -f3 <<< "${ATF_TARGET_MAP}")
|
||||||
|
|
||||||
advanced_patch "atf" "${ATFPATCHDIR}" "$BOARD" "$target_patchdir" "$BRANCH" "${LINUXFAMILY}-${BOARD}-${BRANCH}"
|
advanced_patch "atf" "${ATFPATCHDIR}" "$BOARD" "$target_patchdir" "$BRANCH" "${LINUXFAMILY}-${BOARD}-${BRANCH}"
|
||||||
|
|
||||||
# create patch for manual source changes
|
# create patch for manual source changes
|
||||||
[[ $CREATE_PATCHES == yes ]] && userpatch_create "atf"
|
[[ $CREATE_PATCHES == yes ]] && userpatch_create "atf"
|
||||||
|
|
||||||
echo -e "\n\t== atf ==\n" >>$DEST/debug/compilation.log
|
echo -e "\n\t== atf ==\n" >> "${DEST}"/debug/compilation.log
|
||||||
# ENABLE_BACKTRACE="0" has been added to workaround a regression in ATF.
|
# ENABLE_BACKTRACE="0" has been added to workaround a regression in ATF.
|
||||||
# Check: https://github.com/armbian/build/issues/1157
|
# Check: https://github.com/armbian/build/issues/1157
|
||||||
eval CCACHE_BASEDIR="$(pwd)" env PATH=$toolchain:$toolchain2:$PATH \
|
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${toolchain2}:${PATH}" \
|
||||||
'make ENABLE_BACKTRACE="0" $target_make $CTHREADS \
|
'make ENABLE_BACKTRACE="0" $target_make $CTHREADS \
|
||||||
CROSS_COMPILE="$CCACHE $ATF_COMPILER"' 2>>$DEST/debug/compilation.log \
|
CROSS_COMPILE="$CCACHE $ATF_COMPILER"' 2>> "${DEST}"/debug/compilation.log \
|
||||||
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/compilation.log'} \
|
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/compilation.log'} \
|
||||||
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Compiling ATF..." $TTY_Y $TTY_X'} \
|
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Compiling ATF..." $TTY_Y $TTY_X'} \
|
||||||
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
||||||
|
@ -74,22 +80,25 @@ compile_atf()
|
||||||
[[ $(type -t atf_custom_postprocess) == function ]] && atf_custom_postprocess
|
[[ $(type -t atf_custom_postprocess) == function ]] && atf_custom_postprocess
|
||||||
|
|
||||||
local atftempdir=$SRC/.tmp/atf-${LINUXFAMILY}-${BOARD}-${BRANCH}
|
local atftempdir=$SRC/.tmp/atf-${LINUXFAMILY}-${BOARD}-${BRANCH}
|
||||||
mkdir -p $atftempdir
|
mkdir -p "${atftempdir}"
|
||||||
|
|
||||||
# copy files to temp directory
|
# copy files to temp directory
|
||||||
for f in $target_files; do
|
for f in $target_files; do
|
||||||
local f_src=$(cut -d':' -f1 <<< $f)
|
local f_src
|
||||||
|
f_src=$(cut -d':' -f1 <<< "${f}")
|
||||||
if [[ $f == *:* ]]; then
|
if [[ $f == *:* ]]; then
|
||||||
local f_dst=$(cut -d':' -f2 <<< $f)
|
local f_dst
|
||||||
|
f_dst=$(cut -d':' -f2 <<< "${f}")
|
||||||
else
|
else
|
||||||
local f_dst=$(basename $f_src)
|
local f_dst
|
||||||
|
f_dst=$(basename "${f_src}")
|
||||||
fi
|
fi
|
||||||
[[ ! -f $f_src ]] && exit_with_error "ATF file not found" "$(basename $f_src)"
|
[[ ! -f $f_src ]] && exit_with_error "ATF file not found" "$(basename "${f_src}")"
|
||||||
cp $f_src $atftempdir/$f_dst
|
cp "${f_src}" "${atftempdir}/${f_dst}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# copy license file to pack it to u-boot package later
|
# copy license file to pack it to u-boot package later
|
||||||
[[ -f license.md ]] && cp license.md $atftempdir/
|
[[ -f license.md ]] && cp license.md "${atftempdir}"/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,35 +109,39 @@ compile_uboot()
|
||||||
# not optimal, but extra cleaning before overlayfs_wrapper should keep sources directory clean
|
# not optimal, but extra cleaning before overlayfs_wrapper should keep sources directory clean
|
||||||
if [[ $CLEAN_LEVEL == *make* ]]; then
|
if [[ $CLEAN_LEVEL == *make* ]]; then
|
||||||
display_alert "Cleaning" "$BOOTSOURCEDIR" "info"
|
display_alert "Cleaning" "$BOOTSOURCEDIR" "info"
|
||||||
(cd $SRC/cache/sources/$BOOTSOURCEDIR; make clean > /dev/null 2>&1)
|
(cd "${SRC}/cache/sources/${BOOTSOURCEDIR}"; make clean > /dev/null 2>&1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $USE_OVERLAYFS == yes ]]; then
|
if [[ $USE_OVERLAYFS == yes ]]; then
|
||||||
local ubootdir=$(overlayfs_wrapper "wrap" "$SRC/cache/sources/$BOOTSOURCEDIR" "u-boot_${LINUXFAMILY}_${BRANCH}")
|
local ubootdir
|
||||||
|
ubootdir=$(overlayfs_wrapper "wrap" "$SRC/cache/sources/$BOOTSOURCEDIR" "u-boot_${LINUXFAMILY}_${BRANCH}")
|
||||||
else
|
else
|
||||||
local ubootdir="$SRC/cache/sources/$BOOTSOURCEDIR"
|
local ubootdir="$SRC/cache/sources/$BOOTSOURCEDIR"
|
||||||
fi
|
fi
|
||||||
cd "$ubootdir"
|
cd "${ubootdir}" || exit
|
||||||
|
|
||||||
# read uboot version
|
# read uboot version
|
||||||
local version=$(grab_version "$ubootdir")
|
local version hash
|
||||||
local hash=$(git --git-dir="$ubootdir"/.git rev-parse HEAD)
|
version=$(grab_version "$ubootdir")
|
||||||
|
hash=$(git --git-dir="$ubootdir"/.git rev-parse HEAD)
|
||||||
|
|
||||||
display_alert "Compiling u-boot" "$version" "info"
|
display_alert "Compiling u-boot" "$version" "info"
|
||||||
|
|
||||||
local toolchain=$(find_toolchain "$UBOOT_COMPILER" "$UBOOT_USE_GCC")
|
local toolchain
|
||||||
|
toolchain=$(find_toolchain "$UBOOT_COMPILER" "$UBOOT_USE_GCC")
|
||||||
[[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${UBOOT_COMPILER}gcc $UBOOT_USE_GCC"
|
[[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${UBOOT_COMPILER}gcc $UBOOT_USE_GCC"
|
||||||
|
|
||||||
if [[ -n $UBOOT_TOOLCHAIN2 ]]; then
|
if [[ -n $UBOOT_TOOLCHAIN2 ]]; then
|
||||||
local toolchain2_type=$(cut -d':' -f1 <<< $UBOOT_TOOLCHAIN2)
|
local toolchain2_type toolchain2_ver toolchain2
|
||||||
local toolchain2_ver=$(cut -d':' -f2 <<< $UBOOT_TOOLCHAIN2)
|
toolchain2_type=$(cut -d':' -f1 <<< "${UBOOT_TOOLCHAIN2}")
|
||||||
local toolchain2=$(find_toolchain "$toolchain2_type" "$toolchain2_ver")
|
toolchain2_ver=$(cut -d':' -f2 <<< "${UBOOT_TOOLCHAIN2}")
|
||||||
|
toolchain2=$(find_toolchain "$toolchain2_type" "$toolchain2_ver")
|
||||||
[[ -z $toolchain2 ]] && exit_with_error "Could not find required toolchain" "${toolchain2_type}gcc $toolchain2_ver"
|
[[ -z $toolchain2 ]] && exit_with_error "Could not find required toolchain" "${toolchain2_type}gcc $toolchain2_ver"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
display_alert "Compiler version" "${UBOOT_COMPILER}gcc $(eval env PATH=$toolchain:$toolchain2:$PATH ${UBOOT_COMPILER}gcc -dumpversion)" "info"
|
display_alert "Compiler version" "${UBOOT_COMPILER}gcc $(eval env PATH="${toolchain}:${toolchain2}:${PATH}" "${UBOOT_COMPILER}gcc" -dumpversion)" "info"
|
||||||
[[ -n $toolchain2 ]] && display_alert "Additional compiler version" "${toolchain2_type}gcc $(eval env PATH=$toolchain:$toolchain2:$PATH ${toolchain2_type}gcc -dumpversion)" "info"
|
[[ -n $toolchain2 ]] && display_alert "Additional compiler version" "${toolchain2_type}gcc $(eval env PATH="${toolchain}:${toolchain2}:${PATH}" "${toolchain2_type}gcc" -dumpversion)" "info"
|
||||||
|
|
||||||
# create directory structure for the .deb package
|
# create directory structure for the .deb package
|
||||||
local uboot_name=${CHOSEN_UBOOT}_${REVISION}_${ARCH}
|
local uboot_name=${CHOSEN_UBOOT}_${REVISION}_${ARCH}
|
||||||
|
@ -137,13 +150,14 @@ compile_uboot()
|
||||||
|
|
||||||
# process compilation for one or multiple targets
|
# process compilation for one or multiple targets
|
||||||
while read -r target; do
|
while read -r target; do
|
||||||
local target_make=$(cut -d';' -f1 <<< $target)
|
local target_make target_patchdir target_files
|
||||||
local target_patchdir=$(cut -d';' -f2 <<< $target)
|
target_make=$(cut -d';' -f1 <<< "${target}")
|
||||||
local target_files=$(cut -d';' -f3 <<< $target)
|
target_patchdir=$(cut -d';' -f2 <<< "${target}")
|
||||||
|
target_files=$(cut -d';' -f3 <<< "${target}")
|
||||||
|
|
||||||
if [[ $CLEAN_LEVEL == *make* ]]; then
|
if [[ $CLEAN_LEVEL == *make* ]]; then
|
||||||
display_alert "Cleaning" "$BOOTSOURCEDIR" "info"
|
display_alert "Cleaning" "$BOOTSOURCEDIR" "info"
|
||||||
(cd $SRC/cache/sources/$BOOTSOURCEDIR; make clean > /dev/null 2>&1)
|
(cd "${SRC}/cache/sources/${BOOTSOURCEDIR}"; make clean > /dev/null 2>&1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
advanced_patch "u-boot" "$BOOTPATCHDIR" "$BOARD" "$target_patchdir" "$BRANCH" "${LINUXFAMILY}-${BOARD}-${BRANCH}"
|
advanced_patch "u-boot" "$BOOTPATCHDIR" "$BOARD" "$target_patchdir" "$BRANCH" "${LINUXFAMILY}-${BOARD}-${BRANCH}"
|
||||||
|
@ -153,13 +167,13 @@ compile_uboot()
|
||||||
|
|
||||||
if [[ -n $ATFSOURCE ]]; then
|
if [[ -n $ATFSOURCE ]]; then
|
||||||
local atftempdir=$SRC/.tmp/atf-${LINUXFAMILY}-${BOARD}-${BRANCH}
|
local atftempdir=$SRC/.tmp/atf-${LINUXFAMILY}-${BOARD}-${BRANCH}
|
||||||
cp -Rv $atftempdir/*.bin .
|
cp -Rv "${atftempdir}"/*.bin .
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "\n\t== u-boot ==\n" >>$DEST/debug/compilation.log
|
echo -e "\n\t== u-boot ==\n" >> "${DEST}"/debug/compilation.log
|
||||||
eval CCACHE_BASEDIR="$(pwd)" env PATH=$toolchain:$toolchain2:$PATH \
|
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${toolchain2}:${PATH}" \
|
||||||
'make $CTHREADS $BOOTCONFIG \
|
'make $CTHREADS $BOOTCONFIG \
|
||||||
CROSS_COMPILE="$CCACHE $UBOOT_COMPILER"' 2>>$DEST/debug/compilation.log \
|
CROSS_COMPILE="$CCACHE $UBOOT_COMPILER"' 2>> "${DEST}"/debug/compilation.log \
|
||||||
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/compilation.log'} \
|
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/compilation.log'} \
|
||||||
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
||||||
|
|
||||||
|
@ -181,7 +195,7 @@ compile_uboot()
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -f tools/logos/udoo.bmp ]] && cp $SRC/packages/blobs/splash/udoo.bmp tools/logos/udoo.bmp
|
[[ -f tools/logos/udoo.bmp ]] && cp "${SRC}"/packages/blobs/splash/udoo.bmp tools/logos/udoo.bmp
|
||||||
touch .scmversion
|
touch .scmversion
|
||||||
|
|
||||||
# $BOOTDELAY can be set in board family config, ensure autoboot can be stopped even if set to 0
|
# $BOOTDELAY can be set in board family config, ensure autoboot can be stopped even if set to 0
|
||||||
|
@ -192,10 +206,10 @@ compile_uboot()
|
||||||
cross_compile="CROSS_COMPILE=$CCACHE $UBOOT_COMPILER";
|
cross_compile="CROSS_COMPILE=$CCACHE $UBOOT_COMPILER";
|
||||||
[[ -n $UBOOT_TOOLCHAIN2 ]] && cross_compile="ARMBIAN=foe"; # empty parameter is not allowed
|
[[ -n $UBOOT_TOOLCHAIN2 ]] && cross_compile="ARMBIAN=foe"; # empty parameter is not allowed
|
||||||
|
|
||||||
eval CCACHE_BASEDIR="$(pwd)" env PATH=$toolchain:$toolchain2:$PATH \
|
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${toolchain2}:${PATH}" \
|
||||||
'make $target_make $CTHREADS \
|
'make $target_make $CTHREADS \
|
||||||
"${cross_compile}"' 2>>$DEST/debug/compilation.log \
|
"${cross_compile}"' 2>>"${DEST}"/debug/compilation.log \
|
||||||
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/compilation.log'} \
|
${PROGRESS_LOG_TO_FILE:+' | tee -a "${DEST}"/debug/compilation.log'} \
|
||||||
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Compiling u-boot..." $TTY_Y $TTY_X'} \
|
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Compiling u-boot..." $TTY_Y $TTY_X'} \
|
||||||
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
||||||
|
|
||||||
|
@ -205,19 +219,22 @@ compile_uboot()
|
||||||
|
|
||||||
# copy files to build directory
|
# copy files to build directory
|
||||||
for f in $target_files; do
|
for f in $target_files; do
|
||||||
local f_src=$(cut -d':' -f1 <<< $f)
|
local f_src
|
||||||
|
f_src=$(cut -d':' -f1 <<< "${f}")
|
||||||
if [[ $f == *:* ]]; then
|
if [[ $f == *:* ]]; then
|
||||||
local f_dst=$(cut -d':' -f2 <<< $f)
|
local f_dst
|
||||||
|
f_dst=$(cut -d':' -f2 <<< "${f}")
|
||||||
else
|
else
|
||||||
local f_dst=$(basename $f_src)
|
local f_dst
|
||||||
|
f_dst=$(basename "${f_src}")
|
||||||
fi
|
fi
|
||||||
[[ ! -f $f_src ]] && exit_with_error "U-boot file not found" "$(basename $f_src)"
|
[[ ! -f $f_src ]] && exit_with_error "U-boot file not found" "$(basename "${f_src}")"
|
||||||
cp $f_src $SRC/.tmp/$uboot_name/usr/lib/$uboot_name/$f_dst
|
cp "${f_src}" "${SRC}/.tmp/${uboot_name}/usr/lib/${uboot_name}/${f_dst}"
|
||||||
done
|
done
|
||||||
done <<< "$UBOOT_TARGET_MAP"
|
done <<< "$UBOOT_TARGET_MAP"
|
||||||
|
|
||||||
# declare -f on non-defined function does not do anything
|
# declare -f on non-defined function does not do anything
|
||||||
cat <<-EOF > $SRC/.tmp/$uboot_name/usr/lib/u-boot/platform_install.sh
|
cat <<-EOF > "${SRC}/.tmp/${uboot_name}/usr/lib/u-boot/platform_install.sh"
|
||||||
DIR=/usr/lib/$uboot_name
|
DIR=/usr/lib/$uboot_name
|
||||||
$(declare -f write_uboot_platform)
|
$(declare -f write_uboot_platform)
|
||||||
$(declare -f write_uboot_platform_mtd)
|
$(declare -f write_uboot_platform_mtd)
|
||||||
|
@ -225,7 +242,7 @@ compile_uboot()
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# set up control file
|
# set up control file
|
||||||
cat <<-EOF > $SRC/.tmp/$uboot_name/DEBIAN/control
|
cat <<-EOF > "${SRC}/.tmp/${uboot_name}/DEBIAN/control"
|
||||||
Package: linux-u-boot-${BOARD}-${BRANCH}
|
Package: linux-u-boot-${BOARD}-${BRANCH}
|
||||||
Version: $REVISION
|
Version: $REVISION
|
||||||
Architecture: $ARCH
|
Architecture: $ARCH
|
||||||
|
@ -241,20 +258,20 @@ compile_uboot()
|
||||||
|
|
||||||
# copy config file to the package
|
# copy config file to the package
|
||||||
# useful for FEL boot with overlayfs_wrapper
|
# useful for FEL boot with overlayfs_wrapper
|
||||||
[[ -f .config && -n $BOOTCONFIG ]] && cp .config $SRC/.tmp/$uboot_name/usr/lib/u-boot/$BOOTCONFIG
|
[[ -f .config && -n $BOOTCONFIG ]] && cp .config "${SRC}/.tmp/${uboot_name}/usr/lib/u-boot/${BOOTCONFIG}"
|
||||||
# copy license files from typical locations
|
# copy license files from typical locations
|
||||||
[[ -f COPYING ]] && cp COPYING $SRC/.tmp/$uboot_name/usr/lib/u-boot/LICENSE
|
[[ -f COPYING ]] && cp COPYING "${SRC}/.tmp/${uboot_name}/usr/lib/u-boot/LICENSE"
|
||||||
[[ -f Licenses/README ]] && cp Licenses/README $SRC/.tmp/$uboot_name/usr/lib/u-boot/LICENSE
|
[[ -f Licenses/README ]] && cp Licenses/README "${SRC}/.tmp/${uboot_name}/usr/lib/u-boot/LICENSE"
|
||||||
[[ -n $atftempdir && -f $atftempdir/license.md ]] && cp $atftempdir/license.md $SRC/.tmp/$uboot_name/usr/lib/u-boot/LICENSE.atf
|
[[ -n $atftempdir && -f $atftempdir/license.md ]] && cp "${atftempdir}/license.md" "${SRC}/.tmp/${uboot_name}/usr/lib/u-boot/LICENSE.atf"
|
||||||
|
|
||||||
display_alert "Building deb" "${uboot_name}.deb" "info"
|
display_alert "Building deb" "${uboot_name}.deb" "info"
|
||||||
fakeroot dpkg-deb -b $SRC/.tmp/$uboot_name $SRC/.tmp/${uboot_name}.deb >> $DEST/debug/output.log 2>&1
|
fakeroot dpkg-deb -b "${SRC}/.tmp/${uboot_name}" "${SRC}/.tmp/${uboot_name}.deb" >> "${DEST}"/debug/output.log 2>&1
|
||||||
rm -rf $SRC/.tmp/$uboot_name
|
rm -rf "${SRC}/.tmp/${uboot_name}"
|
||||||
[[ -n $$atftempdir ]] && rm -rf $atftempdir
|
[[ -n $atftempdir ]] && rm -rf "${atftempdir}"
|
||||||
|
|
||||||
[[ ! -f $SRC/.tmp/${uboot_name}.deb ]] && exit_with_error "Building u-boot package failed"
|
[[ ! -f $SRC/.tmp/${uboot_name}.deb ]] && exit_with_error "Building u-boot package failed"
|
||||||
|
|
||||||
mv $SRC/.tmp/${uboot_name}.deb ${DEB_STORAGE}/
|
mv "${SRC}/.tmp/${uboot_name}.deb" "${DEB_STORAGE}/"
|
||||||
|
|
||||||
# store git hash to the file
|
# store git hash to the file
|
||||||
# echo $hash > ${SRC}/cache/hash/${CHOSEN_UBOOT}.githash
|
# echo $hash > ${SRC}/cache/hash/${CHOSEN_UBOOT}.githash
|
||||||
|
@ -265,15 +282,16 @@ compile_kernel()
|
||||||
{
|
{
|
||||||
if [[ $CLEAN_LEVEL == *make* ]]; then
|
if [[ $CLEAN_LEVEL == *make* ]]; then
|
||||||
display_alert "Cleaning" "$LINUXSOURCEDIR" "info"
|
display_alert "Cleaning" "$LINUXSOURCEDIR" "info"
|
||||||
(cd $SRC/cache/sources/$LINUXSOURCEDIR; make ARCH=$ARCHITECTURE clean >/dev/null 2>&1)
|
(cd "${SRC}/cache/sources/${LINUXSOURCEDIR}"; make ARCH="${ARCHITECTURE}" clean >/dev/null 2>&1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $USE_OVERLAYFS == yes ]]; then
|
if [[ $USE_OVERLAYFS == yes ]]; then
|
||||||
local kerneldir=$(overlayfs_wrapper "wrap" "$SRC/cache/sources/$LINUXSOURCEDIR" "kernel_${LINUXFAMILY}_${BRANCH}")
|
local kerneldir
|
||||||
|
kerneldir=$(overlayfs_wrapper "wrap" "$SRC/cache/sources/$LINUXSOURCEDIR" "kernel_${LINUXFAMILY}_${BRANCH}")
|
||||||
else
|
else
|
||||||
local kerneldir="$SRC/cache/sources/$LINUXSOURCEDIR"
|
local kerneldir="$SRC/cache/sources/$LINUXSOURCEDIR"
|
||||||
fi
|
fi
|
||||||
cd "$kerneldir"
|
cd "${kerneldir}" || exit
|
||||||
|
|
||||||
if ! grep -qoE '^-rc[[:digit:]]+' <(grep "^EXTRAVERSION" Makefile | head -1 | awk '{print $(NF)}'); then
|
if ! grep -qoE '^-rc[[:digit:]]+' <(grep "^EXTRAVERSION" Makefile | head -1 | awk '{print $(NF)}'); then
|
||||||
sed -i 's/EXTRAVERSION = .*/EXTRAVERSION = /' Makefile
|
sed -i 's/EXTRAVERSION = .*/EXTRAVERSION = /' Makefile
|
||||||
|
@ -281,10 +299,11 @@ compile_kernel()
|
||||||
rm -f localversion
|
rm -f localversion
|
||||||
|
|
||||||
# read kernel version
|
# read kernel version
|
||||||
local version=$(grab_version "$kerneldir")
|
local version hash
|
||||||
|
version=$(grab_version "$kerneldir")
|
||||||
|
|
||||||
# read kernel git hash
|
# read kernel git hash
|
||||||
local hash=$(git --git-dir="$kerneldir"/.git rev-parse HEAD)
|
hash=$(git --git-dir="$kerneldir"/.git rev-parse HEAD)
|
||||||
|
|
||||||
# build 3rd party drivers
|
# build 3rd party drivers
|
||||||
compilation_prepare
|
compilation_prepare
|
||||||
|
@ -295,83 +314,85 @@ compile_kernel()
|
||||||
[[ $CREATE_PATCHES == yes ]] && userpatch_create "kernel"
|
[[ $CREATE_PATCHES == yes ]] && userpatch_create "kernel"
|
||||||
|
|
||||||
# re-read kernel version after patching
|
# re-read kernel version after patching
|
||||||
local version=$(grab_version "$kerneldir")
|
local version
|
||||||
|
version=$(grab_version "$kerneldir")
|
||||||
|
|
||||||
# create linux-source package - with already patched sources
|
# create linux-source package - with already patched sources
|
||||||
local sources_pkg_dir=$SRC/.tmp/${CHOSEN_KSRC}_${REVISION}_all
|
local sources_pkg_dir=$SRC/.tmp/${CHOSEN_KSRC}_${REVISION}_all
|
||||||
rm -rf ${sources_pkg_dir}
|
rm -rf "${sources_pkg_dir}"
|
||||||
mkdir -p $sources_pkg_dir/usr/src/ $sources_pkg_dir/usr/share/doc/linux-source-${version}-${LINUXFAMILY} $sources_pkg_dir/DEBIAN
|
mkdir -p "${sources_pkg_dir}"/usr/src/ "${sources_pkg_dir}/usr/share/doc/linux-source-${version}-${LINUXFAMILY}" "${sources_pkg_dir}"/DEBIAN
|
||||||
|
|
||||||
if [[ $BUILD_KSRC != no ]]; then
|
if [[ $BUILD_KSRC != no ]]; then
|
||||||
display_alert "Compressing sources for the linux-source package"
|
display_alert "Compressing sources for the linux-source package"
|
||||||
tar cp --directory="$kerneldir" --exclude='./.git/' --owner=root . \
|
tar cp --directory="$kerneldir" --exclude='./.git/' --owner=root . \
|
||||||
| pv -p -b -r -s $(du -sb "$kerneldir" --exclude=='./.git/' | cut -f1) \
|
| pv -p -b -r -s "$(du -sb "$kerneldir" --exclude=='./.git/' | cut -f1)" \
|
||||||
| pixz -4 > $sources_pkg_dir/usr/src/linux-source-${version}-${LINUXFAMILY}.tar.xz
|
| pixz -4 > "${sources_pkg_dir}/usr/src/linux-source-${version}-${LINUXFAMILY}.tar.xz"
|
||||||
cp COPYING $sources_pkg_dir/usr/share/doc/linux-source-${version}-${LINUXFAMILY}/LICENSE
|
cp COPYING "${sources_pkg_dir}/usr/share/doc/linux-source-${version}-${LINUXFAMILY}/LICENSE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
display_alert "Compiling $BRANCH kernel" "$version" "info"
|
display_alert "Compiling $BRANCH kernel" "$version" "info"
|
||||||
|
|
||||||
local toolchain=$(find_toolchain "$KERNEL_COMPILER" "$KERNEL_USE_GCC")
|
local toolchain
|
||||||
|
toolchain=$(find_toolchain "$KERNEL_COMPILER" "$KERNEL_USE_GCC")
|
||||||
[[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${KERNEL_COMPILER}gcc $KERNEL_USE_GCC"
|
[[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${KERNEL_COMPILER}gcc $KERNEL_USE_GCC"
|
||||||
|
|
||||||
display_alert "Compiler version" "${KERNEL_COMPILER}gcc $(eval env PATH=$toolchain:$PATH ${KERNEL_COMPILER}gcc -dumpversion)" "info"
|
display_alert "Compiler version" "${KERNEL_COMPILER}gcc $(eval env PATH="${toolchain}:${PATH}" "${KERNEL_COMPILER}gcc" -dumpversion)" "info"
|
||||||
|
|
||||||
# copy kernel config
|
# copy kernel config
|
||||||
if [[ $KERNEL_KEEP_CONFIG == yes && -f $DEST/config/$LINUXCONFIG.config ]]; then
|
if [[ $KERNEL_KEEP_CONFIG == yes && -f "${DEST}"/config/$LINUXCONFIG.config ]]; then
|
||||||
display_alert "Using previous kernel config" "$DEST/config/$LINUXCONFIG.config" "info"
|
display_alert "Using previous kernel config" "${DEST}/config/$LINUXCONFIG.config" "info"
|
||||||
cp $DEST/config/$LINUXCONFIG.config .config
|
cp "${DEST}/config/${LINUXCONFIG}.config" .config
|
||||||
else
|
else
|
||||||
if [[ -f $USERPATCHES_PATH/$LINUXCONFIG.config ]]; then
|
if [[ -f $USERPATCHES_PATH/$LINUXCONFIG.config ]]; then
|
||||||
display_alert "Using kernel config provided by user" "userpatches/$LINUXCONFIG.config" "info"
|
display_alert "Using kernel config provided by user" "userpatches/$LINUXCONFIG.config" "info"
|
||||||
cp $USERPATCHES_PATH/$LINUXCONFIG.config .config
|
cp "${USERPATCHES_PATH}/${LINUXCONFIG}.config" .config
|
||||||
else
|
else
|
||||||
display_alert "Using kernel config file" "config/kernel/$LINUXCONFIG.config" "info"
|
display_alert "Using kernel config file" "config/kernel/$LINUXCONFIG.config" "info"
|
||||||
cp $SRC/config/kernel/$LINUXCONFIG.config .config
|
cp "${SRC}/config/kernel/${LINUXCONFIG}.config" .config
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# hack for OdroidXU4. Copy firmare files
|
# hack for OdroidXU4. Copy firmare files
|
||||||
if [[ $BOARD == odroidxu4 ]]; then
|
if [[ $BOARD == odroidxu4 ]]; then
|
||||||
mkdir -p $SRC/cache/sources/$LINUXSOURCEDIR/firmware/edid
|
mkdir -p "${SRC}/cache/sources/${LINUXSOURCEDIR}/firmware/edid"
|
||||||
cp $SRC/packages/blobs/odroidxu4/*.bin $SRC/cache/sources/$LINUXSOURCEDIR/firmware/edid
|
cp "${SRC}"/packages/blobs/odroidxu4/*.bin "${SRC}/cache/sources/${LINUXSOURCEDIR}/firmware/edid"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# hack for deb builder. To pack what's missing in headers pack.
|
# hack for deb builder. To pack what's missing in headers pack.
|
||||||
cp $SRC/patch/misc/headers-debian-byteshift.patch /tmp
|
cp "${SRC}"/patch/misc/headers-debian-byteshift.patch /tmp
|
||||||
|
|
||||||
if [[ $KERNEL_CONFIGURE != yes ]]; then
|
if [[ $KERNEL_CONFIGURE != yes ]]; then
|
||||||
if [[ $BRANCH == default ]]; then
|
if [[ $BRANCH == default ]]; then
|
||||||
eval CCACHE_BASEDIR="$(pwd)" env PATH=$toolchain:$PATH \
|
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
|
||||||
'make ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" silentoldconfig'
|
'make ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" silentoldconfig'
|
||||||
else
|
else
|
||||||
# TODO: check if required
|
# TODO: check if required
|
||||||
eval CCACHE_BASEDIR="$(pwd)" env PATH=$toolchain:$PATH \
|
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
|
||||||
'make ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" olddefconfig'
|
'make ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" olddefconfig'
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
eval CCACHE_BASEDIR="$(pwd)" env PATH=$toolchain:$PATH \
|
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
|
||||||
'make $CTHREADS ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" oldconfig'
|
'make $CTHREADS ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" oldconfig'
|
||||||
eval CCACHE_BASEDIR="$(pwd)" env PATH=$toolchain:$PATH \
|
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
|
||||||
'make $CTHREADS ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" ${KERNEL_MENUCONFIG:-menuconfig}'
|
'make $CTHREADS ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" ${KERNEL_MENUCONFIG:-menuconfig}'
|
||||||
|
|
||||||
[[ ${PIPESTATUS[0]} -ne 0 ]] && exit_with_error "Error kernel menuconfig failed"
|
[[ ${PIPESTATUS[0]} -ne 0 ]] && exit_with_error "Error kernel menuconfig failed"
|
||||||
|
|
||||||
# store kernel config in easily reachable place
|
# store kernel config in easily reachable place
|
||||||
display_alert "Exporting new kernel config" "$DEST/config/$LINUXCONFIG.config" "info"
|
display_alert "Exporting new kernel config" "$DEST/config/$LINUXCONFIG.config" "info"
|
||||||
cp .config $DEST/config/$LINUXCONFIG.config
|
cp .config "${DEST}/config/${LINUXCONFIG}.config"
|
||||||
# export defconfig too if requested
|
# export defconfig too if requested
|
||||||
if [[ $KERNEL_EXPORT_DEFCONFIG == yes ]]; then
|
if [[ $KERNEL_EXPORT_DEFCONFIG == yes ]]; then
|
||||||
eval CCACHE_BASEDIR="$(pwd)" env PATH=$toolchain:$PATH \
|
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
|
||||||
'make ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" savedefconfig'
|
'make ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" savedefconfig'
|
||||||
[[ -f defconfig ]] && cp defconfig $DEST/config/$LINUXCONFIG.defconfig
|
[[ -f defconfig ]] && cp defconfig "${DEST}/config/${LINUXCONFIG}.defconfig"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
xz < .config > $sources_pkg_dir/usr/src/${LINUXCONFIG}_${version}_${REVISION}_config.xz
|
xz < .config > "${sources_pkg_dir}/usr/src/${LINUXCONFIG}_${version}_${REVISION}_config.xz"
|
||||||
|
|
||||||
echo -e "\n\t== kernel ==\n" >>$DEST/debug/compilation.log
|
echo -e "\n\t== kernel ==\n" >> "${DEST}"/debug/compilation.log
|
||||||
eval CCACHE_BASEDIR="$(pwd)" env PATH=$toolchain:$PATH \
|
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
|
||||||
'make $CTHREADS ARCH=$ARCHITECTURE \
|
'make $CTHREADS ARCH=$ARCHITECTURE \
|
||||||
CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" \
|
CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" \
|
||||||
$SRC_LOADADDR \
|
$SRC_LOADADDR \
|
||||||
|
@ -387,7 +408,7 @@ compile_kernel()
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# different packaging for 4.3+
|
# different packaging for 4.3+
|
||||||
if linux-version compare $version ge 4.3; then
|
if linux-version compare "${version}" ge 4.3; then
|
||||||
local kernel_packing="bindeb-pkg"
|
local kernel_packing="bindeb-pkg"
|
||||||
else
|
else
|
||||||
local kernel_packing="deb-pkg"
|
local kernel_packing="deb-pkg"
|
||||||
|
@ -396,8 +417,8 @@ compile_kernel()
|
||||||
display_alert "Creating packages"
|
display_alert "Creating packages"
|
||||||
|
|
||||||
# produce deb packages: image, headers, firmware, dtb
|
# produce deb packages: image, headers, firmware, dtb
|
||||||
echo -e "\n\t== deb packages: image, headers, firmware, dtb ==\n" >>$DEST/debug/compilation.log
|
echo -e "\n\t== deb packages: image, headers, firmware, dtb ==\n" >> "${DEST}"/debug/compilation.log
|
||||||
eval CCACHE_BASEDIR="$(pwd)" env PATH=$toolchain:$PATH \
|
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
|
||||||
'make -j1 $kernel_packing \
|
'make -j1 $kernel_packing \
|
||||||
KDEB_PKGVERSION=$REVISION \
|
KDEB_PKGVERSION=$REVISION \
|
||||||
BRANCH=$BRANCH \
|
BRANCH=$BRANCH \
|
||||||
|
@ -411,7 +432,7 @@ compile_kernel()
|
||||||
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Creating kernel packages..." $TTY_Y $TTY_X'} \
|
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Creating kernel packages..." $TTY_Y $TTY_X'} \
|
||||||
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
||||||
|
|
||||||
cat <<-EOF > $sources_pkg_dir/DEBIAN/control
|
cat <<-EOF > "${sources_pkg_dir}"/DEBIAN/control
|
||||||
Package: linux-source-${version}-${BRANCH}-${LINUXFAMILY}
|
Package: linux-source-${version}-${BRANCH}-${LINUXFAMILY}
|
||||||
Version: ${version}-${BRANCH}-${LINUXFAMILY}+${REVISION}
|
Version: ${version}-${BRANCH}-${LINUXFAMILY}+${REVISION}
|
||||||
Architecture: all
|
Architecture: all
|
||||||
|
@ -425,18 +446,18 @@ compile_kernel()
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [[ $BUILD_KSRC != no ]]; then
|
if [[ $BUILD_KSRC != no ]]; then
|
||||||
fakeroot dpkg-deb -z0 -b $sources_pkg_dir ${sources_pkg_dir}.deb
|
fakeroot dpkg-deb -z0 -b "${sources_pkg_dir}" "${sources_pkg_dir}.deb"
|
||||||
mv ${sources_pkg_dir}.deb ${DEB_STORAGE}/
|
mv "${sources_pkg_dir}.deb" "${DEB_STORAGE}/"
|
||||||
fi
|
fi
|
||||||
rm -rf $sources_pkg_dir
|
rm -rf "${sources_pkg_dir}"
|
||||||
|
|
||||||
cd ..
|
cd .. || exit
|
||||||
# remove firmare image packages here - easier than patching ~40 packaging scripts at once
|
# remove firmare image packages here - easier than patching ~40 packaging scripts at once
|
||||||
rm -f linux-firmware-image-*.deb
|
rm -f linux-firmware-image-*.deb
|
||||||
mv *.deb ${DEB_STORAGE}/ || exit_with_error "Failed moving kernel DEBs"
|
mv ./*.deb "${DEB_STORAGE}/" || exit_with_error "Failed moving kernel DEBs"
|
||||||
|
|
||||||
# store git hash to the file
|
# store git hash to the file
|
||||||
echo $hash > ${SRC}/cache/hash/linux-image-${BRANCH}-${LINUXFAMILY}.githash
|
echo "${hash}" > "${SRC}/cache/hash/linux-image-${BRANCH}-${LINUXFAMILY}.githash"
|
||||||
[[ -z ${KERNELPATCHDIR} ]] && KERNELPATCHDIR=$LINUXFAMILY-$BRANCH
|
[[ -z ${KERNELPATCHDIR} ]] && KERNELPATCHDIR=$LINUXFAMILY-$BRANCH
|
||||||
[[ -z ${LINUXCONFIG} ]] && LINUXCONFIG=linux-$LINUXFAMILY-$BRANCH
|
[[ -z ${LINUXCONFIG} ]] && LINUXCONFIG=linux-$LINUXFAMILY-$BRANCH
|
||||||
hash_watch_1=$(find "${SRC}/patch/kernel/${KERNELPATCHDIR}" -maxdepth 1 -printf '%s %P\n')
|
hash_watch_1=$(find "${SRC}/patch/kernel/${KERNELPATCHDIR}" -maxdepth 1 -printf '%s %P\n')
|
||||||
|
@ -456,22 +477,22 @@ compile_firmware()
|
||||||
plugin_repo="https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git"
|
plugin_repo="https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git"
|
||||||
fi
|
fi
|
||||||
local plugin_dir="armbian-firmware${FULL}"
|
local plugin_dir="armbian-firmware${FULL}"
|
||||||
[[ -d $SRC/cache/sources/$plugin_dir ]] && rm -rf $SRC/cache/sources/$plugin_dir
|
[[ -d "${SRC}/cache/sources/${plugin_dir}" ]] && rm -rf "${SRC}/cache/sources/${plugin_dir}"
|
||||||
mkdir -p $SRC/cache/sources/$plugin_dir/lib/firmware
|
mkdir -p "${SRC}/cache/sources/${plugin_dir}/lib/firmware"
|
||||||
|
|
||||||
fetch_from_repo "https://github.com/armbian/firmware" "armbian-firmware-git" "branch:master"
|
fetch_from_repo "https://github.com/armbian/firmware" "armbian-firmware-git" "branch:master"
|
||||||
if [[ -n $FULL ]]; then
|
if [[ -n $FULL ]]; then
|
||||||
fetch_from_repo "$plugin_repo" "linux-firmware-git" "branch:master"
|
fetch_from_repo "$plugin_repo" "linux-firmware-git" "branch:master"
|
||||||
# cp : create hardlinks
|
# cp : create hardlinks
|
||||||
cp -alf $SRC/cache/sources/linux-firmware-git/* $SRC/cache/sources/$plugin_dir/lib/firmware/
|
cp -alf "${SRC}"/cache/sources/linux-firmware-git/* "${SRC}/cache/sources/${plugin_dir}/lib/firmware/"
|
||||||
fi
|
fi
|
||||||
# overlay our firmware
|
# overlay our firmware
|
||||||
# cp : create hardlinks
|
# cp : create hardlinks
|
||||||
cp -alf $SRC/cache/sources/armbian-firmware-git/* $SRC/cache/sources/$plugin_dir/lib/firmware/
|
cp -alf "${SRC}"/cache/sources/armbian-firmware-git/* "${SRC}/cache/sources/${plugin_dir}/lib/firmware/"
|
||||||
|
|
||||||
# cleanup what's not needed for sure
|
# cleanup what's not needed for sure
|
||||||
rm -rf $SRC/cache/sources/$plugin_dir/lib/firmware/{amdgpu,amd-ucode,radeon,nvidia,matrox,.git}
|
rm -rf "${SRC}/cache/sources/${plugin_dir}"/lib/firmware/{amdgpu,amd-ucode,radeon,nvidia,matrox,.git}
|
||||||
cd $SRC/cache/sources/$plugin_dir
|
cd "${SRC}/cache/sources/${plugin_dir}" || exit
|
||||||
|
|
||||||
# set up control file
|
# set up control file
|
||||||
mkdir -p DEBIAN
|
mkdir -p DEBIAN
|
||||||
|
@ -487,12 +508,12 @@ compile_firmware()
|
||||||
Description: Linux firmware${FULL}
|
Description: Linux firmware${FULL}
|
||||||
END
|
END
|
||||||
|
|
||||||
cd $SRC/cache/sources
|
cd "${SRC}"/cache/sources || exit
|
||||||
# pack
|
# pack
|
||||||
mv armbian-firmware${FULL} armbian-firmware${FULL}_${REVISION}_all
|
mv "armbian-firmware${FULL}" "armbian-firmware${FULL}_${REVISION}_all"
|
||||||
fakeroot dpkg -b armbian-firmware${FULL}_${REVISION}_all >> $DEST/debug/install.log 2>&1
|
fakeroot dpkg -b "armbian-firmware${FULL}_${REVISION}_all" >> "${DEST}"/debug/install.log 2>&1
|
||||||
mv armbian-firmware${FULL}_${REVISION}_all armbian-firmware${FULL}
|
mv "armbian-firmware${FULL}_${REVISION}_all" "armbian-firmware${FULL}"
|
||||||
mv armbian-firmware${FULL}_${REVISION}_all.deb ${DEB_STORAGE}/
|
mv "armbian-firmware${FULL}_${REVISION}_all.deb" "${DEB_STORAGE}/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -506,10 +527,10 @@ compile_armbian-config()
|
||||||
|
|
||||||
fetch_from_repo "https://github.com/armbian/config" "armbian-config" "branch:master"
|
fetch_from_repo "https://github.com/armbian/config" "armbian-config" "branch:master"
|
||||||
|
|
||||||
mkdir -p $tmpdir/{DEBIAN,usr/bin/,usr/sbin/,usr/lib/armbian-config/}
|
mkdir -p "${tmpdir}"/{DEBIAN,usr/bin/,usr/sbin/,usr/lib/armbian-config/}
|
||||||
|
|
||||||
# set up control file
|
# set up control file
|
||||||
cat <<-END > $tmpdir/DEBIAN/control
|
cat <<-END > "${tmpdir}"/DEBIAN/control
|
||||||
Package: armbian-config
|
Package: armbian-config
|
||||||
Version: $REVISION
|
Version: $REVISION
|
||||||
Architecture: all
|
Architecture: all
|
||||||
|
@ -524,20 +545,20 @@ compile_armbian-config()
|
||||||
Description: Armbian configuration utility
|
Description: Armbian configuration utility
|
||||||
END
|
END
|
||||||
|
|
||||||
install -m 755 $SRC/cache/sources/armbian-config/scripts/tv_grab_file $tmpdir/usr/bin/tv_grab_file
|
install -m 755 "${SRC}"/cache/sources/armbian-config/scripts/tv_grab_file "${tmpdir}"/usr/bin/tv_grab_file
|
||||||
install -m 755 $SRC/cache/sources/armbian-config/debian-config $tmpdir/usr/sbin/armbian-config
|
install -m 755 "${SRC}"/cache/sources/armbian-config/debian-config "${tmpdir}"/usr/sbin/armbian-config
|
||||||
install -m 644 $SRC/cache/sources/armbian-config/debian-config-jobs $tmpdir/usr/lib/armbian-config/jobs.sh
|
install -m 644 "${SRC}"/cache/sources/armbian-config/debian-config-jobs "${tmpdir}"/usr/lib/armbian-config/jobs.sh
|
||||||
install -m 644 $SRC/cache/sources/armbian-config/debian-config-submenu $tmpdir/usr/lib/armbian-config/submenu.sh
|
install -m 644 "${SRC}"/cache/sources/armbian-config/debian-config-submenu "${tmpdir}"/usr/lib/armbian-config/submenu.sh
|
||||||
install -m 644 $SRC/cache/sources/armbian-config/debian-config-functions $tmpdir/usr/lib/armbian-config/functions.sh
|
install -m 644 "${SRC}"/cache/sources/armbian-config/debian-config-functions "${tmpdir}"/usr/lib/armbian-config/functions.sh
|
||||||
install -m 644 $SRC/cache/sources/armbian-config/debian-config-functions-network $tmpdir/usr/lib/armbian-config/functions-network.sh
|
install -m 644 "${SRC}"/cache/sources/armbian-config/debian-config-functions-network "${tmpdir}"/usr/lib/armbian-config/functions-network.sh
|
||||||
install -m 755 $SRC/cache/sources/armbian-config/softy $tmpdir/usr/sbin/softy
|
install -m 755 "${SRC}"/cache/sources/armbian-config/softy "${tmpdir}"/usr/sbin/softy
|
||||||
# fallback to replace armbian-config in BSP
|
# fallback to replace armbian-config in BSP
|
||||||
ln -sf /usr/sbin/armbian-config $tmpdir/usr/bin/armbian-config
|
ln -sf /usr/sbin/armbian-config "${tmpdir}"/usr/bin/armbian-config
|
||||||
ln -sf /usr/sbin/softy $tmpdir/usr/bin/softy
|
ln -sf /usr/sbin/softy "${tmpdir}"/usr/bin/softy
|
||||||
|
|
||||||
fakeroot dpkg -b ${tmpdir} >/dev/null
|
fakeroot dpkg -b "${tmpdir}" >/dev/null
|
||||||
mv ${tmpdir}.deb ${DEB_STORAGE}/
|
mv "${tmpdir}.deb" "${DEB_STORAGE}/"
|
||||||
rm -rf $tmpdir
|
rm -rf "${tmpdir}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -546,7 +567,7 @@ compile_armbian-config()
|
||||||
compile_sunxi_tools()
|
compile_sunxi_tools()
|
||||||
{
|
{
|
||||||
# Compile and install only if git commit hash changed
|
# Compile and install only if git commit hash changed
|
||||||
cd $SRC/cache/sources/sunxi-tools
|
cd "${SRC}"/cache/sources/sunxi-tools || exit
|
||||||
# need to check if /usr/local/bin/sunxi-fexc to detect new Docker containers with old cached sources
|
# need to check if /usr/local/bin/sunxi-fexc to detect new Docker containers with old cached sources
|
||||||
if [[ ! -f .commit_id || $(git rev-parse @ 2>/dev/null) != $(<.commit_id) || ! -f /usr/local/bin/sunxi-fexc ]]; then
|
if [[ ! -f .commit_id || $(git rev-parse @ 2>/dev/null) != $(<.commit_id) || ! -f /usr/local/bin/sunxi-fexc ]]; then
|
||||||
display_alert "Compiling" "sunxi-tools" "info"
|
display_alert "Compiling" "sunxi-tools" "info"
|
||||||
|
@ -561,7 +582,7 @@ compile_sunxi_tools()
|
||||||
install_rkbin_tools()
|
install_rkbin_tools()
|
||||||
{
|
{
|
||||||
# install only if git commit hash changed
|
# install only if git commit hash changed
|
||||||
cd $SRC/cache/sources/rkbin-tools
|
cd "${SRC}"/cache/sources/rkbin-tools || exit
|
||||||
# need to check if /usr/local/bin/sunxi-fexc to detect new Docker containers with old cached sources
|
# need to check if /usr/local/bin/sunxi-fexc to detect new Docker containers with old cached sources
|
||||||
if [[ ! -f .commit_id || $(git rev-parse @ 2>/dev/null) != $(<.commit_id) || ! -f /usr/local/bin/loaderimage ]]; then
|
if [[ ! -f .commit_id || $(git rev-parse @ 2>/dev/null) != $(<.commit_id) || ! -f /usr/local/bin/loaderimage ]]; then
|
||||||
display_alert "Installing" "rkbin-tools" "info"
|
display_alert "Installing" "rkbin-tools" "info"
|
||||||
|
@ -575,10 +596,10 @@ install_rkbin_tools()
|
||||||
grab_version()
|
grab_version()
|
||||||
{
|
{
|
||||||
local ver=()
|
local ver=()
|
||||||
ver[0]=$(grep "^VERSION" $1/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
|
ver[0]=$(grep "^VERSION" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
|
||||||
ver[1]=$(grep "^PATCHLEVEL" $1/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
|
ver[1]=$(grep "^PATCHLEVEL" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
|
||||||
ver[2]=$(grep "^SUBLEVEL" $1/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
|
ver[2]=$(grep "^SUBLEVEL" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
|
||||||
ver[3]=$(grep "^EXTRAVERSION" $1/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^-rc[[:digit:]]+')
|
ver[3]=$(grep "^EXTRAVERSION" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^-rc[[:digit:]]+')
|
||||||
echo "${ver[0]:-0}${ver[1]:+.${ver[1]}}${ver[2]:+.${ver[2]}}${ver[3]}"
|
echo "${ver[0]:-0}${ver[1]:+.${ver[1]}}${ver[2]:+.${ver[2]}}${ver[3]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -593,19 +614,22 @@ find_toolchain()
|
||||||
local dist=10
|
local dist=10
|
||||||
local toolchain=""
|
local toolchain=""
|
||||||
# extract target major.minor version from expression
|
# extract target major.minor version from expression
|
||||||
local target_ver=$(grep -oE "[[:digit:]]+\.[[:digit:]]" <<< "$expression")
|
local target_ver
|
||||||
for dir in $SRC/cache/toolchains/*/; do
|
target_ver=$(grep -oE "[[:digit:]]+\.[[:digit:]]" <<< "$expression")
|
||||||
|
for dir in "${SRC}"/cache/toolchains/*/; do
|
||||||
# check if is a toolchain for current $ARCH
|
# check if is a toolchain for current $ARCH
|
||||||
[[ ! -f ${dir}bin/${compiler}gcc ]] && continue
|
[[ ! -f ${dir}bin/${compiler}gcc ]] && continue
|
||||||
# get toolchain major.minor version
|
# get toolchain major.minor version
|
||||||
local gcc_ver=$(${dir}bin/${compiler}gcc -dumpversion | grep -oE "^[[:digit:]]+\.[[:digit:]]")
|
local gcc_ver
|
||||||
|
gcc_ver=$("${dir}bin/${compiler}gcc" -dumpversion | grep -oE "^[[:digit:]]+\.[[:digit:]]")
|
||||||
# check if toolchain version satisfies requirement
|
# check if toolchain version satisfies requirement
|
||||||
awk "BEGIN{exit ! ($gcc_ver $expression)}" >/dev/null || continue
|
awk "BEGIN{exit ! ($gcc_ver $expression)}" >/dev/null || continue
|
||||||
# check if found version is the closest to target
|
# check if found version is the closest to target
|
||||||
# may need different logic here with more than 1 digit minor version numbers
|
# may need different logic here with more than 1 digit minor version numbers
|
||||||
# numbers: 3.9 > 3.10; versions: 3.9 < 3.10
|
# numbers: 3.9 > 3.10; versions: 3.9 < 3.10
|
||||||
# dpkg --compare-versions can be used here if operators are changed
|
# dpkg --compare-versions can be used here if operators are changed
|
||||||
local d=$(awk '{x = $1 - $2}{printf "%.1f\n", (x > 0) ? x : -x}' <<< "$target_ver $gcc_ver")
|
local d
|
||||||
|
d=$(awk '{x = $1 - $2}{printf "%.1f\n", (x > 0) ? x : -x}' <<< "$target_ver $gcc_ver")
|
||||||
if awk "BEGIN{exit ! ($d < $dist)}" >/dev/null ; then
|
if awk "BEGIN{exit ! ($d < $dist)}" >/dev/null ; then
|
||||||
dist=$d
|
dist=$d
|
||||||
toolchain=${dir}bin
|
toolchain=${dir}bin
|
||||||
|
@ -613,12 +637,12 @@ find_toolchain()
|
||||||
done
|
done
|
||||||
echo "$toolchain"
|
echo "$toolchain"
|
||||||
# logging a stack of used compilers.
|
# logging a stack of used compilers.
|
||||||
if [[ -f $DEST/debug/compiler.log ]]; then
|
if [[ -f "${DEST}"/debug/compiler.log ]]; then
|
||||||
if ! grep -q "$toolchain" $DEST/debug/compiler.log; then
|
if ! grep -q "$toolchain" "${DEST}"/debug/compiler.log; then
|
||||||
echo "$toolchain" >> $DEST/debug/compiler.log;
|
echo "$toolchain" >> "${DEST}"/debug/compiler.log;
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "$toolchain" >> $DEST/debug/compiler.log;
|
echo "$toolchain" >> "${DEST}"/debug/compiler.log;
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -671,12 +695,13 @@ advanced_patch()
|
||||||
# get patch file names
|
# get patch file names
|
||||||
for dir in "${dirs[@]}"; do
|
for dir in "${dirs[@]}"; do
|
||||||
for patch in ${dir%%:*}/*.patch; do
|
for patch in ${dir%%:*}/*.patch; do
|
||||||
names+=($(basename $patch))
|
names+=($(basename "${patch}"))
|
||||||
done
|
done
|
||||||
# add linked patch directories
|
# add linked patch directories
|
||||||
if [[ -d ${dir%%:*} ]]; then
|
if [[ -d ${dir%%:*} ]]; then
|
||||||
local findlinks=$(find ${dir%%:*} -maxdepth 1 -type l -print0 2>&1 | xargs -0)
|
local findlinks
|
||||||
[[ -n $findlinks ]] && readarray -d '' links < <(find $findlinks -maxdepth 1 -type f -follow -print -iname "*.patch" -print | grep "\.patch$" | sed "s|${dir%%:*}/||g" 2>&1)
|
findlinks=$(find "${dir%%:*}" -maxdepth 1 -type l -print0 2>&1 | xargs -0)
|
||||||
|
[[ -n $findlinks ]] && readarray -d '' links < <(find "${findlinks}" -maxdepth 1 -type f -follow -print -iname "*.patch" -print | grep "\.patch$" | sed "s|${dir%%:*}/||g" 2>&1)
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
# merge static and linked
|
# merge static and linked
|
||||||
|
@ -710,18 +735,18 @@ process_patch_file()
|
||||||
local status=$2
|
local status=$2
|
||||||
|
|
||||||
# detect and remove files which patch will create
|
# detect and remove files which patch will create
|
||||||
lsdiff -s --strip=1 $patch | grep '^+' | awk '{print $2}' | xargs -I % sh -c 'rm -f %'
|
lsdiff -s --strip=1 "${patch}" | grep '^+' | awk '{print $2}' | xargs -I % sh -c 'rm -f %'
|
||||||
|
|
||||||
echo "Processing file $patch" >> $DEST/debug/patching.log
|
echo "Processing file $patch" >> "${DEST}"/debug/patching.log
|
||||||
patch --batch --silent -p1 -N < $patch >> $DEST/debug/patching.log 2>&1
|
patch --batch --silent -p1 -N < "${patch}" >> "${DEST}"/debug/patching.log 2>&1
|
||||||
|
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
display_alert "* $status $(basename $patch)" "failed" "wrn"
|
display_alert "* $status $(basename "${patch}")" "failed" "wrn"
|
||||||
[[ $EXIT_PATCHING_ERROR == yes ]] && exit_with_error "Aborting due to" "EXIT_PATCHING_ERROR"
|
[[ $EXIT_PATCHING_ERROR == yes ]] && exit_with_error "Aborting due to" "EXIT_PATCHING_ERROR"
|
||||||
else
|
else
|
||||||
display_alert "* $status $(basename $patch)" "" "info"
|
display_alert "* $status $(basename "${patch}")" "" "info"
|
||||||
fi
|
fi
|
||||||
echo >> $DEST/debug/patching.log
|
echo >> "${DEST}"/debug/patching.log
|
||||||
}
|
}
|
||||||
|
|
||||||
userpatch_create()
|
userpatch_create()
|
||||||
|
@ -733,17 +758,17 @@ userpatch_create()
|
||||||
local patch="$DEST/patch/$1-$LINUXFAMILY-$BRANCH.patch"
|
local patch="$DEST/patch/$1-$LINUXFAMILY-$BRANCH.patch"
|
||||||
|
|
||||||
# apply previous user debug mode created patches
|
# apply previous user debug mode created patches
|
||||||
[[ -f $patch ]] && display_alert "Applying existing $1 patch" "$patch" "wrn" && patch --batch --silent -p1 -N < $patch
|
[[ -f $patch ]] && display_alert "Applying existing $1 patch" "$patch" "wrn" && patch --batch --silent -p1 -N < "${patch}"
|
||||||
|
|
||||||
# prompt to alter source
|
# prompt to alter source
|
||||||
display_alert "Make your changes in this directory:" "$(pwd)" "wrn"
|
display_alert "Make your changes in this directory:" "$(pwd)" "wrn"
|
||||||
display_alert "Press <Enter> after you are done" "waiting" "wrn"
|
display_alert "Press <Enter> after you are done" "waiting" "wrn"
|
||||||
read </dev/tty
|
read -r </dev/tty
|
||||||
tput cuu1
|
tput cuu1
|
||||||
git add .
|
git add .
|
||||||
# create patch out of changes
|
# create patch out of changes
|
||||||
if ! git diff-index --quiet --cached HEAD; then
|
if ! git diff-index --quiet --cached HEAD; then
|
||||||
git diff --staged > $patch
|
git diff --staged > "${patch}"
|
||||||
display_alert "You will find your patch here:" "$patch" "info"
|
display_alert "You will find your patch here:" "$patch" "info"
|
||||||
else
|
else
|
||||||
display_alert "No changes found, skipping patch creation" "" "wrn"
|
display_alert "No changes found, skipping patch creation" "" "wrn"
|
||||||
|
@ -773,9 +798,10 @@ overlayfs_wrapper()
|
||||||
local srcdir="$2"
|
local srcdir="$2"
|
||||||
local description="$3"
|
local description="$3"
|
||||||
mkdir -p /tmp/overlay_components/ /tmp/armbian_build/
|
mkdir -p /tmp/overlay_components/ /tmp/armbian_build/
|
||||||
local tempdir=$(mktemp -d --tmpdir="/tmp/overlay_components/")
|
local tempdir workdir mergeddir
|
||||||
local workdir=$(mktemp -d --tmpdir="/tmp/overlay_components/")
|
tempdir=$(mktemp -d --tmpdir="/tmp/overlay_components/")
|
||||||
local mergeddir=$(mktemp -d --suffix="_$description" --tmpdir="/tmp/armbian_build/")
|
workdir=$(mktemp -d --tmpdir="/tmp/overlay_components/")
|
||||||
|
mergeddir=$(mktemp -d --suffix="_$description" --tmpdir="/tmp/armbian_build/")
|
||||||
mount -t overlay overlay -o lowerdir="$srcdir",upperdir="$tempdir",workdir="$workdir" "$mergeddir"
|
mount -t overlay overlay -o lowerdir="$srcdir",upperdir="$tempdir",workdir="$workdir" "$mergeddir"
|
||||||
# this is executed in a subshell, so use temp files to pass extra data outside
|
# this is executed in a subshell, so use temp files to pass extra data outside
|
||||||
echo "$tempdir" >> /tmp/.overlayfs_wrapper_cleanup
|
echo "$tempdir" >> /tmp/.overlayfs_wrapper_cleanup
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
# common options
|
# common options
|
||||||
# daily beta build contains date in subrevision
|
# daily beta build contains date in subrevision
|
||||||
#if [[ $BETA == yes && -z $SUBREVISION ]]; then SUBREVISION="."$(date --date="tomorrow" +"%j"); fi
|
#if [[ $BETA == yes && -z $SUBREVISION ]]; then SUBREVISION="."$(date --date="tomorrow" +"%j"); fi
|
||||||
REVISION=$(cat ${SRC}/VERSION)"$SUBREVISION" # all boards have same revision
|
REVISION=$(cat "${SRC}"/VERSION)"$SUBREVISION" # all boards have same revision
|
||||||
[[ -z $ROOTPWD ]] && ROOTPWD="1234" # Must be changed @first login
|
[[ -z $ROOTPWD ]] && ROOTPWD="1234" # Must be changed @first login
|
||||||
[[ -z $MAINTAINER ]] && MAINTAINER="Igor Pecovnik" # deb signature
|
[[ -z $MAINTAINER ]] && MAINTAINER="Igor Pecovnik" # deb signature
|
||||||
[[ -z $MAINTAINERMAIL ]] && MAINTAINERMAIL="igor.pecovnik@****l.com" # deb signature
|
[[ -z $MAINTAINERMAIL ]] && MAINTAINERMAIL="igor.pecovnik@****l.com" # deb signature
|
||||||
|
@ -20,10 +20,9 @@ TZDATA=$(cat /etc/timezone) # Timezone for target is taken from host or defined
|
||||||
USEALLCORES=yes # Use all CPU cores for compiling
|
USEALLCORES=yes # Use all CPU cores for compiling
|
||||||
EXIT_PATCHING_ERROR="" # exit patching if failed
|
EXIT_PATCHING_ERROR="" # exit patching if failed
|
||||||
[[ -z $HOST ]] && HOST="$BOARD" # set hostname to the board
|
[[ -z $HOST ]] && HOST="$BOARD" # set hostname to the board
|
||||||
cd ${SRC}
|
cd "${SRC}" || exit
|
||||||
ROOTFSCACHE_VERSION=29
|
ROOTFSCACHE_VERSION=29
|
||||||
CHROOT_CACHE_VERSION=7
|
CHROOT_CACHE_VERSION=7
|
||||||
cd ${SRC}
|
|
||||||
BUILD_REPOSITORY_URL=$(git remote get-url $(git remote 2>/dev/null) 2>/dev/null)
|
BUILD_REPOSITORY_URL=$(git remote get-url $(git remote 2>/dev/null) 2>/dev/null)
|
||||||
BUILD_REPOSITORY_COMMIT=$(git describe --match=d_e_a_d_b_e_e_f --always --dirty 2>/dev/null)
|
BUILD_REPOSITORY_COMMIT=$(git describe --match=d_e_a_d_b_e_e_f --always --dirty 2>/dev/null)
|
||||||
ROOTFS_CACHE_MAX=42 # max number of rootfs cache, older ones will be cleaned up
|
ROOTFS_CACHE_MAX=42 # max number of rootfs cache, older ones will be cleaned up
|
||||||
|
@ -141,7 +140,6 @@ DEBOOTSTRAP_LIST="locales gnupg ifupdown apt-utils apt-transport-https ca-certif
|
||||||
# tab cleanup is mandatory
|
# tab cleanup is mandatory
|
||||||
DEBOOTSTRAP_LIST=$(echo $DEBOOTSTRAP_LIST | sed -e 's,\\[trn],,g')
|
DEBOOTSTRAP_LIST=$(echo $DEBOOTSTRAP_LIST | sed -e 's,\\[trn],,g')
|
||||||
|
|
||||||
|
|
||||||
# For minimal build different set of packages is needed
|
# For minimal build different set of packages is needed
|
||||||
# Essential packages for minimal build
|
# Essential packages for minimal build
|
||||||
PACKAGE_LIST="bc cpufrequtils device-tree-compiler fping fake-hwclock psmisc chrony parted dialog \
|
PACKAGE_LIST="bc cpufrequtils device-tree-compiler fping fake-hwclock psmisc chrony parted dialog \
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
# Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com
|
# Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com
|
||||||
#
|
#
|
||||||
# This file is licensed under the terms of the GNU General Public
|
# This file is licensed under the terms of the GNU General Public
|
||||||
|
@ -26,8 +28,8 @@ debootstrap_ng()
|
||||||
trap unmount_on_exit INT TERM EXIT
|
trap unmount_on_exit INT TERM EXIT
|
||||||
|
|
||||||
# stage: clean and create directories
|
# stage: clean and create directories
|
||||||
rm -rf $SDCARD $MOUNT
|
rm -rf "${SDCARD}" "${MOUNT}"
|
||||||
mkdir -p $SDCARD $MOUNT $DEST/images $SRC/cache/rootfs
|
mkdir -p "${SDCARD}" "${MOUNT}" "${DEST}/images" "${SRC}/cache/rootfs"
|
||||||
|
|
||||||
# stage: verify tmpfs configuration and mount
|
# stage: verify tmpfs configuration and mount
|
||||||
# default maximum size for tmpfs mount is 1/2 of available RAM
|
# default maximum size for tmpfs mount is 1/2 of available RAM
|
||||||
|
@ -41,7 +43,7 @@ debootstrap_ng()
|
||||||
fi
|
fi
|
||||||
[[ -n $FORCE_TMPFS_SIZE ]] && phymem=$FORCE_TMPFS_SIZE
|
[[ -n $FORCE_TMPFS_SIZE ]] && phymem=$FORCE_TMPFS_SIZE
|
||||||
|
|
||||||
[[ $use_tmpfs == yes ]] && mount -t tmpfs -o size=${phymem}M tmpfs $SDCARD
|
[[ $use_tmpfs == yes ]] && mount -t tmpfs -o size="${phymem}M" tmpfs "${SDCARD}"
|
||||||
|
|
||||||
# stage: prepare basic rootfs: unpack cache or create from scratch
|
# stage: prepare basic rootfs: unpack cache or create from scratch
|
||||||
create_rootfs_cache
|
create_rootfs_cache
|
||||||
|
@ -66,28 +68,29 @@ debootstrap_ng()
|
||||||
chroot $SDCARD /bin/bash -c "dpkg --get-selections" | grep -v deinstall | awk '{print $1}' | cut -f1 -d':' > $DEST/debug/installed-packages-${RELEASE}$([[ ${BUILD_MINIMAL} == yes ]] && echo "-minimal")$([[ ${BUILD_DESKTOP} == yes ]] && echo "-desktop").list 2>&1
|
chroot $SDCARD /bin/bash -c "dpkg --get-selections" | grep -v deinstall | awk '{print $1}' | cut -f1 -d':' > $DEST/debug/installed-packages-${RELEASE}$([[ ${BUILD_MINIMAL} == yes ]] && echo "-minimal")$([[ ${BUILD_DESKTOP} == yes ]] && echo "-desktop").list 2>&1
|
||||||
|
|
||||||
# clean up / prepare for making the image
|
# clean up / prepare for making the image
|
||||||
umount_chroot "$SDCARD"
|
umount_chroot "${SDCARD}"
|
||||||
post_debootstrap_tweaks
|
post_debootstrap_tweaks
|
||||||
|
|
||||||
if [[ $ROOTFS_TYPE == fel ]]; then
|
if [[ $ROOTFS_TYPE == fel ]]; then
|
||||||
FEL_ROOTFS=$SDCARD/
|
FEL_ROOTFS=$SDCARD/
|
||||||
display_alert "Starting FEL boot" "$BOARD" "info"
|
display_alert "Starting FEL boot" "$BOARD" "info"
|
||||||
source $SRC/lib/fel-load.sh
|
# shellcheck source=lib/fel-load.sh
|
||||||
|
source "${SRC}/lib/fel-load.sh"
|
||||||
else
|
else
|
||||||
prepare_partitions
|
prepare_partitions
|
||||||
create_image
|
create_image
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# stage: unmount tmpfs
|
# stage: unmount tmpfs
|
||||||
umount $SDCARD 2>&1
|
umount "${SDCARD}" 2>&1
|
||||||
if [[ $use_tmpfs = yes ]]; then
|
if [[ $use_tmpfs = yes ]]; then
|
||||||
while grep -qs "$SDCARD" /proc/mounts
|
while grep -qs "${SDCARD}" /proc/mounts
|
||||||
do
|
do
|
||||||
umount $SDCARD
|
umount "${SDCARD}"
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
rm -rf $SDCARD
|
rm -rf "${SDCARD}"
|
||||||
|
|
||||||
# remove exit trap
|
# remove exit trap
|
||||||
trap - INT TERM EXIT
|
trap - INT TERM EXIT
|
||||||
|
@ -107,11 +110,12 @@ create_rootfs_cache()
|
||||||
# seek last cache, proceed to previous otherwise build it
|
# seek last cache, proceed to previous otherwise build it
|
||||||
for ((n=0;n<${cycles};n++)); do
|
for ((n=0;n<${cycles};n++)); do
|
||||||
|
|
||||||
local packages_hash=$(get_package_list_hash "$(($ROOTFSCACHE_VERSION - $n))")
|
local packages_hash cache_type cache_name cache_fname display_name
|
||||||
local cache_type=$(if [[ ${BUILD_DESKTOP} == yes ]]; then echo "desktop"; elif [[ ${BUILD_MINIMAL} == yes ]]; then echo "minimal"; else echo "cli";fi)
|
packages_hash=$(get_package_list_hash "$(($ROOTFSCACHE_VERSION - $n))")
|
||||||
local cache_name=${RELEASE}-${cache_type}-${ARCH}.$packages_hash.tar.lz4
|
cache_type=$(if [[ ${BUILD_DESKTOP} == yes ]]; then echo "desktop"; elif [[ ${BUILD_MINIMAL} == yes ]]; then echo "minimal"; else echo "cli";fi)
|
||||||
local cache_fname=${SRC}/cache/rootfs/${cache_name}
|
cache_name=${RELEASE}-${cache_type}-${ARCH}.$packages_hash.tar.lz4
|
||||||
local display_name=${RELEASE}-${cache_type}-${ARCH}.${packages_hash:0:3}...${packages_hash:29}.tar.lz4
|
cache_fname=${SRC}/cache/rootfs/${cache_name}
|
||||||
|
display_name=${RELEASE}-${cache_type}-${ARCH}.${packages_hash:0:3}...${packages_hash:29}.tar.lz4
|
||||||
|
|
||||||
display_alert "Checking for local cache" "$display_name" "info"
|
display_alert "Checking for local cache" "$display_name" "info"
|
||||||
|
|
||||||
|
@ -129,12 +133,12 @@ create_rootfs_cache()
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ -f $cache_fname && "$ROOT_FS_CREATE_ONLY" != "force" ]]; then
|
if [[ -f $cache_fname && "$ROOT_FS_CREATE_ONLY" != "force" ]]; then
|
||||||
local date_diff=$(( ($(date +%s) - $(stat -c %Y $cache_fname)) / 86400 ))
|
local date_diff=$(( ($(date +%s) - $(stat -c %Y "${cache_fname}")) / 86400 ))
|
||||||
display_alert "Extracting $display_name" "$date_diff days old" "info"
|
display_alert "Extracting $display_name" "$date_diff days old" "info"
|
||||||
pv -p -b -r -c -N "[ .... ] $display_name" "$cache_fname" | lz4 -dc | tar xp --xattrs -C $SDCARD/
|
pv -p -b -r -c -N "[ .... ] ${display_name}" "${cache_fname}" | lz4 -dc | tar xp --xattrs -C "${SDCARD}"/
|
||||||
[[ $? -ne 0 ]] && rm $cache_fname && exit_with_error "Cache $cache_fname is corrupted and was deleted. Restart."
|
[[ $? -ne 0 ]] && rm $cache_fname && exit_with_error "Cache $cache_fname is corrupted and was deleted. Restart."
|
||||||
rm $SDCARD/etc/resolv.conf
|
rm "${SDCARD}"/etc/resolv.conf
|
||||||
echo "nameserver $NAMESERVER" >> $SDCARD/etc/resolv.conf
|
echo "nameserver $NAMESERVER" >> "${SDCARD}"/etc/resolv.conf
|
||||||
create_sources_list "$RELEASE" "$SDCARD/"
|
create_sources_list "$RELEASE" "$SDCARD/"
|
||||||
else
|
else
|
||||||
display_alert "... remote not found" "Creating new rootfs cache for $RELEASE" "info"
|
display_alert "... remote not found" "Creating new rootfs cache for $RELEASE" "info"
|
||||||
|
@ -159,12 +163,12 @@ create_rootfs_cache()
|
||||||
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Debootstrap (stage 1/2)..." $TTY_Y $TTY_X'} \
|
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Debootstrap (stage 1/2)..." $TTY_Y $TTY_X'} \
|
||||||
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
||||||
|
|
||||||
[[ ${PIPESTATUS[0]} -ne 0 || ! -f $SDCARD/debootstrap/debootstrap ]] && exit_with_error "Debootstrap base system first stage failed"
|
[[ ${PIPESTATUS[0]} -ne 0 || ! -f "${SDCARD}"/debootstrap/debootstrap ]] && exit_with_error "Debootstrap base system first stage failed"
|
||||||
|
|
||||||
cp /usr/bin/$QEMU_BINARY $SDCARD/usr/bin/
|
cp "/usr/bin/${QEMU_BINARY}" "${SDCARD}/usr/bin/"
|
||||||
|
|
||||||
mkdir -p $SDCARD/usr/share/keyrings/
|
mkdir -p "${SDCARD}/usr/share/keyrings/"
|
||||||
cp /usr/share/keyrings/*-archive-keyring.gpg $SDCARD/usr/share/keyrings/
|
cp /usr/share/keyrings/*-archive-keyring.gpg "${SDCARD}/usr/share/keyrings/"
|
||||||
|
|
||||||
display_alert "Installing base system" "Stage 2/2" "info"
|
display_alert "Installing base system" "Stage 2/2" "info"
|
||||||
eval 'chroot $SDCARD /bin/bash -c "/debootstrap/debootstrap --second-stage"' \
|
eval 'chroot $SDCARD /bin/bash -c "/debootstrap/debootstrap --second-stage"' \
|
||||||
|
@ -172,31 +176,31 @@ create_rootfs_cache()
|
||||||
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Debootstrap (stage 2/2)..." $TTY_Y $TTY_X'} \
|
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Debootstrap (stage 2/2)..." $TTY_Y $TTY_X'} \
|
||||||
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
||||||
|
|
||||||
[[ ${PIPESTATUS[0]} -ne 0 || ! -f $SDCARD/bin/bash ]] && exit_with_error "Debootstrap base system second stage failed"
|
[[ ${PIPESTATUS[0]} -ne 0 || ! -f "${SDCARD}"/bin/bash ]] && exit_with_error "Debootstrap base system second stage failed"
|
||||||
|
|
||||||
mount_chroot "$SDCARD"
|
mount_chroot "${SDCARD}"
|
||||||
|
|
||||||
# policy-rc.d script prevents starting or reloading services during image creation
|
# policy-rc.d script prevents starting or reloading services during image creation
|
||||||
printf '#!/bin/sh\nexit 101' > $SDCARD/usr/sbin/policy-rc.d
|
printf '#!/bin/sh\nexit 101' > "${SDCARD}"/usr/sbin/policy-rc.d
|
||||||
chroot $SDCARD /bin/bash -c "dpkg-divert --quiet --local --rename --add /sbin/initctl"
|
chroot "${SDCARD}" /bin/bash -c "dpkg-divert --quiet --local --rename --add /sbin/initctl"
|
||||||
chroot $SDCARD /bin/bash -c "dpkg-divert --quiet --local --rename --add /sbin/start-stop-daemon"
|
chroot "${SDCARD}" /bin/bash -c "dpkg-divert --quiet --local --rename --add /sbin/start-stop-daemon"
|
||||||
printf '#!/bin/sh\necho "Warning: Fake start-stop-daemon called, doing nothing"' > $SDCARD/sbin/start-stop-daemon
|
printf '#!/bin/sh\necho "Warning: Fake start-stop-daemon called, doing nothing"' > "${SDCARD}"/sbin/start-stop-daemon
|
||||||
printf '#!/bin/sh\necho "Warning: Fake initctl called, doing nothing"' > $SDCARD/sbin/initctl
|
printf '#!/bin/sh\necho "Warning: Fake initctl called, doing nothing"' > "${SDCARD}"/sbin/initctl
|
||||||
chmod 755 $SDCARD/usr/sbin/policy-rc.d
|
chmod 755 "${SDCARD}"/usr/sbin/policy-rc.d
|
||||||
chmod 755 $SDCARD/sbin/initctl
|
chmod 755 "${SDCARD}"/sbin/initctl
|
||||||
chmod 755 $SDCARD/sbin/start-stop-daemon
|
chmod 755 "${SDCARD}"/sbin/start-stop-daemon
|
||||||
|
|
||||||
# stage: configure language and locales
|
# stage: configure language and locales
|
||||||
display_alert "Configuring locales" "$DEST_LANG" "info"
|
display_alert "Configuring locales" "$DEST_LANG" "info"
|
||||||
|
|
||||||
[[ -f $SDCARD/etc/locale.gen ]] && sed -i "s/^# $DEST_LANG/$DEST_LANG/" $SDCARD/etc/locale.gen
|
[[ -f "${SDCARD}"/etc/locale.gen ]] && sed -i "s/^# $DEST_LANG/$DEST_LANG/" "${SDCARD}"/etc/locale.gen
|
||||||
eval 'LC_ALL=C LANG=C chroot $SDCARD /bin/bash -c "locale-gen $DEST_LANG"' ${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
eval 'LC_ALL=C LANG=C chroot $SDCARD /bin/bash -c "locale-gen $DEST_LANG"' ${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
||||||
eval 'LC_ALL=C LANG=C chroot $SDCARD /bin/bash -c "update-locale LANG=$DEST_LANG LANGUAGE=$DEST_LANG LC_MESSAGES=$DEST_LANG"' \
|
eval 'LC_ALL=C LANG=C chroot $SDCARD /bin/bash -c "update-locale LANG=$DEST_LANG LANGUAGE=$DEST_LANG LC_MESSAGES=$DEST_LANG"' \
|
||||||
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
||||||
|
|
||||||
if [[ -f $SDCARD/etc/default/console-setup ]]; then
|
if [[ -f "${SDCARD}"/etc/default/console-setup ]]; then
|
||||||
sed -e 's/CHARMAP=.*/CHARMAP="UTF-8"/' -e 's/FONTSIZE=.*/FONTSIZE="8x16"/' \
|
sed -e 's/CHARMAP=.*/CHARMAP="UTF-8"/' -e 's/FONTSIZE=.*/FONTSIZE="8x16"/' \
|
||||||
-e 's/CODESET=.*/CODESET="guess"/' -i $SDCARD/etc/default/console-setup
|
-e 's/CODESET=.*/CODESET="guess"/' -i "${SDCARD}"/etc/default/console-setup
|
||||||
eval 'LC_ALL=C LANG=C chroot $SDCARD /bin/bash -c "setupcon --save"'
|
eval 'LC_ALL=C LANG=C chroot $SDCARD /bin/bash -c "setupcon --save"'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -207,7 +211,7 @@ create_rootfs_cache()
|
||||||
[[ $ARCH == arm64 ]] && eval 'LC_ALL=C LANG=C chroot $SDCARD /bin/bash -c "dpkg --add-architecture armhf"'
|
[[ $ARCH == arm64 ]] && eval 'LC_ALL=C LANG=C chroot $SDCARD /bin/bash -c "dpkg --add-architecture armhf"'
|
||||||
|
|
||||||
# this should fix resolvconf installation failure in some cases
|
# this should fix resolvconf installation failure in some cases
|
||||||
chroot $SDCARD /bin/bash -c 'echo "resolvconf resolvconf/linkify-resolvconf boolean false" | debconf-set-selections'
|
chroot "${SDCARD}" /bin/bash -c 'echo "resolvconf resolvconf/linkify-resolvconf boolean false" | debconf-set-selections'
|
||||||
|
|
||||||
# stage: update packages list
|
# stage: update packages list
|
||||||
display_alert "Updating package list" "$RELEASE" "info"
|
display_alert "Updating package list" "$RELEASE" "info"
|
||||||
|
@ -239,52 +243,52 @@ create_rootfs_cache()
|
||||||
[[ ${PIPESTATUS[0]} -ne 0 ]] && exit_with_error "Installation of Armbian packages failed"
|
[[ ${PIPESTATUS[0]} -ne 0 ]] && exit_with_error "Installation of Armbian packages failed"
|
||||||
|
|
||||||
# stage: remove downloaded packages
|
# stage: remove downloaded packages
|
||||||
chroot $SDCARD /bin/bash -c "apt clean"
|
chroot "${SDCARD}" /bin/bash -c "apt clean"
|
||||||
|
|
||||||
# DEBUG: print free space
|
# DEBUG: print free space
|
||||||
echo -e "\nFree space:"
|
echo -e "\nFree space:"
|
||||||
eval 'df -h' ${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/debootstrap.log'}
|
eval 'df -h' ${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/debootstrap.log'}
|
||||||
|
|
||||||
# create list of installed packages for debug purposes
|
# create list of installed packages for debug purposes
|
||||||
chroot $SDCARD /bin/bash -c "dpkg --get-selections" | grep -v deinstall | awk '{print $1}' | cut -f1 -d':' > ${cache_fname}.list 2>&1
|
chroot "${SDCARD}" /bin/bash -c "dpkg --get-selections" | grep -v deinstall | awk '{print $1}' | cut -f1 -d':' > "${cache_fname}.list" 2>&1
|
||||||
|
|
||||||
# creating xapian index that synaptic runs faster
|
# creating xapian index that synaptic runs faster
|
||||||
if [[ $BUILD_DESKTOP == yes ]]; then
|
if [[ $BUILD_DESKTOP == yes ]]; then
|
||||||
display_alert "Recreating Synaptic search index" "Please wait" "info"
|
display_alert "Recreating Synaptic search index" "Please wait" "info"
|
||||||
chroot $SDCARD /bin/bash -c "/usr/sbin/update-apt-xapian-index -u"
|
chroot "${SDCARD}" /bin/bash -c "/usr/sbin/update-apt-xapian-index -u"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# this is needed for the build process later since resolvconf generated file in /run is not saved
|
# this is needed for the build process later since resolvconf generated file in /run is not saved
|
||||||
rm $SDCARD/etc/resolv.conf
|
rm "${SDCARD}"/etc/resolv.conf
|
||||||
echo "nameserver $NAMESERVER" >> $SDCARD/etc/resolv.conf
|
echo "nameserver $NAMESERVER" >> "${SDCARD}"/etc/resolv.conf
|
||||||
|
|
||||||
# stage: make rootfs cache archive
|
# stage: make rootfs cache archive
|
||||||
display_alert "Ending debootstrap process and preparing cache" "$RELEASE" "info"
|
display_alert "Ending debootstrap process and preparing cache" "$RELEASE" "info"
|
||||||
sync
|
sync
|
||||||
# the only reason to unmount here is compression progress display
|
# the only reason to unmount here is compression progress display
|
||||||
# based on rootfs size calculation
|
# based on rootfs size calculation
|
||||||
umount_chroot "$SDCARD"
|
umount_chroot "${SDCARD}"
|
||||||
|
|
||||||
tar cp --xattrs --directory=$SDCARD/ --exclude='./dev/*' --exclude='./proc/*' --exclude='./run/*' --exclude='./tmp/*' \
|
tar cp --xattrs --directory="${SDCARD}"/ --exclude='./dev/*' --exclude='./proc/*' --exclude='./run/*' --exclude='./tmp/*' \
|
||||||
--exclude='./sys/*' . | pv -p -b -r -s $(du -sb $SDCARD/ | cut -f1) -N "$display_name" | lz4 -c > $cache_fname
|
--exclude='./sys/*' . | pv -p -b -r -s "$(du -sb "${SDCARD}"/ | cut -f1)" -N "$display_name" | lz4 -c > "${cache_fname}"
|
||||||
|
|
||||||
# sign rootfs cache archive that it can be used for web cache once. Internal purposes
|
# sign rootfs cache archive that it can be used for web cache once. Internal purposes
|
||||||
if [[ -n $GPG_PASS ]]; then
|
if [[ -n $GPG_PASS ]]; then
|
||||||
echo $GPG_PASS | gpg --passphrase-fd 0 --armor --detach-sign --pinentry-mode loopback --batch --yes $cache_fname
|
echo "${GPG_PASS}" | gpg --passphrase-fd 0 --armor --detach-sign --pinentry-mode loopback --batch --yes "${cache_fname}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# used for internal purposes. Faster rootfs cache rebuilding
|
# used for internal purposes. Faster rootfs cache rebuilding
|
||||||
if [[ -n "$ROOT_FS_CREATE_ONLY" ]]; then
|
if [[ -n "$ROOT_FS_CREATE_ONLY" ]]; then
|
||||||
[[ $use_tmpfs = yes ]] && umount $SDCARD
|
[[ $use_tmpfs = yes ]] && umount "${SDCARD}"
|
||||||
rm -rf $SDCARD
|
rm -rf "${SDCARD}"
|
||||||
# remove exit trap
|
# remove exit trap
|
||||||
trap - INT TERM EXIT
|
trap - INT TERM EXIT
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mount_chroot "$SDCARD"
|
mount_chroot "${SDCARD}"
|
||||||
} #############################################################################
|
} #############################################################################
|
||||||
|
|
||||||
# prepare_partitions
|
# prepare_partitions
|
||||||
|
@ -375,7 +379,8 @@ prepare_partitions()
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# stage: calculate rootfs size
|
# stage: calculate rootfs size
|
||||||
local rootfs_size=$(du -sm $SDCARD/ | cut -f1) # MiB
|
local rootfs_size
|
||||||
|
rootfs_size=$(du -sm "${SDCARD}"/ | cut -f1) # MiB
|
||||||
display_alert "Current rootfs size" "$rootfs_size MiB" "info"
|
display_alert "Current rootfs size" "$rootfs_size MiB" "info"
|
||||||
if [[ -n $FIXED_IMAGE_SIZE && $FIXED_IMAGE_SIZE =~ ^[0-9]+$ ]]; then
|
if [[ -n $FIXED_IMAGE_SIZE && $FIXED_IMAGE_SIZE =~ ^[0-9]+$ ]]; then
|
||||||
display_alert "Using user-defined image size" "$FIXED_IMAGE_SIZE MiB" "info"
|
display_alert "Using user-defined image size" "$FIXED_IMAGE_SIZE MiB" "info"
|
||||||
|
@ -390,15 +395,18 @@ prepare_partitions()
|
||||||
btrfs)
|
btrfs)
|
||||||
# Used for server images, currently no swap functionality, so disk space
|
# Used for server images, currently no swap functionality, so disk space
|
||||||
# requirements are rather low since rootfs gets filled with compress-force=zlib
|
# requirements are rather low since rootfs gets filled with compress-force=zlib
|
||||||
local sdsize=$(bc -l <<< "scale=0; (($imagesize * 0.8) / 4 + 1) * 4")
|
local sdsize
|
||||||
|
sdsize=$(bc -l <<< "scale=0; (($imagesize * 0.8) / 4 + 1) * 4")
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
# Hardcoded overhead +25% is needed for desktop images,
|
# Hardcoded overhead +25% is needed for desktop images,
|
||||||
# for CLI it could be lower. Align the size up to 4MiB
|
# for CLI it could be lower. Align the size up to 4MiB
|
||||||
if [[ $BUILD_DESKTOP == yes ]]; then
|
if [[ $BUILD_DESKTOP == yes ]]; then
|
||||||
local sdsize=$(bc -l <<< "scale=0; ((($imagesize * 1.30) / 1 + 0) / 4 + 1) * 4")
|
local sdsize
|
||||||
|
sdsize=$(bc -l <<< "scale=0; ((($imagesize * 1.30) / 1 + 0) / 4 + 1) * 4")
|
||||||
else
|
else
|
||||||
local sdsize=$(bc -l <<< "scale=0; ((($imagesize * 1.25) / 1 + 0) / 4 + 1) * 4")
|
local sdsize
|
||||||
|
sdsize=$(bc -l <<< "scale=0; ((($imagesize * 1.25) / 1 + 0) / 4 + 1) * 4")
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -407,7 +415,7 @@ prepare_partitions()
|
||||||
# stage: create blank image
|
# stage: create blank image
|
||||||
display_alert "Creating blank image for rootfs" "$sdsize MiB" "info"
|
display_alert "Creating blank image for rootfs" "$sdsize MiB" "info"
|
||||||
# truncate --size=${sdsize}M ${SDCARD}.raw # sometimes results in fs corruption, revert to previous know to work solution
|
# truncate --size=${sdsize}M ${SDCARD}.raw # sometimes results in fs corruption, revert to previous know to work solution
|
||||||
dd if=/dev/zero bs=1M status=none count=$sdsize | pv -p -b -r -s $(( $sdsize * 1024 * 1024 )) -N "[ .... ] dd" | dd status=none of=${SDCARD}.raw
|
dd if=/dev/zero bs=1M status=none count="${sdsize}" | pv -p -b -r -s $(( $sdsize * 1024 * 1024 )) -N "[ .... ] dd" | dd status=none of="${SDCARD}.raw"
|
||||||
|
|
||||||
# stage: calculate boot partition size
|
# stage: calculate boot partition size
|
||||||
local bootstart=$(($OFFSET * 2048))
|
local bootstart=$(($OFFSET * 2048))
|
||||||
|
@ -416,46 +424,46 @@ prepare_partitions()
|
||||||
|
|
||||||
# stage: create partition table
|
# stage: create partition table
|
||||||
display_alert "Creating partitions" "${bootfs:+/boot: $bootfs }root: $ROOTFS_TYPE" "info"
|
display_alert "Creating partitions" "${bootfs:+/boot: $bootfs }root: $ROOTFS_TYPE" "info"
|
||||||
parted -s ${SDCARD}.raw -- mklabel ${IMAGE_PARTITION_TABLE}
|
parted -s "${SDCARD}.raw" -- mklabel "${IMAGE_PARTITION_TABLE}"
|
||||||
if [[ $ROOTFS_TYPE == nfs ]]; then
|
if [[ $ROOTFS_TYPE == nfs ]]; then
|
||||||
# single /boot partition
|
# single /boot partition
|
||||||
parted -s ${SDCARD}.raw -- mkpart primary ${parttype[$bootfs]} ${bootstart}s 100%
|
parted -s "${SDCARD}.raw" -- mkpart primary ${parttype[$bootfs]} ${bootstart}s 100%
|
||||||
elif [[ $BOOTSIZE == 0 ]]; then
|
elif [[ $BOOTSIZE == 0 ]]; then
|
||||||
# single root partition
|
# single root partition
|
||||||
parted -s ${SDCARD}.raw -- mkpart primary ${parttype[$ROOTFS_TYPE]} ${rootstart}s 100%
|
parted -s "${SDCARD}.raw" -- mkpart primary ${parttype[$ROOTFS_TYPE]} ${rootstart}s 100%
|
||||||
else
|
else
|
||||||
# /boot partition + root partition
|
# /boot partition + root partition
|
||||||
parted -s ${SDCARD}.raw -- mkpart primary ${parttype[$bootfs]} ${bootstart}s ${bootend}s
|
parted -s "${SDCARD}.raw" -- mkpart primary ${parttype[$bootfs]} ${bootstart}s ${bootend}s
|
||||||
parted -s ${SDCARD}.raw -- mkpart primary ${parttype[$ROOTFS_TYPE]} ${rootstart}s 100%
|
parted -s "${SDCARD}.raw" -- mkpart primary ${parttype[$ROOTFS_TYPE]} ${rootstart}s 100%
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# stage: mount image
|
# stage: mount image
|
||||||
# lock access to loop devices
|
# lock access to loop devices
|
||||||
exec {FD}>/var/lock/armbian-debootstrap-losetup
|
exec {FD}>/var/lock/armbian-debootstrap-losetup
|
||||||
flock -x $FD
|
flock -x "${FD}"
|
||||||
|
|
||||||
LOOP=$(losetup -f)
|
LOOP=$(losetup -f)
|
||||||
[[ -z $LOOP ]] && exit_with_error "Unable to find free loop device"
|
[[ -z $LOOP ]] && exit_with_error "Unable to find free loop device"
|
||||||
|
|
||||||
check_loop_device "$LOOP"
|
check_loop_device "${LOOP}"
|
||||||
|
|
||||||
# NOTE: losetup -P option is not available in Trusty
|
# NOTE: losetup -P option is not available in Trusty
|
||||||
losetup $LOOP ${SDCARD}.raw
|
losetup "${LOOP}" "${SDCARD}.raw"
|
||||||
|
|
||||||
# loop device was grabbed here, unlock
|
# loop device was grabbed here, unlock
|
||||||
flock -u $FD
|
flock -u "${FD}"
|
||||||
|
|
||||||
partprobe $LOOP
|
partprobe "${LOOP}"
|
||||||
|
|
||||||
# stage: create fs, mount partitions, create fstab
|
# stage: create fs, mount partitions, create fstab
|
||||||
rm -f $SDCARD/etc/fstab
|
rm -f "${SDCARD}"/etc/fstab
|
||||||
if [[ -n $rootpart ]]; then
|
if [[ -n $rootpart ]]; then
|
||||||
local rootdevice="${LOOP}p${rootpart}"
|
local rootdevice="${LOOP}p${rootpart}"
|
||||||
|
|
||||||
if [[ $CRYPTROOT_ENABLE == yes ]]; then
|
if [[ $CRYPTROOT_ENABLE == yes ]]; then
|
||||||
display_alert "Encrypting root partition with LUKS..." "cryptsetup luksFormat $rootdevice" ""
|
display_alert "Encrypting root partition with LUKS..." "cryptsetup luksFormat $rootdevice" ""
|
||||||
echo -n $CRYPTROOT_PASSPHRASE | cryptsetup luksFormat $CRYPTROOT_PARAMETERS $rootdevice -
|
echo -n "${CRYPTROOT_PASSPHRASE}" | cryptsetup luksFormat $CRYPTROOT_PARAMETERS $rootdevice -
|
||||||
echo -n $CRYPTROOT_PASSPHRASE | cryptsetup luksOpen $rootdevice $ROOT_MAPPER -
|
echo -n "${CRYPTROOT_PASSPHRASE}" | cryptsetup luksOpen $rootdevice $ROOT_MAPPER -
|
||||||
display_alert "Root partition encryption complete." "" "ext"
|
display_alert "Root partition encryption complete." "" "ext"
|
||||||
# TODO: pass /dev/mapper to Docker
|
# TODO: pass /dev/mapper to Docker
|
||||||
rootdevice=/dev/mapper/$ROOT_MAPPER # used by `mkfs` and `mount` commands
|
rootdevice=/dev/mapper/$ROOT_MAPPER # used by `mkfs` and `mount` commands
|
||||||
|
@ -466,67 +474,67 @@ prepare_partitions()
|
||||||
mkfs.${mkfs[$ROOTFS_TYPE]} ${mkopts[$ROOTFS_TYPE]} $rootdevice
|
mkfs.${mkfs[$ROOTFS_TYPE]} ${mkopts[$ROOTFS_TYPE]} $rootdevice
|
||||||
[[ $ROOTFS_TYPE == ext4 ]] && tune2fs -o journal_data_writeback $rootdevice > /dev/null
|
[[ $ROOTFS_TYPE == ext4 ]] && tune2fs -o journal_data_writeback $rootdevice > /dev/null
|
||||||
[[ $ROOTFS_TYPE == btrfs ]] && local fscreateopt="-o compress-force=zlib"
|
[[ $ROOTFS_TYPE == btrfs ]] && local fscreateopt="-o compress-force=zlib"
|
||||||
mount ${fscreateopt} $rootdevice $MOUNT/
|
mount "${fscreateopt}" "${rootdevice}" "${MOUNT}"/
|
||||||
# create fstab (and crypttab) entry
|
# create fstab (and crypttab) entry
|
||||||
if [[ $CRYPTROOT_ENABLE == yes ]]; then
|
if [[ $CRYPTROOT_ENABLE == yes ]]; then
|
||||||
# map the LUKS container partition via its UUID to be the 'cryptroot' device
|
# map the LUKS container partition via its UUID to be the 'cryptroot' device
|
||||||
echo "$ROOT_MAPPER UUID=$(blkid -s UUID -o value ${LOOP}p${rootpart}) none luks" >> $SDCARD/etc/crypttab
|
echo "$ROOT_MAPPER UUID=$(blkid -s UUID -o value "${LOOP}p${rootpart}") none luks" >> "${SDCARD}"/etc/crypttab
|
||||||
local rootfs=$rootdevice # used in fstab
|
local rootfs=$rootdevice # used in fstab
|
||||||
else
|
else
|
||||||
local rootfs="UUID=$(blkid -s UUID -o value $rootdevice)"
|
local rootfs="UUID=$(blkid -s UUID -o value "${rootdevice}")"
|
||||||
fi
|
fi
|
||||||
echo "$rootfs / ${mkfs[$ROOTFS_TYPE]} defaults,noatime,nodiratime${mountopts[$ROOTFS_TYPE]} 0 1" >> $SDCARD/etc/fstab
|
echo "$rootfs / ${mkfs[$ROOTFS_TYPE]} defaults,noatime,nodiratime${mountopts[$ROOTFS_TYPE]} 0 1" >> "${SDCARD}"/etc/fstab
|
||||||
fi
|
fi
|
||||||
if [[ -n $bootpart ]]; then
|
if [[ -n $bootpart ]]; then
|
||||||
display_alert "Creating /boot" "$bootfs"
|
display_alert "Creating /boot" "$bootfs"
|
||||||
check_loop_device "${LOOP}p${bootpart}"
|
check_loop_device "${LOOP}p${bootpart}"
|
||||||
mkfs.${mkfs[$bootfs]} ${mkopts[$bootfs]} ${LOOP}p${bootpart}
|
mkfs."${mkfs[$bootfs]}" "${mkopts[$bootfs]}" "${LOOP}p${bootpart}"
|
||||||
mkdir -p $MOUNT/boot/
|
mkdir -p "${MOUNT}"/boot/
|
||||||
mount ${LOOP}p${bootpart} $MOUNT/boot/
|
mount "${LOOP}p${bootpart}" "${MOUNT}"/boot/
|
||||||
echo "UUID=$(blkid -s UUID -o value ${LOOP}p${bootpart}) /boot ${mkfs[$bootfs]} defaults${mountopts[$bootfs]} 0 2" >> $SDCARD/etc/fstab
|
echo "UUID="$(blkid -s UUID -o value "${LOOP}p${bootpart}")" /boot ${mkfs[$bootfs]} defaults${mountopts[$bootfs]} 0 2" >> "${SDCARD}"/etc/fstab
|
||||||
fi
|
fi
|
||||||
[[ $ROOTFS_TYPE == nfs ]] && echo "/dev/nfs / nfs defaults 0 0" >> $SDCARD/etc/fstab
|
[[ $ROOTFS_TYPE == nfs ]] && echo "/dev/nfs / nfs defaults 0 0" >> "${SDCARD}"/etc/fstab
|
||||||
echo "tmpfs /tmp tmpfs defaults,nosuid 0 0" >> $SDCARD/etc/fstab
|
echo "tmpfs /tmp tmpfs defaults,nosuid 0 0" >> "${SDCARD}"/etc/fstab
|
||||||
|
|
||||||
# stage: adjust boot script or boot environment
|
# stage: adjust boot script or boot environment
|
||||||
if [[ -f $SDCARD/boot/armbianEnv.txt ]]; then
|
if [[ -f $SDCARD/boot/armbianEnv.txt ]]; then
|
||||||
if [[ $CRYPTROOT_ENABLE == yes ]]; then
|
if [[ $CRYPTROOT_ENABLE == yes ]]; then
|
||||||
echo "rootdev=$rootdevice cryptdevice=UUID=$(blkid -s UUID -o value ${LOOP}p${rootpart}):$ROOT_MAPPER" >> $SDCARD/boot/armbianEnv.txt
|
echo "rootdev=$rootdevice cryptdevice=UUID=$(blkid -s UUID -o value ${LOOP}p${rootpart}):$ROOT_MAPPER" >> "${SDCARD}"/boot/armbianEnv.txt
|
||||||
else
|
else
|
||||||
echo "rootdev=$rootfs" >> $SDCARD/boot/armbianEnv.txt
|
echo "rootdev=$rootfs" >> "${SDCARD}"/boot/armbianEnv.txt
|
||||||
fi
|
fi
|
||||||
echo "rootfstype=$ROOTFS_TYPE" >> $SDCARD/boot/armbianEnv.txt
|
echo "rootfstype=$ROOTFS_TYPE" >> "${SDCARD}"/boot/armbianEnv.txt
|
||||||
elif [[ $rootpart != 1 ]]; then
|
elif [[ $rootpart != 1 ]]; then
|
||||||
local bootscript_dst=${BOOTSCRIPT##*:}
|
local bootscript_dst=${BOOTSCRIPT##*:}
|
||||||
sed -i 's/mmcblk0p1/mmcblk0p2/' $SDCARD/boot/$bootscript_dst
|
sed -i 's/mmcblk0p1/mmcblk0p2/' "${SDCARD}/boot/${bootscript_dst}"
|
||||||
sed -i -e "s/rootfstype=ext4/rootfstype=$ROOTFS_TYPE/" \
|
sed -i -e "s/rootfstype=ext4/rootfstype=$ROOTFS_TYPE/" \
|
||||||
-e "s/rootfstype \"ext4\"/rootfstype \"$ROOTFS_TYPE\"/" $SDCARD/boot/$bootscript_dst
|
-e "s/rootfstype \"ext4\"/rootfstype \"$ROOTFS_TYPE\"/" "${SDCARD}/boot/${bootscript_dst}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if we have boot.ini = remove armbianEnv.txt and add UUID there if enabled
|
# if we have boot.ini = remove armbianEnv.txt and add UUID there if enabled
|
||||||
if [[ -f $SDCARD/boot/boot.ini ]]; then
|
if [[ -f $SDCARD/boot/boot.ini ]]; then
|
||||||
sed -i -e "s/rootfstype \"ext4\"/rootfstype \"$ROOTFS_TYPE\"/" $SDCARD/boot/boot.ini
|
sed -i -e "s/rootfstype \"ext4\"/rootfstype \"$ROOTFS_TYPE\"/" "${SDCARD}"/boot/boot.ini
|
||||||
if [[ $CRYPTROOT_ENABLE == yes ]]; then
|
if [[ $CRYPTROOT_ENABLE == yes ]]; then
|
||||||
local rootpart="UUID=$(blkid -s UUID -o value ${LOOP}p${rootpart})"
|
local rootpart="UUID=$(blkid -s UUID -o value ${LOOP}p${rootpart})"
|
||||||
sed -i 's/^setenv rootdev .*/setenv rootdev "\/dev\/mapper\/'$ROOT_MAPPER' cryptdevice='$rootpart':'$ROOT_MAPPER'"/' $SDCARD/boot/boot.ini
|
sed -i 's/^setenv rootdev .*/setenv rootdev "\/dev\/mapper\/'$ROOT_MAPPER' cryptdevice='$rootpart':'$ROOT_MAPPER'"/' "${SDCARD}"/boot/boot.ini
|
||||||
else
|
else
|
||||||
sed -i 's/^setenv rootdev .*/setenv rootdev "'$rootfs'"/' $SDCARD/boot/boot.ini
|
sed -i 's/^setenv rootdev .*/setenv rootdev "'$rootfs'"/' "${SDCARD}"/boot/boot.ini
|
||||||
fi
|
fi
|
||||||
[[ -f $SDCARD/boot/armbianEnv.txt ]] && rm $SDCARD/boot/armbianEnv.txt
|
[[ -f $SDCARD/boot/armbianEnv.txt ]] && rm "${SDCARD}"/boot/armbianEnv.txt
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if we have a headless device, set console to DEFAULT_CONSOLE
|
# if we have a headless device, set console to DEFAULT_CONSOLE
|
||||||
if [[ -n $DEFAULT_CONSOLE && -f $SDCARD/boot/armbianEnv.txt ]]; then
|
if [[ -n $DEFAULT_CONSOLE && -f $SDCARD/boot/armbianEnv.txt ]]; then
|
||||||
if grep -lq "^console=" $SDCARD/boot/armbianEnv.txt; then
|
if grep -lq "^console=" "${SDCARD}"/boot/armbianEnv.txt; then
|
||||||
sed -i "s/console=.*/console=$DEFAULT_CONSOLE/" $SDCARD/boot/armbianEnv.txt
|
sed -i "s/console=.*/console=$DEFAULT_CONSOLE/" "${SDCARD}"/boot/armbianEnv.txt
|
||||||
else
|
else
|
||||||
echo "console=$DEFAULT_CONSOLE" >> $SDCARD/boot/armbianEnv.txt
|
echo "console=$DEFAULT_CONSOLE" >> "${SDCARD}"/boot/armbianEnv.txt
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# recompile .cmd to .scr if boot.cmd exists
|
# recompile .cmd to .scr if boot.cmd exists
|
||||||
[[ -f $SDCARD/boot/boot.cmd ]] && \
|
[[ -f $SDCARD/boot/boot.cmd ]] && \
|
||||||
mkimage -C none -A arm -T script -d $SDCARD/boot/boot.cmd $SDCARD/boot/boot.scr > /dev/null 2>&1
|
mkimage -C none -A arm -T script -d "${SDCARD}"/boot/boot.cmd "${SDCARD}"/boot/boot.scr > /dev/null 2>&1
|
||||||
|
|
||||||
} #############################################################################
|
} #############################################################################
|
||||||
|
|
||||||
|
@ -549,14 +557,14 @@ update_initramfs()
|
||||||
local chroot_target=$1
|
local chroot_target=$1
|
||||||
update_initramfs_cmd="update-initramfs -uv -k ${VER}-${LINUXFAMILY}"
|
update_initramfs_cmd="update-initramfs -uv -k ${VER}-${LINUXFAMILY}"
|
||||||
display_alert "Updating initramfs..." "$update_initramfs_cmd" ""
|
display_alert "Updating initramfs..." "$update_initramfs_cmd" ""
|
||||||
cp /usr/bin/$QEMU_BINARY $chroot_target/usr/bin/
|
cp "/usr/bin/${QEMU_BINARY}" "${chroot_target}/usr/bin/"
|
||||||
mount_chroot "$chroot_target/"
|
mount_chroot "${chroot_target}/"
|
||||||
|
|
||||||
chroot $chroot_target /bin/bash -c "$update_initramfs_cmd" >> $DEST/debug/install.log 2>&1
|
chroot "${chroot_target}" /bin/bash -c "${update_initramfs_cmd}" >> "${DEST}"/debug/install.log 2>&1
|
||||||
display_alert "Updated initramfs." "for details see: $DEST/debug/install.log" "ext"
|
display_alert "Updated initramfs." "for details see: ${DEST}/debug/install.log" "ext"
|
||||||
|
|
||||||
umount_chroot "$chroot_target/"
|
umount_chroot "${chroot_target}/"
|
||||||
rm $chroot_target/usr/bin/$QEMU_BINARY
|
rm "${chroot_target}/usr/bin/${QEMU_BINARY}"
|
||||||
|
|
||||||
} #############################################################################
|
} #############################################################################
|
||||||
|
|
||||||
|
@ -575,41 +583,41 @@ create_image()
|
||||||
if [[ $ROOTFS_TYPE != nfs ]]; then
|
if [[ $ROOTFS_TYPE != nfs ]]; then
|
||||||
display_alert "Copying files to root directory"
|
display_alert "Copying files to root directory"
|
||||||
rsync -aHWXh --exclude="/boot/*" --exclude="/dev/*" --exclude="/proc/*" --exclude="/run/*" --exclude="/tmp/*" \
|
rsync -aHWXh --exclude="/boot/*" --exclude="/dev/*" --exclude="/proc/*" --exclude="/run/*" --exclude="/tmp/*" \
|
||||||
--exclude="/sys/*" --info=progress2,stats1 $SDCARD/ $MOUNT/
|
--exclude="/sys/*" --info=progress2,stats1 "${SDCARD}"/ "${MOUNT}"/
|
||||||
else
|
else
|
||||||
display_alert "Creating rootfs archive" "rootfs.tgz" "info"
|
display_alert "Creating rootfs archive" "rootfs.tgz" "info"
|
||||||
tar cp --xattrs --directory=$SDCARD/ --exclude='./boot/*' --exclude='./dev/*' --exclude='./proc/*' --exclude='./run/*' --exclude='./tmp/*' \
|
tar cp --xattrs --directory="${SDCARD}"/ --exclude='./boot/*' --exclude='./dev/*' --exclude='./proc/*' --exclude='./run/*' --exclude='./tmp/*' \
|
||||||
--exclude='./sys/*' . | pv -p -b -r -s $(du -sb $SDCARD/ | cut -f1) -N "rootfs.tgz" | gzip -c > $DEST/images/${version}-rootfs.tgz
|
--exclude='./sys/*' . | pv -p -b -r -s "$(du -sb "${SDCARD}/" | cut -f1)" -N "rootfs.tgz" | gzip -c > "${DEST}/images/${version}-rootfs.tgz"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# stage: rsync /boot
|
# stage: rsync /boot
|
||||||
display_alert "Copying files to /boot directory"
|
display_alert "Copying files to /boot directory"
|
||||||
if [[ $(findmnt --target $MOUNT/boot -o FSTYPE -n) == vfat ]]; then
|
if [[ $(findmnt --target "${MOUNT}"/boot -o FSTYPE -n) == vfat ]]; then
|
||||||
# fat32
|
# fat32
|
||||||
rsync -rLtWh --info=progress2,stats1 $SDCARD/boot $MOUNT
|
rsync -rLtWh --info=progress2,stats1 "${SDCARD}/boot" "${MOUNT}"
|
||||||
else
|
else
|
||||||
# ext4
|
# ext4
|
||||||
rsync -aHWXh --info=progress2,stats1 $SDCARD/boot $MOUNT
|
rsync -aHWXh --info=progress2,stats1 "${SDCARD}/boot" "${MOUNT}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# stage: create final initramfs
|
# stage: create final initramfs
|
||||||
update_initramfs $MOUNT
|
update_initramfs "${MOUNT}"
|
||||||
|
|
||||||
# DEBUG: print free space
|
# DEBUG: print free space
|
||||||
display_alert "Free space:" "SD card" "info"
|
display_alert "Free space:" "SD card" "info"
|
||||||
eval 'df -h' ${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/debootstrap.log'}
|
eval 'df -h' ${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/debootstrap.log'}
|
||||||
|
|
||||||
# stage: write u-boot
|
# stage: write u-boot
|
||||||
write_uboot $LOOP
|
write_uboot "${LOOP}"
|
||||||
|
|
||||||
# fix wrong / permissions
|
# fix wrong / permissions
|
||||||
chmod 755 $MOUNT
|
chmod 755 "${MOUNT}"
|
||||||
|
|
||||||
# unmount /boot first, rootfs second, image file last
|
# unmount /boot first, rootfs second, image file last
|
||||||
sync
|
sync
|
||||||
[[ $BOOTSIZE != 0 ]] && umount -l $MOUNT/boot
|
[[ $BOOTSIZE != 0 ]] && umount -l "${MOUNT}"/boot
|
||||||
[[ $ROOTFS_TYPE != nfs ]] && umount -l $MOUNT
|
[[ $ROOTFS_TYPE != nfs ]] && umount -l "${MOUNT}"
|
||||||
[[ $CRYPTROOT_ENABLE == yes ]] && cryptsetup luksClose $ROOT_MAPPER
|
[[ $CRYPTROOT_ENABLE == yes ]] && cryptsetup luksClose "${ROOT_MAPPER}"
|
||||||
|
|
||||||
# to make sure its unmounted
|
# to make sure its unmounted
|
||||||
while grep -Eq '(${MOUNT}|${DESTIMG})' /proc/mounts
|
while grep -Eq '(${MOUNT}|${DESTIMG})' /proc/mounts
|
||||||
|
@ -618,11 +626,11 @@ create_image()
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
|
|
||||||
losetup -d $LOOP
|
losetup -d "${LOOP}"
|
||||||
rm -rf --one-file-system $DESTIMG $MOUNT
|
rm -rf --one-file-system "${DESTIMG}" "${MOUNT}"
|
||||||
|
|
||||||
mkdir -p $DESTIMG
|
mkdir -p "${DESTIMG}"
|
||||||
mv ${SDCARD}.raw $DESTIMG/${version}.img
|
mv "${SDCARD}.raw" "${DESTIMG}/${version}.img"
|
||||||
|
|
||||||
if [[ $BUILD_ALL != yes ]]; then
|
if [[ $BUILD_ALL != yes ]]; then
|
||||||
|
|
||||||
|
@ -634,32 +642,32 @@ create_image()
|
||||||
|
|
||||||
if [[ $COMPRESS_OUTPUTIMAGE == *gz* ]]; then
|
if [[ $COMPRESS_OUTPUTIMAGE == *gz* ]]; then
|
||||||
display_alert "Compressing" "$DEST/images/${version}.img.gz" "info"
|
display_alert "Compressing" "$DEST/images/${version}.img.gz" "info"
|
||||||
pigz -3 < $DESTIMG/${version}.img > $DEST/images/${version}.img.gz
|
pigz -3 < "${DESTIMG}/${version}.img" > "$DEST/images/${version}.img.gz"
|
||||||
compression_type=".gz"
|
compression_type=".gz"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $COMPRESS_OUTPUTIMAGE == *xz* ]]; then
|
if [[ $COMPRESS_OUTPUTIMAGE == *xz* ]]; then
|
||||||
display_alert "Compressing" "$DEST/images/${version}.img.xz" "info"
|
display_alert "Compressing" "$DEST/images/${version}.img.xz" "info"
|
||||||
pixz -3 < $DESTIMG/${version}.img > $DEST/images/${version}.img.xz
|
pixz -3 < "${DESTIMG}/${version}.img" > "${DEST}/images/${version}.img.xz"
|
||||||
compression_type=".xz"
|
compression_type=".xz"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $COMPRESS_OUTPUTIMAGE == *img* || $COMPRESS_OUTPUTIMAGE == *7z* ]]; then
|
if [[ $COMPRESS_OUTPUTIMAGE == *img* || $COMPRESS_OUTPUTIMAGE == *7z* ]]; then
|
||||||
mv $DESTIMG/${version}.img $DEST/images/${version}.img || exit 1
|
mv "${DESTIMG}/${version}.img" "${DEST}/images/${version}.img" || exit 1
|
||||||
compression_type=""
|
compression_type=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $COMPRESS_OUTPUTIMAGE == *sha* ]]; then
|
if [[ $COMPRESS_OUTPUTIMAGE == *sha* ]]; then
|
||||||
cd $DEST/images
|
cd "${DEST}"/images || exit
|
||||||
display_alert "SHA256 calculating" "${version}.img${compression_type}" "info"
|
display_alert "SHA256 calculating" "${version}.img${compression_type}" "info"
|
||||||
sha256sum -b ${version}.img${compression_type} > ${version}.img${compression_type}.sha
|
sha256sum -b "${version}.img${compression_type}" > "${version}.img${compression_type}.sha"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $COMPRESS_OUTPUTIMAGE == *gpg* ]]; then
|
if [[ $COMPRESS_OUTPUTIMAGE == *gpg* ]]; then
|
||||||
cd $DEST/images
|
cd "${DEST}"/images || exit
|
||||||
if [[ -n $GPG_PASS ]]; then
|
if [[ -n $GPG_PASS ]]; then
|
||||||
display_alert "GPG signing" "${version}.img${compression_type}" "info"
|
display_alert "GPG signing" "${version}.img${compression_type}" "info"
|
||||||
echo $GPG_PASS | gpg --passphrase-fd 0 --armor --detach-sign --pinentry-mode loopback --batch --yes $DEST/images/${version}.img${compression_type} || exit 1
|
echo "${GPG_PASS}" | gpg --passphrase-fd 0 --armor --detach-sign --pinentry-mode loopback --batch --yes "${DEST}/images/${version}.img${compression_type}" || exit 1
|
||||||
else
|
else
|
||||||
display_alert "GPG signing skipped - no GPG_PASS" "${version}.img" "wrn"
|
display_alert "GPG signing skipped - no GPG_PASS" "${version}.img" "wrn"
|
||||||
fi
|
fi
|
||||||
|
@ -670,13 +678,13 @@ create_image()
|
||||||
if [[ $COMPRESS_OUTPUTIMAGE == *7z* ]]; then
|
if [[ $COMPRESS_OUTPUTIMAGE == *7z* ]]; then
|
||||||
display_alert "Compressing" "$DEST/images/${version}.7z" "info"
|
display_alert "Compressing" "$DEST/images/${version}.7z" "info"
|
||||||
7za a -t7z -bd -m0=lzma2 -mx=3 -mfb=64 -md=32m -ms=on \
|
7za a -t7z -bd -m0=lzma2 -mx=3 -mfb=64 -md=32m -ms=on \
|
||||||
$DEST/images/${version}.7z ${version}.key ${version}.img* >/dev/null 2>&1
|
"${DEST}/images/${version}.7z" "${version}.key" "${version}".img* >/dev/null 2>&1
|
||||||
find $DEST/images/ -type \
|
find "${DEST}"/images/ -type \
|
||||||
f \( -name "${version}.img" -o -name "${version}.img.asc" -o -name "${version}.img.txt" -o -name "${version}.img.sha" \) -print0 \
|
f \( -name "${version}.img" -o -name "${version}.img.asc" -o -name "${version}.img.txt" -o -name "${version}.img.sha" \) -print0 \
|
||||||
| xargs -0 rm >/dev/null 2>&1
|
| xargs -0 rm >/dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf $DESTIMG
|
rm -rf "${DESTIMG}"
|
||||||
fi
|
fi
|
||||||
display_alert "Done building" "$DEST/images/${version}.img" "info"
|
display_alert "Done building" "$DEST/images/${version}.img" "info"
|
||||||
|
|
||||||
|
@ -688,25 +696,28 @@ create_image()
|
||||||
|
|
||||||
# make sha256sum if it does not exists. we need it for comparisson
|
# make sha256sum if it does not exists. we need it for comparisson
|
||||||
if [[ -f "$DEST/images/${version}".img.sha ]]; then
|
if [[ -f "$DEST/images/${version}".img.sha ]]; then
|
||||||
local ifsha=$(cat $DEST/images/${version}.img.sha | awk '{print $1}')
|
local ifsha
|
||||||
|
ifsha=$(cat "${DEST}/images/${version}.img.sha" | awk '{print $1}')
|
||||||
else
|
else
|
||||||
local ifsha=$(sha256sum -b "$DEST/images/${version}".img | awk '{print $1}')
|
local ifsha
|
||||||
|
ifsha=$(sha256sum -b "${DEST}/images/${version}.img" | awk '{print $1}')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
display_alert "Writing image" "$CARD_DEVICE ${readsha}" "info"
|
display_alert "Writing image" "$CARD_DEVICE ${readsha}" "info"
|
||||||
|
|
||||||
# write to SD card
|
# write to SD card
|
||||||
pv -p -b -r -c -N "[ .... ] dd" $DEST/images/${version}.img | dd of=$CARD_DEVICE bs=1M iflag=fullblock oflag=direct status=none
|
pv -p -b -r -c -N "[ .... ] dd" "${DEST}/images/${version}.img" | dd of="${CARD_DEVICE}" bs=1M iflag=fullblock oflag=direct status=none
|
||||||
|
|
||||||
# read and compare
|
# read and compare
|
||||||
display_alert "Verifying. Please wait!"
|
display_alert "Verifying. Please wait!"
|
||||||
local ofsha=$(dd if=$CARD_DEVICE count=$(du -b $DEST/images/${version}.img | cut -f1) status=none iflag=count_bytes oflag=direct | sha256sum | awk '{print $1}')
|
local ofsha
|
||||||
if [[ $ifsha == $ofsha ]]; then
|
ofsha=$(dd if="${CARD_DEVICE}" count="$(du -b "${DEST}/images/${version}.img" | cut -f1)" status=none iflag=count_bytes oflag=direct | sha256sum | awk '{print $1}')
|
||||||
|
if [[ "${ifsha}" == "${ofsha}" ]]; then
|
||||||
display_alert "Writing verified" "${version}.img" "info"
|
display_alert "Writing verified" "${version}.img" "info"
|
||||||
else
|
else
|
||||||
display_alert "Writing failed" "${version}.img" "err"
|
display_alert "Writing failed" "${version}.img" "err"
|
||||||
fi
|
fi
|
||||||
elif [[ `systemd-detect-virt` == 'docker' && -n $CARD_DEVICE ]]; then
|
elif [[ $(systemd-detect-virt) == 'docker' && -n $CARD_DEVICE ]]; then
|
||||||
# display warning when we want to write sd card under Docker
|
# display warning when we want to write sd card under Docker
|
||||||
display_alert "Can't write to $CARD_DEVICE" "Enable docker privileged mode in config-docker.conf" "wrn"
|
display_alert "Can't write to $CARD_DEVICE" "Enable docker privileged mode in config-docker.conf" "wrn"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue