sdk (3097B)
1 #!/usr/bin/env zsh 2 # Copyright (c) 2016-2018 Dyne.org Foundation 3 # vm-sdk is written and maintained by Ivan J. <parazyd@dyne.org> 4 # 5 # This file is part of vm-sdk 6 # 7 # This source code is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 3 of the License, or 10 # (at your option) any later version. 11 # 12 # This software is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with this source code. If not, see <http://www.gnu.org/licenses/>. 19 20 vmsdk_version="0.2" 21 22 R=${VM_SDK:-$PWD} 23 24 DEBUG=0 25 QUIET=0 26 27 source $R/lib/zuper/zuper 28 29 ## global vars 30 vars+=(vmsdk_version) 31 vars+=(R workdir strapdir) 32 vars+=(os oslib blendlib) 33 vars+=(MAKEOPTS) 34 35 ## global arrs 36 arrs+=(extra_packages) 37 38 ## global maps 39 maps+=(board_map os_map blend_map) 40 41 source $R/config 42 43 ## conclude zuper initialization 44 source $R/lib/zuper/zuper.init 45 46 load() { 47 fn load "$@" 48 os="$1" 49 blend="$2" 50 req=(os) 51 ckreq || return 1 52 53 os_map=( 54 "devuan" "$R/lib/libdevuansdk/libdevuansdk" 55 ) 56 57 blend_map=( 58 "decode" "$R/../decode.blend" 59 "maemo" "$R/../maemo.blend" 60 ) 61 62 oslib="${os_map[$os]}" 63 [[ -f $oslib ]] || { die "no valid distro specified"; exit 1 } 64 source $oslib 65 66 blendlib="${blend_map[$blend]}" 67 68 if [[ -z "$blendlib" ]] && [[ -n "$blend" ]]; then 69 if [[ "$blend" =~ '^http' ]]; then 70 notice "grabbing blend from the internetz" 71 dlpath="$R/extra/blends/$(basename $blend)" 72 wget -O "$dlpath" "$blend" 73 sed 1q "$dlpath" | grep -q '^#!/usr/bin/env zsh' && blendlib="$dlpath" 74 fi 75 76 if [[ -z "$blendlib" ]] && [[ -n "$blend" ]]; then 77 [[ -n "$dlpath" ]] && blend="$dlpath" 78 act "trying to parse an unknown blend" 79 # Check if it's a Dockerfile 80 if grep -qi '^FROM ' "$blend"; then 81 act "The blend is a Dockerfile" 82 parsedfile="$($LIBPATH/extra/dockerfile_parse.py "$blend")" 83 [[ $? = 0 ]] || { die "Could not parse the Dockerfile" ; exit 1} 84 cat > "$R/$(basename ${blend}).blend" << __EOF__ 85 #!/usr/bin/env zsh 86 # Parsed with dockerfile_parse.py 87 # 88 blend_postinst() { 89 fn blend_postinst 90 req=(strapdir blend) 91 ckreq || return 1 92 93 notice "executing blend postinst" 94 cat << ___EOF___ | sudo tee \$strapdir/blendpostinst >/dev/null 95 ${parsedfile} 96 ___EOF___ 97 98 chroot-script -d blendpostinst || zerr 99 } 100 __EOF__ 101 blendlib="$R/$(basename ${blend}).blend" 102 fi 103 fi 104 fi 105 106 [[ -f $blendlib ]] || { act "no blend specified" } 107 [[ -f $blendlib ]] && { 108 source $blendlib || zerr 109 act "$(basename $blend) blend loaded" 110 export BLEND=1 111 } 112 113 workdir="$R/tmp/${os}-${arch}-build" 114 strapdir="$workdir/bootstrap" 115 mkdir -p $strapdir 116 117 export LANG=C 118 export LC_ALL=C 119 120 source $R/lib/zuper/zuper.init 121 } 122 123 TRAPZERR() { zerr; return $? } 124 125 notice "vm-sdk loaded" 126 export PROMPT="%F{yellow}%(?..%? )%{$reset_color%}vmsdk@%{$fg[red]%}%m %{$reset_color%}%3c %# "