#!/usr/bin/env zsh # Copyright (c) 2016-2018 Dyne.org Foundation # arm-sdk is written and maintained by Ivan J. # # This file is part of arm-sdk # # This source code is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this source code. If not, see . armsdk_version="0.7" R=${ARM_SDK:-$PWD} DEBUG=0 QUIET=0 source $R/lib/zuper/zuper ## global vars vars+=(armsdk_version) vars+=(R workdir strapdir) vars+=(os boardlib oslib blendlib) vars+=(MAKEOPTS) ## global arrs arrs+=(extra_packages) ## global maps maps+=(board_map os_map blend_map) source $R/config source $R/lib/helpers ## conclude zuper initialization source $R/lib/zuper/zuper.init load() { fn load "$@" os="$1" dev="$2" blend="$3" req=(os dev) ckreq || return 1 ## initialize binfmt_misc if not already, needed to run qemu if [[ -f /etc/init.d/binfmt-support ]]; then sudo /etc/init.d/binfmt-support restart elif [[ -f /etc/init.d/qemu-binfmt ]]; then sudo /etc/init.d/qemu-binfmt restart else [[ -d /proc/sys/fs/binfmt_misc ]] \ || sudo modprobe binfmt_misc [[ -f /proc/sys/fs/binfmt_misc/register ]] \ || sudo mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc fi board_map=( "beagleboneblack" "$R/boards/beaglebone-black.sh" "chromeacer" "$R/boards/chromebook-acer.sh" "chromeveyron" "$R/boards/chromebook-veyron.sh" "n900" "$R/boards/nokia-n900.sh" "n950" "$R/boards/nokia-n950.sh" "n9" "$R/boards/nokia-n9.sh" "droid4" "$R/boards/droid4.sh" "odroidxu" "$R/boards/odroid-xu.sh" "odroidxu4" "$R/boards/odroid-xu4.sh" "ouya" "$R/boards/ouya.sh" "raspi1" "$R/boards/raspberry-pi1.sh" "raspi2" "$R/boards/raspberry-pi2.sh" "raspi3" "$R/boards/raspberry-pi3.sh" "raspi4" "$R/boards/raspberry-pi4.sh" "rock64" "$R/boards/rock64.sh" "pinephone-dontbeevil" "$R/boards/pinephone-dontbeevil.sh" "sunxi" "$R/boards/sunxi.sh" "turbox-twister" "$R/boards/turbox-twister.sh" ) os_map=( "devuan" "$R/lib/libdevuansdk/libdevuansdk" "alpine" "$R/lib/libalpine/libalpine" ) blend_map=( "decode" "../decode.blend" "maemo" "../maemo.blend" ) boardlib="${board_map[$dev]}" [[ -f $boardlib ]] || { die "no valid boards specified"; exit 1 } source $boardlib ## XXX: remove this line oslib="${os_map[$os]}" [[ -f $oslib ]] || { die "no valid distro specified"; exit 1 } source $oslib blendlib="${blend_map[$blend]}" if [[ -z "$blendlib" ]]; then if [[ "$blend" =~ '^http' ]]; then notice "grabbing blend from the internetz" dlpath="$R/extra/blends/$(basename $blend)" wget -O "$dlpath" "$blend" sed 1q "$dlpath" | grep -q '^#!/usr/bin/env zsh' && blendlib="$dlpath" fi if [[ -z "$blendlib" ]]; then [[ -n "$dlpath" ]] && blend="$dlpath" act "trying to parse an unknown blend" # Check if it's a Dockerfile if grep -qi '^FROM ' "$blend" 2>&/dev/null; then act "The blend is a Dockerfile" parsedfile="$($LIBPATH/extra/dockerfile_parse.py "$blend")" [[ $? = 0 ]] || { die "Could not parse the Dockerfile" ; exit 1} cat > "$R/$(basename ${blend}).blend" << __EOF__ #!/usr/bin/env zsh # Parsed with dockerfile_parse.py # blend_postinst() { fn blend_postinst req=(strapdir blend) ckreq || return 1 notice "executing blend postinst" cat << ___EOF___ | sudo tee \$strapdir/blendpostinst >/dev/null ${parsedfile} ___EOF___ chroot-script -d blendpostinst || zerr } __EOF__ blendlib="$R/$(basename ${blend}).blend" fi fi fi [[ -f $blendlib ]] || { act "no blend specified" } source $boardlib && act "$device_name build script loaded" source $R/lib/overrides [[ -f $blendlib ]] && { source $blendlib || zerr act "$(basename $blend) blend loaded" export BLEND=1 } workdir="$R/tmp/${os}-${arch}-build" strapdir="$workdir/bootstrap" mkdir -p $strapdir case "$arch" in armhf) export compiler="$armhftc";; armel) export compiler="$armeltc";; arm64) export compiler="$arm64tc";; *) die "invalid architecture in board script"; exit 1;; esac [[ -n "$USEDEVUANTC" ]] && export compiler="$devuantc" export LANG=C export LC_ALL=C source $R/lib/zuper/zuper.init } TRAPZERR() { zerr; return $? } notice "arm-sdk loaded" export PROMPT="%F{yellow}%(?..%? )%{$reset_color%}armsdk@%{$fg[red]%}%m %{$reset_color%} %{$fg[blue]%}%#%{$fg_bold[blue]%}%{$reset_color%} "