Adds the mapper option, that helps mapping a zip file name to a repository.

This commit is contained in:
Llewellyn van der Merwe 2021-04-06 21:16:32 +02:00
parent 36a3f5eae0
commit 6ebaa5780a
Signed by: Llewellyn
GPG Key ID: EFC0C720A240551C
2 changed files with 54 additions and 5 deletions

2
src/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.octozipo
.octozipo.mapper

View File

@ -5,7 +5,7 @@ PROGRAM_NAME="Octozipo"
PROGRAM_CODE="octozipo"
PROGRAM_VERSION="1.0.1"
PROGRAM_V="1.0"
PROGRAM_URL="https://git.vdm.dev/octoleo/${PROGRAM_CODE}"
# PROGRAM_URL="https://git.vdm.dev/octoleo/${PROGRAM_CODE}"
# Do some prep work
command -v git >/dev/null 2>&1 || {
@ -55,6 +55,7 @@ getRepoName() {
name=$(rightStrip "$1" "-v*")
name=$(rightStrip "$name" "_v*")
name=$(rightStrip "$name" ".zip")
name=$(getMapped "$name")
echo "$name"
}
@ -85,6 +86,10 @@ leftStrip() {
# setup new repository
setNewRepository() {
# some locals
local repo_path
local zip_path
# give heads up of the new repo
_echo "[info] New repository (${VDM_REMOTE_SYSTEM}:${VDM_ORG}/$1)"
# set repo path
repo_path="$VDM_ROOT_DIR/$1"
@ -145,7 +150,7 @@ setGitInit() {
fi
fi
else
git init || return 4
git init >/dev/null 2>&1 || return 4
setGitCommit "$2" "first commit - v$2" || return 4
git remote add origin "git@${VDM_REMOTE_SYSTEM}:${VDM_ORG}/${1}.git"
fi
@ -174,6 +179,10 @@ setPushChanges() {
# update repository repository
setExistingRepository() {
# some locals
local repo_path
local zip_path
# give heads up of the update repo
_echo "[info] Update ($1-v$2) repository"
# set repo path
repo_path="$VDM_ROOT_DIR/$1"
@ -218,6 +227,17 @@ setExistingRepository() {
return 0
}
# get mapped name
function getMapped() {
local PROP_KEY="$1"
local PROP_VALUE
if [ -f "${VDM_MAPPER_FILE_PATH}" ]; then
# get the value if set
PROP_VALUE=$( grep "$PROP_KEY" "${VDM_MAPPER_FILE_PATH}" | cut -d'=' -f2)
fi
echo "${PROP_VALUE:-$PROP_KEY}"
}
# only if not set to be quiet
function _echo() {
if (("$QUIET" == 0)); then
@ -282,6 +302,11 @@ function show_help() {
Usage: ${PROGRAM_CODE} [OPTION...]
Options
======================================================
-m | --mapper=<file>
load the mapping file
that convert zip names to repo names
example: ${PROGRAM_CODE} --mapper=/src/.mapper
======================================================
-e | --env=<file>
load the environment variables file
example: ${PROGRAM_CODE} --env=/src/.env
@ -349,6 +374,22 @@ while :; do
echo '[error] "--env=" requires a non-empty option argument.'
exit 17
;;
-m | --mapper) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
VDM_MAPPER_FILE_PATH=$2
shift
else
echo '[error] "--mapper" requires a non-empty option argument.'
exit 17
fi
;;
-m=?* | --mapper=?*)
VDM_MAPPER_FILE_PATH=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
-m= | --mapper=) # Handle the case of an empty --packages=
echo '[error] "--mapper=" requires a non-empty option argument.'
exit 17
;;
*) # Default case: No more options, so break out of the loop.
break ;;
esac
@ -357,14 +398,20 @@ done
# the environment variables path
tmp_path="$VDM_ROOT_DIR/.${PROGRAM_CODE}"
# if path not set try VDM_ROOT_DIR path
# if path not set try global path
[ -f "$tmp_path" ] || tmp_path="/home/$USER/.config/${PROGRAM_CODE}/.env"
tmp_path="${VDM_ENV_FILE_PATH:-$tmp_path}"
# add env to system
if [ -f ".${tmp_path}" ]; then
if [ -f "${tmp_path}" ]; then
# shellcheck disable=SC1090
source ".${tmp_path}"
source "${tmp_path}"
fi
# the mapper path
tmp_path="$VDM_ROOT_DIR/.${PROGRAM_CODE}.mapper"
# if path not set try global path
[ -f "$tmp_path" ] || tmp_path="/home/$USER/.config/${PROGRAM_CODE}/.mapper"
VDM_MAPPER_FILE_PATH="${VDM_MAPPER_FILE_PATH:-$tmp_path}"
# done with the tmp_path
unset tmp_path
# catch the values passed