375 lines
12 KiB
Bash
375 lines
12 KiB
Bash
## DebMirror Manager Actions Library
|
|
|
|
# doAddRepo (Busy)
|
|
# doEditRepo
|
|
# doHelper
|
|
# doHelperAdd
|
|
# doHelperEditRepo
|
|
# doHelperExitCodes
|
|
# doHelperListRepos
|
|
# doHelperQuietSyncRepos
|
|
# doHelperRemoveRepo
|
|
# doHelperRepoUsage
|
|
# doHelperShowRepo
|
|
# doHelperSyncRepos
|
|
# doHelperTestRepo
|
|
# doHelperUpdater
|
|
# doLicense
|
|
# doQuietSyncRepos
|
|
# doRepoUsage
|
|
# doShowRepo
|
|
# doSyncRepos
|
|
# doTestRepo
|
|
# doUpdater
|
|
|
|
function doAddRepo {
|
|
local architecture
|
|
local debinst
|
|
local distribution
|
|
local keyring
|
|
local keyringurl
|
|
local localrepo
|
|
local method
|
|
local prettyname
|
|
local remotefqdn
|
|
local remoterepo
|
|
local section
|
|
local sources
|
|
|
|
echo -en "What is the FQDN for the repo server you want to mirror? "
|
|
read -r remotefqdn
|
|
[[ "${remotefqdn}" =~ ^([a-z0-9](-?[a-z0-9])*\.)+[a-z]{2,}$ ]] || funcError "Not a valid FQDN..."
|
|
nslookup "${remotefqdn}" > /dev/null 2>&1 || funcError "FQDN does not resolve to an IP address..."
|
|
echo -en "What is the name of the repo on ${remotefqdn} you want to mirror? "
|
|
read -r remoterepo
|
|
[[ "${remoterepo}" =~ ^[a-z0-9]+([a-z0-9-]*[a-z0-9])?$ ]] || funcError "Invalid repo name...\nMust use lowercase letter, digits and/or dash - (dash can not be the first or last character)..."
|
|
echo -en "What is the name you want to use for the repo on your local mirror server ${localfqdn}?\n(Press ENTER to use ${remoterepo}) "
|
|
read -r localrepo
|
|
if [[ -z "${localrepo}" ]]; then
|
|
localrepo="${remoterepo}"
|
|
fi
|
|
[[ "${localrepo}" =~ ^[a-z0-9]+([a-z0-9-]*[a-z0-9])?$ ]] || funcError "Invalid repo name...\nMust use lowercase letter, digits and/or dash - (dash can not be the first or last character)..."
|
|
echo -en "What is the name of the section(s) on ${remotefqdn}/${remoterepo} that you want to mirror?\n(Use a comma , as a delimeter if you want to use more than one - no spaces) "
|
|
read -r section
|
|
[[ "${section}" =~ ^([a-z0-9]+([a-z0-9-]*[a-z0-9])?)(,([a-z0-9]+([a-z0-9-]*[a-z0-9])?))*$ ]] || funcError "Invalid section(s) name(s)...\nMust use lowercase letter, digits and/or dash - (dash can not be the first or last character)...\nYou can use a comma , as a delimiter for multiple sections, but no spaces..."
|
|
echo -en "What is the name of the distribution(s) on ${remotefqdn}/${remoterepo} that you want to mirror?\n(Use a comma , as a delimeter if you want to use more than one - no spaces) "
|
|
read -r distribution
|
|
[[ "${distribution}" =~ ^([a-z0-9]+([a-z0-9-]*[a-z0-9])?)(,([a-z0-9]+([a-z0-9-]*[a-z0-9])?))*$ ]] || funcError "Invalid distribution(s) name(s)...\nMust use lowercase letter, digits and/or dash - (dash can not be the first or last character)...\nYou can use a comma , as a delimiter for multiple distributions, but no spaces..."
|
|
echo -en "What hardware architecture(s) do you want to mirror? (Use a comma , as a delimeter\nif you want to use more than one - no spaces) "
|
|
read -r architecture
|
|
[[ "${architecture}" =~ ^([a-z0-9]+)(,[a-z0-9]+)*$ ]] || funcError "Invalid architecture string given...\nMust use lowercase letter, digits and/or dash - (dash can not be the first or last character)...\nYou can use a comma , as a delimiter for multiple architectures, but no spaces..."
|
|
echo -en "Must we use HTTPS for the remote repo? (Y/n) "
|
|
read -r -n 1 method
|
|
if [[ -z "${method}" || "${method,,}" == "y" ]]; then
|
|
echo "Using HTTPS..."
|
|
method="https"
|
|
else
|
|
echo "Using HTTP..."
|
|
method="http"
|
|
fi
|
|
echo -en "If this repo requires a GPG key then paste the URL to download it, or just press\nENTER if there is no GPG key. "
|
|
read -r keyringurl
|
|
if [[ -z "${keyringurl}" ]]; then
|
|
echo "No keyring is being used..."
|
|
keyring=false
|
|
else
|
|
echo "Downloading keyring file and saving it to /etc/debmirrorman/${localrepo}.gpg..."
|
|
curl -sSLo "/etc/debmirrorman/${localrepo}.gpg" "${keyringurl}" || funcError "Failed to down ${keyringurl}..."
|
|
keyring=true
|
|
fi
|
|
echo -en "Do you want to mirror the Source data and files (y/N) "
|
|
read -r -n 1 sources
|
|
if [[ -z "${sources}" || "${sources,,}" != "y" ]]; then
|
|
echo "Not including Source data..."
|
|
sources=false
|
|
else
|
|
echo "Including Source data..."
|
|
sources=true
|
|
fi
|
|
echo -en "Do you want to mirror the Debian Install data (normally only needed when mirroring\nthe main Debian repos at deb.debian.org) (y/N) "
|
|
read -r -n 1 debinst
|
|
if [[ -z "${debinst}" || "${debinst,,}" != "y" ]]; then
|
|
echo "Not including Debian Install data..."
|
|
debinst=false
|
|
else
|
|
echo "Including Debian Install data..."
|
|
debinst=true
|
|
fi
|
|
echo -en "Choose a memorable name that you can use to identify this repo in the future... "
|
|
read -r prettyname
|
|
echo "Writing configuration files..."
|
|
echo "declare -a localrepos=(" >> "/etc/debmirrorman/settings.conf" || funcError "Failed to write /etc/debmirrorman/settings.conf"
|
|
echo " \"${localrepo}\"" >> "/etc/debmirrorman/settings.conf" || funcError "Failed to write /etc/debmirrorman/settings.conf"
|
|
echo ")" >> "/etc/debmirrorman/settings.conf" || funcError "Failed to write /etc/debmirrorman/settings.conf"
|
|
echo "declare -A prettynames=(" >> "/etc/debmirrorman/settings.conf" || funcError "Failed to write /etc/debmirrorman/settings.conf"
|
|
echo " [${localrepo}]=\"${prettyname}\"" >> "/etc/debmirrorman/settings.conf" || funcError "Failed to write /etc/debmirrorman/settings.conf"
|
|
echo ")" >> "/etc/debmirrorman/settings.conf" || funcError "Failed to write /etc/debmirrorman/settings.conf"
|
|
echo "## Details for ${prettyname}" > "/etc/debmirrorman/${localrepo}.repo" || funcError "Failed to write /etc/debmirrorman/${localrepo}.repo"
|
|
echo "declare remotefqdn=\"${remotefqdn}\"" >> "/etc/debmirrorman/${localrepo}.repo" || funcError "Failed to write /etc/debmirrorman/${localrepo}.repo"
|
|
echo "declare remoterepo=\"${remoterepo}\"" >> "/etc/debmirrorman/${localrepo}.repo" || funcError "Failed to write /etc/debmirrorman/${localrepo}.repo"
|
|
echo "declare section=\"${section}\"" >> "/etc/debmirrorman/${localrepo}.repo" || funcError "Failed to write /etc/debmirrorman/${localrepo}.repo"
|
|
echo "declare distribution=\"${distribution}\"" >> "/etc/debmirrorman/${localrepo}.repo" || funcError "Failed to write /etc/debmirrorman/${localrepo}.repo"
|
|
echo "declare architecture=\"${architecture}\"" >> "/etc/debmirrorman/${localrepo}.repo" || funcError "Failed to write /etc/debmirrorman/${localrepo}.repo"
|
|
echo "declare method=\"${method}\"" >> "/etc/debmirrorman/${localrepo}.repo" || funcError "Failed to write /etc/debmirrorman/${localrepo}.repo"
|
|
echo "declare keyring=${keyring}" >> "/etc/debmirrorman/${localrepo}.repo" || funcError "Failed to write /etc/debmirrorman/${localrepo}.repo"
|
|
echo "declare keyringurl=\"${keyringurl}\"" >> "/etc/debmirrorman/${localrepo}.repo" || funcError "Failed to write /etc/debmirrorman/${localrepo}.repo"
|
|
echo "declare sources=${sources}" >> "/etc/debmirrorman/${localrepo}.repo" || funcError "Failed to write /etc/debmirrorman/${localrepo}.repo"
|
|
echo "declare debinst=${debinst}" >> "/etc/debmirrorman/${localrepo}.repo" || funcError "Failed to write /etc/debmirrorman/${localrepo}.repo"
|
|
echo "## This file was last updated on $(date)" >> "/etc/debmirrorman/${localrepo}.repo" || funcError "Failed to write /etc/debmirrorman/${localrepo}.repo"
|
|
echo
|
|
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 doHelperExitCodes {
|
|
echo "${TITLE} Documentation - Exit Codes"
|
|
echo
|
|
echo "Use up and down arrows to scroll or press Q to exit"
|
|
echo
|
|
echo " No Errors"
|
|
echo " 0 - Completed and exited with no errors"
|
|
echo
|
|
echo " Command Errors"
|
|
echo " 1 - Command not valid"
|
|
echo " 2 - Command does not support a local repo name"
|
|
echo " 3 - Command requires a local repo name"
|
|
echo " 4 - Local repo name is not valid"
|
|
echo " 5 - Local repo name is not found in ${etcdirectory}/settings.conf"
|
|
echo " 6 - Local repo file is not found in ${etcdirectory}"
|
|
echo " 9 - Unknown error with local repo"
|
|
echo
|
|
echo " Help Errors"
|
|
echo " 11 - No help documentation available for invalid command"
|
|
echo " 12 - No help documentation available for command"
|
|
echo
|
|
echo " Configuration Errors"
|
|
echo " 21 - ${etcdirectory}/settings.conf does not exist"
|
|
echo " 22 - No \${localfqdn} defined in ${etcdirectory}/settings.conf"
|
|
echo " 23 - Invalid \${localfqdn} defined in ${etcdirectory}/settings.conf"
|
|
echo " 29 - Unknown error loading ${etcdirectory}/settings.conf"
|
|
echo
|
|
echo " Adding Repo Errors"
|
|
echo " 31 - No local repo name given"
|
|
echo " 32 - Given local repo name is invalid"
|
|
echo " 33 - Given local repo name already exists in ${etcdirectory}/settings.conf"
|
|
echo " 34 - There is already a file {localreponame}.repo in /etc/debmirrorman"
|
|
echo " 35 - No pretty name given"
|
|
echo " 36 - No remote FQDN given"
|
|
echo " 37 - Given remote FQDN is invalid"
|
|
echo " 38 - Given remote FQDN does not resolve to an IP address"
|
|
echo " 39 - No remote repo name given"
|
|
echo " 40 - Given remote repo name is invalid"
|
|
echo " 41 - No section name given"
|
|
echo " 42 - Given section name is invalid"
|
|
echo " 43 - No distributions list given"
|
|
echo " 44 - Given distributions list is invalid"
|
|
echo " 45 - No architectures list given"
|
|
echo " 46 - Given architectures list is invalid"
|
|
echo " 47 - Given keyring URL is invalid"
|
|
echo " 48 - Given keyring URL cannot be downloaded"
|
|
}
|
|
|
|
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 {
|
|
local diff
|
|
local n
|
|
local repo
|
|
local reponamelength
|
|
local reponamemaxlength
|
|
|
|
reponamemaxlength=10
|
|
|
|
for repo in ${localrepos[@]}; do
|
|
reponamelength=${#repo}
|
|
[[ ${reponamelength} -gt ${reponamemaxlength} ]] && reponamemaxlength=${reponamelength}
|
|
done
|
|
|
|
diff=$((reponamemaxlength-7))
|
|
|
|
echo -n "Local Repo"
|
|
|
|
for ((n=0; n<${diff}; n++)); do
|
|
echo -n " "
|
|
done
|
|
|
|
echo "Pretty Name"
|
|
echo
|
|
|
|
for repo in ${localrepos[@]}; do
|
|
reponamelength=${#repo}
|
|
diff=$((reponamemaxlength-${reponamelength}+3))
|
|
|
|
echo -n "${repo}"
|
|
|
|
for ((n=0; n<${diff}; n++)); do
|
|
echo -n " "
|
|
done
|
|
|
|
echo "${prettynames[${repo}]}"
|
|
done | sort
|
|
echo
|
|
|
|
exit
|
|
}
|
|
|
|
function doQuietSyncRepos {
|
|
if [[ -z "${1}" ]]; then
|
|
echo "Silent Run All Repos"
|
|
else
|
|
echo "Silent Run Repo ${1}"
|
|
fi
|
|
exit
|
|
}
|
|
|
|
function doRemoveRepo {
|
|
local confirmation
|
|
local repo="${1}"
|
|
|
|
echo "Removing '${prettynames[${repo}]}'..."
|
|
echo -n "This cannot be undone. Type REMOVE then press ENTER to continue... "
|
|
read -r confirmation
|
|
|
|
if [[ "${confirmation,,}" != "remove" ]]; then
|
|
echo "Exiting without removing!"
|
|
echo
|
|
exit
|
|
fi
|
|
|
|
if [[ -f /etc/debmirrorman/${repo}.repo ]]; then
|
|
echo "Deleting /etc/debmirrorman/${repo}.repo..."
|
|
rm -f /etc/debmirrorman/${repo}.repo
|
|
fi
|
|
|
|
if [[ -f /etc/debmirrorman/${repo}.gpg ]]; then
|
|
echo "Deleting /etc/debmirrorman/${repo}.gpg..."
|
|
rm -f /etc/debmirrorman/${repo}.gpg
|
|
fi
|
|
|
|
echo "Writing /etc/debmirrorman/settings.conf..."
|
|
|
|
localrepos+=("${repo}")
|
|
localrepos=($(echo "${localrepos[@]}" | tr ' ' '\n' | sort | uniq -u))
|
|
|
|
echo "declare localfqdn=\"${localfqdn}\"" > /etc/debmirrorman/settings.conf
|
|
echo "declare -a localrepos=(" >> /etc/debmirrorman/settings.conf
|
|
|
|
for repo in ${localrepos[@]}; do
|
|
echo " \"${repo}\"" >> /etc/debmirrorman/settings.conf
|
|
done
|
|
|
|
echo ")" >> /etc/debmirrorman/settings.conf
|
|
echo "declare -A prettynames=(" >> /etc/debmirrorman/settings.conf
|
|
|
|
for repo in ${localrepos[@]}; do
|
|
echo " [${repo}]=\"${prettynames[${repo}]}\"" >> /etc/debmirrorman/settings.conf
|
|
done
|
|
|
|
echo ")" >> /etc/debmirrorman/settings.conf
|
|
|
|
echo "DONE!"
|
|
echo
|
|
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}"
|
|
echo
|
|
exit
|
|
}
|