351 lines
6.5 KiB
Bash
351 lines
6.5 KiB
Bash
|
|
#!/bin/sh
|
||
|
|
set -eu
|
||
|
|
|
||
|
|
# *************
|
||
|
|
# DO NOT EDIT
|
||
|
|
#
|
||
|
|
# install.sh was bundled together from
|
||
|
|
#
|
||
|
|
# - ./ci/sub/lib/rand.sh
|
||
|
|
# - ./ci/sub/lib/log.sh
|
||
|
|
# - ./ci/sub/lib/flag.sh
|
||
|
|
# - ./ci/release/_install.sh
|
||
|
|
#
|
||
|
|
# The last of which implements the installation logic.
|
||
|
|
#
|
||
|
|
# Generated by ./ci/release/gen_install.sh.
|
||
|
|
# *************
|
||
|
|
|
||
|
|
#!/bin/sh
|
||
|
|
if [ "${LIB_RAND-}" ]; then
|
||
|
|
return 0
|
||
|
|
fi
|
||
|
|
LIB_RAND=1
|
||
|
|
|
||
|
|
rand() {
|
||
|
|
seed="$1"
|
||
|
|
range="$2"
|
||
|
|
|
||
|
|
seed_file="$(mktemp)"
|
||
|
|
_echo "$seed" | md5sum > "$seed_file"
|
||
|
|
shuf -i "$range" -n 1 --random-source="$seed_file"
|
||
|
|
}
|
||
|
|
|
||
|
|
pick() {
|
||
|
|
seed="$1"
|
||
|
|
shift
|
||
|
|
i="$(rand "$seed" "1-$#")"
|
||
|
|
eval "_echo \"\$$i\""
|
||
|
|
}
|
||
|
|
#!/bin/sh
|
||
|
|
if [ "${LIB_LOG-}" ]; then
|
||
|
|
return 0
|
||
|
|
fi
|
||
|
|
LIB_LOG=1
|
||
|
|
|
||
|
|
tput() {
|
||
|
|
if [ -n "$TERM" ]; then
|
||
|
|
command tput "$@"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
setaf() {
|
||
|
|
tput setaf "$1"
|
||
|
|
shift
|
||
|
|
printf '%s' "$*"
|
||
|
|
tput sgr0
|
||
|
|
}
|
||
|
|
|
||
|
|
_echo() {
|
||
|
|
printf '%s\n' "$*"
|
||
|
|
}
|
||
|
|
|
||
|
|
get_rand_color() {
|
||
|
|
# 1-6 are regular and 9-14 are bright.
|
||
|
|
# 1,2 and 9,10 are red and green but we use those for success and failure.
|
||
|
|
pick "$*" 3 4 5 6 11 12 13 14
|
||
|
|
}
|
||
|
|
|
||
|
|
echop() {
|
||
|
|
prefix="$1"
|
||
|
|
shift
|
||
|
|
|
||
|
|
if [ "$#" -gt 0 ]; then
|
||
|
|
printfp "$prefix" "%s\n" "$*"
|
||
|
|
else
|
||
|
|
printfp "$prefix"
|
||
|
|
printf '\n'
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
printfp() {(
|
||
|
|
prefix="$1"
|
||
|
|
shift
|
||
|
|
|
||
|
|
if [ -z "${COLOR:-}" ]; then
|
||
|
|
COLOR="$(get_rand_color "$prefix")"
|
||
|
|
fi
|
||
|
|
printf '%s' "$(setaf "$COLOR" "$prefix")"
|
||
|
|
|
||
|
|
if [ $# -gt 0 ]; then
|
||
|
|
printf ': '
|
||
|
|
printf "$@"
|
||
|
|
fi
|
||
|
|
)}
|
||
|
|
|
||
|
|
catp() {
|
||
|
|
prefix="$1"
|
||
|
|
shift
|
||
|
|
|
||
|
|
printfp "$prefix"
|
||
|
|
printf ': '
|
||
|
|
read -r line
|
||
|
|
_echo "$line"
|
||
|
|
|
||
|
|
indent=$(repeat ' ' 2)
|
||
|
|
sed "s/^/$indent/"
|
||
|
|
}
|
||
|
|
|
||
|
|
repeat() {
|
||
|
|
char="$1"
|
||
|
|
times="$2"
|
||
|
|
seq -s "$char" "$times" | tr -d '[:digit:]'
|
||
|
|
}
|
||
|
|
|
||
|
|
strlen() {
|
||
|
|
printf %s "$1" | wc -c
|
||
|
|
}
|
||
|
|
|
||
|
|
echoerr() {
|
||
|
|
COLOR=1 echop err "$*" >&2
|
||
|
|
}
|
||
|
|
|
||
|
|
caterr() {
|
||
|
|
COLOR=1 catp err "$@" >&2
|
||
|
|
}
|
||
|
|
|
||
|
|
printferr() {
|
||
|
|
COLOR=1 printfp err "$@" >&2
|
||
|
|
}
|
||
|
|
|
||
|
|
logp() {
|
||
|
|
echop "$@" >&2
|
||
|
|
}
|
||
|
|
|
||
|
|
logfp() {
|
||
|
|
printfp "$@" >&2
|
||
|
|
}
|
||
|
|
|
||
|
|
logpcat() {
|
||
|
|
catp "$@" >&2
|
||
|
|
}
|
||
|
|
|
||
|
|
log() {
|
||
|
|
COLOR=5 logp log "$@"
|
||
|
|
}
|
||
|
|
|
||
|
|
logf() {
|
||
|
|
COLOR=5 logfp log "$@"
|
||
|
|
}
|
||
|
|
|
||
|
|
logcat() {
|
||
|
|
COLOR=5 catp log "$@" >&2
|
||
|
|
}
|
||
|
|
|
||
|
|
sh_c() {
|
||
|
|
COLOR=3 logp exec "$*"
|
||
|
|
if [ -z "${DRYRUN-}" ]; then
|
||
|
|
eval "$@"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
header() {
|
||
|
|
logp "/* $1 */"
|
||
|
|
}
|
||
|
|
|
||
|
|
hide() {
|
||
|
|
out="$(mktemp)"
|
||
|
|
set +e
|
||
|
|
"$@" >"$out" 2>&1
|
||
|
|
code="$?"
|
||
|
|
set -e
|
||
|
|
if [ "$code" -eq 0 ]; then
|
||
|
|
return
|
||
|
|
fi
|
||
|
|
cat "$out" >&2
|
||
|
|
exit "$code"
|
||
|
|
}
|
||
|
|
|
||
|
|
echo_dur() {
|
||
|
|
local dur=$1
|
||
|
|
local h=$((dur/60/60))
|
||
|
|
local m=$((dur/60%60))
|
||
|
|
local s=$((dur%60))
|
||
|
|
printf '%dh%dm%ds' "$h" "$m" "$s"
|
||
|
|
}
|
||
|
|
|
||
|
|
sponge() {
|
||
|
|
dst="$1"
|
||
|
|
tmp="$(mktemp)"
|
||
|
|
cat > "$tmp"
|
||
|
|
cat "$tmp" > "$dst"
|
||
|
|
}
|
||
|
|
|
||
|
|
stripansi() {
|
||
|
|
# First regex gets rid of standard xterm escape sequences for controlling
|
||
|
|
# visual attributes.
|
||
|
|
# The second regex I'm not 100% sure, the reference says it selects the US
|
||
|
|
# encoding but I'm not sure why that's necessary or why it always occurs
|
||
|
|
# in tput sgr0 before the standard escape sequence.
|
||
|
|
# See tput sgr0 | xxd
|
||
|
|
sed -e $'s/\x1b\[[0-9;]*m//g' -e $'s/\x1b(.//g'
|
||
|
|
}
|
||
|
|
|
||
|
|
runtty() {
|
||
|
|
case "$(uname)" in
|
||
|
|
Darwin)
|
||
|
|
script -q /dev/null "$@"
|
||
|
|
;;
|
||
|
|
Linux)
|
||
|
|
script -eqc "$*"
|
||
|
|
;;
|
||
|
|
*)
|
||
|
|
echoerr "runtty: unsupported OS $(uname)"
|
||
|
|
return 1
|
||
|
|
esac
|
||
|
|
}
|
||
|
|
#!/bin/sh
|
||
|
|
if [ "${LIB_FLAG-}" ]; then
|
||
|
|
return 0
|
||
|
|
fi
|
||
|
|
LIB_FLAG=1
|
||
|
|
|
||
|
|
# flag_parse implements a robust flag parser.
|
||
|
|
#
|
||
|
|
# For a full fledge example see ../examples/date.sh
|
||
|
|
#
|
||
|
|
# It differs from getopts(1) in that long form options are supported. Currently the only
|
||
|
|
# deficiency is that short combined options are not supported like -xyzq. That would be
|
||
|
|
# interpreted as a single -xyzq flag. The other deficiency is lack of support for short
|
||
|
|
# flag syntax like -carg where the arg is not separated from the flag. This one is
|
||
|
|
# unfixable I believe unfortunately but for combined short flags I have opened
|
||
|
|
# https://github.com/terrastruct/ci/issues/6
|
||
|
|
#
|
||
|
|
# flag_parse stores state in $FLAG, $FLAGRAW, $FLAGARG and $FLAGSHIFT.
|
||
|
|
# FLAG contains the name of the flag without hyphens.
|
||
|
|
# FLAGRAW contains the name of the flag as passed in with hyphens.
|
||
|
|
# FLAGARG contains the argument for the flag if there was any.
|
||
|
|
# If there was none, it will not be set.
|
||
|
|
# FLAGSHIFT contains the number by which the arguments should be shifted to
|
||
|
|
# start at the next flag/argument
|
||
|
|
#
|
||
|
|
# After each call check $FLAG for the name of the parsed flag.
|
||
|
|
# If empty, then no more flags are left.
|
||
|
|
# Still, call shift "$FLAGSHIFT" in case there was a --
|
||
|
|
#
|
||
|
|
# If the argument for the flag is optional, then use ${FLAGARG-} to access
|
||
|
|
# the argument if one was passed. Use ${FLAGARG+x} = x to check if it was set.
|
||
|
|
# You only need to explicitly check if the flag was set if you care whether the user
|
||
|
|
# explicitly passed the empty string as the argument.
|
||
|
|
#
|
||
|
|
# Otherwise, call one of the flag_*arg functions:
|
||
|
|
#
|
||
|
|
# If a flag requires an argument, call flag_reqarg
|
||
|
|
# - $FLAGARG is guaranteed to be set after.
|
||
|
|
# If a flag requires a non empty argument, call flag_nonemptyarg
|
||
|
|
# - $FLAGARG is guaranteed to be set to a non empty string after.
|
||
|
|
# If a flag should not be passed an argument, call flag_noarg
|
||
|
|
# - $FLAGARG is guaranteed to be unset after.
|
||
|
|
#
|
||
|
|
# And then shift "$FLAGSHIFT"
|
||
|
|
flag_parse() {
|
||
|
|
case "${1-}" in
|
||
|
|
-*=*)
|
||
|
|
# Remove everything after first equal sign.
|
||
|
|
FLAG="${1%%=*}"
|
||
|
|
FLAGRAW="$FLAG"
|
||
|
|
# Remove leading hyphens.
|
||
|
|
FLAG="${FLAG#-}"; FLAG="${FLAG#-}"
|
||
|
|
# Remove everything before first equal sign.
|
||
|
|
FLAGARG="${1#*=}"
|
||
|
|
FLAGSHIFT=1
|
||
|
|
;;
|
||
|
|
-)
|
||
|
|
FLAG=
|
||
|
|
FLAGRAW=
|
||
|
|
unset FLAGARG
|
||
|
|
FLAGSHIFT=0
|
||
|
|
;;
|
||
|
|
--)
|
||
|
|
FLAG=
|
||
|
|
FLAGRAW=
|
||
|
|
unset FLAGARG
|
||
|
|
FLAGSHIFT=1
|
||
|
|
;;
|
||
|
|
-*)
|
||
|
|
# Remove leading hyphens.
|
||
|
|
FLAG="${1#-}"; FLAG="${FLAG#-}"
|
||
|
|
FLAGRAW=$1
|
||
|
|
unset FLAGARG
|
||
|
|
FLAGSHIFT=1
|
||
|
|
if [ $# -gt 1 ]; then
|
||
|
|
case "$2" in
|
||
|
|
-)
|
||
|
|
FLAGARG="$2"
|
||
|
|
FLAGSHIFT=2
|
||
|
|
;;
|
||
|
|
-*)
|
||
|
|
;;
|
||
|
|
*)
|
||
|
|
FLAGARG="$2"
|
||
|
|
FLAGSHIFT=2
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
fi
|
||
|
|
;;
|
||
|
|
*)
|
||
|
|
FLAG=
|
||
|
|
FLAGRAW=
|
||
|
|
unset FLAGARG
|
||
|
|
FLAGSHIFT=0
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
return 0
|
||
|
|
}
|
||
|
|
|
||
|
|
flag_reqarg() {
|
||
|
|
if [ "${FLAGARG+x}" != x ]; then
|
||
|
|
flag_errusage "flag $FLAGRAW requires an argument"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
flag_nonemptyarg() {
|
||
|
|
flag_reqarg
|
||
|
|
if [ -z "$FLAGARG" ]; then
|
||
|
|
flag_errusage "flag $FLAGRAW requires a non-empty argument"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
flag_noarg() {
|
||
|
|
if [ "$FLAGSHIFT" -eq 2 ]; then
|
||
|
|
unset FLAGARG
|
||
|
|
FLAGSHIFT=1
|
||
|
|
elif [ "${FLAGARG+x}" = x ]; then
|
||
|
|
# Means an argument was passed via equal sign as in -$FLAG=$FLAGARG
|
||
|
|
flag_errusage "flag $FLAGRAW does not accept an argument"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
flag_errusage() {
|
||
|
|
caterr <<EOF
|
||
|
|
$1
|
||
|
|
Run with --help for usage.
|
||
|
|
EOF
|
||
|
|
return 1
|
||
|
|
}
|
||
|
|
#!/bin/sh
|
||
|
|
set -eu
|
||
|
|
|
||
|
|
|
||
|
|
doing installation here
|