2020-08-24 15:01:16 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
#############
|
|
|
|
# CONSTANTS #
|
|
|
|
#############
|
|
|
|
|
2020-08-25 12:34:30 +00:00
|
|
|
# default installation directory
|
2020-08-24 18:18:46 +00:00
|
|
|
INSTALL_DIR_DEFAULT="/usr/local/bin"
|
2020-08-24 15:01:16 +00:00
|
|
|
|
|
|
|
|
2020-08-25 12:34:30 +00:00
|
|
|
############
|
|
|
|
# CLI ARGS #
|
|
|
|
############
|
2020-08-24 15:01:16 +00:00
|
|
|
|
2020-08-25 12:34:30 +00:00
|
|
|
# installation directory
|
|
|
|
install_dir="${1}"
|
|
|
|
# adjust default if given
|
|
|
|
INSTALL_DIR_DEFAULT="${1:-${INSTALL_DIR_DEFAULT}}"
|
2020-08-24 15:01:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
########
|
|
|
|
# MAIN #
|
|
|
|
########
|
|
|
|
|
|
|
|
# prompt for installation directory
|
2020-08-25 12:34:30 +00:00
|
|
|
while [ ! -d "${install_dir}" ]; do
|
2020-08-24 18:18:46 +00:00
|
|
|
printf "Select installation directory [Default: '%s']: " "${INSTALL_DIR_DEFAULT}"
|
2020-08-25 12:34:30 +00:00
|
|
|
read -r install_dir </dev/tty || install_dir="${INSTALL_DIR_DEFAULT}"
|
2020-08-24 18:18:46 +00:00
|
|
|
install_dir="${install_dir:-${INSTALL_DIR_DEFAULT}}"
|
2020-08-24 15:01:16 +00:00
|
|
|
|
2020-08-25 12:34:30 +00:00
|
|
|
# check if given dir exists
|
|
|
|
if [ ! -d "${install_dir}" ]; then
|
2020-08-24 15:01:16 +00:00
|
|
|
printf "Install directory doesn't exist. Try creating? [Y|n] "
|
2020-08-25 12:34:30 +00:00
|
|
|
read -r yesno </dev/tty || yesno="yes"
|
|
|
|
yesno=$(printf '%.1s' "${yesno}")
|
2020-08-24 15:01:16 +00:00
|
|
|
|
2020-08-25 12:34:30 +00:00
|
|
|
if [ ! "${yesno}" = "N" ] && [ ! "${yesno}" = "n" ]; then
|
|
|
|
# fail this script if we can't create the install dir
|
|
|
|
if ! mkdir -p "${install_dir}"; then
|
2020-08-24 15:01:16 +00:00
|
|
|
echo "Invalid install directory." >/dev/stderr
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-08-25 12:34:30 +00:00
|
|
|
if [ ! -d "${install_dir}" ]; then
|
|
|
|
echo "wtf?"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-08-24 15:01:16 +00:00
|
|
|
# start actual installation
|
|
|
|
printf "Installing into '%s' ... " "${install_dir}"
|
|
|
|
|
|
|
|
# install "kiwi" script
|
|
|
|
uri="https://raw.githubusercontent.com/ldericher/kiwi-config/master/kiwi"
|
|
|
|
tmp_file="$(mktemp)"
|
|
|
|
|
2020-08-24 18:18:46 +00:00
|
|
|
if ! curl --proto '=https' --tlsv1.2 -sSf -o "${tmp_file}" "${uri}" >/dev/null 2>/dev/null; then
|
2020-08-24 15:01:16 +00:00
|
|
|
rm "${tmp_file}"
|
|
|
|
echo "Download 'kiwi' failed!" >/dev/stderr
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-08-24 15:43:14 +00:00
|
|
|
if ! install -m 0755 "${tmp_file}" "${install_dir}/kiwi" >/dev/null 2>/dev/null; then
|
2020-08-24 15:01:16 +00:00
|
|
|
rm "${tmp_file}"
|
|
|
|
echo "Install 'kiwi' failed!" >/dev/stderr
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm "${tmp_file}"
|
|
|
|
|
|
|
|
# finalization
|
|
|
|
echo "OK"
|
2020-08-24 15:43:14 +00:00
|
|
|
exit 0
|