Last active
June 18, 2018 13:48
-
-
Save jesbrd/e50a2cf3b1d5b37e22dcb6f5f9baa49c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Boondocks OS Yocto Build Wrapper | |
set -e # fail fast | |
# capture the root directory of the Boondocks OS source repo. | |
repo_root=$(pwd) | |
# function onError() { | |
# onExit(); | |
# } | |
# trap onError ERR | |
function help { | |
echo | |
echo -e "Options:" | |
echo -e "\t-h | --help" | |
echo -e "\t\t Print this message." | |
echo -e "\t-d | --development-image" | |
echo -e "\t\t Build as a development image." | |
echo -e "\t\t Default: do not build as a development image (will be production)." | |
echo -e "\t-p | --prereqs" | |
echo -e "\t\t Install host build prerequisites." | |
echo -e "\t\t Default: do not install host build prerequisites." | |
echo -e "\t-r | --dry-run" | |
echo -e "\t\t Perform a build dry run." | |
echo -e "\t\t Default: do not perform a build dry run." | |
echo -e "\t-v | --boondocks-version" | |
echo -e "\t\t Specify the Boondocks Agent version to be installed in the Boondocks OS image." | |
echo -e "\t\t Default: v$bndk_agent_version." | |
} | |
# perform exit and/or cleanup functions. | |
function onExit() { | |
# restore the barys build script backup. | |
[ -f $build_script_root/barys_clone ] && rm -f $build_script_root/barys_clone | |
# rename the barys log file. | |
[ -f $build_script_root/barys_clone.log ] && mv -f $build_script_root/barys_clone.log $build_script_root/barys.log | |
# restore ignored device types. | |
[ -f $repo_root/fincm3.coffee.ignore ] && mv -f $repo_root/fincm3.coffee.ignore $repo_root/fincm3.coffee | |
[ -f $repo_root/raspberrypi.coffee.ignore ] && mv -f $repo_root/raspberrypi.coffee.ignore $repo_root/raspberrypi.coffee | |
[ -f $repo_root/raspberrypi2.coffee.ignore ] && mv -f $repo_root/raspberrypi2.coffee.ignore $repo_root/raspberrypi2.coffee | |
[ -f $repo_root/raspberrypi3-64.coffee.ignore ] && mv -f $repo_root/raspberrypi3-64.coffee.ignore $repo_root/raspberrypi3-64.coffee | |
# log final build information. | |
echo | |
echo "Build phase duration: $(($bndk_build_duration / 60))m $(($bndk_build_duration % 60))s." | |
echo "Compress phase duration: $(($bndk_compress_duration / 60))m $(($bndk_compress_duration % 60))s." | |
echo | |
echo "Boondocks OS build ended at: $(date -Iseconds)" # local time | |
echo | |
} | |
trap onExit EXIT | |
# log the build context. | |
function log_boondocks_configuration() { | |
printf "Boondocks configuration:\n\n" | |
declare -A build_context=( | |
[Boondocks Agent Repo]=$bndk_agent_repo | |
[Boondocks Agent Version]=$bndk_agent_version | |
[Boondocks Agent Tag]=$bndk_agent_tag | |
[Boondocks Build Type]=$bndk_build_type | |
[Boondocks Build Dry Run?]=$bndk_build_dry_run | |
[Boondocks OS Compressed Image]=$bndk_os_compressed_image | |
[Boondocks OS Image]=$bndk_os_image | |
[Boondocks OS Development Build?]=$bndk_dev_build | |
[Boondocks OS Build Prerequisites Install?]=$bndk_build_prereq | |
[Yocto State]=$yocto_state | |
[Yocto Downloads]=$yocto_downloads | |
) | |
for key in "${!build_context[@]}"; do | |
printf "%s = \"%s\"\n" "$key" "${build_context[$key]}" | |
done | sort | |
printf "\n" | |
} | |
printf "\nBoondocks OS build started at: $(date -Iseconds)\n\n" # local time | |
# Build script artifacts, pathes, etc. | |
build_script_root="resin-yocto-scripts/build" | |
# timing values | |
bndk_build_duration=0 | |
bndk_compress_duration=0 | |
# build options. | |
bndk_build_dry_run="no" | |
bndk_build_prereq="no" | |
bndk_build_type="prod" | |
bndk_dev_build=no | |
# Boondocks Agent version. | |
bndk_agent_repo="boondocks/boondocks-agent-raspberrypi3" | |
bndk_agent_version="1.3.65" | |
# parse command line arguments. | |
while [[ $# -ge 1 ]]; do | |
i="$1" | |
case $i in | |
-h|--help) | |
help | |
exit 0 | |
;; | |
-d|--development-image) | |
bndk_build_type="dev" | |
bndk_dev_build=yes | |
echo "Development image requested." | |
;; | |
-p|--prereqs) | |
bndk_build_prereq="yes" | |
;; | |
-r|--dry-run) | |
bndk_build_dry_run="yes" | |
;; | |
-v|--boondocks-version) | |
if [ -z "$2" ]; then | |
log ERROR "\"$1\" argument needs a value." | |
fi | |
bndk_agent_version=$2 | |
shift | |
;; | |
*) | |
echo "Unrecognized command line option: $1." | |
echo "Please use -h|--help for assistance." | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
# Boondocks OS Image | |
bndk_os_image="boondocks-os-v2.13.0+rev1-$bndk_build_type-$bndk_agent_version" | |
bndk_os_compressed_image="$bndk_os_image.zip" | |
# Boondocks Agent - repository + tag (version) | |
bndk_agent_tag="boondocks-agent-raspberrypi3-v$bndk_agent_version" | |
# Yocto build artifacts. | |
yocto_downloads="${HOME}/boondocks-os/yocto/downloads" | |
yocto_state="${HOME}/boondocks-os/yocto/state" | |
# create yocto 'working' directories. | |
mkdir -p $yocto_downloads | |
mkdir -p $yocto_state | |
# log the top-level Boondocks configuration specifics. | |
log_boondocks_configuration | |
# check if prerequisites should be installed/updated. | |
if [ "$bndk_build_prereq" == "yes" ]; then | |
echo "You may be prompted for elevated privileges in order to continue." | |
$repo_root/prerequisites.sh -u -p -n -d | |
else | |
echo "Skipping Boondocks OS build prerequisites install." | |
fi | |
# ignore device types Boondocks does not support. | |
mv fincm3.coffee fincm3.coffee.ignore | |
mv raspberrypi.coffee raspberrypi.coffee.ignore | |
mv raspberrypi2.coffee raspberrypi2.coffee.ignore | |
mv raspberrypi3-64.coffee raspberrypi3-64.coffee.ignore | |
# change to the build script directory. | |
cd $build_script_root | |
# clone the barys build script so it can be manipulated prior to executing. | |
# forcibly overwrite any previous clone. | |
yes | cp -f barys barys_clone | |
# Override barys script variables for default build values based on supplied command line to this build script. | |
# DEVELOPMENT_IMAGE = yes/no; corresponds with [-d] and alternate [--development-image] command line options. | |
# DRY_RUN = yes/no; corresponds with [-r] and alternate [--dry-run] command line options. | |
sed -i "s/^DEVELOPMENT_IMAGE=no/DEVELOPMENT_IMAGE=$bndk_dev_build/" barys_clone | |
sed -i "s/^DRY_RUN=no/DRY_RUN=$bndk_build_dry_run/" barys_clone | |
# reset duration for build phase. | |
SECONDS=0 | |
# Barys Build Script | |
# execute the cloned and modified barys build script. | |
./barys_clone \ | |
--log \ | |
--remove-build \ | |
--machine raspberrypi3 \ | |
--shared-downloads "$yocto_downloads" \ | |
--shared-sstate "$yocto_state" \ | |
--supervisor-tag "$bndk_agent_tag" \ | |
--additional-variable "TARGET_REPOSITORY=$bndk_agent_repo" \ | |
--additional-variable "TARGET_TAG=$bndk_agent_tag" \ | |
--additional-variable "BALENA_STORAGE=overlay2" "--development-image" | |
# move back to the root of the repo. | |
cd ../.. | |
# capture build duration. | |
bndk_build_duration=$SECONDS | |
# reset duration for compress phase. | |
SECONDS=0 | |
# move + rename the built image file. | |
mv $(readlink -f ./build/tmp/deploy/images/raspberrypi3/resin-image-raspberrypi3.resinos-img) ./build/sdcard.img | |
# compress the image file; removing original. | |
zip ./build/$bndk_os_compressed_image ./build/sdcard.img | |
# cleanup. | |
rm ./build/sdcard.img | |
# capture compress duration. | |
bndk_compress_duration=$SECONDS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Boondocks OS Build Prerequisites. | |
echo "Boondocks OS Build Prerequisites." | |
update_host=no | |
install_build_packages=no | |
install_nodejs=no | |
install_docker=no | |
function help { | |
echo | |
echo -e "Options:" | |
echo -e "\t-h | --help" | |
echo -e "\t\t Print this message." | |
echo -e "\t-u | --update-host" | |
echo -e "\t\t Update and upgrade the host." | |
echo -e "\t\t Default: do not update the host." | |
echo -e "\t-p | --install-build-packages" | |
echo -e "\t\t Install host packages required for the build." | |
echo -e "\t\t Default: do not install host build packages." | |
echo -e "\t-n | --install-nodejs" | |
echo -e "\t\t Install Node.js on the host." | |
echo -e "\t\t Default: do not install Node.js on the host." | |
echo -e "\t-d | --install-docker" | |
echo -e "\t\t Install Docker on the host." | |
echo -e "\t\t Default: do not install Docker on the host." | |
} | |
# perform exit and/or cleanup functions. | |
function onExit() { | |
# log final information. | |
echo "Boondocks OS Build Prerequisites ended at: $(date -Iseconds)" # local time | |
} | |
trap onExit EXIT | |
# parse command line arguments. | |
while [[ $# -ge 1 ]]; do | |
i="$1" | |
case $i in | |
-h|--help) | |
help | |
exit 0 | |
;; | |
-u|--update-host) | |
update_host=yes | |
;; | |
-p|--install-build-packages) | |
install_build_packages=yes | |
;; | |
-n|--install-nodejs) | |
install_nodejs=yes | |
;; | |
-d|--install-docker) | |
install_docker=yes | |
;; | |
*) | |
echo "Unrecognized option $1." | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
# Update host. | |
if [ "$update_host" == "yes" ]; then | |
# update the host | |
echo "Updating the Boondocks OS build host..." | |
sudo apt update | |
sudo apt -y upgrade | |
fi | |
# Install build prerequisites packages. | |
if [ "$install_build_packages" == "yes" ]; then | |
# the build host may have one or more of these dependencies already installed. | |
echo "Installing Boondocks OS build packages..." | |
sudo apt install \ | |
apt-transport-https \ | |
build-essential \ | |
ca-certificates \ | |
chrpath \ | |
cpio \ | |
curl \ | |
debianutils \ | |
diffstat \ | |
gawk \ | |
git \ | |
iputils-ping \ | |
iptables \ | |
jq \ | |
make \ | |
python \ | |
python3 \ | |
python3-pexpect \ | |
python3-pip \ | |
socat \ | |
software-properties-common \ | |
texinfo \ | |
xz-utils \ | |
zip | |
fi | |
# NodeJs install. | |
if [ "$install_nodejs" == "yes" ]; then | |
if type -p node > /dev/null; then | |
echo "Node.js is already installed." | |
else | |
echo "Installing Node.js..." | |
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - | |
sudo apt install -y nodejs | |
# verify nodjs install. | |
nodejs --version | |
npm --version | |
fi | |
fi | |
# Docker install. | |
if [ "$install_docker" == "yes" ]; then | |
if type -p docker > /dev/null; then | |
echo "Docker is already installed." | |
else | |
echo "Installing Docker..." | |
# https://docs.docker.com/install/linux/docker-ce/ubuntu/ | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | |
sudo apt update | |
sudo apt install -y docker-ce | |
fi | |
fi | |
# verify/test Docker install. | |
#docker run hello-world | |
#docker image list | |
# cleanup Docker test. | |
#docker system prune --force | |
#docker image rm hello-world | |
#docker image list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment