mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-22 12:53:00 +00:00
Some unstable shellscript work
This commit is contained in:
parent
bd71a6dea4
commit
d2be89ee45
7 changed files with 124 additions and 43 deletions
13
bin/main.sh
13
bin/main.sh
|
@ -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
|
|
41
kiwi
41
kiwi
|
@ -4,10 +4,10 @@
|
||||||
# CONSTANTS #
|
# CONSTANTS #
|
||||||
#############
|
#############
|
||||||
|
|
||||||
# base config filename (constant)
|
# base config filename
|
||||||
KIWI_CONF_NAME="kiwi.conf"
|
export KIWI_CONF_NAME="kiwi.conf"
|
||||||
# base install dir
|
# base install dir
|
||||||
KIWI_BASEDIR="${HOME}/.cache/kiwi-config-bin"
|
KIWI_BASEDIR="${HOME}/.cache/kiwi-config"
|
||||||
# repository uri
|
# repository uri
|
||||||
KIWI_REPO="https://github.com/ldericher/kiwi-config"
|
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
|
# use latest version by default
|
||||||
version="master"
|
export KIWI_VERSION="master"
|
||||||
|
|
||||||
# check if pwd is a kiwi folder
|
# check if pwd is a kiwi folder
|
||||||
if [ -f "./${KIWI_CONF_NAME}" ]; then
|
if [ -f "./${KIWI_CONF_NAME}" ]; then
|
||||||
# determine needed kiwi-config version
|
# determine needed kiwi-config version
|
||||||
version=$(source "./${KIWI_CONF_NAME}" && echo "v${VERSION}")
|
export KIWI_VERSION=$(source "./${KIWI_CONF_NAME}" && echo "${VERSION}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# install if kiwi-config not found
|
# install if kiwi-config not found
|
||||||
if [ ! -x "${KIWI_BASEDIR}/${version}/main.sh" ]; then
|
if [ ! -x "${KIWI_BASEDIR}/${KIWI_VERSION}/bin/main.sh" ]; then
|
||||||
echo -n "Installing kiwi-config ${version} into ${KIWI_BASEDIR} ... "
|
echo -n "Installing kiwi-config v${KIWI_VERSION} into ${KIWI_BASEDIR} ... "
|
||||||
|
|
||||||
### production version ###
|
### production version ###
|
||||||
|
|
||||||
# # create temp dir
|
# # switch to temp dir
|
||||||
|
# workdir=$(pwd)
|
||||||
# tmpdir=$(mktemp -d)
|
# tmpdir=$(mktemp -d)
|
||||||
|
|
||||||
# (
|
|
||||||
# cd "${tmpdir}"
|
# cd "${tmpdir}"
|
||||||
|
|
||||||
# # download archive
|
# # download archive
|
||||||
# wget "${KIWI_REPO}/archive/${version}.zip"
|
# wget "${KIWI_REPO}/archive/${KIWI_VERSION}.zip"
|
||||||
# unzip "${version}.zip"
|
# unzip "${KIWI_VERSION}.zip"
|
||||||
|
|
||||||
# # read archive version tag
|
# # read archive version tag
|
||||||
# cd "kiwi-config-${version}"
|
# cd "kiwi-config-${KIWI_VERSION}"
|
||||||
# version=$(cat ./version-tag)
|
# export KIWI_VERSION=$(cat ./version-tag)
|
||||||
|
|
||||||
# # install archive
|
# # install archive
|
||||||
# mkdir -p "${KIWI_BASEDIR}"
|
# mkdir -p "${KIWI_BASEDIR}"
|
||||||
# mv ./bin "${KIWI_BASEDIR}/${version}"
|
# mv ./src "${KIWI_BASEDIR}/${KIWI_VERSION}"
|
||||||
# )
|
|
||||||
|
|
||||||
# # discard temp dir
|
# # discard temp dir
|
||||||
|
# cd "${workdir}"
|
||||||
# rm -rf "${tmpdir}"
|
# rm -rf "${tmpdir}"
|
||||||
|
|
||||||
### development version ###
|
### development version ###
|
||||||
|
|
||||||
(
|
|
||||||
# read this version tag
|
# read this version tag
|
||||||
version=$(cat ./version-tag)
|
export KIWI_VERSION=$(cat ./version-tag)
|
||||||
|
|
||||||
# install this
|
# install this
|
||||||
mkdir -p "${KIWI_BASEDIR}"
|
mkdir -p "${KIWI_BASEDIR}"
|
||||||
ln -s "$(readlink -f ./bin)" "${KIWI_BASEDIR}/${version}"
|
ln -s "$(readlink -f ./src)" "${KIWI_BASEDIR}/${KIWI_VERSION}"
|
||||||
)
|
|
||||||
|
|
||||||
echo "OK"
|
echo "OK"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
export KIWI_ROOT="${KIWI_BASEDIR}/${KIWI_VERSION}"
|
||||||
|
|
||||||
# run main script
|
# run main script
|
||||||
exec "${KIWI_BASEDIR}/${version}/main.sh" "${@}"
|
exec "${KIWI_ROOT}/bin/main.sh" "${@}"
|
59
src/bin/init.sh
Executable file
59
src/bin/init.sh
Executable 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
14
src/bin/main.sh
Executable 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
|
7
src/etc/default.kiwi.conf
Normal file
7
src/etc/default.kiwi.conf
Normal 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
15
src/inc/functions.sh
Normal 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_}"
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1 +1 @@
|
||||||
v0.1
|
0.1
|
Loading…
Reference in a new issue