2015-12-02 20:33:32 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com
|
|
|
|
#
|
|
|
|
# This file is licensed under the terms of the GNU General Public
|
|
|
|
# License version 2. This program is licensed "as is" without any
|
|
|
|
# warranty of any kind, whether express or implied.
|
|
|
|
#
|
|
|
|
# This file is a part of tool chain https://github.com/igorpecovnik/lib
|
|
|
|
#
|
|
|
|
|
2015-12-18 12:22:42 +03:00
|
|
|
# Functions:
|
|
|
|
# cleaning
|
2016-03-05 21:26:01 +03:00
|
|
|
# exit_with_error
|
2016-03-04 00:00:37 +03:00
|
|
|
# get_package_list_hash
|
2015-12-18 12:22:42 +03:00
|
|
|
# fetch_from_github
|
|
|
|
# display_alert
|
|
|
|
# grab_version
|
|
|
|
# fingerprint_image
|
|
|
|
# addtorepo
|
|
|
|
# prepare_host
|
2015-12-02 20:33:32 +01:00
|
|
|
|
2015-12-10 21:21:52 +03:00
|
|
|
# cleaning <target>
|
|
|
|
#
|
|
|
|
# target: what to clean
|
|
|
|
# "make" - "make clean" for selected kernel and u-boot
|
|
|
|
# "debs" - delete output/debs
|
|
|
|
# "cache" - delete output/cache
|
|
|
|
# "images" - delete output/images
|
|
|
|
# "sources" - delete output/sources
|
|
|
|
#
|
2015-12-02 20:33:32 +01:00
|
|
|
cleaning()
|
|
|
|
{
|
2015-12-10 21:21:52 +03:00
|
|
|
case $1 in
|
2016-05-05 16:49:46 +03:00
|
|
|
make) # clean u-boot and kernel sources
|
2016-05-23 17:39:51 +02:00
|
|
|
[[ -d $SOURCES/$BOOTSOURCEDIR ]] && display_alert "Cleaning" "$BOOTSOURCEDIR" "info" && cd $SOURCES/$BOOTSOURCEDIR && eval ${UBOOT_TOOLCHAIN:+env PATH=$UBOOT_TOOLCHAIN:$PATH} 'make clean CROSS_COMPILE="$CCACHE $UBOOT_COMPILER" >/dev/null 2>/dev/null'
|
|
|
|
[[ -d $SOURCES/$LINUXSOURCEDIR ]] && display_alert "Cleaning" "$LINUXSOURCEDIR" "info" && cd $SOURCES/$LINUXSOURCEDIR && eval ${UBOOT_TOOLCHAIN:+env PATH=$UBOOT_TOOLCHAIN:$PATH} 'make clean CROSS_COMPILE="$CCACHE $UBOOT_COMPILER" >/dev/null 2>/dev/null'
|
2015-12-10 21:21:52 +03:00
|
|
|
;;
|
2015-12-02 20:33:32 +01:00
|
|
|
|
2016-05-05 16:49:46 +03:00
|
|
|
debs) # delete output/debs for current branch and family
|
|
|
|
if [[ -d $DEST/debs ]]; then
|
2016-03-14 23:39:21 +03:00
|
|
|
display_alert "Cleaning $DEST/debs for" "$BOARD $BRANCH" "info"
|
|
|
|
# easier than dealing with variable expansion and escaping dashes in file names
|
|
|
|
find $DEST/debs -name '*.deb' | grep -E "${CHOSEN_KERNEL/image/.*}|$CHOSEN_UBOOT" | xargs rm -f
|
2016-03-23 20:58:58 +01:00
|
|
|
[[ -n $RELEASE ]] && rm -f $DEST/debs/$RELEASE/${CHOSEN_ROOTFS}_${REVISION}_${ARCH}.deb
|
2016-03-14 23:39:21 +03:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
2016-05-05 16:49:46 +03:00
|
|
|
alldebs) # delete output/debs
|
|
|
|
[[ -d $DEST/debs ]] && display_alert "Cleaning" "$DEST/debs" "info" && rm -rf $DEST/debs/*
|
2015-12-10 21:21:52 +03:00
|
|
|
;;
|
2015-12-02 20:33:32 +01:00
|
|
|
|
2016-05-05 16:49:46 +03:00
|
|
|
cache) # delete output/cache
|
|
|
|
[[ -d $CACHEDIR ]] && display_alert "Cleaning" "$CACHEDIR" "info" && find $CACHEDIR/ -type f -delete
|
2015-12-10 21:21:52 +03:00
|
|
|
;;
|
2015-12-07 14:32:25 +01:00
|
|
|
|
2016-05-05 16:49:46 +03:00
|
|
|
images) # delete output/images
|
|
|
|
[[ -d $DEST/images ]] && display_alert "Cleaning" "$DEST/images" "info" && rm -rf $DEST/images/*
|
2015-12-10 21:21:52 +03:00
|
|
|
;;
|
|
|
|
|
2016-05-05 16:49:46 +03:00
|
|
|
sources) # delete output/sources
|
|
|
|
[[ -d $SOURCES ]] && display_alert "Cleaning" "$SOURCES" "info" && rm -rf $SOURCES/*
|
2015-12-10 21:21:52 +03:00
|
|
|
;;
|
|
|
|
|
|
|
|
*) # unknown
|
|
|
|
display_alert "Cleaning: unrecognized option" "$1" "wrn"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
2015-12-07 14:32:25 +01:00
|
|
|
|
2016-03-05 21:26:01 +03:00
|
|
|
# exit_with_error <message> <highlight>
|
|
|
|
#
|
|
|
|
# a way to terminate build process
|
|
|
|
# with verbose error message
|
|
|
|
#
|
|
|
|
|
|
|
|
exit_with_error()
|
|
|
|
{
|
|
|
|
local _file=$(basename ${BASH_SOURCE[1]})
|
|
|
|
local _line=${BASH_LINENO[0]}
|
|
|
|
local _function=${FUNCNAME[1]}
|
|
|
|
local _description=$1
|
|
|
|
local _highlight=$2
|
|
|
|
|
|
|
|
display_alert "ERROR in function $_function" "$_file:$_line" "err"
|
|
|
|
display_alert "$_description" "$_highlight" "err"
|
|
|
|
display_alert "Process terminated" "" "info"
|
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
2016-03-04 00:00:37 +03:00
|
|
|
# get_package_list_hash <package_list>
|
|
|
|
#
|
|
|
|
# outputs md5hash for space-separated <package_list>
|
|
|
|
# for rootfs cache
|
|
|
|
|
|
|
|
get_package_list_hash()
|
|
|
|
{
|
|
|
|
echo $(printf '%s\n' $PACKAGE_LIST | sort -u | md5sum | cut -d' ' -f 1)
|
|
|
|
}
|
|
|
|
|
2015-12-08 19:25:30 +01:00
|
|
|
# fetch_from_github <URL> <directory> <tag> <tagsintosubdir>
|
|
|
|
#
|
|
|
|
# parameters:
|
|
|
|
# <URL>: Git repository
|
|
|
|
# <directory>: where to place under SOURCES
|
|
|
|
# <device>: cubieboard, cubieboard2, cubietruck, ...
|
|
|
|
# <description>: additional description text
|
|
|
|
# <tagintosubdir>: boolean
|
2015-12-07 14:32:25 +01:00
|
|
|
|
2015-12-08 19:25:30 +01:00
|
|
|
fetch_from_github (){
|
|
|
|
GITHUBSUBDIR=$3
|
2016-05-23 17:39:51 +02:00
|
|
|
local githuburl=$1
|
2015-12-08 19:25:30 +01:00
|
|
|
[[ -z "$3" ]] && GITHUBSUBDIR="branchless"
|
|
|
|
[[ -z "$4" ]] && GITHUBSUBDIR="" # only kernel and u-boot have subdirs for tags
|
2016-03-17 20:16:26 +01:00
|
|
|
if [ -d "$SOURCES/$2/$GITHUBSUBDIR" ]; then
|
2015-12-08 19:25:30 +01:00
|
|
|
cd $SOURCES/$2/$GITHUBSUBDIR
|
2016-05-23 17:39:51 +02:00
|
|
|
git checkout -q $FORCE $3 2> /dev/null
|
|
|
|
local bar_1=$(git ls-remote $githuburl --tags $GITHUBSUBDIR* | sed -n '1p' | cut -f1 | cut -c1-7)
|
|
|
|
local bar_2=$(git ls-remote $githuburl --tags $GITHUBSUBDIR* | sed -n '2p' | cut -f1 | cut -c1-7)
|
|
|
|
local bar_3=$(git ls-remote $githuburl --tags HEAD * | sed -n '1p' | cut -f1 | cut -c1-7)
|
|
|
|
local localbar="$(git rev-parse HEAD | cut -c1-7)"
|
|
|
|
|
|
|
|
# debug
|
|
|
|
# echo "git ls-remote $githuburl --tags $GITHUBSUBDIR* | sed -n '1p' | cut -f1"
|
|
|
|
# echo "git ls-remote $githuburl --tags $GITHUBSUBDIR* | sed -n '2p' | cut -f1"
|
|
|
|
# echo "git ls-remote $githuburl --tags HEAD * | sed -n '1p' | cut -f1"
|
|
|
|
# echo "$3 - $bar_1 || $bar_2 = $localbar"
|
|
|
|
# echo "$3 - $bar_3 = $localbar"
|
|
|
|
|
|
|
|
# ===>> workaround >> [[ $bar_1 == "" && $bar_2 == "" ]]
|
|
|
|
|
|
|
|
if [[ "$3" != "" ]] && [[ "$bar_1" == "$localbar" || "$bar_2" == "$localbar" ]] || [[ "$3" == "" && "$bar_3" == "$localbar" ]] || [[ $bar_1 == "" && $bar_2 == "" ]]; then
|
2016-05-21 17:27:41 +02:00
|
|
|
display_alert "... you have latest sources" "$2 $3" "info"
|
|
|
|
else
|
|
|
|
display_alert "... your sources are outdated - creating new shallow clone" "$2 $3" "info"
|
2016-05-23 17:39:51 +02:00
|
|
|
if [[ -z "$GITHUBSUBDIR" ]]; then
|
|
|
|
rm -rf $SOURCES/$2".old"
|
|
|
|
mv $SOURCES/$2 $SOURCES/$2".old"
|
|
|
|
else
|
|
|
|
rm -rf $SOURCES/$2/$GITHUBSUBDIR".old"
|
|
|
|
mv $SOURCES/$2/$GITHUBSUBDIR $SOURCES/$2/$GITHUBSUBDIR".old"
|
|
|
|
fi
|
|
|
|
|
2016-05-21 17:27:41 +02:00
|
|
|
if [[ -n $3 && -n "$(git ls-remote $1 | grep "$tag")" ]]; then
|
|
|
|
git clone -n $1 $SOURCES/$2/$GITHUBSUBDIR -b $3 --depth 1 || git clone -n $1 $SOURCES/$2/$GITHUBSUBDIR -b $3
|
|
|
|
else
|
|
|
|
git clone -n $1 $SOURCES/$2/$GITHUBSUBDIR --depth 1
|
|
|
|
fi
|
|
|
|
cd $SOURCES/$2/$GITHUBSUBDIR
|
|
|
|
git checkout -q
|
|
|
|
fi
|
2016-03-17 20:16:26 +01:00
|
|
|
else
|
|
|
|
if [[ -n $3 && -n "$(git ls-remote $1 | grep "$tag")" ]]; then
|
|
|
|
display_alert "... creating a shallow clone" "$2 $3" "info"
|
2016-01-06 12:58:06 +01:00
|
|
|
# Toradex git's doesn't support shallow clone. Need different solution than this.
|
2016-03-17 20:16:26 +01:00
|
|
|
git clone -n $1 $SOURCES/$2/$GITHUBSUBDIR -b $3 --depth 1 || git clone -n $1 $SOURCES/$2/$GITHUBSUBDIR -b $3
|
|
|
|
cd $SOURCES/$2/$GITHUBSUBDIR
|
2015-12-08 19:25:30 +01:00
|
|
|
git checkout -q $3
|
2015-12-07 14:32:25 +01:00
|
|
|
else
|
2016-03-17 20:16:26 +01:00
|
|
|
display_alert "... creating a shallow clone" "$2" "info"
|
2015-12-08 19:25:30 +01:00
|
|
|
git clone -n $1 $SOURCES/$2/$GITHUBSUBDIR --depth 1
|
|
|
|
cd $SOURCES/$2/$GITHUBSUBDIR
|
|
|
|
git checkout -q
|
|
|
|
fi
|
2016-03-17 20:16:26 +01:00
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
fi
|
2015-12-07 14:32:25 +01:00
|
|
|
cd $SRC
|
2016-03-09 16:24:05 +03:00
|
|
|
if [ $? -ne 0 ]; then
|
2016-03-17 20:16:26 +01:00
|
|
|
exit_with_error "Github download failed" "$1"
|
2016-03-09 16:24:05 +03:00
|
|
|
fi
|
2015-12-02 20:33:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
display_alert()
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Let's have unique way of displaying alerts
|
|
|
|
#--------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
{
|
2015-12-24 19:37:34 +03:00
|
|
|
# log function parameters to install.log
|
|
|
|
echo "Displaying message: $@" >> $DEST/debug/install.log
|
|
|
|
|
2016-05-24 18:12:48 +03:00
|
|
|
[[ -n $2 ]] && local tmp="[\e[0;33m $2 \x1B[0m]"
|
|
|
|
|
|
|
|
case $3 in
|
|
|
|
err)
|
|
|
|
echo -e "[\e[0;31m error \x1B[0m] $1 $tmp"
|
|
|
|
;;
|
|
|
|
|
|
|
|
wrn)
|
|
|
|
echo -e "[\e[0;35m warn \x1B[0m] $1 $tmp"
|
|
|
|
;;
|
|
|
|
|
|
|
|
ext)
|
|
|
|
echo -e "[\e[0;32m o.k. \x1B[0m] \e[1;32m$1\x1B[0m $tmp"
|
|
|
|
;;
|
|
|
|
|
|
|
|
*) # info or empty
|
|
|
|
echo -e "[\e[0;32m o.k. \x1B[0m] $1 $tmp"
|
|
|
|
;;
|
|
|
|
esac
|
2015-12-02 20:33:32 +01:00
|
|
|
}
|
|
|
|
|
2015-12-08 19:25:30 +01:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------------
|
2016-04-18 18:21:43 +03:00
|
|
|
# grab_version <path> <var_name>
|
2015-12-08 19:25:30 +01:00
|
|
|
#
|
|
|
|
# <PATH>: Extract kernel or uboot version from Makefile
|
2016-04-18 18:21:43 +03:00
|
|
|
# <var_name>: write version to this variable
|
2015-12-08 19:25:30 +01:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
grab_version ()
|
|
|
|
{
|
|
|
|
local var=("VERSION" "PATCHLEVEL" "SUBLEVEL" "EXTRAVERSION")
|
2016-04-18 18:21:43 +03:00
|
|
|
local ver=""
|
2015-12-08 19:25:30 +01:00
|
|
|
for dir in "${var[@]}"; do
|
|
|
|
tmp=$(cat $1/Makefile | grep $dir | head -1 | awk '{print $(NF)}' | cut -d '=' -f 2)"#"
|
2016-04-18 18:21:43 +03:00
|
|
|
[[ $tmp != "#" ]] && ver=$ver$tmp
|
2015-12-08 19:25:30 +01:00
|
|
|
done
|
2016-04-18 18:21:43 +03:00
|
|
|
ver=${ver//#/.}; ver=${ver%.}; ver=${ver//.-/-}
|
|
|
|
eval $"$2"="$ver"
|
2015-12-02 20:33:32 +01:00
|
|
|
}
|
|
|
|
|
2016-06-08 18:16:11 +03:00
|
|
|
fingerprint_image()
|
|
|
|
{
|
2015-12-02 20:33:32 +01:00
|
|
|
#--------------------------------------------------------------------------------------------------------------------------------
|
2016-03-17 20:16:26 +01:00
|
|
|
# Saving build summary to the image
|
2015-12-02 20:33:32 +01:00
|
|
|
#--------------------------------------------------------------------------------------------------------------------------------
|
2016-06-08 18:16:11 +03:00
|
|
|
display_alert "Fingerprinting" "$VERSION" "info"
|
|
|
|
cat <<-EOF > $1
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
Title: $VERSION
|
|
|
|
Kernel: Linux $VER
|
|
|
|
Build date: $(date +'%d.%m.%Y')
|
|
|
|
Author: Igor Pecovnik, www.igorpecovnik.com
|
|
|
|
Sources: http://github.com/igorpecovnik/lib
|
|
|
|
Support: http://www.armbian.com, http://forum.armbian.com/
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
$(cat $SRC/lib/LICENSE)
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
EOF
|
2015-12-02 20:33:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
addtorepo ()
|
|
|
|
{
|
|
|
|
# add all deb files to repository
|
|
|
|
# parameter "remove" dumps all and creates new
|
|
|
|
# function: cycle trough distributions
|
2016-05-23 20:07:05 +02:00
|
|
|
DISTROS=("wheezy" "jessie" "trusty" "xenial")
|
2015-12-02 20:33:32 +01:00
|
|
|
IFS=" "
|
|
|
|
j=0
|
|
|
|
while [[ $j -lt ${#DISTROS[@]} ]]
|
|
|
|
do
|
|
|
|
# add each packet to distribution
|
|
|
|
DIS=${DISTROS[$j]}
|
2016-03-17 20:16:26 +01:00
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# let's drop from publish if exits
|
2016-03-17 20:16:26 +01:00
|
|
|
if [ "$(aptly publish list -config=config/aptly.conf -raw | awk '{print $(NF)}' | grep $DIS)" != "" ]; then
|
2015-12-02 20:33:32 +01:00
|
|
|
aptly publish drop -config=config/aptly.conf $DIS > /dev/null 2>&1
|
|
|
|
fi
|
|
|
|
#aptly db cleanup -config=config/aptly.conf
|
|
|
|
|
2016-03-17 20:16:26 +01:00
|
|
|
if [ "$1" == "remove" ]; then
|
2015-12-02 20:33:32 +01:00
|
|
|
# remove repository
|
|
|
|
aptly repo drop -config=config/aptly.conf $DIS > /dev/null 2>&1
|
|
|
|
aptly db cleanup -config=config/aptly.conf > /dev/null 2>&1
|
|
|
|
fi
|
2016-03-17 20:16:26 +01:00
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# create repository if not exist
|
|
|
|
OUT=$(aptly repo list -config=config/aptly.conf -raw | awk '{print $(NF)}' | grep $DIS)
|
|
|
|
if [[ "$OUT" != "$DIS" ]]; then
|
|
|
|
display_alert "Creating section" "$DIS" "info"
|
|
|
|
aptly repo create -config=config/aptly.conf -distribution=$DIS -component=main -comment="Armbian stable" $DIS > /dev/null 2>&1
|
|
|
|
fi
|
2016-03-17 20:16:26 +01:00
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# add all packages
|
|
|
|
aptly repo add -force-replace=true -config=config/aptly.conf $DIS $POT/*.deb
|
2016-03-17 20:16:26 +01:00
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# add all distribution packages
|
|
|
|
if [ -d "$POT/$DIS" ]; then
|
|
|
|
aptly repo add -force-replace=true -config=config/aptly.conf $DIS $POT/$DIS/*.deb
|
|
|
|
fi
|
2016-03-17 20:16:26 +01:00
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
aptly publish -passphrase=$GPG_PASS -force-overwrite=true -config=config/aptly.conf -component="main" --distribution=$DIS repo $DIS > /dev/null 2>&1
|
2016-03-17 20:16:26 +01:00
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
#aptly repo show -config=config/aptly.conf $DIS
|
2016-03-17 20:16:26 +01:00
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
j=$[$j+1]
|
|
|
|
done
|
2015-12-12 18:35:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# prepare_host
|
|
|
|
#
|
|
|
|
# * checks and installs necessary packages
|
|
|
|
# * creates directory structure
|
|
|
|
# * changes system settings
|
|
|
|
#
|
|
|
|
prepare_host() {
|
|
|
|
|
|
|
|
display_alert "Preparing" "host" "info"
|
|
|
|
|
2016-05-26 18:42:14 +03:00
|
|
|
if [[ $(dpkg --print-architecture) == arm* ]]; then
|
2016-03-05 21:26:01 +03:00
|
|
|
display_alert "Please read documentation to set up proper compilation environment" "..." "info"
|
|
|
|
display_alert "http://www.armbian.com/using-armbian-tools/" "..." "info"
|
|
|
|
exit_with_error "Running this tool on board itself is not supported"
|
2016-01-08 12:31:46 +03:00
|
|
|
fi
|
|
|
|
|
2015-12-12 18:35:38 +03:00
|
|
|
# dialog may be used to display progress
|
2016-01-08 12:31:46 +03:00
|
|
|
if [[ $(dpkg-query -W -f='${db:Status-Abbrev}\n' dialog 2>/dev/null) != *ii* ]]; then
|
2015-12-12 18:35:38 +03:00
|
|
|
display_alert "Installing package" "dialog" "info"
|
2015-12-14 17:03:41 +03:00
|
|
|
apt-get install -qq -y --no-install-recommends dialog >/dev/null 2>&1
|
2015-12-12 18:35:38 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# wget is needed
|
2016-01-08 12:31:46 +03:00
|
|
|
if [[ $(dpkg-query -W -f='${db:Status-Abbrev}\n' wget 2>/dev/null) != *ii* ]]; then
|
2015-12-12 18:35:38 +03:00
|
|
|
display_alert "Installing package" "wget" "info"
|
2015-12-14 17:03:41 +03:00
|
|
|
apt-get install -qq -y --no-install-recommends wget >/dev/null 2>&1
|
2015-12-12 18:35:38 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# need lsb_release to decide what to install
|
2016-01-08 12:31:46 +03:00
|
|
|
if [[ $(dpkg-query -W -f='${db:Status-Abbrev}\n' lsb-release 2>/dev/null) != *ii* ]]; then
|
2015-12-12 18:35:38 +03:00
|
|
|
display_alert "Installing package" "lsb-release" "info"
|
2015-12-14 17:03:41 +03:00
|
|
|
apt-get install -qq -y --no-install-recommends lsb-release >/dev/null 2>&1
|
2015-12-12 18:35:38 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# packages list for host
|
2016-05-26 18:42:14 +03:00
|
|
|
local hostdeps="ca-certificates device-tree-compiler pv bc lzop zip binfmt-support build-essential ccache debootstrap ntpdate pigz \
|
2016-01-08 22:23:42 +03:00
|
|
|
gawk gcc-arm-linux-gnueabihf gcc-arm-linux-gnueabi qemu-user-static u-boot-tools uuid-dev zlib1g-dev unzip libusb-1.0-0-dev ntpdate \
|
2016-03-04 12:29:21 +03:00
|
|
|
parted pkg-config libncurses5-dev whiptail debian-keyring debian-archive-keyring f2fs-tools libfile-fcntllock-perl rsync libssl-dev \
|
2016-05-26 18:42:14 +03:00
|
|
|
nfs-kernel-server btrfs-tools gcc-aarch64-linux-gnu ncurses-term p7zip-full dos2unix dosfstools libc6-dev-armhf-cross libc6-dev-armel-cross\
|
2016-06-08 15:14:38 +02:00
|
|
|
libc6-dev-arm64-cross curl"
|
2015-12-12 18:35:38 +03:00
|
|
|
|
|
|
|
# warning: apt-cacher-ng will fail if installed and used both on host and in container/chroot environment with shared network
|
|
|
|
# set NO_APT_CACHER=yes to prevent installation errors in such case
|
2016-05-26 18:42:14 +03:00
|
|
|
if [[ $NO_APT_CACHER != yes ]]; then hostdeps="$hostdeps apt-cacher-ng"; fi
|
2015-12-12 18:35:38 +03:00
|
|
|
|
|
|
|
local codename=$(lsb_release -sc)
|
2016-05-26 18:42:14 +03:00
|
|
|
if [[ -z $codename || "trusty wily xenial" != *"$codename"* ]]; then
|
2015-12-12 18:35:38 +03:00
|
|
|
display_alert "Host system support was not tested" "${codename:-(unknown)}" "wrn"
|
2016-04-03 10:13:13 +02:00
|
|
|
echo -e "Press \e[0;33m<Ctrl-C>\x1B[0m to abort compilation, \e[0;33m<Enter>\x1B[0m to ignore and continue"
|
|
|
|
read
|
2015-12-12 18:35:38 +03:00
|
|
|
fi
|
|
|
|
|
2016-05-26 18:42:14 +03:00
|
|
|
if [[ $codename == trusty && ! -f /etc/apt/sources.list.d/aptly.list ]]; then
|
|
|
|
display_alert "Adding repository for trusty" "aptly" "info"
|
|
|
|
echo 'deb http://repo.aptly.info/ squeeze main' > /etc/apt/sources.list.d/aptly.list
|
|
|
|
apt-key adv --keyserver keys.gnupg.net --recv-keys 9E3E53F19C7DE460
|
2016-01-08 22:23:42 +03:00
|
|
|
fi
|
2015-12-12 18:35:38 +03:00
|
|
|
|
2016-05-16 22:45:58 +02:00
|
|
|
# Deboostrap in trusty breaks due too old debootstrap. We are installing Xenial package
|
2016-05-26 18:42:14 +03:00
|
|
|
local debootstrap_version=$(dpkg-query -W -f='${Version}\n' debootstrap | cut -f1 -d'+')
|
2016-05-16 22:45:58 +02:00
|
|
|
local debootstrap_minimal="1.0.78"
|
|
|
|
|
|
|
|
if [[ "$debootstrap_version" < "$debootstrap_minimal" ]]; then
|
|
|
|
display_alert "Upgrading" "debootstrap" "info"
|
|
|
|
dpkg -i $SRC/lib/bin/debootstrap_1.0.78+nmu1ubuntu1.1_all.deb
|
|
|
|
fi
|
2016-05-26 18:42:14 +03:00
|
|
|
|
2015-12-12 18:35:38 +03:00
|
|
|
local deps=()
|
|
|
|
local installed=$(dpkg-query -W -f '${db:Status-Abbrev}|${binary:Package}\n' '*' 2>/dev/null | grep '^ii' | awk -F '|' '{print $2}' | cut -d ':' -f 1)
|
|
|
|
|
2016-05-26 18:42:14 +03:00
|
|
|
for packet in $hostdeps; do
|
2016-04-20 15:38:09 +03:00
|
|
|
if ! grep -q -x -e "$packet" <<< "$installed"; then deps+=("$packet"); fi
|
2015-12-12 18:35:38 +03:00
|
|
|
done
|
|
|
|
|
2016-01-08 12:31:46 +03:00
|
|
|
if [[ ${#deps[@]} -gt 0 ]]; then
|
2015-12-14 17:03:41 +03:00
|
|
|
eval '( apt-get update; apt-get -y --no-install-recommends install "${deps[@]}" )' \
|
2015-12-12 18:35:38 +03:00
|
|
|
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/output.log'} \
|
2016-03-27 15:39:08 +02:00
|
|
|
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Installing ${#deps[@]} host dependencies..." $TTY_Y $TTY_X'} \
|
2015-12-12 18:35:38 +03:00
|
|
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
|
|
|
fi
|
|
|
|
|
2016-04-14 18:04:28 +03:00
|
|
|
# install aptly separately
|
|
|
|
if [[ $(dpkg-query -W -f='${db:Status-Abbrev}\n' aptly 2>/dev/null) != *ii* ]]; then
|
|
|
|
apt-get install -qq -y --no-install-recommends aptly >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
|
2015-12-12 18:35:38 +03:00
|
|
|
# TODO: Check for failed installation process
|
|
|
|
# test exit code propagation for commands in parentheses
|
|
|
|
|
|
|
|
# enable arm binary format so that the cross-architecture chroot environment will work
|
|
|
|
test -e /proc/sys/fs/binfmt_misc/qemu-arm || update-binfmts --enable qemu-arm
|
2016-04-20 15:38:09 +03:00
|
|
|
test -e /proc/sys/fs/binfmt_misc/qemu-aarch64 || update-binfmts --enable qemu-aarch64
|
2015-12-12 18:35:38 +03:00
|
|
|
|
|
|
|
# create directory structure
|
2016-04-20 15:38:09 +03:00
|
|
|
mkdir -p $SOURCES $DEST/debug $CACHEDIR/rootfs $SRC/userpatches/overlay $SRC/toolchains
|
2015-12-12 18:35:38 +03:00
|
|
|
find $SRC/lib/patch -type d ! -name . | sed "s%lib/patch%userpatches%" | xargs mkdir -p
|
|
|
|
|
2016-06-08 17:48:15 +03:00
|
|
|
# download external Linaro compiler and missing special dependencies since they are needed for certain sources
|
2016-06-08 15:14:38 +02:00
|
|
|
cd $SRC/toolchains
|
2016-06-08 17:48:15 +03:00
|
|
|
[[ ! -d $SRC/toolchains/gcc-linaro-4.9-2016.02-x86_64_aarch64-linux-gnu ]] && display_alert "Updating external compiler" "aarch64-linux-gnu 4.9" "info" \
|
|
|
|
&& curl -LS --progress-bar "http://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/aarch64-linux-gnu/gcc-linaro-4.9-2016.02-x86_64_aarch64-linux-gnu.tar.xz" | tar xJf -
|
|
|
|
#[[ ! -d $SRC/toolchains/gcc-linaro-4.9-2016.02-x86_64_arm-eabi ]] && display_alert "Updating external compiler" "arm-eabi 4.9" "info" \
|
|
|
|
# && curl -LS --progress-bar "http://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/arm-eabi/gcc-linaro-4.9-2016.02-x86_64_arm-eabi.tar.xz" | tar xJf -
|
|
|
|
[[ ! -d $SRC/toolchains/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabi ]] && display_alert "Updating external compilers" "arm-linux-gnueabi 4.9" "info" \
|
|
|
|
&& curl -LS --progress-bar "http://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/arm-linux-gnueabi/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabi.tar.xz" | tar xJf -
|
|
|
|
[[ ! -d $SRC/toolchains/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf ]] && display_alert "Updating external compilers" "arm-linux-gnueabihf 4.9" "info" \
|
|
|
|
&& curl -LS --progress-bar "http://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/arm-linux-gnueabihf/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf.tar.xz" | tar xJf -
|
|
|
|
[[ ! -d $SRC/toolchains/gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux ]] && display_alert "Updating external compilers" "arm-linux-gnueabihf 4.8" "info" \
|
|
|
|
&& curl -LS --progress-bar "http://releases.linaro.org/14.04/components/toolchain/binaries/gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux.tar.xz" | tar xJf -
|
|
|
|
|
2016-06-08 15:14:38 +02:00
|
|
|
dpkg --add-architecture i386
|
|
|
|
apt-get install -qq -y --no-install-recommends lib32stdc++6 libc6-i386 lib32ncurses5 lib32tinfo5 zlib1g:i386 >/dev/null 2>&1
|
2016-06-08 17:48:15 +03:00
|
|
|
|
2015-12-22 20:41:43 +03:00
|
|
|
[[ ! -f $SRC/userpatches/customize-image.sh ]] && cp $SRC/lib/scripts/customize-image.sh.template $SRC/userpatches/customize-image.sh
|
|
|
|
|
2016-05-26 18:42:14 +03:00
|
|
|
if [[ ! -f $SRC/userpatches/README ]]; then
|
|
|
|
rm $SRC/userpatches/readme.txt
|
|
|
|
echo 'Please read documentation about customizing build configuration' > $SRC/userpatches/README
|
|
|
|
echo 'http://www.armbian.com/using-armbian-tools/' >> $SRC/userpatches/README
|
|
|
|
fi
|
2016-05-24 18:44:45 +03:00
|
|
|
|
2016-05-26 18:42:14 +03:00
|
|
|
# check free space (basic), doesn't work on Trusty
|
|
|
|
local freespace=$(findmnt --target $SRC -n -o AVAIL -b 2>/dev/null) # in bytes
|
|
|
|
[[ -n $freespace && $(( $freespace / 1073741824 )) -lt 10 ]] && display_alert "Low free space left" "$(( $freespace / 1073741824 )) GiB" "wrn"
|
2015-12-12 18:35:38 +03:00
|
|
|
}
|