2015-12-02 19:33:32 +00: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.
#
2017-08-01 09:51:10 +00:00
# This file is a part of the Armbian build script
# https://github.com/armbian/build/
2015-12-02 19:33:32 +00:00
2017-08-06 14:11:16 +00:00
# DO NOT EDIT THIS FILE
# use configuration files like config-default.conf to set the build configuration
# check Armbian documentation for more info
2019-05-30 20:19:53 +00:00
SRC = " $( dirname " $( realpath " ${ BASH_SOURCE [0] } " ) " ) "
2017-09-13 10:59:03 +00:00
2020-06-18 14:06:21 +00:00
# check for whitespace in ${SRC} and exit for safety reasons
2017-09-14 10:13:26 +00:00
grep -q "[[:space:]]" <<< " ${ SRC } " && { echo " \" ${ SRC } \" contains whitespace. Not supported. Aborting. " >& 2 ; exit 1 ; }
2017-09-13 10:59:03 +00:00
2019-05-30 20:19:53 +00:00
cd " ${ SRC } " || exit
2015-12-02 19:33:32 +00:00
2019-09-07 21:32:18 +00:00
if [ [ -f " ${ SRC } " /lib/general.sh ] ] ; then
2019-05-30 20:19:53 +00:00
# shellcheck source=lib/general.sh
source " ${ SRC } " /lib/general.sh
2017-07-11 09:39:32 +00:00
else
echo "Error: missing build directory structure"
echo "Please clone the full repository https://github.com/armbian/build/"
2019-05-30 20:19:53 +00:00
exit 255
2015-12-02 19:33:32 +00:00
fi
2020-06-25 13:23:16 +00:00
# Add the variables needed at the beginning of the path
check_args ( )
{
for p in " $@ " ; do
case " ${ p %=* } " in
LIB_TAG)
# Take a variable if the branch exists locally
if [ " ${ p #*= } " = = " $( git branch | \
gawk -v b = " ${ p #*= } " '{if ( $NF == b ) {print $NF}}' ) " ]; then
echo " Setting $p "
eval " $p "
else
echo " Skip $p Set as LIB_TAG=\"\" "
eval LIB_TAG = ""
fi
; ;
esac
done
}
check_args " $@ "
2019-07-06 20:35:43 +00:00
2019-09-29 09:41:43 +00:00
update_src( ) {
cd " ${ SRC } " || exit
2020-06-18 14:06:21 +00:00
if [ [ ! -f " ${ SRC } " /.ignore_changes ] ] ; then
2019-09-29 09:41:43 +00:00
echo -e "[\e[0;32m o.k. \x1B[0m] This script will try to update"
2020-06-25 13:23:16 +00:00
2019-09-29 09:41:43 +00:00
CHANGED_FILES = $( git diff --name-only)
2020-06-18 14:06:21 +00:00
if [ [ -n " ${ CHANGED_FILES } " ] ] ; then
2019-09-29 09:41:43 +00:00
echo -e " [\e[0;35m warn \x1B[0m] Can't update since you made changes to: \e[0;32m\n ${ CHANGED_FILES } \x1B[0m "
while true; do
echo -e "Press \e[0;33m<Ctrl-C>\x1B[0m or \e[0;33mexit\x1B[0m to abort compilation, \e[0;33m<Enter>\x1B[0m to ignore and continue, \e[0;33mdiff\x1B[0m to display changes"
read -r
2020-06-18 14:06:21 +00:00
if [ [ " ${ REPLY } " = = "diff" ] ] ; then
2019-09-29 09:41:43 +00:00
git diff
2020-06-18 14:06:21 +00:00
elif [ [ " ${ REPLY } " = = "exit" ] ] ; then
2019-09-29 09:41:43 +00:00
exit 1
2020-06-18 14:06:21 +00:00
elif [ [ " ${ REPLY } " = = "" ] ] ; then
2019-09-29 09:41:43 +00:00
break
else
echo "Unknown command!"
fi
done
else
git checkout " ${ LIB_TAG :- master } "
2020-06-25 13:23:16 +00:00
git pull
2019-09-29 09:41:43 +00:00
fi
fi
}
2020-06-18 14:06:21 +00:00
TMPFILE = $( mktemp)
chmod 644 " ${ TMPFILE } "
2020-06-25 13:23:16 +00:00
{
echo SRC = " $SRC "
echo LIB_TAG = " $LIB_TAG "
declare -f update_src
echo "update_src"
} > " $TMPFILE "
2019-09-29 09:41:43 +00:00
#do not update/checkout git with root privileges to messup files onwership.
#due to in docker/VM, we can't su to a normal user, so do not update/checkout git.
2020-06-18 14:06:21 +00:00
if [ [ $( systemd-detect-virt) = = 'none' ] ] ; then
if [ [ " ${ EUID } " = = "0" ] ] ; then
su " $( stat --format= %U " ${ SRC } " /.git) " -c " bash ${ TMPFILE } "
2019-09-29 09:41:43 +00:00
else
2020-06-18 14:06:21 +00:00
bash " ${ TMPFILE } "
2019-09-29 09:41:43 +00:00
fi
fi
2020-06-18 14:06:21 +00:00
rm " ${ TMPFILE } "
2019-09-29 09:41:43 +00:00
2020-06-25 13:23:16 +00:00
if [ [ " ${ EUID } " = = "0" ] ] || [ [ " ${ 1 } " = = "vagrant" ] ] ; then
:
elif [ [ " ${ 1 } " = = docker || " ${ 1 } " = = dockerpurge || " ${ 1 } " = = docker-shell ] ] && grep -q " $( whoami) " <( getent group docker) ; then
:
else
display_alert "This script requires root privileges, trying to use sudo" "" "wrn"
sudo " ${ SRC } /compile.sh " " $@ "
exit $?
fi
2020-01-30 17:28:31 +00:00
# Check for required packages for compiling
2020-06-18 14:06:21 +00:00
if [ [ -z " $( command -v dialog) " ] ] ; then
2020-04-25 19:25:05 +00:00
sudo apt-get update
sudo apt-get install -y dialog
2020-01-30 17:28:31 +00:00
fi
2020-08-28 09:50:42 +00:00
if [ [ -z " $( command -v fuser) " ] ] ; then
sudo apt-get update
sudo apt-get install -y psmisc
fi
2020-06-18 14:06:21 +00:00
if [ [ -z " $( command -v getfacl) " ] ] ; then
2020-05-10 09:27:14 +00:00
sudo apt-get update
sudo apt-get install -y acl
fi
2021-02-24 17:19:09 +00:00
if [ [ -z " $( command -v uuidgen) " ] ] ; then
sudo apt-get update
sudo apt-get install -y uuid-runtime
fi
2020-01-30 17:28:31 +00:00
2019-09-28 18:49:28 +00:00
# Check for Vagrant
2020-06-18 14:06:21 +00:00
if [ [ " ${ 1 } " = = vagrant && -z " $( command -v vagrant) " ] ] ; then
2019-09-28 18:49:28 +00:00
display_alert "Vagrant not installed." "Installing"
2020-04-25 19:25:05 +00:00
sudo apt-get update
sudo apt-get install -y vagrant virtualbox
2017-07-11 09:46:08 +00:00
fi
2020-06-18 14:06:21 +00:00
if [ [ " ${ 1 } " = = dockerpurge && -f /etc/debian_version ] ] ; then
2019-11-28 14:24:22 +00:00
display_alert "Purging Armbian Docker containers" "" "wrn"
docker container ls -a | grep armbian | awk '{print $1}' | xargs docker container rm & > /dev/null
docker image ls | grep armbian | awk '{print $3}' | xargs docker image rm & > /dev/null
shift
set -- "docker" " $@ "
fi
2020-06-18 14:06:21 +00:00
if [ [ " ${ 1 } " = = docker-shell ] ] ; then
2019-11-28 14:24:22 +00:00
shift
2020-06-18 14:06:21 +00:00
#shellcheck disable=SC2034
2019-11-28 14:24:22 +00:00
SHELL_ONLY = yes
set -- "docker" " $@ "
fi
2019-09-28 19:00:46 +00:00
# Install Docker if not there but wanted. We cover only Debian based distro install. Else, manual Docker install is needed
2020-06-18 14:06:21 +00:00
if [ [ " ${ 1 } " = = docker && -f /etc/debian_version && -z " $( command -v docker) " ] ] ; then
2020-02-02 09:31:30 +00:00
2021-05-30 19:09:48 +00:00
DOCKER_BINARY = "docker-ce"
2020-02-02 09:31:30 +00:00
# add exception for Ubuntu Focal until Docker provides dedicated binary
2021-05-02 16:06:38 +00:00
codename = $( cat /etc/os-release | grep VERSION_CODENAME | cut -d"=" -f2)
codeid = $( cat /etc/os-release | grep ^NAME | cut -d"=" -f2 | awk '{print tolower($0)}' | tr -d '"' | awk '{print $1}' )
[ [ " ${ codename } " = = "debbie" ] ] && codename = "buster" && codeid = "debian"
[ [ " ${ codename } " = = "ulyana" ] ] && codename = "focal" && codeid = "ubuntu"
2020-02-02 09:31:30 +00:00
2021-06-04 13:24:41 +00:00
# different binaries for some. TBD. Need to check for all others
2021-06-04 09:06:54 +00:00
[ [ " ${ codename } " = ~ focal| hirsute ] ] && DOCKER_BINARY = "docker containerd docker.io"
2021-05-30 19:09:48 +00:00
2019-09-28 18:49:28 +00:00
display_alert "Docker not installed." "Installing" "Info"
2021-06-04 08:53:45 +00:00
echo " deb [arch= $( dpkg --print-architecture) ] https://download.docker.com/linux/ ${ codeid } ${ codename } stable " > /etc/apt/sources.list.d/docker.list
2019-09-29 09:47:49 +00:00
2019-09-29 09:41:43 +00:00
# minimal set of utilities that are needed for prep
2021-05-31 22:33:52 +00:00
packages = ( "curl" "gnupg" )
2019-09-29 09:41:43 +00:00
for i in " ${ packages [@] } "
do
2020-06-18 14:06:21 +00:00
[ [ ! $( command -v " ${ i } " ) ] ] && install_packages += ${ i } " "
2019-09-29 09:41:43 +00:00
done
2021-05-02 16:06:38 +00:00
[ [ -z " ${ install_packages } " ] ] && apt-get update; apt-get install -y -qq --no-install-recommends ${ install_packages }
2019-09-29 09:47:49 +00:00
2020-04-20 06:12:27 +00:00
curl -fsSL " https://download.docker.com/linux/ ${ codeid } /gpg " | apt-key add -qq - > /dev/null 2>& 1
2019-09-28 18:49:28 +00:00
export DEBIAN_FRONTEND = noninteractive
2020-04-25 19:25:05 +00:00
apt-get update
2021-05-30 19:09:48 +00:00
apt-get install -y -qq --no-install-recommends ${ DOCKER_BINARY }
2019-09-29 09:41:43 +00:00
display_alert "Add yourself to docker group to avoid root privileges" "" "wrn"
2020-06-18 14:06:21 +00:00
" ${ SRC } /compile.sh " " $@ "
2019-09-29 09:41:43 +00:00
exit $?
2019-09-28 18:49:28 +00:00
fi
2021-05-02 16:06:38 +00:00
# check if Docker version is high enough
[ [ $( systemd-detect-virt) = = 'none' ] ] && dockerversion = $( docker version | grep runc -A1 | tail -n 1 | awk '{print $2}' )
if [ [ " ${ 1 } " = = docker && -n ${ dockerversion } ] ] && linux-version compare " ${ dockerversion } " lt 1.0.0-rc93; then
display_alert "Your Docker engine is too old - using Docker from nigtly builds" "Required > 1.0.0-rc92" "wrn"
sed -i "s/edge/nightly/" /etc/apt/sources.list.d/docker.list
apt-get update
apt-get upgrade -y -qq
fi
2019-09-28 18:49:28 +00:00
# Create userpatches directory if not exists
2020-06-18 14:06:21 +00:00
mkdir -p " ${ SRC } " /userpatches
2019-09-28 18:49:28 +00:00
# Create example configs if none found in userpatches
2020-06-18 14:06:21 +00:00
if ! ls " ${ SRC } " /userpatches/{ config-example.conf,config-docker.conf,config-vagrant.conf} 1> /dev/null 2>& 1; then
2019-09-28 18:49:28 +00:00
# Migrate old configs
2020-06-18 14:06:21 +00:00
if ls " ${ SRC } " /*.conf 1> /dev/null 2>& 1; then
2019-09-28 18:49:28 +00:00
display_alert "Migrate config files to userpatches directory" "all *.conf" "info"
cp " ${ SRC } " /*.conf " ${ SRC } " /userpatches || exit 1
rm " ${ SRC } " /*.conf
[ [ ! -L " ${ SRC } " /userpatches/config-example.conf ] ] && ln -fs config-example.conf " ${ SRC } " /userpatches/config-default.conf || exit 1
fi
display_alert "Create example config file using template" "config-default.conf" "info"
# Create example config
if [ [ ! -f " ${ SRC } " /userpatches/config-example.conf ] ] ; then
cp " ${ SRC } " /config/templates/config-example.conf " ${ SRC } " /userpatches/config-example.conf || exit 1
ln -fs config-example.conf " ${ SRC } " /userpatches/config-default.conf || exit 1
fi
# Create Docker config
if [ [ ! -f " ${ SRC } " /userpatches/config-docker.conf ] ] ; then
cp " ${ SRC } " /config/templates/config-docker.conf " ${ SRC } " /userpatches/config-docker.conf || exit 1
fi
# Create Docker file
if [ [ ! -f " ${ SRC } " /userpatches/Dockerfile ] ] ; then
cp " ${ SRC } " /config/templates/Dockerfile " ${ SRC } " /userpatches/Dockerfile || exit 1
fi
# Create Vagrant config
if [ [ ! -f " ${ SRC } " /userpatches/config-vagrant.conf ] ] ; then
cp " ${ SRC } " /config/templates/config-vagrant.conf " ${ SRC } " /userpatches/config-vagrant.conf || exit 1
fi
# Create Vagrant file
if [ [ ! -f " ${ SRC } " /userpatches/Vagrantfile ] ] ; then
cp " ${ SRC } " /config/templates/Vagrantfile " ${ SRC } " /userpatches/Vagrantfile || exit 1
fi
fi
2020-06-18 14:06:21 +00:00
if [ [ -z " ${ CONFIG } " && -n " $1 " && -f " ${ SRC } /userpatches/config- $1 .conf " ] ] ; then
2019-09-28 18:49:28 +00:00
CONFIG = " userpatches/config- $1 .conf "
2019-11-26 17:00:39 +00:00
shift
2015-12-07 13:55:53 +00:00
fi
2015-12-02 19:33:32 +00:00
2019-09-28 18:49:28 +00:00
# usind default if custom not found
2020-06-18 14:06:21 +00:00
if [ [ -z " ${ CONFIG } " && -f " ${ SRC } /userpatches/config-default.conf " ] ] ; then
2019-09-28 18:49:28 +00:00
CONFIG = "userpatches/config-default.conf"
fi
# source build configuration file
2020-06-18 14:06:21 +00:00
CONFIG_FILE = " $( realpath " ${ CONFIG } " ) "
2019-09-28 18:49:28 +00:00
2020-06-18 14:06:21 +00:00
if [ [ ! -f " ${ CONFIG_FILE } " ] ] ; then
display_alert "Config file does not exist" " ${ CONFIG } " "error"
2019-09-28 18:49:28 +00:00
exit 254
fi
2020-06-18 14:06:21 +00:00
CONFIG_PATH = $( dirname " ${ CONFIG_FILE } " )
2019-09-28 18:49:28 +00:00
2020-06-18 14:06:21 +00:00
display_alert "Using config file" " ${ CONFIG_FILE } " "info"
pushd " ${ CONFIG_PATH } " > /dev/null || exit
2019-09-28 18:49:28 +00:00
# shellcheck source=/dev/null
2020-06-18 14:06:21 +00:00
source " ${ CONFIG_FILE } "
popd > /dev/null || exit
2019-09-28 18:49:28 +00:00
2020-06-18 14:06:21 +00:00
[ [ -z " ${ USERPATCHES_PATH } " ] ] && USERPATCHES_PATH = " ${ CONFIG_PATH } "
2019-09-28 18:49:28 +00:00
2018-05-24 19:33:16 +00:00
# Script parameters handling
2020-06-18 14:06:21 +00:00
while [ [ " ${ 1 } " = = *= * ] ] ; do
2019-11-26 17:00:39 +00:00
parameter = ${ 1 %%=* }
value = ${ 1 ##*= }
shift
display_alert " Command line: setting $parameter to " " ${ value :- (empty) } " "info"
eval " $parameter =\" $value \" "
2018-05-24 19:33:16 +00:00
done
2020-06-18 14:06:21 +00:00
if [ [ " ${ BUILD_ALL } " = = "yes" || " ${ BUILD_ALL } " = = "demo" ] ] ; then
2019-09-01 20:13:13 +00:00
# shellcheck source=lib/build-all-ng.sh
source " ${ SRC } " /lib/build-all-ng.sh
2015-12-02 19:33:32 +00:00
else
2019-05-30 20:19:53 +00:00
# shellcheck source=lib/main.sh
source " ${ SRC } " /lib/main.sh
2015-12-02 19:33:32 +00:00
fi