From deff81117da61c4523485fcb3c9e950d86366f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Sat, 6 Sep 2014 14:01:33 +0200 Subject: [PATCH] Now downloads dependencies at installation time --- include/getopt.sh | 223 ----------------------------------- include/read_ini.sh | 280 -------------------------------------------- install.sh | 18 ++- love-release.sh | 4 +- 4 files changed, 19 insertions(+), 506 deletions(-) delete mode 100755 include/getopt.sh delete mode 100755 include/read_ini.sh diff --git a/include/getopt.sh b/include/getopt.sh deleted file mode 100755 index c0514ef..0000000 --- a/include/getopt.sh +++ /dev/null @@ -1,223 +0,0 @@ -#! /bin/bash -# -# getopt.sh: -# functions like getopts but do long-named options parsing -# and support optional arguments -# -# Version 1.0 1997 by Grigoriy Strokin (grg@philol.msu.ru), Public Domain -# Date created: December 21, 1997 -# Date modified: December 21, 1997 -# -# IMPORTANT FEATURES -# -# 1) Parses both short and long-named options -# 2) Supports optional arguments -# 3) Only uses bash builtins, thus no calls to external -# utilities such as expr or sed is done. Therefore, -# parsing speed is high enough -# -# -# DESCRIPTION -# -# FUNCTION getopt -# Usage: getopt OPTLIST {"$@"|ALTERNATIVE_PARAMETERS} -# -# like getopts, but parse options with both required and optional arguments, -# Options with optional arguments must have "." instead of ":" after them. -# Furthemore, a variable name to place option name cannot be specified -# and is always placed in OPTOPT variable -# -# This function is provided for compatibility with getopts() -# OPTLIST style, and it actually calls getoptex (see bellow) -# -# NOTE that a list of parameters is required and must be either "$@", -# if processing command line arguments, or some alternative parameters. -# -# FUNCTION getoptex -# Usage: getoptex OPTION_LIST {"$@"|ALTERNATIVE_PARAMETERS} -# -# like getopts, but parse long-named options. -# -# Both getopt and getoptex return 0 if an option has been parsed, -# and 1 if all options are already parsed or an error occured -# -# Both getopt and getoptex set or test the following variables: -# -# OPTERR -- tested for whether error messages must be given for invalid options -# -# OPTOPT -- set to the name of an option parsed, -# or to "?" if no more options or error -# OPTARG -- set to the option argument, if any; -# unset if ther is no argument; -# on error, set to the erroneous option name -# -# OPTIND -- Initialized to 1. -# Then set to the number of the next parameter to be parsed -# when getopt or getoptex will be called next time. -# When all options are parsed, contains a number of -# the first non-option argument. -# -# -# OPTOFS -- If a parameter number $OPTIND containg an option parsed -# does not contain any more options, OPTOFS is unset; -# otherwise, OPTOFS is set to such a number of "?" signs -# which is equal to the number of options parsed -# -# You might not set variables OPTIND and OPTOFS yourself -# unless you want to parse a list of parameters more than once. -# Otherwise, you whould unset OPTIND (or set it to 1) -# and unset OPTOFS each time you want to parse a new parameters list -# -# Option list format is DIFFERENT from one for getopts or getopt. -# getopts-style option list can be converted to getoptex-style using a function optlistex -# (see bellow) -# -# DESCRIPTION of option list used with getoptex: -# Option names are separated by whitespace. Options consiting of -# more than one character are treated as long-named (--option) -# -# Special characters can appear at the and of option names specifying -# whether an argument is required (default is ";"): -# ";" (default) -- no argument -# ":" -- required argument -# "," -- optional argument -# -# For example, an option list "a b c help version f: file: separator." -# defines the following options: -# -a, -b, -c, --help, --version -- no argument -# -f, --file -- argument required -# --separator -- optional argument -# -# FUNCTION optlistex -# Usage new_style_optlist=`optlistex OLD_STYLE_OPTLIST` -# -# Converts getopts-style option list in a format suitable for use with getoptex -# Namely, it inserts spaces after each option name. -# -# -# HOW TO USE -# -# In order to use in your bash scripts the functions described, -# include a command ". getopt.sh" to the file containing the script, -# which will define functions getopt, getoptex, and optlistex -# -# EXAMPLES -# -# See files 'getopt1' and 'getopt2' that contain sample scripts that use -# getopt and getoptex functions respectively -# -# -# Please send your comments to grg@philol.msu.ru - -function getoptex() -{ - let $# || return 1 - local optlist="${1#;}" - let OPTIND || OPTIND=1 - [ $OPTIND -lt $# ] || return 1 - shift $OPTIND - if [ "$1" != "-" ] && [ "$1" != "${1#-}" ] - then OPTIND=$[OPTIND+1]; if [ "$1" != "--" ] - then - local o - o="-${1#-$OPTOFS}" - for opt in ${optlist#;} - do - OPTOPT="${opt%[;.:]}" - unset OPTARG - local opttype="${opt##*[^;:.]}" - [ -z "$opttype" ] && opttype=";" - if [ ${#OPTOPT} -gt 1 ] - then # long-named option - case $o in - "--$OPTOPT") - if [ "$opttype" != ":" ]; then return 0; fi - OPTARG="$2" - if [ -z "$OPTARG" ]; - then # error: must have an agrument - let OPTERR && echo "$0: error: $OPTOPT must have an argument" >&2 - OPTARG="$OPTOPT"; - OPTOPT="?" - return 1; - fi - OPTIND=$[OPTIND+1] # skip option's argument - return 0 - ;; - "--$OPTOPT="*) - if [ "$opttype" = ";" ]; - then # error: must not have arguments - let OPTERR && echo "$0: error: $OPTOPT must not have arguments" >&2 - OPTARG="$OPTOPT" - OPTOPT="?" - return 1 - fi - OPTARG=${o#"--$OPTOPT="} - return 0 - ;; - esac - else # short-named option - case "$o" in - "-$OPTOPT") - unset OPTOFS - [ "$opttype" != ":" ] && return 0 - OPTARG="$2" - if [ -z "$OPTARG" ] - then - echo "$0: error: -$OPTOPT must have an argument" >&2 - OPTARG="$OPTOPT" - OPTOPT="?" - return 1 - fi - OPTIND=$[OPTIND+1] # skip option's argument - return 0 - ;; - "-$OPTOPT"*) - if [ $opttype = ";" ] - then # an option with no argument is in a chain of options - OPTOFS="$OPTOFS?" # move to the next option in the chain - OPTIND=$[OPTIND-1] # the chain still has other options - return 0 - else - unset OPTOFS - OPTARG="${o#-$OPTOPT}" - return 0 - fi - ;; - esac - fi - done - echo "$0: error: invalid option: $o" - fi; fi - OPTOPT="?" - unset OPTARG - return 1 -} - -function optlistex -{ - local l="$1" - local m # mask - local r # to store result - while [ ${#m} -lt $[${#l}-1] ]; do m="$m?"; done # create a "???..." mask - while [ -n "$l" ] - do - r="${r:+"$r "}${l%$m}" # append the first character of $l to $r - l="${l#?}" # cut the first charecter from $l - m="${m#?}" # cut one "?" sign from m - if [ -n "${l%%[^:.;]*}" ] - then # a special character (";", ".", or ":") was found - r="$r${l%$m}" # append it to $r - l="${l#?}" # cut the special character from l - m="${m#?}" # cut one more "?" sign - fi - done - echo $r -} - -function getopt() -{ - local optlist=`optlistex "$1"` - shift - getoptex "$optlist" "$@" - return $? -} diff --git a/include/read_ini.sh b/include/read_ini.sh deleted file mode 100755 index 08974fe..0000000 --- a/include/read_ini.sh +++ /dev/null @@ -1,280 +0,0 @@ -# -# Copyright (c) 2009 Kevin Porter / Advanced Web Construction Ltd -# (http://coding.tinternet.info, http://webutils.co.uk) -# Copyright (c) 2010-2012 Ruediger Meier -# (https://github.com/rudimeier/) -# -# Simple INI file parser. -# -# See README for usage. -# -# - - - - -function read_ini() -{ - # Be strict with the prefix, since it's going to be run through eval - function check_prefix() - { - if ! [[ "${VARNAME_PREFIX}" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] ;then - echo "read_ini: invalid prefix '${VARNAME_PREFIX}'" >&2 - return 1 - fi - } - - function check_ini_file() - { - if [ ! -r "$INI_FILE" ] ;then - echo "read_ini: '${INI_FILE}' doesn't exist or not" \ - "readable" >&2 - return 1 - fi - } - - # enable some optional shell behavior (shopt) - function pollute_bash() - { - if ! shopt -q extglob ;then - SWITCH_SHOPT="${SWITCH_SHOPT} extglob" - fi - if ! shopt -q nocasematch ;then - SWITCH_SHOPT="${SWITCH_SHOPT} nocasematch" - fi - shopt -q -s ${SWITCH_SHOPT} - } - - # unset all local functions and restore shopt settings before returning - # from read_ini() - function cleanup_bash() - { - shopt -q -u ${SWITCH_SHOPT} - unset -f check_prefix check_ini_file pollute_bash cleanup_bash - } - - local INI_FILE="" - local INI_SECTION="" - - # {{{ START Deal with command line args - - # Set defaults - local BOOLEANS=1 - local VARNAME_PREFIX=INI - local CLEAN_ENV=0 - - # {{{ START Options - - # Available options: - # --boolean Whether to recognise special boolean values: ie for 'yes', 'true' - # and 'on' return 1; for 'no', 'false' and 'off' return 0. Quoted - # values will be left as strings - # Default: on - # - # --prefix=STRING String to begin all returned variables with (followed by '__'). - # Default: INI - # - # First non-option arg is filename, second is section name - - while [ $# -gt 0 ] - do - - case $1 in - - --clean | -c ) - CLEAN_ENV=1 - ;; - - --booleans | -b ) - shift - BOOLEANS=$1 - ;; - - --prefix | -p ) - shift - VARNAME_PREFIX=$1 - ;; - - * ) - if [ -z "$INI_FILE" ] - then - INI_FILE=$1 - else - if [ -z "$INI_SECTION" ] - then - INI_SECTION=$1 - fi - fi - ;; - - esac - - shift - done - - if [ -z "$INI_FILE" ] && [ "${CLEAN_ENV}" = 0 ] ;then - echo -e "Usage: read_ini [-c] [-b 0| -b 1]] [-p PREFIX] FILE"\ - "[SECTION]\n or read_ini -c [-p PREFIX]" >&2 - cleanup_bash - return 1 - fi - - if ! check_prefix ;then - cleanup_bash - return 1 - fi - - local INI_ALL_VARNAME="${VARNAME_PREFIX}__ALL_VARS" - local INI_ALL_SECTION="${VARNAME_PREFIX}__ALL_SECTIONS" - local INI_NUMSECTIONS_VARNAME="${VARNAME_PREFIX}__NUMSECTIONS" - if [ "${CLEAN_ENV}" = 1 ] ;then - eval unset "\$${INI_ALL_VARNAME}" - fi - unset ${INI_ALL_VARNAME} - unset ${INI_ALL_SECTION} - unset ${INI_NUMSECTIONS_VARNAME} - - if [ -z "$INI_FILE" ] ;then - cleanup_bash - return 0 - fi - - if ! check_ini_file ;then - cleanup_bash - return 1 - fi - - # Sanitise BOOLEANS - interpret "0" as 0, anything else as 1 - if [ "$BOOLEANS" != "0" ] - then - BOOLEANS=1 - fi - - - # }}} END Options - - # }}} END Deal with command line args - - local LINE_NUM=0 - local SECTIONS_NUM=0 - local SECTION="" - - # IFS is used in "read" and we want to switch it within the loop - local IFS=$' \t\n' - local IFS_OLD="${IFS}" - - # we need some optional shell behavior (shopt) but want to restore - # current settings before returning - local SWITCH_SHOPT="" - pollute_bash - - while read -r line || [ -n "$line" ] - do -#echo line = "$line" - - ((LINE_NUM++)) - - # Skip blank lines and comments - if [ -z "$line" -o "${line:0:1}" = ";" -o "${line:0:1}" = "#" ] - then - continue - fi - - # Section marker? - if [[ "${line}" =~ ^\[[a-zA-Z0-9_]{1,}\]$ ]] - then - - # Set SECTION var to name of section (strip [ and ] from section marker) - SECTION="${line#[}" - SECTION="${SECTION%]}" - eval "${INI_ALL_SECTION}=\"\${${INI_ALL_SECTION}# } $SECTION\"" - ((SECTIONS_NUM++)) - - continue - fi - - # Are we getting only a specific section? And are we currently in it? - if [ ! -z "$INI_SECTION" ] - then - if [ "$SECTION" != "$INI_SECTION" ] - then - continue - fi - fi - - # Valid var/value line? (check for variable name and then '=') - if ! [[ "${line}" =~ ^[a-zA-Z0-9._]{1,}[[:space:]]*= ]] - then - echo "Error: Invalid line:" >&2 - echo " ${LINE_NUM}: $line" >&2 - cleanup_bash - return 1 - fi - - - # split line at "=" sign - IFS="=" - read -r VAR VAL <<< "${line}" - IFS="${IFS_OLD}" - - # delete spaces around the equal sign (using extglob) - VAR="${VAR%%+([[:space:]])}" - VAL="${VAL##+([[:space:]])}" - VAR=$(echo $VAR) - - - # Construct variable name: - # ${VARNAME_PREFIX}__$SECTION__$VAR - # Or if not in a section: - # ${VARNAME_PREFIX}__$VAR - # In both cases, full stops ('.') are replaced with underscores ('_') - if [ -z "$SECTION" ] - then - VARNAME=${VARNAME_PREFIX}__${VAR//./_} - else - VARNAME=${VARNAME_PREFIX}__${SECTION}__${VAR//./_} - fi - eval "${INI_ALL_VARNAME}=\"\${${INI_ALL_VARNAME}# } ${VARNAME}\"" - - if [[ "${VAL}" =~ ^\".*\"$ ]] - then - # remove existing double quotes - VAL="${VAL##\"}" - VAL="${VAL%%\"}" - elif [[ "${VAL}" =~ ^\'.*\'$ ]] - then - # remove existing single quotes - VAL="${VAL##\'}" - VAL="${VAL%%\'}" - elif [ "$BOOLEANS" = 1 ] - then - # Value is not enclosed in quotes - # Booleans processing is switched on, check for special boolean - # values and convert - - # here we compare case insensitive because - # "shopt nocasematch" - case "$VAL" in - yes | true | on ) - VAL=1 - ;; - no | false | off ) - VAL=0 - ;; - esac - fi - - - # enclose the value in single quotes and escape any - # single quotes and backslashes that may be in the value - VAL="${VAL//\\/\\\\}" - VAL="\$'${VAL//\'/\'}'" - - eval "$VARNAME=$VAL" - done <"${INI_FILE}" - - # return also the number of parsed sections - eval "$INI_NUMSECTIONS_VARNAME=$SECTIONS_NUM" - - cleanup_bash -} diff --git a/install.sh b/install.sh index 63f25b1..d31cf0c 100755 --- a/install.sh +++ b/install.sh @@ -21,7 +21,23 @@ mkdir -p "$INSTALL_DIR" cp ./README.md "$INSTALL_DIR" cp ./config.ini "$INSTALL_DIR" cp -r ./scripts "$INSTALL_DIR" -cp -r ./include "$INSTALL_DIR" + +mkdir -p "$INSTALL_DIR"/include +_PWD=$PWD +if [ -d "$INSTALL_DIR"/include/getopt ]; then + cd "$INSTALL_DIR"/include/getopt + git pull + cd "$_PWD" +else + git clone https://gist.github.com/MisterDA/7284755 "$INSTALL_DIR"/include/getopt +fi +if [ -d "$INSTALL_DIR"/include/bash_ini_parser ]; then + cd "$INSTALL_DIR"/include/bash_ini_parser + git pull + cd "$_PWD" +else + git clone https://github.com/rudimeier/bash_ini_parser "$INSTALL_DIR"/include/bash_ini_parser +fi mkdir -p "$MANPAGE_DIR" sed -e "s/scripts/$SED_ARG\/scripts/g" -e "s/config.ini/$SED_ARG\/config.ini/g" love-release.1 > "$MANPAGE_DIR"/love-release.1 diff --git a/love-release.sh b/love-release.sh index e120359..f4c83f2 100755 --- a/love-release.sh +++ b/love-release.sh @@ -115,11 +115,11 @@ $SHORT_HELP" # Read config missing_operands=true -source "$INCLUDE_DIR"/getopt.sh +source "$INCLUDE_DIR"/getopt/getopt.sh while getoptex "$SCRIPT_ARGS" "$@" do if [ "$OPTOPT" = "config" ]; then - source "$INCLUDE_DIR"/read_ini.sh + source "$INCLUDE_DIR"/bash_ini_parser/read_ini.sh missing_operands=false CONFIG_FILE=$OPTARG read_ini "$CONFIG_FILE" || exit 1