mirror of
https://github.com/Fishwaldo/build.git
synced 2025-03-17 04:11:36 +00:00
260 lines
8.4 KiB
Bash
260 lines
8.4 KiB
Bash
#!/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
|
|
#
|
|
#
|
|
# Main program
|
|
#
|
|
#
|
|
|
|
TTY_X=$(($(stty size | awk '{print $2}')-6)) # determine terminal width
|
|
TTY_Y=$(($(stty size | awk '{print $1}')-6)) # determine terminal height
|
|
|
|
# Include here to make "display_alert" and "prepare_host" available
|
|
source $SRC/lib/general.sh # General functions
|
|
|
|
# clean unfinished DEB packing
|
|
rm -rf $DEST/debs/*/*/
|
|
|
|
# compress and remove old logs
|
|
mkdir -p $DEST/debug
|
|
(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
|
|
|
|
# Script parameters handling
|
|
for i in "$@"; do
|
|
if [[ "$i" == *"="* ]]; then
|
|
parameter=${i%%=*}
|
|
value=${i##*=}
|
|
display_alert "Command line: setting $parameter to" "${value:-(empty)}" "info"
|
|
eval $parameter=$value
|
|
fi
|
|
done
|
|
|
|
if [[ $PROGRESS_DISPLAY == none ]]; then
|
|
OUTPUT_VERYSILENT=yes;
|
|
elif [[ $PROGRESS_DISPLAY != plain ]]; then
|
|
OUTPUT_DIALOG=yes;
|
|
fi
|
|
if [[ $PROGRESS_LOG_TO_FILE != yes ]]; then unset PROGRESS_LOG_TO_FILE; fi
|
|
|
|
if [[ $USE_CCACHE != no ]]; then
|
|
CCACHE=ccache
|
|
else
|
|
CCACHE=""
|
|
fi
|
|
|
|
# compile.sh version checking
|
|
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
|
|
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
|
|
|
|
# We'll use this title on all menus
|
|
backtitle="Armbian building script, http://www.armbian.com | Author: Igor Pecovnik"
|
|
|
|
# if language not set, set to english
|
|
[[ -z $LANGUAGE ]] && export LANGUAGE="en_US:en"
|
|
|
|
# default console if not set
|
|
[[ -z $CONSOLE_CHAR ]] && export CONSOLE_CHAR="UTF-8"
|
|
|
|
# Check and fix dependencies, directory structure and settings
|
|
prepare_host
|
|
|
|
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"
|
|
fi
|
|
|
|
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"
|
|
fi
|
|
|
|
source $SRC/lib/config/boards/$BOARD.conf
|
|
|
|
[[ -z $KERNEL_TARGET ]] && exit_with_error "Board configuration does not define valid kernel config"
|
|
|
|
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
|
|
BRANCH="${#options[0]}"
|
|
else
|
|
BRANCH=$(dialog --stdout --title "Choose a kernel" --backtitle "$backtitle" --menu "Select one of supported kernels" $TTY_Y $TTY_X $(($TTY_Y - 8)) "${options[@]}")
|
|
fi
|
|
unset options
|
|
[[ -z $BRANCH ]] && exit_with_error "No kernel branch selected"
|
|
fi
|
|
|
|
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
|
|
|
|
# naming to distro
|
|
if [[ $RELEASE == trusty || $RELEASE == xenial ]]; then DISTRIBUTION="Ubuntu"; else DISTRIBUTION="Debian"; fi
|
|
|
|
# set hostname to the board
|
|
HOST="$BOARD"
|
|
|
|
# Load libraries
|
|
source $SRC/lib/configuration.sh # Board configuration
|
|
source $SRC/lib/debootstrap.sh # System specific install (old)
|
|
source $SRC/lib/debootstrap-ng.sh # System specific install (extended)
|
|
source $SRC/lib/distributions.sh # System specific install
|
|
source $SRC/lib/patching.sh # Source patching
|
|
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
|
|
|
|
# The name of the job
|
|
VERSION="Armbian $REVISION ${BOARD^} $DISTRIBUTION $RELEASE $BRANCH"
|
|
|
|
echo `date +"%d.%m.%Y %H:%M:%S"` $VERSION >> $DEST/debug/install.log
|
|
|
|
display_alert "Starting Armbian build script" "@host" "info"
|
|
|
|
# optimize build time with 100% CPU usage
|
|
CPUS=$(grep -c 'processor' /proc/cpuinfo)
|
|
if [[ $USEALLCORES != no ]]; then
|
|
CTHREADS="-j$(($CPUS + $CPUS/2))"
|
|
else
|
|
CTHREADS="-j1"
|
|
fi
|
|
|
|
# display what we do
|
|
if [[ $KERNEL_ONLY == yes ]]; then
|
|
display_alert "Compiling kernel" "$BOARD" "info"
|
|
else
|
|
display_alert "Building" "$VERSION" "info"
|
|
fi
|
|
|
|
# sync clock
|
|
if [[ $SYNC_CLOCK != no ]]; then
|
|
display_alert "Syncing clock" "host" "info"
|
|
eval ntpdate -s ${NTP_SERVER:- time.ijs.si}
|
|
fi
|
|
start=`date +%s`
|
|
|
|
# fetch_from_github [repository, sub directory]
|
|
|
|
if [[ $FORCE_CHECKOUT == yes ]]; then FORCE="-f"; else FORCE=""; fi
|
|
|
|
[[ $CLEAN_LEVEL == *sources* ]] && cleaning "sources"
|
|
|
|
display_alert "source downloading" "@host" "info"
|
|
fetch_from_github "$BOOTLOADER" "$BOOTSOURCE" "$BOOTBRANCH" "yes"
|
|
BOOTSOURCEDIR=$BOOTSOURCE/$GITHUBSUBDIR
|
|
fetch_from_github "$LINUXKERNEL" "$LINUXSOURCE" "$KERNELBRANCH" "yes"
|
|
LINUXSOURCEDIR=$LINUXSOURCE/$GITHUBSUBDIR
|
|
|
|
if [[ -n $MISC1 ]]; then fetch_from_github "$MISC1" "$MISC1_DIR"; fi
|
|
if [[ -n $MISC5 ]]; then fetch_from_github "$MISC5" "$MISC5_DIR"; fi
|
|
|
|
# compile sunxi tools
|
|
if [[ $LINUXFAMILY == sun*i ]]; then
|
|
compile_sunxi_tools
|
|
[[ $BRANCH != default ]] && LINUXFAMILY="sunxi"
|
|
fi
|
|
|
|
# define package names
|
|
DEB_BRANCH=${BRANCH//default}
|
|
# if not empty, append hyphen
|
|
DEB_BRANCH=${DEB_BRANCH:+${DEB_BRANCH}-}
|
|
|
|
CHOSEN_UBOOT=linux-u-boot-${DEB_BRANCH}${BOARD}
|
|
|
|
CHOSEN_KERNEL=linux-image-${DEB_BRANCH}${LINUXFAMILY}
|
|
|
|
CHOSEN_ROOTFS=linux-${RELEASE}-root-${DEB_BRANCH}${BOARD}
|
|
|
|
for option in $(tr ',' ' ' <<< "$CLEAN_LEVEL"); do
|
|
[[ $option != sources ]] && cleaning "$option"
|
|
done
|
|
|
|
[[ ! -f $DEST/debs/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb ]] && NEEDS_UBOOT=yes
|
|
[[ ! -f $DEST/debs/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb ]] && NEEDS_KERNEL=yes
|
|
|
|
# patching sources if we need to compile u-boot or kernel
|
|
[[ $NEEDS_UBOOT == yes || $NEEDS_KERNEL == yes ]] && patching_sources
|
|
|
|
# Compile source if packed not exists
|
|
[[ $NEEDS_UBOOT = yes ]] && compile_uboot
|
|
[[ $NEEDS_KERNEL = yes ]] && compile_kernel
|
|
|
|
[[ -n $RELEASE ]] && create_board_package
|
|
|
|
if [[ $KERNEL_ONLY != yes ]]; then
|
|
if [[ $EXTENDED_DEBOOTSTRAP == yes ]]; then
|
|
debootstrap_ng
|
|
else
|
|
|
|
# create or use prepared root file-system
|
|
custom_debootstrap
|
|
|
|
# add kernel to the image
|
|
install_kernel
|
|
|
|
# install board specific applications
|
|
install_distribution_specific
|
|
install_board_specific
|
|
|
|
# install desktop
|
|
if [[ $BUILD_DESKTOP == yes ]]; then
|
|
install_desktop
|
|
fi
|
|
|
|
# install external applications
|
|
[[ $EXTERNAL == yes ]] && install_external_applications
|
|
|
|
# closing image
|
|
closing_image
|
|
fi
|
|
|
|
else
|
|
display_alert "Kernel building done" "@host" "info"
|
|
display_alert "Target directory" "$DEST/debs/" "info"
|
|
display_alert "File name" "${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb" "info"
|
|
fi
|
|
|
|
# workaround for bug introduced with desktop build -- please remove when fixed
|
|
chmod 777 /tmp
|
|
|
|
end=`date +%s`
|
|
runtime=$(((end-start)/60))
|
|
display_alert "Runtime" "$runtime min" "info"
|