pvincent
3 years ago
2 changed files with 88 additions and 90 deletions
-
110install.sh
-
56lib/functions.sh
@ -1,45 +1,53 @@ |
|||||
|
# idempotent apt install [package1 package2 ...] |
||||
|
function idem_apt_install() { |
||||
|
for i in $@; do |
||||
|
if ! (/usr/bin/dpkg-query --status "$i" >/dev/null 2>&1); then |
||||
|
/usr/bin/apt install -y "$i" |
||||
|
fi |
||||
|
done |
||||
|
} |
||||
|
|
||||
## |
## |
||||
# return 0 (true) if array (passed by name) contains element |
# return 0 (true) if array (passed by name) contains element |
||||
# usage: |
# usage: |
||||
# ARRAY = ( a b c ) |
# ARRAY = ( a b c ) |
||||
# containsElement ARRAY 'a' => 0 |
# containsElement ARRAY 'a' => 0 |
||||
containsElement () { |
|
||||
local -a 'arraykeys=("${!'"$1"'[@]}")' |
|
||||
|
containsElement() { |
||||
|
local -a 'arraykeys=("${!'"$1"'[@]}")' |
||||
if $(isArray $1); then |
if $(isArray $1); then |
||||
for index in ${arraykeys[*]}; do |
|
||||
current=$1"[$index]" |
|
||||
[[ "${!current}" == "$2" ]] && return 0; # found |
|
||||
done |
|
||||
return 1; # not found |
|
||||
|
for index in ${arraykeys[*]}; do |
||||
|
current=$1"[$index]" |
||||
|
[[ "${!current}" == "$2" ]] && return 0 # found |
||||
|
done |
||||
|
return 1 # not found |
||||
else |
else |
||||
>&2 echo "ERROR: $1 not an array!" |
|
||||
return 2; # not an array |
|
||||
|
echo >&2 "ERROR: $1 not an array!" |
||||
|
return 2 # not an array |
||||
fi |
fi |
||||
} |
} |
||||
|
|
||||
isArray(){ |
|
||||
[[ "$(declare -p $1 2> /dev/null)" =~ "declare -a" ]] && return 0; # is an array |
|
||||
return 1; # not an array |
|
||||
|
isArray() { |
||||
|
[[ "$(declare -p $1 2>/dev/null)" =~ "declare -a" ]] && return 0 # is an array |
||||
|
return 1 # not an array |
||||
} |
} |
||||
|
|
||||
## |
## |
||||
# |
# |
||||
askConfirmation () { |
|
||||
|
askConfirmation() { |
||||
case "$1" in |
case "$1" in |
||||
y|Y|yes|YES ) |
|
||||
QUESTION="(Y/n)?" |
|
||||
DEFAULT=0 |
|
||||
;; |
|
||||
* ) |
|
||||
QUESTION="(y/N)?" |
|
||||
DEFAULT=1 |
|
||||
;; |
|
||||
|
y | Y | yes | YES) |
||||
|
QUESTION="(Y/n)?" |
||||
|
DEFAULT=0 |
||||
|
;; |
||||
|
*) |
||||
|
QUESTION="(y/N)?" |
||||
|
DEFAULT=1 |
||||
|
;; |
||||
esac |
esac |
||||
read -p "$QUESTION : " choice |
read -p "$QUESTION : " choice |
||||
case "$choice" in |
case "$choice" in |
||||
y|Y|yes|YES ) return 0;; #true |
|
||||
n|no|N|NO ) return 1;; #false |
|
||||
* ) return $DEFAULT;; |
|
||||
|
y | Y | yes | YES) return 0 ;; #true |
||||
|
n | no | N | NO) return 1 ;; #false |
||||
|
*) return $DEFAULT ;; |
||||
esac |
esac |
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue