Some unstable shellscript work

This commit is contained in:
Jörn-Michael Miehe 2020-08-04 16:38:51 +02:00
parent bd71a6dea4
commit d2be89ee45
7 changed files with 124 additions and 43 deletions

View file

@ -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

57
kiwi
View file

@ -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" "${@}"
exec "${KIWI_ROOT}/bin/main.sh" "${@}"

59
src/bin/init.sh Executable file
View file

@ -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}"

14
src/bin/main.sh Executable file
View file

@ -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

View file

@ -0,0 +1,7 @@
SUFFIX_PROJECT=.project
SUFFIX_DOWN=.down
DOCKERNET=kiwinet
DOCKERCIDR=10.22.46.0/24
TARGETROOT=/var/kiwi

15
src/inc/functions.sh Normal file
View file

@ -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_}"
}

View file

@ -1 +1 @@
v0.1
0.1