#!/bin/bash ################################################################################ # # The MIT License (MIT) # # Copyright (c) 2016 Stéphane Desneux # (c) 2016 Jan-Simon Möller # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # ################################################################################ # this script shouldn't be called directly, but through aglsetup.sh that will in # turn execute (source) generated instructions back in the parent shell, # whether it's bash, zsh, or any other supported shell VERSION=1.1.0 DEFAULT_MACHINE=qemux86-64 DEFAULT_BUILDDIR=./build VERBOSE=0 DEBUG=0 #SCRIPT=$(basename $BASH_SOURCE) SCRIPT=aglsetup.sh SCRIPTDIR=$(cd $(dirname $BASH_SOURCE) && pwd -P) METADIR=$(cd $(dirname $BASH_SOURCE)/../.. && pwd -P) function info() { echo "$@" >&2; } function infon() { echo -n "$@" >&2; } function error() { echo "ERROR: $@" >&2; return 1; } function verbose() { [[ $VERBOSE == 1 ]] && echo "$@" >&2; return 0; } function debug() { [[ $DEBUG == 1 ]] && echo "DEBUG: $@" >&2; return 0;} info "------------ $SCRIPT: Starting" #compute AGL_REPOSITORIES AGL_REPOSITORIES=$(for x in $(ls -d $METADIR/*/templates/{machine,feature}); do echo $(basename $(dirname $(dirname $x))); done | sort -u) function list_machines() { for x in $@; do for y in $(ls -d $METADIR/$x/templates/machine/* 2>/dev/null); do echo $(basename $y) done done } function list_all_machines() { for x in $AGL_REPOSITORIES; do list_machines $x done } function validate_builddir() { if [[ "$BUILDDIR" =~ [[:space:]] ]]; then error "Build dir '$BUILDDIR' shouldn't contain any space" fi debug "Build dir is valid" } function validate_machines() { list_all_machines | sort | uniq -c | while read cnt machine; do [[ $cnt == 1 ]] && continue info "Machine $machine found in the following repositories:" for x in $(ls -d $METADIR/*/templates/machine/$machine); do info " - $x" done error "Multiple machine templates are not allowed" done debug "Machines list has no duplicate." } function list_features() { for x in $@; do for y in $(ls -d $METADIR/$x/templates/feature/* 2>/dev/null); do echo $(basename $y) done done } function list_all_features() { for x in $AGL_REPOSITORIES; do list_features $x done } function validate_features() { list_all_features | sort | uniq -c | while read cnt feature; do [[ $cnt == 1 ]] && continue; info "Feature $feature found in the following repositories:" for x in $(ls -d $METADIR/*/templates/feature/$feature); do info " - $x" done error "Multiple feature templates are not allowed" done debug "Features list has no duplicate." } function find_machine_dir() { machine=$1 for x in $AGL_REPOSITORIES; do dir=$METADIR/$x/templates/machine/$machine [[ -d $dir ]] && { echo $dir; return 0; } done return 1 } function find_feature_dir() { feature=$1 for x in $AGL_REPOSITORIES; do dir=$METADIR/$x/templates/feature/$feature [[ -d $dir ]] && { echo $dir; return 0; } done return 1 } function usage() { cat <&2 Usage: . $SCRIPT [options] [feature [feature [... ]]] Version: $VERSION Compatibility: bash, zsh, ksh Options: -m|--machine what machine to use default: '$DEFAULT_MACHINE' -b|--build build directory to use default: '$DEFAULT_BUILDDIR' -s|--script file where setup script is generated default: none (no script) -f|--force flag to force overwriting any existing configuration default: false -v|--verbose verbose mode default: false -d|--debug debug mode default: false -h|--help get some help EOF local buf echo "Available machines:" >&2 for x in $AGL_REPOSITORIES; do buf=$(list_machines $x) [[ -z "$buf" ]] && continue echo " [$x]" for y in $buf; do [[ $y == $DEFAULT_MACHINE ]] && def="* " || def=" " echo " $def$y" done done echo >&2 echo "Available features:" >&2 for x in $AGL_REPOSITORIES; do buf=$(list_features $x) [[ -z "$buf" ]] && continue echo " [$x]" for feature in $buf; do print_feature="$feature" featuredir=$(find_feature_dir $feature) if [ -e $featuredir/included.dep ];then print_feature="$