Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/next/build.sh
Views: 3950
#!/bin/bash1#2# Copyright (c) 2013-2021 Igor Pecovnik, igor.pecovnik@gma**.com3#4# This file is licensed under the terms of the GNU General Public5# License version 2. This program is licensed "as is" without any6# warranty of any kind, whether express or implied.78# DO NOT EDIT THIS FILE9# use configuration files like config-default.conf to set the build configuration10# Please check Orange Pi documentation for more info11# http://www.orangepi.cn/downloadresourcescn12# http://www.orangepi.org/downloadresources1314SRC="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"1516# check for whitespace in ${SRC} and exit for safety reasons17grep -q "[[:space:]]" <<<"${SRC}" && { echo "\"${SRC}\" contains whitespace. Not supported. Aborting." >&2 ; exit 1 ; }1819cd "${SRC}" || exit2021if [[ "${ORANGEPI_ENABLE_CALL_TRACING}" == "yes" ]]; then22set -T # inherit return/debug traps23mkdir -p "${SRC}"/output/debug24echo -n "" > "${SRC}"/output/debug/calls.txt25trap 'echo "${BASH_LINENO[@]}|${BASH_SOURCE[@]}|${FUNCNAME[@]}" >> ${SRC}/output/debug/calls.txt ;' RETURN26fi2728if [[ -f "${SRC}"/scripts/general.sh ]]; then2930# shellcheck source=scripts/general.sh31source "${SRC}"/scripts/general.sh3233else3435echo "Error: missing build directory structure"36echo "Please clone the full repository by https://github.com/orangepi-xunlong/orangepi-build"37exit 2553839fi4041# Add the variables needed at the beginning of the path42check_args ()43{4445for p in "$@"; do4647case "${p%=*}" in48LIB_TAG)49# Take a variable if the branch exists locally50if [ "${p#*=}" == "$(git branch | \51gawk -v b="${p#*=}" '{if ( $NF == b ) {print $NF}}')" ]; then52echo -e "[\e[0;35m warn \x1B[0m] Setting $p"53eval "$p"54else55echo -e "[\e[0;35m warn \x1B[0m] Skip $p setting as LIB_TAG=\"\""56eval LIB_TAG=""57fi58;;59esac6061done6263}646566check_args "$@"676869update_src() {7071cd "${SRC}" || exit72if [[ ! -f "${SRC}"/.ignore_changes ]]; then73echo -e "[\e[0;32m o.k. \x1B[0m] This script will try to update"7475CHANGED_FILES=$(git diff --name-only)76if [[ -n "${CHANGED_FILES}" ]]; then77echo -e "[\e[0;35m warn \x1B[0m] Can't update since you made changes to: \e[0;32m\n${CHANGED_FILES}\x1B[0m"78while true; do79echo -e "Press \e[0;33m<Ctrl-C>\x1B[0m or \e[0;33mexit\x1B[0m to abort compilation"\80", \e[0;33m<Enter>\x1B[0m to ignore and continue, \e[0;33mdiff\x1B[0m to display changes"81read -r82if [[ "${REPLY}" == "diff" ]]; then83git diff84elif [[ "${REPLY}" == "exit" ]]; then85exit 186elif [[ "${REPLY}" == "" ]]; then87break88else89echo "Unknown command!"90fi91done92elif [[ $(git branch | grep "*" | awk '{print $2}') != "${LIB_TAG}" && -n "${LIB_TAG}" ]]; then93git checkout "${LIB_TAG:-master}"94git pull95fi96fi9798}99100101TMPFILE=$(mktemp)102chmod 644 "${TMPFILE}"103{104105echo SRC="$SRC"106echo LIB_TAG="$LIB_TAG"107declare -f update_src108#echo "update_src"109110} > "$TMPFILE"111112#do not update/checkout git with root privileges to messup files onwership.113#due to in docker/VM, we can't su to a normal user, so do not update/checkout git.114if [[ $(systemd-detect-virt) == 'none' ]]; then115116if [[ "${EUID}" == "0" ]]; then117su "$(stat --format=%U "${SRC}"/.git)" -c "bash ${TMPFILE}"118else119bash "${TMPFILE}"120fi121122fi123124125rm "${TMPFILE}"126127128if [[ "${EUID}" == "0" ]] || [[ "${1}" == "vagrant" ]]; then129:130elif [[ "${1}" == docker || "${1}" == dockerpurge || "${1}" == docker-shell ]] && grep -q "$(whoami)" <(getent group docker); then131:132else133display_alert "This script requires root privileges, trying to use sudo" "" "wrn"134sudo "${SRC}/build.sh" "$@"135exit $?136fi137138if [ "$OFFLINE_WORK" == "yes" ]; then139140echo -e "\n"141display_alert "* " "You are working offline."142display_alert "* " "Sources, time and host will not be checked"143echo -e "\n"144sleep 3s145146else147148# check and install the basic utilities here149prepare_host_basic150151fi152153# Check for Vagrant154if [[ "${1}" == vagrant && -z "$(command -v vagrant)" ]]; then155display_alert "Vagrant not installed." "Installing"156sudo apt-get update157sudo apt-get install -y vagrant virtualbox158fi159160# Purge Orange Pi Docker images161if [[ "${1}" == dockerpurge && -f /etc/debian_version ]]; then162display_alert "Purging Orange Pi Docker containers" "" "wrn"163docker container ls -a | grep orangepi | awk '{print $1}' | xargs docker container rm &> /dev/null164docker image ls | grep orangepi | awk '{print $3}' | xargs docker image rm &> /dev/null165shift166set -- "docker" "$@"167fi168169# Docker shell170if [[ "${1}" == docker-shell ]]; then171shift172#shellcheck disable=SC2034173SHELL_ONLY=yes174set -- "docker" "$@"175fi176177# Install Docker if not there but wanted. We cover only Debian based distro install. On other distros, manual Docker install is needed178if [[ "${1}" == docker && -f /etc/debian_version && -z "$(command -v docker)" ]]; then179180DOCKER_BINARY="docker-ce"181182# add exception for Ubuntu Focal until Docker provides dedicated binary183codename=$(cat /etc/os-release | grep VERSION_CODENAME | cut -d"=" -f2)184codeid=$(cat /etc/os-release | grep ^NAME | cut -d"=" -f2 | awk '{print tolower($0)}' | tr -d '"' | awk '{print $1}')185[[ "${codename}" == "debbie" ]] && codename="buster" && codeid="debian"186[[ "${codename}" == "ulyana" || "${codename}" == "jammy" ]] && codename="focal" && codeid="ubuntu"187188# different binaries for some. TBD. Need to check for all others189[[ "${codename}" =~ focal|hirsute ]] && DOCKER_BINARY="docker containerd docker.io"190191display_alert "Docker not installed." "Installing" "Info"192sudo bash -c "echo \"deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/${codeid} ${codename} stable\" > /etc/apt/sources.list.d/docker.list"193194sudo bash -c "curl -fsSL \"https://download.docker.com/linux/${codeid}/gpg\" | apt-key add -qq - > /dev/null 2>&1 "195export DEBIAN_FRONTEND=noninteractive196sudo apt-get update197sudo apt-get install -y -qq --no-install-recommends ${DOCKER_BINARY}198display_alert "Add yourself to docker group to avoid root privileges" "" "wrn"199"${SRC}/build.sh" "$@"200exit $?201202fi203204EXTER="${SRC}/external"205206# Create userpatches directory if not exists207mkdir -p "${SRC}"/userpatches208209210# Create example configs if none found in userpatches211if ! ls "${SRC}"/userpatches/{config-example.conf,config-docker.conf,config-vagrant.conf} 1> /dev/null 2>&1; then212213# Migrate old configs214if ls "${SRC}"/*.conf 1> /dev/null 2>&1; then215display_alert "Migrate config files to userpatches directory" "all *.conf" "info"216cp "${SRC}"/*.conf "${SRC}"/userpatches || exit 1217rm "${SRC}"/*.conf218[[ ! -L "${SRC}"/userpatches/config-example.conf ]] && ln -fs config-example.conf "${SRC}"/userpatches/config-default.conf || exit 1219fi220221display_alert "Create example config file using template" "config-default.conf" "info"222223# Create example config224if [[ ! -f "${SRC}"/userpatches/config-example.conf ]]; then225cp "${EXTER}"/config/templates/config-example.conf "${SRC}"/userpatches/config-example.conf || exit 1226ln -fs config-example.conf "${SRC}"/userpatches/config-default.conf || exit 1227fi228229# Create Docker config230if [[ ! -f "${SRC}"/userpatches/config-docker.conf ]]; then231cp "${EXTER}"/config/templates/config-docker.conf "${SRC}"/userpatches/config-docker.conf || exit 1232fi233234# Create Docker file235if [[ ! -f "${SRC}"/userpatches/Dockerfile ]]; then236cp "${EXTER}"/config/templates/Dockerfile "${SRC}"/userpatches/Dockerfile || exit 1237fi238239# Create Vagrant config240if [[ ! -f "${SRC}"/userpatches/config-vagrant.conf ]]; then241cp "${EXTER}"/config/templates/config-vagrant.conf "${SRC}"/userpatches/config-vagrant.conf || exit 1242fi243244# Create Vagrant file245if [[ ! -f "${SRC}"/userpatches/Vagrantfile ]]; then246cp "${EXTER}"/config/templates/Vagrantfile "${SRC}"/userpatches/Vagrantfile || exit 1247fi248249fi250251if [[ -z "${CONFIG}" && -n "$1" && -f "${SRC}/userpatches/config-$1.conf" ]]; then252CONFIG="userpatches/config-$1.conf"253shift254fi255256# usind default if custom not found257if [[ -z "${CONFIG}" && -f "${SRC}/userpatches/config-default.conf" ]]; then258CONFIG="userpatches/config-default.conf"259fi260261# source build configuration file262CONFIG_FILE="$(realpath "${CONFIG}")"263264if [[ ! -f "${CONFIG_FILE}" ]]; then265display_alert "Config file does not exist" "${CONFIG}" "error"266exit 254267fi268269CONFIG_PATH=$(dirname "${CONFIG_FILE}")270271# Source the extensions manager library at this point, before sourcing the config.272# This allows early calls to enable_extension(), but initialization proper is done later.273# shellcheck source=scripts/extensions.sh274source "${SRC}"/scripts/extensions.sh275276display_alert "Using config file" "${CONFIG_FILE}" "info"277pushd "${CONFIG_PATH}" > /dev/null || exit278# shellcheck source=/dev/null279source "${CONFIG_FILE}"280popd > /dev/null || exit281282[[ -z "${USERPATCHES_PATH}" ]] && USERPATCHES_PATH="${CONFIG_PATH}"283284# Script parameters handling285while [[ "${1}" == *=* ]]; do286287parameter=${1%%=*}288value=${1##*=}289shift290display_alert "Command line: setting $parameter to" "${value:-(empty)}" "info"291eval "$parameter=\"$value\""292293done294295296if [[ "${BUILD_ALL}" == "yes" || "${BUILD_ALL}" == "demo" ]]; then297298# shellcheck source=scripts/build-all-ng.sh299source "${SRC}"/scripts/build-all-ng.sh300301else302303# shellcheck source=scripts/main.sh304source "${SRC}"/scripts/main.sh305306fi307308309