From accd076d0cb7946fde9f1dc9a4f7cda69f5163c2 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Tue, 7 Jun 2016 20:24:47 +0200 Subject: [PATCH] Added per-package options, documented a bit more --- astronaut/astronaut | 47 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/astronaut/astronaut b/astronaut/astronaut index 9a36897..124b626 100755 --- a/astronaut/astronaut +++ b/astronaut/astronaut @@ -1,15 +1,37 @@ #!/bin/sh -e # Configuration + +# Build/install-time directories dir_build="/tmp/astronaut/build" # Temporary directory to build packages dir_source="/tmp/astronaut/source" # Directory where the package sources will be placed dir_install="/tmp/astronaut/install" # Directory where the package will be installed + +# Runtime directories dir_sysroot="" # The root directory of the system dir_prefix="/usr" # Prefix directory (for /bin, /lib, /share and such) + +# Default commands cmd_download="curl -# -L -o {dst} {src}" # Command to execute to download files cmd_extract="tar -x -C {dst} -f {src}" # Command to execute to extract files -unset dir_satellites # Directory where the satellite files are placed. -unset options + +# If we can't find the satellite file, we'll look in this directory for it. +unset dir_satellites + +# Options are comma-separated and parsed from front to back. +# This means that in "!opt,someotheropt,opt", opt is disabled. + +unset options # The least-priority global options +package_options() { :; } # Per-package options function. +# Example for package_options: +# package_options() { +# case "$1" in +# package1) echo "opt1,opt2,opt3" ;; +# package2) echo "someotheropts" ;; +# esac +# } + +# Load any user configuration [ -f /etc/astronaut.conf ] && . /etc/astronaut.conf [ -f "$HOME/.astronaut.conf" ] && . "$HOME/.astronaut.conf" @@ -17,6 +39,7 @@ unset options _download_only=false _vcs_only=false vcs_compile=false +unset _user_options # Options specified in the command line get the highest priority #_nuke_dir_install (This can be set from wrappers) # Some printing functions @@ -34,7 +57,14 @@ Usage: $0 [-sbipr ] [-Id] [-o ] -I Nuke install directory before build [WARNING: You will not be prompted] -d Only download package files -v Only build vcs package if any updates have been made to it --o Set package options (comma-separated)" +-o Set package options (comma-separated) + +Tips: +- Use \`head -n 32 $0 > astronaut.conf.example\` to generate a default configuration file. +- Keep in mind that when specifying options on the command line in a string, the first always takes priority. + For example, in \"opt,someotheropt,!opt\", opt is enabled, due to it being the first occurrence. +- If you have set \$dir_satellites in the config, you can omit the .sat suffix. +" } _msg() { @@ -78,7 +108,7 @@ while getopts "h?s:b:i:r:p:IcCdvo:" opt; do _vcs_only=true ;; o) - options="$options,$OPTARG" + _user_options="$OPTARG,$_user_options" ;; esac done @@ -164,15 +194,19 @@ option() { local enabled=false local opt local IFS=','; for option in $options; do + local option_negate=false case "$option" in *=*) local value="$(echo "$option" | cut -d '=' -f 2)" local option="$(echo "$option" | cut -d '=' -f 1)" ;; + !*) + local option="$(echo "$option" | cut -c 2-)" + local option_negate=true esac if [ "$option" = "$check" ]; then - local enabled=true + [ "$option_negate" = true ] && local enabled=false || local enabled=true break fi done @@ -243,6 +277,9 @@ if [ ! -f "$_satellite" ]; then fi fi +# Build the definitive options list +options="$_user_options$(package_options "$_satname"),$options" + # Create the directories if [ "$_download_only" = false ]; then # This variable can be set by a wrapper script in need to nuke the install dir.