2014-10-13 19:04:03 +02:00
#!/bin/bash
#
2015-12-02 20:33:32 +01:00
# Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com
2014-10-13 19:04:03 +02:00
#
2015-12-02 20:33:32 +01:00
# 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.
2014-10-13 19:04:03 +02:00
#
2015-12-02 20:33:32 +01:00
# This file is a part of tool chain https://github.com/igorpecovnik/lib
#
#
# Main program
#
#
2016-04-16 18:12:34 +03:00
TTY_X = $(( $( stty size | awk '{print $2}' ) - 6 )) # determine terminal width
TTY_Y = $(( $( stty size | awk '{print $1}' ) - 6 )) # determine terminal height
2016-03-27 15:39:08 +02:00
2015-12-12 18:35:38 +03:00
# Include here to make "display_alert" and "prepare_host" available
source $SRC /lib/general.sh # General functions
2016-02-10 20:20:54 +01:00
# clean unfinished DEB packing
rm -rf $DEST /debs/*/*/
2015-12-24 19:37:34 +03:00
# compress and remove old logs
2016-01-07 11:47:38 +03:00
mkdir -p $DEST /debug
2015-12-24 19:37:34 +03:00
( cd $DEST /debug && tar -czf logs-$( date +"%d_%m_%Y-%H_%M_%S" ) .tgz *.log) > /dev/null 2>& 1
rm -f $DEST /debug/*.log > /dev/null 2>& 1
2015-12-11 20:49:10 +03:00
# Script parameters handling
for i in " $@ " ; do
if [ [ " $i " = = *"=" * ] ] ; then
parameter = ${ i %%=* }
value = ${ i ##*= }
2015-12-12 18:35:38 +03:00
display_alert " Command line: setting $parameter to " " ${ value :- (empty) } " "info"
2015-12-11 20:49:10 +03:00
eval $parameter = $value
2015-12-09 18:02:04 +03:00
fi
2015-12-11 20:49:10 +03:00
done
2016-01-03 13:51:56 +03:00
if [ [ $PROGRESS_DISPLAY = = none ] ] ; then
2015-12-11 20:49:10 +03:00
OUTPUT_VERYSILENT = yes;
2016-01-03 13:51:56 +03:00
elif [ [ $PROGRESS_DISPLAY != plain ] ] ; then
2015-12-11 20:49:10 +03:00
OUTPUT_DIALOG = yes;
fi
2016-01-03 13:51:56 +03:00
if [ [ $PROGRESS_LOG_TO_FILE != yes ] ] ; then unset PROGRESS_LOG_TO_FILE; fi
if [ [ $USE_CCACHE != no ] ] ; then
CCACHE = ccache
else
CCACHE = ""
fi
2015-12-11 20:49:10 +03:00
2015-12-12 18:35:38 +03:00
# compile.sh version checking
2016-02-13 09:36:28 +01:00
ver1 = $( awk -F"=" '/^# VERSION/ {print $2}' <" $SRC /compile.sh " )
ver2 = $( awk -F"=" '/^# VERSION/ {print $2}' <" $SRC /lib/compile.sh " 2>/dev/null) || ver2 = 0
if [ -z " $ver1 " ] || [ $ver1 -lt $ver2 ] ; then
2015-12-12 18:35:38 +03:00
display_alert " File $0 is outdated. Please overwrite is with updated version from " " $SRC /lib " "wrn"
read -p "Press <Ctrl-C> to abort compilation, <Enter> to ignore and continue"
fi
2015-12-11 20:49:10 +03:00
2015-12-12 18:35:38 +03:00
# We'll use this title on all menus
backtitle = "Armbian building script, http://www.armbian.com | Author: Igor Pecovnik"
2015-12-11 20:49:10 +03:00
# if language not set, set to english
2016-04-16 18:12:34 +03:00
[ [ -z $LANGUAGE ] ] && export LANGUAGE = "en_US:en"
2015-12-11 20:49:10 +03:00
# default console if not set
2016-04-16 18:12:34 +03:00
[ [ -z $CONSOLE_CHAR ] ] && export CONSOLE_CHAR = "UTF-8"
2015-12-11 20:49:10 +03:00
2015-12-12 18:35:38 +03:00
# Check and fix dependencies, directory structure and settings
prepare_host
2015-12-11 20:49:10 +03:00
2016-04-16 18:06:21 +03:00
if [ [ -z $KERNEL_ONLY ] ] ; then
options += ( "yes" "Kernel, u-boot and other packages" )
options += ( "no" "Full OS image for writing to SD card" )
KERNEL_ONLY = $( dialog --stdout --title "Choose an option" --backtitle " $backtitle " --no-tags --menu "Select what to build" $TTY_Y $TTY_X $(( $TTY_Y - 8 )) " ${ options [@] } " )
unset options
[ [ -z $KERNEL_ONLY ] ] && exit_with_error "No option selected"
2015-12-11 20:49:10 +03:00
fi
2015-12-02 20:33:32 +01:00
2016-04-16 18:06:21 +03:00
if [ [ -z $BOARD ] ] ; then
options = ( )
for board in $SRC /lib/config/boards/*.conf; do
options += ( " $( basename $board | cut -d'.' -f1) " " $( head -1 $board | cut -d'#' -f2) " )
done
BOARD = $( dialog --stdout --title "Choose a board" --backtitle " $backtitle " --scrollbar --menu "Select one of supported boards" $TTY_Y $TTY_X $(( $TTY_Y - 8 )) " ${ options [@] } " )
unset options
[ [ -z $BOARD ] ] && exit_with_error "No board selected"
2015-12-11 20:49:10 +03:00
fi
2015-12-02 20:33:32 +01:00
2016-04-16 18:06:21 +03:00
source $SRC /lib/config/boards/$BOARD .conf
2015-12-02 20:33:32 +01:00
2016-04-16 18:06:21 +03:00
[ [ -z $KERNEL_TARGET ] ] && exit_with_error "Board configuration does not define valid kernel config"
2015-12-02 20:33:32 +01:00
2016-04-16 18:06:21 +03:00
if [ [ -z $BRANCH ] ] ; then
options = ( )
[ [ $KERNEL_TARGET = = *default* ] ] && options += ( "default" "3.4.x - 3.14.x legacy" )
[ [ $KERNEL_TARGET = = *next* ] ] && options += ( "next" "Latest stable @kernel.org" )
[ [ $KERNEL_TARGET = = *dev* ] ] && options += ( "dev" "Latest dev @kernel.org" )
# do not display selection dialog if only one kernel branch is available
if [ [ " ${# options [@] } " = = 2 ] ] ; then
2016-04-17 15:12:09 +03:00
BRANCH = " ${ options [0] } "
2016-04-16 18:06:21 +03:00
else
BRANCH = $( dialog --stdout --title "Choose a kernel" --backtitle " $backtitle " --menu "Select one of supported kernels" $TTY_Y $TTY_X $(( $TTY_Y - 8 )) " ${ options [@] } " )
2015-12-02 20:33:32 +01:00
fi
2016-04-16 18:06:21 +03:00
unset options
[ [ -z $BRANCH ] ] && exit_with_error "No kernel branch selected"
2015-12-11 20:49:10 +03:00
fi
2016-04-16 18:06:21 +03:00
if [ [ $KERNEL_ONLY != yes && -z $RELEASE ] ] ; then
options = ( )
options += ( "wheezy" "Debian 7 Wheezy (oldstable)" )
options += ( "jessie" "Debian 8 Jessie (stable)" )
options += ( "trusty" "Ubuntu Trusty 14.04.x LTS" )
options += ( "xenial" "Ubuntu Xenial 16.04.x LTS" )
RELEASE = $( dialog --stdout --title "Choose a release" --backtitle " $backtitle " --menu "Select one of supported releases" $TTY_Y $TTY_X $(( $TTY_Y - 8 )) " ${ options [@] } " )
unset options
[ [ -z $RELEASE ] ] && exit_with_error "No release selected"
options = ( )
options += ( "no" "Image with console interface" )
options += ( "yes" "Image with desktop environment" )
BUILD_DESKTOP = $( dialog --stdout --title "Choose image type" --backtitle " $backtitle " --no-tags --menu "Select image type" $TTY_Y $TTY_X $(( $TTY_Y - 8 )) " ${ options [@] } " )
unset options
[ [ -z $BUILD_DESKTOP ] ] && exit_with_error "No option selected"
fi
2015-12-11 20:49:10 +03:00
# naming to distro
2016-03-08 21:22:35 +03:00
if [ [ $RELEASE = = trusty || $RELEASE = = xenial ] ] ; then DISTRIBUTION = "Ubuntu" ; else DISTRIBUTION = "Debian" ; fi
2015-12-11 20:49:10 +03:00
2015-12-12 18:35:38 +03:00
# set hostname to the board
2015-12-11 20:49:10 +03:00
HOST = " $BOARD "
# Load libraries
source $SRC /lib/configuration.sh # Board configuration
2015-12-30 14:31:33 +03:00
source $SRC /lib/debootstrap.sh # System specific install (old)
2016-03-05 15:54:44 +03:00
source $SRC /lib/debootstrap-ng.sh # System specific install (extended)
2015-12-11 20:49:10 +03:00
source $SRC /lib/distributions.sh # System specific install
source $SRC /lib/patching.sh # Source patching
2015-12-12 18:35:38 +03:00
source $SRC /lib/boards.sh # Board specific install
source $SRC /lib/desktop.sh # Desktop specific install
source $SRC /lib/common.sh # Functions
source $SRC /lib/makeboarddeb.sh # Create board support package
2015-12-11 20:49:10 +03:00
2015-12-14 19:50:14 +01:00
# The name of the job
VERSION = " Armbian $REVISION ${ BOARD ^ } $DISTRIBUTION $RELEASE $BRANCH "
2015-12-20 16:19:36 +03:00
2015-12-24 19:37:34 +03:00
echo ` date +"%d.%m.%Y %H:%M:%S" ` $VERSION >> $DEST /debug/install.log
2015-12-14 19:50:14 +01:00
2015-12-20 16:19:36 +03:00
display_alert "Starting Armbian build script" "@host" "info"
2015-12-11 20:49:10 +03:00
# optimize build time with 100% CPU usage
CPUS = $( grep -c 'processor' /proc/cpuinfo)
2016-04-16 18:12:34 +03:00
if [ [ $USEALLCORES != no ] ] ; then
CTHREADS = " -j $(( $CPUS + $CPUS / 2 )) "
2015-12-11 20:49:10 +03:00
else
2016-04-16 18:12:34 +03:00
CTHREADS = "-j1"
2015-12-11 20:49:10 +03:00
fi
# display what we do
2016-04-16 18:12:34 +03:00
if [ [ $KERNEL_ONLY = = yes ] ] ; then
2015-12-11 20:49:10 +03:00
display_alert "Compiling kernel" " $BOARD " "info"
else
display_alert "Building" " $VERSION " "info"
fi
# sync clock
2016-04-16 18:12:34 +03:00
if [ [ $SYNC_CLOCK != no ] ] ; then
2015-12-20 16:19:36 +03:00
display_alert "Syncing clock" "host" "info"
2015-12-30 14:31:33 +03:00
eval ntpdate -s ${ NTP_SERVER :- time.ijs.si }
2015-12-11 20:49:10 +03:00
fi
start = ` date +%s`
# fetch_from_github [repository, sub directory]
2016-04-16 18:12:34 +03:00
if [ [ $FORCE_CHECKOUT = = yes ] ] ; then FORCE = "-f" ; else FORCE = "" ; fi
2015-12-11 20:49:10 +03:00
2016-04-16 18:12:34 +03:00
[ [ $CLEAN_LEVEL = = *sources* ] ] && cleaning "sources"
2015-12-11 20:49:10 +03:00
display_alert "source downloading" "@host" "info"
fetch_from_github " $BOOTLOADER " " $BOOTSOURCE " " $BOOTBRANCH " "yes"
BOOTSOURCEDIR = $BOOTSOURCE /$GITHUBSUBDIR
2016-04-16 18:12:34 +03:00
fetch_from_github " $LINUXKERNEL " " $LINUXSOURCE " " $KERNELBRANCH " "yes"
2015-12-11 20:49:10 +03:00
LINUXSOURCEDIR = $LINUXSOURCE /$GITHUBSUBDIR
2016-04-16 18:12:34 +03:00
if [ [ -n $MISC1 ] ] ; then fetch_from_github " $MISC1 " " $MISC1_DIR " ; fi
if [ [ -n $MISC5 ] ] ; then fetch_from_github " $MISC5 " " $MISC5_DIR " ; fi
2015-12-11 20:49:10 +03:00
# compile sunxi tools
if [ [ $LINUXFAMILY = = sun*i ] ] ; then
compile_sunxi_tools
2016-04-16 18:12:34 +03:00
[ [ $BRANCH != default ] ] && LINUXFAMILY = "sunxi"
2015-12-11 20:49:10 +03:00
fi
2016-03-14 21:54:03 +03:00
# define package names
DEB_BRANCH = ${ BRANCH //default }
2016-04-02 13:40:09 +03:00
# if not empty, append hyphen
2016-03-14 21:54:03 +03:00
DEB_BRANCH = ${ DEB_BRANCH : + ${ DEB_BRANCH } - }
CHOSEN_UBOOT = linux-u-boot-${ DEB_BRANCH } ${ BOARD }
CHOSEN_KERNEL = linux-image-${ DEB_BRANCH } ${ LINUXFAMILY }
2015-12-11 20:49:10 +03:00
2016-03-14 21:54:03 +03:00
CHOSEN_ROOTFS = linux-${ RELEASE } -root-${ DEB_BRANCH } ${ BOARD }
2015-12-11 20:49:10 +03:00
for option in $( tr ',' ' ' <<< " $CLEAN_LEVEL " ) ; do
2016-03-14 21:54:03 +03:00
[ [ $option != sources ] ] && cleaning " $option "
2015-12-11 20:49:10 +03:00
done
2016-04-08 16:56:20 +03:00
[ [ ! -f $DEST /debs/${ CHOSEN_UBOOT } _${ REVISION } _${ ARCH } .deb ] ] && NEEDS_UBOOT = yes
[ [ ! -f $DEST /debs/${ CHOSEN_KERNEL } _${ REVISION } _${ ARCH } .deb ] ] && NEEDS_KERNEL = yes
2015-12-19 17:35:43 +03:00
# patching sources if we need to compile u-boot or kernel
2016-04-08 16:56:20 +03:00
[ [ $NEEDS_UBOOT = = yes || $NEEDS_KERNEL = = yes ] ] && patching_sources
2015-12-11 20:49:10 +03:00
2015-12-19 17:35:43 +03:00
# Compile source if packed not exists
2016-04-08 16:56:20 +03:00
[ [ $NEEDS_UBOOT = yes ] ] && compile_uboot
[ [ $NEEDS_KERNEL = yes ] ] && compile_kernel
2015-12-11 20:49:10 +03:00
2016-03-14 21:54:03 +03:00
[ [ -n $RELEASE ] ] && create_board_package
2015-12-21 18:28:40 +03:00
2015-12-30 14:31:33 +03:00
if [ [ $KERNEL_ONLY != yes ] ] ; then
2016-03-05 15:54:44 +03:00
if [ [ $EXTENDED_DEBOOTSTRAP = = yes ] ] ; then
2015-12-30 14:31:33 +03:00
debootstrap_ng
else
2015-12-11 20:49:10 +03:00
2015-12-30 14:31:33 +03:00
# create or use prepared root file-system
custom_debootstrap
2015-12-02 20:33:32 +01:00
2015-12-30 14:31:33 +03:00
# add kernel to the image
install_kernel
2014-10-13 19:04:03 +02:00
2015-12-30 14:31:33 +03:00
# install board specific applications
install_distribution_specific
install_board_specific
2014-10-13 19:04:03 +02:00
2015-12-30 14:31:33 +03:00
# install desktop
2016-04-16 18:12:34 +03:00
if [ [ $BUILD_DESKTOP = = yes ] ] ; then
2015-12-30 14:31:33 +03:00
install_desktop
fi
2014-10-13 19:04:03 +02:00
2015-12-30 14:31:33 +03:00
# install external applications
2016-04-08 16:36:56 +03:00
[ [ $EXTERNAL = = yes ] ] && install_external_applications
2015-12-30 14:31:33 +03:00
# closing image
closing_image
2015-12-02 20:33:32 +01:00
fi
2014-10-13 19:04:03 +02:00
2015-12-30 14:31:33 +03:00
else
display_alert "Kernel building done" "@host" "info"
display_alert "Target directory" " $DEST /debs/ " "info"
2016-03-23 20:58:58 +01:00
display_alert "File name" " ${ CHOSEN_KERNEL } _ ${ REVISION } _ ${ ARCH } .deb " "info"
2015-12-11 20:49:10 +03:00
fi
2016-03-03 11:49:23 +01:00
# workaround for bug introduced with desktop build -- please remove when fixed
chmod 777 /tmp
2015-12-11 20:49:10 +03:00
end = ` date +%s`
2016-04-16 18:12:34 +03:00
runtime = $(( ( end-start) / 60 ))
2016-02-13 09:36:28 +01:00
display_alert "Runtime" " $runtime min " "info"