From 1c648f2739fccfc7e4405448e623b2914fa2e8bb Mon Sep 17 00:00:00 2001 From: Ze'ev Schurmann Date: Sun, 29 Mar 2026 04:29:18 +0200 Subject: [PATCH] Built and tested basic structure of the source of debmirrorman, added build.sh for building the source into a single executable file from the individual .sh and .lib.sh files. --- source/.actions.lib.sh.kate-swp | Bin 77 -> 0 bytes source/.debmirrorman.sh.kate-swp | Bin 8641 -> 0 bytes source/.vars.lib.sh.kate-swp | Bin 108 -> 0 bytes source/actions.lib.sh | 128 +++++++++++++++++++++++++++++++ source/build.count | 1 + source/build.sh | 99 ++++++++++++++++++++++++ source/debmirrorman.sh | 60 +++++++++++++++ source/functions.lib.sh | 30 ++++++++ source/vars.lib.sh | 46 +++++++++++ 9 files changed, 364 insertions(+) delete mode 100644 source/.actions.lib.sh.kate-swp delete mode 100644 source/.debmirrorman.sh.kate-swp delete mode 100644 source/.vars.lib.sh.kate-swp create mode 100644 source/build.count create mode 100755 source/build.sh diff --git a/source/.actions.lib.sh.kate-swp b/source/.actions.lib.sh.kate-swp deleted file mode 100644 index 5343f7bebe8655f85611ecad26386ddb714d7890..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 77 zcmZQzU=Z?7EJ;-eE>A2_aLdd|RWQ;sU|?Vnc{caa>`fQ1IeT|&t}Bnaap*};@WfzG SpbQK!Cc6d)!8kyg(G>ue5EJhJ diff --git a/source/.debmirrorman.sh.kate-swp b/source/.debmirrorman.sh.kate-swp deleted file mode 100644 index 00a557a11e26f26ef5eae86b2d676d5554ef8291..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8641 zcmc(k&5m7H5rzBMjnnP?V49E^V#sy3f6@stAyed0)F`bWklad;h=OF2MvgEcN(_-e zc>z3-+y!R+mqvAscZSk z(d1>^T<#y8+_MqB(8%4TM+*;{_4M`T3k?58^F{ba&D-$%&7XrmXufpj`Nz&YzXOlm zmN&cb$IX}F2S+F0AOCVazJ6t!Tk9xx$hExHEH93l<;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ff --git a/source/actions.lib.sh b/source/actions.lib.sh index e69de29..5873ee2 100644 --- a/source/actions.lib.sh +++ b/source/actions.lib.sh @@ -0,0 +1,128 @@ +## DebMirror Manager Actions Library + +function doAddRepo { + echo "Add Repo" + exit +} + +function doEditRepo { + echo "Edit Repo ${1}" + exit +} + +function doHelper { + echo "Helper" + exit +} + +function doHelperAdd { + echo "Helper Add" + exit +} + +function doHelperEditRepo { + echo "Helper Edit" + exit +} + +function doHelperListRepos { + echo "Helper List" + exit +} + +function doHelperQuietSyncRepos { + echo "Helper Silent Run" + exit +} + +function doHelperRemoveRepo { + echo "Helper Remove" + exit +} + +function doHelperRepoUsage { + echo "Helper Usage" + exit +} + +function doHelperShowRepo { + echo "Helper Show" + exit +} + +function doHelperSyncRepos { + echo "Helper Run" + exit +} + +function doHelperTestRepo { + echo "Helper Dryrun" + exit +} + +function doHelperUpdater { + echo "Helper Update" + exit +} + +function doLicense { + echo "License" + exit +} + +function doListRepos { + echo "List Repos" + exit +} + +function doQuietSyncRepos { + if [[ -z "${1}" ]]; then + echo "Silent Run All Repos" + else + echo "Silent Run Repo ${1}" + fi + exit +} + +function doRemoveRepo { + echo "Remove Repo ${1}" + exit +} + +function doRepoUsage { + if [[ -z "${1}" ]]; then + echo "Usage All Repos" + else + echo "Usage Repo ${1}" + fi + exit +} + +function doShowRepo { + echo "Show Repo ${1}" + exit +} + +function doSyncRepos { + if [[ -z "${1}" ]]; then + echo "Run All Repos" + else + echo "Run Repo ${1}" + fi + exit +} + +function doTestRepo { + echo "Dryrun Repo ${1}" + exit +} + +function doUpdater { + echo "Updater" + exit +} + +function doVersion { + echo "DebMirror Manager version ${VERSION}" + exit +} diff --git a/source/build.count b/source/build.count new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/source/build.count @@ -0,0 +1 @@ +10 diff --git a/source/build.sh b/source/build.sh new file mode 100755 index 0000000..b9b117d --- /dev/null +++ b/source/build.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +if [[ -z "${1}" ]]; then + echo "Must give Bash filename..." >&2 + echo "Example:" >&2 + echo " $0 bashscript.sh" >&2 + exit 1 +fi + +if [[ ${1: -3} != ".sh" ]]; then + echo "Bash file ${1} does not have a .sh extension..." >&2 + exit 2 +fi + +if [[ -f "${1}" ]]; then + bashscript="${1}" +else + echo "Bash file ${1} does not exist..." >&2 + exit 3 +fi + +declaration="$(head -1 "${bashscript}")" + +if [[ ${declaration: -5} != '/bash' ]]; then + echo "Bash file ${bashscript} does not invoke Bash binary..." >&2 + exit 4 +fi + +pathtobash="${declaration:2}" + +if [[ ! -f "${pathtobash}" ]]; then + echo "Bash file ${bashscript} invokes Bash binary at invalid location ${pathtobash}..." >&2 + exit 5 +fi + +builddatetime="$(date "+%y%m%d%H%M")" +builddatestring="$(date)" + +bashscriptfile="${bashscript##*/}" +bashscriptpath="${bashscript%/*}" +if [[ -z "${bashscriptpath}" || "${bashscriptpath}" == "${bashscriptfile}" ]]; then + bashscriptpath="." +fi + +if [[ ! -f "${bashscriptpath}/build.count" ]]; then + buildcount=1 +else + buildcount=$(head -1 "${bashscriptpath}/build.count") +####################################################### +# Add Regex to check buildcount is an integer about 0 # +####################################################### + ((buildcount++)) +fi +echo ${buildcount} > "${bashscriptpath}/build.count" +buildfile="${bashscriptfile%.*}" +buildpath="./build-${builddatetime}-${buildcount}" + +echo "Reading ${bashscriptfile}" +echo "Project path ${bashscriptpath}" +echo "Build number ${buildcount}" +echo "Build date and time ${builddatetime}" +echo "Build path ${buildpath}" +echo "Writing to ${buildfile}" + +isstart=true + +mkdir -p "${buildpath}" +while IFS= read -r line; do + if [[ ${isstart} == true ]]; then + echo "${line}" > "${buildpath}/${buildfile}" + echo "## Built on ${builddatestring}" >> "${buildpath}/${buildfile}" + echo "## Source script ${bashscriptfile}" >> "${buildpath}/${buildfile}" + echo "## Project path ${bashscriptpath}" >> "${buildpath}/${buildfile}" + echo "## Build number ${buildcount}" >> "${buildpath}/${buildfile}" + echo "## Build path ${buildpath}" >> "${buildpath}/${buildfile}" + echo "## Build file ${buildfile}" >> "${buildpath}/${buildfile}" + echo >> "${buildpath}/${buildfile}" + isstart=false + else + if [[ "$line" =~ ^[[:space:]]*source[[:space:]]+([^[:space:]]+\.lib\.sh)[[:space:]]*$ ]]; then + library="${BASH_REMATCH[1]}" + #if [[ ${line} =~ ^source && ${line} =~ \.lib\.sh$ ]]; then + # library="${line:7}" + if [[ -f "${bashscriptpath}/${library}" ]]; then + echo "Importing library ${library} from path ${bashscriptpath}" + cat "${bashscriptpath}/${library}" >> "${buildpath}/${buildfile}" + echo >> "${buildpath}/${buildfile}" + else + echo "Library ${library} not found at ${bashscriptpath}" + echo "Build failed!" + exit 6 + fi + else + echo "${line}" >> "${buildpath}/${buildfile}" + fi + fi +done < "${bashscript}" +chmod +x "${buildpath}/${buildfile}" +echo "Build complete!" diff --git a/source/debmirrorman.sh b/source/debmirrorman.sh index e69de29..642be8f 100644 --- a/source/debmirrorman.sh +++ b/source/debmirrorman.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +TITLE="DebMirror Manager" +VERSION="0.0.1" +URL="https://git.3volve.net.za/thisiszeev/debmirrorman" +AUTHOR="Ze'ev Schurmann" +AUTHORURL="https://reddit.com/u/thisiszeev" + +source vars.lib.sh +source functions.lib.sh +source actions.lib.sh + +if [[ -z "${1}" ]]; then + doHelper + exit +else + command="${1,,}" + if [[ -z "${commands[${command}]}" ]]; then + echo "Command ${1} not valid..." + exit 1 + else + if [[ -n "${2}" ]]; then + if [[ "${commandsneedreponame[${command}]}" == "none" ]]; then + echo "Command ${1} does not support a repo name..." + exit 1 + elif [[ "${commandsneedreponame[${command}]}" == "help" ]]; then + helpcommand="${2,,}" + if [[ -z "${commands[${helpcommand}]}" ]]; then + echo "Command ${2} not valid..." + exit 1 + else + if [[ -z "${helpercommands[${helpcommand}]}" ]]; then + echo "No help documentation for command ${2}..." + exit 1 + else + ${helpercommands[${helpcommand}]} + exit + fi + fi + else + if funcCheckLocalRepo "${2}"; then + ${commands[${command}]} "${2}" + exit + else + echo "Invalid local repo name..." + exit 1 + fi + fi + else + if [[ "${commandsneedreponame[${command}]}" == "required" ]]; then + echo "Command ${1} requires a repo name..." + exit 1 + else + ${commands[${command}]} + exit + fi + fi + fi +fi +exit 127 diff --git a/source/functions.lib.sh b/source/functions.lib.sh index e69de29..8c914b1 100644 --- a/source/functions.lib.sh +++ b/source/functions.lib.sh @@ -0,0 +1,30 @@ +## DebMirror Manager Functions Library + +function funcCheckLocalRepo { + if [[ -z "${1}" ]]; then + return 5 + else + localrepo="${1}" + fi + + if [[ "${localrepo}" =~ ^[a-z0-9]+([a-z0-9-]*[a-z0-9])?$ ]]; then + if [[ -f "/etc/debmirrorman/settings.conf" ]]; then + source "/etc/debmirrorman/settings.conf" + if echo ${localrepos[@]} | tr ' ' '\n' | grep -q ^${localrepo}$; then + if [[ -f "/etc/debmirrorman/${localrepo}.repo" ]]; then + return 0 + else + return 3 + fi + else + return 2 + fi + else + return 4 + fi + else + return 1 + fi + + return 127 +} diff --git a/source/vars.lib.sh b/source/vars.lib.sh index e69de29..388eda1 100644 --- a/source/vars.lib.sh +++ b/source/vars.lib.sh @@ -0,0 +1,46 @@ +## DebMirror Manager Variables Declarations Library + +declare -A commands=( + [add]="doAddRepo" + [dryrun]="doTestRepo" + [edit]="doEditRepo" + [help]="doHelper" + [license]="doLicense" + [list]="doListRepos" + [remove]="doRemoveRepo" + [usage]="doRepoUsage" + [run]="doSyncRepos" + [show]="doShowRepo" + [silentrun]="doQuietSyncRepos" + [update]="doUpdater" + [version]="doVersion" +) + +declare -A commandsneedreponame=( + [add]="none" + [dryrun]="required" + [edit]="required" + [help]="help" + [license]="none" + [list]="none" + [remove]="required" + [usage]="optional" + [run]="optional" + [show]="required" + [silentrun]="optional" + [update]="none" + [version]="none" +) + +declare -A helpercommands=( + [add]="doHelperAdd" + [dryrun]="doHelperTestRepo" + [edit]="doHelperEditRepo" + [list]="doHelperListRepos" + [remove]="doHelperRemoveRepo" + [usage]="doHelperRepoUsage" + [run]="doHelperSyncRepos" + [show]="doHelperShowRepo" + [silentrun]="doHelperQuietSyncRepos" + [update]="doHelperUpdater" +)