2020-08-04 00:56:29 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#############
|
|
|
|
# CONSTANTS #
|
2020-08-20 22:04:26 +00:00
|
|
|
#############
|
2020-08-04 00:56:29 +00:00
|
|
|
|
2020-08-04 14:38:51 +00:00
|
|
|
# base config filename
|
2020-08-20 15:38:25 +00:00
|
|
|
KIWI_CONF_NAME="kiwi.yml"
|
|
|
|
# version tag filename
|
|
|
|
KIWI_VERSION_TAG="etc/version_tag"
|
|
|
|
|
|
|
|
# dependencies to run kiwi-config
|
2020-08-24 15:01:16 +00:00
|
|
|
KIWI_DEPS=(docker docker-compose)
|
2020-08-20 22:04:26 +00:00
|
|
|
# base install dir
|
2020-08-24 15:01:16 +00:00
|
|
|
KIWI_BASEDIR="${HOME}/.local/lib/kiwi-config"
|
2020-08-20 15:38:25 +00:00
|
|
|
# per-user env setup script
|
|
|
|
KIWI_ENVFILE="${HOME}/.kiwienv"
|
|
|
|
|
2020-08-04 00:56:29 +00:00
|
|
|
# repository uri
|
|
|
|
KIWI_REPO="https://github.com/ldericher/kiwi-config"
|
2020-08-20 15:38:25 +00:00
|
|
|
# use latest version by default
|
|
|
|
KIWI_VERSION="master"
|
|
|
|
|
|
|
|
###################
|
|
|
|
# DYNAMIC STRINGS #
|
|
|
|
###################
|
|
|
|
|
|
|
|
# directory of correct installation
|
|
|
|
function kiwi_installdir() {
|
|
|
|
echo "${KIWI_BASEDIR}/${KIWI_VERSION}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# src directory in installed version
|
|
|
|
function kiwi_root() {
|
|
|
|
echo "$(kiwi_installdir)/src"
|
|
|
|
}
|
|
|
|
|
|
|
|
# main script in installed version
|
|
|
|
function kiwi_executable() {
|
|
|
|
echo "$(kiwi_root)/kiwi-config.py"
|
|
|
|
}
|
|
|
|
|
|
|
|
# cache current work directory
|
|
|
|
WORKDIR="$(pwd)"
|
|
|
|
|
|
|
|
##################
|
|
|
|
# PER-USER SETUP #
|
|
|
|
##################
|
|
|
|
|
|
|
|
# add in environment setup
|
|
|
|
if [ -f "${KIWI_ENVFILE}" ]; then
|
2020-08-20 22:04:26 +00:00
|
|
|
# shellcheck source=$HOME/.kiwienv
|
|
|
|
source "${KIWI_ENVFILE}"
|
2020-08-20 15:38:25 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
##########
|
|
|
|
# CHECKS #
|
|
|
|
##########
|
|
|
|
|
|
|
|
for dep in "${KIWI_DEPS[@]}"; do
|
2020-08-20 22:04:26 +00:00
|
|
|
if ! command -v "${dep}" &>/dev/null; then
|
2020-08-24 15:01:16 +00:00
|
|
|
echo "Dependency '${dep}' not found, please install!" >/dev/stderr
|
2020-08-20 15:38:25 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2020-08-04 00:56:29 +00:00
|
|
|
|
|
|
|
########
|
|
|
|
# MAIN #
|
|
|
|
########
|
|
|
|
|
|
|
|
# check if pwd is a kiwi folder
|
|
|
|
if [ -f "./${KIWI_CONF_NAME}" ]; then
|
2020-08-20 22:04:26 +00:00
|
|
|
# determine needed kiwi-config version
|
|
|
|
re_version_line='version\s*:\s*'
|
2020-08-24 12:48:50 +00:00
|
|
|
eval "$(grep -E "${re_version_line}" "./${KIWI_CONF_NAME}" | sed -r "s/${re_version_line}/KIWI_VERSION=/")"
|
2020-08-04 00:56:29 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# install if kiwi-config not found
|
2020-08-20 15:38:25 +00:00
|
|
|
if [ ! -x "$(kiwi_executable)" ]; then
|
2020-08-20 22:04:26 +00:00
|
|
|
echo -n "Installing kiwi-config v${KIWI_VERSION} into ${KIWI_BASEDIR} ... "
|
2020-08-04 00:56:29 +00:00
|
|
|
|
2020-08-24 15:01:16 +00:00
|
|
|
# switch to temp dir
|
|
|
|
tmpdir=$(mktemp -d)
|
|
|
|
cd "${tmpdir}" || :
|
2020-08-04 00:56:29 +00:00
|
|
|
|
2020-08-24 15:01:16 +00:00
|
|
|
# download archive
|
|
|
|
curl -o "kiwi-config.zip" "${KIWI_REPO}/archive/${KIWI_VERSION}.zip"
|
|
|
|
unzip "kiwi-config.zip"
|
2020-08-04 00:56:29 +00:00
|
|
|
|
2020-08-24 15:01:16 +00:00
|
|
|
# read archive version tag
|
|
|
|
cd "kiwi-config-${KIWI_VERSION}" || :
|
|
|
|
KIWI_VERSION=$(cat "./src/${KIWI_VERSION_TAG}")
|
2020-08-04 00:56:29 +00:00
|
|
|
|
2020-08-24 15:01:16 +00:00
|
|
|
# install archive
|
|
|
|
mkdir -p "$(kiwi_installdir)"
|
|
|
|
mv "src" "Pipfile" "Pipfile.lock" "$(kiwi_installdir)/"
|
2020-08-04 00:56:29 +00:00
|
|
|
|
2020-08-24 15:01:16 +00:00
|
|
|
# discard temp dir
|
|
|
|
cd "${WORKDIR}" || :
|
|
|
|
rm -rf "${tmpdir}"
|
2020-08-20 15:38:25 +00:00
|
|
|
|
2020-08-24 15:01:16 +00:00
|
|
|
echo "OK"
|
2020-08-04 00:56:29 +00:00
|
|
|
fi
|
|
|
|
|
2020-08-20 15:38:25 +00:00
|
|
|
# check virtualenv
|
2020-08-20 22:04:26 +00:00
|
|
|
cd "$(kiwi_installdir)" || :
|
|
|
|
if ! pipenv --venv &>/dev/null; then
|
2020-08-20 15:38:25 +00:00
|
|
|
# install virtualenv
|
|
|
|
echo -n "Preparing virtualenv ... "
|
2020-08-20 22:04:26 +00:00
|
|
|
pipenv sync &>/dev/null
|
2020-08-20 15:38:25 +00:00
|
|
|
echo "OK"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# go back to the original work directory
|
2020-08-20 22:04:26 +00:00
|
|
|
cd "${WORKDIR}" || :
|
2020-08-20 15:38:25 +00:00
|
|
|
|
|
|
|
# setup main environment
|
|
|
|
KIWI_ROOT="$(kiwi_root)"
|
|
|
|
|
|
|
|
export KIWI_ROOT
|
|
|
|
export KIWI_CONF_NAME
|
2020-08-20 22:04:26 +00:00
|
|
|
export PIPENV_VERBOSITY=-1
|
2020-08-04 14:38:51 +00:00
|
|
|
|
2020-08-04 00:56:29 +00:00
|
|
|
# run main script
|
2020-08-20 22:04:26 +00:00
|
|
|
exec pipenv run "$(kiwi_executable)" "${@}"
|