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.
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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
|
||||
}
|
||||
|
||||
1
source/build.count
Normal file
1
source/build.count
Normal file
@@ -0,0 +1 @@
|
||||
10
|
||||
99
source/build.sh
Executable file
99
source/build.sh
Executable file
@@ -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!"
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user