diff --git a/bin/main.sh b/bin/main.sh deleted file mode 100755 index ece7b24..0000000 --- a/bin/main.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -echo "Hello World!" - -echo "This is ${0}." - -echo "A.K.A. $(readlink -f ${0})." - -echo "Arguments are:" - -for an_arg in "${@}" ; do - echo "- ${an_arg}" -done \ No newline at end of file diff --git a/kiwi b/kiwi index 1b330e9..0e66857 100755 --- a/kiwi +++ b/kiwi @@ -4,10 +4,10 @@ # CONSTANTS # ############# -# base config filename (constant) -KIWI_CONF_NAME="kiwi.conf" +# base config filename +export KIWI_CONF_NAME="kiwi.conf" # base install dir -KIWI_BASEDIR="${HOME}/.cache/kiwi-config-bin" +KIWI_BASEDIR="${HOME}/.cache/kiwi-config" # repository uri KIWI_REPO="https://github.com/ldericher/kiwi-config" @@ -16,55 +16,54 @@ KIWI_REPO="https://github.com/ldericher/kiwi-config" ######## # use latest version by default -version="master" +export KIWI_VERSION="master" # check if pwd is a kiwi folder if [ -f "./${KIWI_CONF_NAME}" ]; then # determine needed kiwi-config version - version=$(source "./${KIWI_CONF_NAME}" && echo "v${VERSION}") + export KIWI_VERSION=$(source "./${KIWI_CONF_NAME}" && echo "${VERSION}") fi # install if kiwi-config not found -if [ ! -x "${KIWI_BASEDIR}/${version}/main.sh" ]; then - echo -n "Installing kiwi-config ${version} into ${KIWI_BASEDIR} ... " +if [ ! -x "${KIWI_BASEDIR}/${KIWI_VERSION}/bin/main.sh" ]; then + echo -n "Installing kiwi-config v${KIWI_VERSION} into ${KIWI_BASEDIR} ... " ### production version ### - # # create temp dir + # # switch to temp dir + # workdir=$(pwd) # tmpdir=$(mktemp -d) + # cd "${tmpdir}" - # ( - # cd "${tmpdir}" + # # download archive + # wget "${KIWI_REPO}/archive/${KIWI_VERSION}.zip" + # unzip "${KIWI_VERSION}.zip" - # # download archive - # wget "${KIWI_REPO}/archive/${version}.zip" - # unzip "${version}.zip" + # # read archive version tag + # cd "kiwi-config-${KIWI_VERSION}" + # export KIWI_VERSION=$(cat ./version-tag) - # # read archive version tag - # cd "kiwi-config-${version}" - # version=$(cat ./version-tag) - - # # install archive - # mkdir -p "${KIWI_BASEDIR}" - # mv ./bin "${KIWI_BASEDIR}/${version}" - # ) + # # install archive + # mkdir -p "${KIWI_BASEDIR}" + # mv ./src "${KIWI_BASEDIR}/${KIWI_VERSION}" # # discard temp dir + # cd "${workdir}" # rm -rf "${tmpdir}" ### development version ### - ( - # read this version tag - version=$(cat ./version-tag) + # read this version tag + export KIWI_VERSION=$(cat ./version-tag) - # install this - mkdir -p "${KIWI_BASEDIR}" - ln -s "$(readlink -f ./bin)" "${KIWI_BASEDIR}/${version}" - ) + # install this + mkdir -p "${KIWI_BASEDIR}" + ln -s "$(readlink -f ./src)" "${KIWI_BASEDIR}/${KIWI_VERSION}" echo "OK" fi +export KIWI_ROOT="${KIWI_BASEDIR}/${KIWI_VERSION}" + # run main script -exec "${KIWI_BASEDIR}/${version}/main.sh" "${@}" \ No newline at end of file +exec "${KIWI_ROOT}/bin/main.sh" "${@}" \ No newline at end of file diff --git a/src/bin/init.sh b/src/bin/init.sh new file mode 100755 index 0000000..561de07 --- /dev/null +++ b/src/bin/init.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +source "${KIWI_ROOT}/inc/functions.sh" + +# read default baseconfig +conf_VERSION="${KIWI_VERSION}" +read_kiwi_config "${KIWI_ROOT}/etc/default.${KIWI_CONF_NAME}" + +# if pwd is a kiwi folder, read local baseconfig +if [ -f "./${KIWI_CONF_NAME}" ]; then + echo "[WARN] Overwriting existing '${KIWI_CONF_NAME}'" + read_kiwi_config "./${KIWI_CONF_NAME}" +fi + +function user_input() { + local prompt="${1}" + local varname="${2}" + + local input + read -p "${prompt} [Default '${!varname}']: " input + + eval "${varname}='${input:-${!varname}}'" +} + +declare -A config_explain +config_explain=( + [VERSION]="kiwi-config version" + [SUFFIX_PROJECT]="suffix for project directories" + [SUFFIX_DOWN]="suffix for disabled projects" +) + +for varname in "${!config_explain[@]}"; do + echo "${varname}" + user_input "Enter ${config_explain[${varname}]}" conf_${varname} +done + +exit 0 + +user_input "Choose kiwi-config version" conf_VERSION + +user_input "Enter suffix for project directories" conf_SUFFIX_PROJECT +user_input "Enter suffix for disabled projects" conf_SUFFIX_DOWN + +user_input "Enter suffix for disabled projects" conf_SUFFIX_DOWN +user_input "Enter suffix for disabled projects" conf_SUFFIX_DOWN + +user_input "Enter suffix for disabled projects" conf_SUFFIX_DOWN + +echo "conf_VERSION: ${conf_VERSION}" +echo "conf_SUFFIX_PROJECT: ${conf_SUFFIX_PROJECT}" + +exit 0 + +read -p "Choose kiwi-config version [Default '${conf_version}']: " kiwi_VERSION +conf_VERSION=${kiwi_VERSION:-${conf_VERSION}} + +read -p "suffix for kiwi-config version to use [Default '${conf_version}']: " kiwi_suffix_project + +echo "conf_VERSION: ${conf_VERSION}" \ No newline at end of file diff --git a/src/bin/main.sh b/src/bin/main.sh new file mode 100755 index 0000000..5a442fa --- /dev/null +++ b/src/bin/main.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +command="${1}" +shift 1 + +case "${command}" in + "init") + exec "${KIWI_ROOT}/bin/${command}.sh" "${@}" + ;; + *) + echo "Unknown kiwi command '${command}'." + exit 1 + ;; +esac \ No newline at end of file diff --git a/src/etc/default.kiwi.conf b/src/etc/default.kiwi.conf new file mode 100644 index 0000000..4e9712d --- /dev/null +++ b/src/etc/default.kiwi.conf @@ -0,0 +1,7 @@ +SUFFIX_PROJECT=.project +SUFFIX_DOWN=.down + +DOCKERNET=kiwinet +DOCKERCIDR=10.22.46.0/24 + +TARGETROOT=/var/kiwi diff --git a/src/inc/functions.sh b/src/inc/functions.sh new file mode 100644 index 0000000..6f88a53 --- /dev/null +++ b/src/inc/functions.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +function read_kiwi_config() { + local conf_file="${1}" + local conf_prefix="${2:-conf_}" + + local conf_file_content=$(sed -r 's/^\s*(\S+)/'${conf_prefix}'\1/g' "${conf_file}") + eval "${conf_file_content}" +} + +function write_kiwi_config() { + local conf_prefix="${2:-conf_}" + + +} \ No newline at end of file diff --git a/version-tag b/version-tag index aa33868..ceab6e1 100644 --- a/version-tag +++ b/version-tag @@ -1 +1 @@ -v0.1 \ No newline at end of file +0.1 \ No newline at end of file