mirror of https://github.com/parazyd/vm-sdk.git
128 lines
3.1 KiB
Bash
Executable File
128 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env zsh
|
|
# Copyright (c) 2016-2018 Dyne.org Foundation
|
|
# vm-sdk is written and maintained by Ivan J. <parazyd@dyne.org>
|
|
#
|
|
# This file is part of vm-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 <http://www.gnu.org/licenses/>.
|
|
|
|
vmsdk_version="0.2"
|
|
|
|
R=${VM_SDK:-$PWD}
|
|
|
|
DEBUG=0
|
|
QUIET=0
|
|
|
|
source $R/lib/zuper/zuper
|
|
|
|
## global vars
|
|
vars+=(vmsdk_version)
|
|
vars+=(R workdir strapdir)
|
|
vars+=(os oslib blendlib)
|
|
vars+=(MAKEOPTS)
|
|
|
|
## global arrs
|
|
arrs+=(extra_packages)
|
|
|
|
## global maps
|
|
maps+=(board_map os_map blend_map)
|
|
|
|
source $R/config
|
|
|
|
## conclude zuper initialization
|
|
source $R/lib/zuper/zuper.init
|
|
|
|
load() {
|
|
fn load "$@"
|
|
os="$1"
|
|
blend="$2"
|
|
req=(os)
|
|
ckreq || return 1
|
|
|
|
os_map=(
|
|
"devuan" "$R/lib/libdevuansdk/libdevuansdk"
|
|
)
|
|
|
|
blend_map=(
|
|
"decode" "$R/../decode.blend"
|
|
"maemo" "$R/../maemo.blend"
|
|
"cobox" "$R/../cobox.blend"
|
|
)
|
|
|
|
oslib="${os_map[$os]}"
|
|
[[ -f $oslib ]] || { die "no valid distro specified"; exit 1 }
|
|
source $oslib
|
|
|
|
blendlib="${blend_map[$blend]}"
|
|
|
|
if [[ -z "$blendlib" ]] && [[ -n "$blend" ]]; 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" ]] && [[ -n "$blend" ]]; then
|
|
[[ -n "$dlpath" ]] && blend="$dlpath"
|
|
act "trying to parse an unknown blend"
|
|
# Check if it's a Dockerfile
|
|
if grep -qi '^FROM ' "$blend"; 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" }
|
|
[[ -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
|
|
|
|
export LANG=C
|
|
export LC_ALL=C
|
|
|
|
source $R/lib/zuper/zuper.init
|
|
}
|
|
|
|
TRAPZERR() { zerr; return $? }
|
|
|
|
notice "vm-sdk loaded"
|
|
export PROMPT="%F{yellow}%(?..%? )%{$reset_color%}vmsdk@%{$fg[red]%}%m %{$reset_color%}%3c %# "
|