mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-24 13:43:01 +00:00
POSIX compliance, remove bash dependency
This commit is contained in:
parent
bcf348a5a3
commit
8fbc44e3ff
2 changed files with 46 additions and 53 deletions
55
install.sh
55
install.sh
|
@ -4,55 +4,39 @@
|
||||||
# CONSTANTS #
|
# CONSTANTS #
|
||||||
#############
|
#############
|
||||||
|
|
||||||
# dependencies to run kiwi-config
|
# default installation directory
|
||||||
KIWI_DEPS="bash python3 pipenv less"
|
|
||||||
# default install directory
|
|
||||||
INSTALL_DIR_DEFAULT="/usr/local/bin"
|
INSTALL_DIR_DEFAULT="/usr/local/bin"
|
||||||
|
|
||||||
##########
|
|
||||||
# CHECKS #
|
|
||||||
##########
|
|
||||||
|
|
||||||
printf "checking dependencies ... "
|
############
|
||||||
|
# CLI ARGS #
|
||||||
|
############
|
||||||
|
|
||||||
for dep in ${KIWI_DEPS}; do
|
# installation directory
|
||||||
printf "%s, " "${dep}"
|
install_dir="${1}"
|
||||||
|
# adjust default if given
|
||||||
|
INSTALL_DIR_DEFAULT="${1:-${INSTALL_DIR_DEFAULT}}"
|
||||||
|
|
||||||
if ! command -v "${dep}" >/dev/null 2>/dev/null; then
|
|
||||||
echo
|
|
||||||
echo "Dependency '${dep}' not found, please install!" >/dev/stderr
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "OK"
|
|
||||||
|
|
||||||
########
|
########
|
||||||
# MAIN #
|
# MAIN #
|
||||||
########
|
########
|
||||||
|
|
||||||
# prompt for installation directory
|
# prompt for installation directory
|
||||||
valid="no"
|
while [ ! -d "${install_dir}" ]; do
|
||||||
|
|
||||||
while [ "${valid}" = "no" ]; do
|
|
||||||
printf "Select installation directory [Default: '%s']: " "${INSTALL_DIR_DEFAULT}"
|
printf "Select installation directory [Default: '%s']: " "${INSTALL_DIR_DEFAULT}"
|
||||||
read install_dir </dev/tty || install_dir="${INSTALL_DIR_DEFAULT}"
|
read -r install_dir </dev/tty || install_dir="${INSTALL_DIR_DEFAULT}"
|
||||||
install_dir="${install_dir:-${INSTALL_DIR_DEFAULT}}"
|
install_dir="${install_dir:-${INSTALL_DIR_DEFAULT}}"
|
||||||
|
|
||||||
# check
|
# check if given dir exists
|
||||||
if [ -d "${install_dir}" ]; then
|
if [ ! -d "${install_dir}" ]; then
|
||||||
valid="yes"
|
|
||||||
|
|
||||||
else
|
|
||||||
printf "Install directory doesn't exist. Try creating? [Y|n] "
|
printf "Install directory doesn't exist. Try creating? [Y|n] "
|
||||||
read yesno </dev/tty || yesno="yes"
|
read -r yesno </dev/tty || yesno="yes"
|
||||||
if [ ! "${yesno}" = "N" ] || [ ! "${yesno}" = "n" ]; then
|
yesno=$(printf '%.1s' "${yesno}")
|
||||||
|
|
||||||
# check creation failure
|
if [ ! "${yesno}" = "N" ] && [ ! "${yesno}" = "n" ]; then
|
||||||
if mkdir -p "${install_dir}"; then
|
# fail this script if we can't create the install dir
|
||||||
valid="yes"
|
if ! mkdir -p "${install_dir}"; then
|
||||||
|
|
||||||
else
|
|
||||||
echo "Invalid install directory." >/dev/stderr
|
echo "Invalid install directory." >/dev/stderr
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -60,6 +44,11 @@ while [ "${valid}" = "no" ]; do
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ ! -d "${install_dir}" ]; then
|
||||||
|
echo "wtf?"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# start actual installation
|
# start actual installation
|
||||||
printf "Installing into '%s' ... " "${install_dir}"
|
printf "Installing into '%s' ... " "${install_dir}"
|
||||||
|
|
||||||
|
|
44
kiwi
44
kiwi
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
#############
|
#############
|
||||||
# CONSTANTS #
|
# CONSTANTS #
|
||||||
|
@ -10,7 +10,7 @@ KIWI_CONF_NAME="kiwi.yml"
|
||||||
KIWI_VERSION_TAG="etc/version_tag"
|
KIWI_VERSION_TAG="etc/version_tag"
|
||||||
|
|
||||||
# dependencies to run kiwi-config
|
# dependencies to run kiwi-config
|
||||||
KIWI_DEPS=(docker docker-compose)
|
KIWI_DEPS="python3 pipenv less docker docker-compose"
|
||||||
# base install dir
|
# base install dir
|
||||||
KIWI_BASEDIR="${HOME}/.local/lib/kiwi-config"
|
KIWI_BASEDIR="${HOME}/.local/lib/kiwi-config"
|
||||||
# per-user env setup script
|
# per-user env setup script
|
||||||
|
@ -21,28 +21,30 @@ KIWI_REPO="https://github.com/ldericher/kiwi-config"
|
||||||
# use latest version by default
|
# use latest version by default
|
||||||
KIWI_VERSION="master"
|
KIWI_VERSION="master"
|
||||||
|
|
||||||
|
|
||||||
###################
|
###################
|
||||||
# DYNAMIC STRINGS #
|
# DYNAMIC STRINGS #
|
||||||
###################
|
###################
|
||||||
|
|
||||||
# directory of correct installation
|
# directory of correct installation
|
||||||
function kiwi_installdir() {
|
kiwi_installdir() {
|
||||||
echo "${KIWI_BASEDIR}/${KIWI_VERSION}"
|
echo "${KIWI_BASEDIR}/${KIWI_VERSION}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# src directory in installed version
|
# src directory in installed version
|
||||||
function kiwi_root() {
|
kiwi_root() {
|
||||||
echo "$(kiwi_installdir)/src"
|
echo "$(kiwi_installdir)/src"
|
||||||
}
|
}
|
||||||
|
|
||||||
# main script in installed version
|
# main script in installed version
|
||||||
function kiwi_executable() {
|
kiwi_executable() {
|
||||||
echo "$(kiwi_root)/kiwi-config.py"
|
echo "$(kiwi_root)/kiwi-config.py"
|
||||||
}
|
}
|
||||||
|
|
||||||
# cache current work directory
|
# cache current work directory
|
||||||
WORKDIR="$(pwd)"
|
WORKDIR="$(pwd)"
|
||||||
|
|
||||||
|
|
||||||
##################
|
##################
|
||||||
# PER-USER SETUP #
|
# PER-USER SETUP #
|
||||||
##################
|
##################
|
||||||
|
@ -50,20 +52,22 @@ WORKDIR="$(pwd)"
|
||||||
# add in environment setup
|
# add in environment setup
|
||||||
if [ -f "${KIWI_ENVFILE}" ]; then
|
if [ -f "${KIWI_ENVFILE}" ]; then
|
||||||
# shellcheck source=$HOME/.kiwienv
|
# shellcheck source=$HOME/.kiwienv
|
||||||
source "${KIWI_ENVFILE}"
|
. "${KIWI_ENVFILE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
##########
|
##########
|
||||||
# CHECKS #
|
# CHECKS #
|
||||||
##########
|
##########
|
||||||
|
|
||||||
for dep in "${KIWI_DEPS[@]}"; do
|
for dep in ${KIWI_DEPS}; do
|
||||||
if ! command -v "${dep}" &>/dev/null; then
|
if ! command -v "${dep}" >/dev/null 2>/dev/null; then
|
||||||
echo "Dependency '${dep}' not found, please install!" >/dev/stderr
|
echo "Dependency '${dep}' not found, please install!" >/dev/stderr
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
########
|
########
|
||||||
# MAIN #
|
# MAIN #
|
||||||
########
|
########
|
||||||
|
@ -77,7 +81,7 @@ fi
|
||||||
|
|
||||||
# install if kiwi-config not found
|
# install if kiwi-config not found
|
||||||
if [ ! -x "$(kiwi_executable)" ]; then
|
if [ ! -x "$(kiwi_executable)" ]; then
|
||||||
echo -n "Installing kiwi-config v${KIWI_VERSION} into ${KIWI_BASEDIR} ... "
|
printf "Installing kiwi-config v%s into %s ... " "${KIWI_VERSION}" "${KIWI_BASEDIR}"
|
||||||
|
|
||||||
# switch to temp dir
|
# switch to temp dir
|
||||||
tmpdir=$(mktemp -d)
|
tmpdir=$(mktemp -d)
|
||||||
|
@ -92,7 +96,7 @@ if [ ! -x "$(kiwi_executable)" ]; then
|
||||||
|
|
||||||
if [ -x "$(kiwi_executable)" ]; then
|
if [ -x "$(kiwi_executable)" ]; then
|
||||||
# after version update: no need to install
|
# after version update: no need to install
|
||||||
echo "kiwi-config v${KIWI_VERSION} found!"
|
echo "v${KIWI_VERSION} already installed!"
|
||||||
|
|
||||||
else
|
else
|
||||||
# install archive
|
# install archive
|
||||||
|
@ -106,15 +110,6 @@ if [ ! -x "$(kiwi_executable)" ]; then
|
||||||
rm -rf "${tmpdir}"
|
rm -rf "${tmpdir}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check virtualenv
|
|
||||||
cd "$(kiwi_installdir)" || :
|
|
||||||
if ! pipenv --venv &>/dev/null; then
|
|
||||||
# install virtualenv
|
|
||||||
echo -n "Preparing virtualenv ... "
|
|
||||||
pipenv sync &>/dev/null
|
|
||||||
echo "OK"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# go back to the original work directory
|
# go back to the original work directory
|
||||||
cd "${WORKDIR}" || :
|
cd "${WORKDIR}" || :
|
||||||
|
|
||||||
|
@ -123,10 +118,19 @@ KIWI_ROOT="$(kiwi_root)"
|
||||||
PIPENV_VERBOSITY=-1
|
PIPENV_VERBOSITY=-1
|
||||||
PIPENV_PIPFILE="$(kiwi_installdir)/Pipfile"
|
PIPENV_PIPFILE="$(kiwi_installdir)/Pipfile"
|
||||||
|
|
||||||
export KIWI_ROOT
|
|
||||||
export KIWI_CONF_NAME
|
export KIWI_CONF_NAME
|
||||||
|
export KIWI_ROOT
|
||||||
export PIPENV_VERBOSITY
|
export PIPENV_VERBOSITY
|
||||||
export PIPENV_PIPFILE
|
export PIPENV_PIPFILE
|
||||||
|
|
||||||
|
# check virtualenv
|
||||||
|
cd "$(kiwi_installdir)" || :
|
||||||
|
if ! pipenv --venv >/dev/null 2>/dev/null; then
|
||||||
|
# install virtualenv
|
||||||
|
printf "Preparing virtualenv ... "
|
||||||
|
pipenv sync >/dev/null 2>/dev/null
|
||||||
|
echo "OK"
|
||||||
|
fi
|
||||||
|
|
||||||
# run main script
|
# run main script
|
||||||
exec pipenv run "$(kiwi_executable)" "${@}"
|
exec pipenv run "$(kiwi_executable)" "${@}"
|
||||||
|
|
Loading…
Reference in a new issue