Created ./source and touched debmirrorman.sh functions.lib.sh vars.lib.sh and actions.lib.sh - Also neatened up and improved installer script.

This commit is contained in:
2026-03-29 01:34:53 +02:00
parent 8276ca491c
commit 7431547536
9 changed files with 68 additions and 48 deletions

View File

@@ -1 +1 @@
0.1.1
0.1.2

View File

@@ -1,6 +1,6 @@
#!/bin/bash
VERSION="0.1.1"
VERSION="0.1.2"
function doError {
if [[ -z ${1} ]]; then
@@ -13,7 +13,7 @@ function doError {
}
function doFinalStep {
echo "declare laststep=99" > "/etc/debmirrorman/last.step" || doError "Failed to write /etc/debmirrorman/last.step..."
echo "declare laststep=999" > "/etc/debmirrorman/last.step" || doError "Failed to write /etc/debmirrorman/last.step..."
}
function doMessageDelay {
@@ -52,7 +52,11 @@ function doMessageDelay {
}
function doNextStep {
if [[ -n "${1}" ]] && [[ "${1}" =~ ^[1-9][0-9]?$ ]]; then
laststep=$((laststep+${1}))
else
((laststep++))
fi
echo "declare laststep=${laststep}" > "/etc/debmirrorman/last.step" || doError "Failed to write /etc/debmirrorman/last.step..."
}
@@ -65,29 +69,29 @@ unset ID
mkdir -p "/etc/debmirrorman" || doError "Failed to create settings folder /etc/debmirrorman..."
[[ -f "/etc/debmirrorman/last.step" ]] || echo "declare laststep=0" > "/etc/debmirrorman/last.step" || doError "Failed to write /etc/debmirrorman/last.step..."
source "/etc/debmirrorman/last.step" || doError "Failed to read /etc/debmirrorman/last.step..."
[[ "${laststep}" == 99 ]] && echo -e "DebMirrorMan has already been installed...\nUse debmirrorman help to information on how to use it..." && exit
[[ "${laststep}" == 999 ]] && echo -e "DebMirrorMan has already been installed...\nUse debmirrorman help to information on how to use it..." && exit
doMessageDelay "First let's make sure Debian is fully updated"
apt update && apt -y upgrade || doError "Error running update..."
doMessageDelay "If this installer script stops with an error, you can resolve the cause of the error\nand then just rerun this script and the installation will pick up from where it left off" 10
doMessageDelay "If this installer script stops with an error, you can resolve the cause of the error and\nthen just rerun this script and the installation will pick up from where it left off" 10
if [[ "${laststep}" -lt 1 ]]; then
doMessageDelay "Step $((laststep+1)): Let's first make sure that there is nothing already listening on ports 80 and/or 443"
if [[ "${laststep}" -lt 10 ]]; then
doMessageDelay "Let's first make sure that there is nothing already listening on ports 80 and/or 443"
ss -tuln | grep -qE ':(80|443)\s' && doError "Can't continue as there is already a service listening on ports 80 and/or 443...\nI would recommend you run this script on a vanilla server..."
doNextStep
doNextStep 10
fi
if [[ "${laststep}" -lt 2 ]]; then
doMessageDelay "Step $((laststep+1)): Let's install required software"
if [[ "${laststep}" -lt 20 ]]; then
doMessageDelay "Let's install required software"
apt -y install nginx debmirror ca-certificates gnupg curl || doError "Error installing required software..."
#wget https://git.3volve.net.za/thisiszeev......
doNextStep
doNextStep 10
fi
if [[ "${laststep}" -lt 3 ]]; then
doMessageDelay "Step $((laststep+1)): Let's setup Nginx"
echo -n "What is the FQDN you want for the repo server? "
if [[ "${laststep}" -lt 30 ]]; then
doMessageDelay "Let's setup Nginx"
echo -en "What is the FQDN you want for the repo server? "
read -r localfqdn
echo
[[ "${localfqdn}" =~ ^([a-z0-9](-?[a-z0-9])*\.)+[a-z]{2,}$ ]] || doError "Not a valid FQDN..."
@@ -106,44 +110,44 @@ if [[ "${laststep}" -lt 3 ]]; then
rm -f "/etc/nginx/sites-enabled/default" || doError "Error disabling default VHost..."
nginx -t && systemctl reload nginx || doError "Error restarting Nginx..."
echo "declare localfqdn=\"${localfqdn}\"" > "/etc/debmirrorman/settings.conf" || doError "Failed to write /etc/debmirrorman/settings.conf"
doNextStep
doNextStep 10
fi
if [[ "${laststep}" -lt 4 ]]; then
doMessageDelay "Step $((laststep+1)): Let's add our first repo to be mirrored"
if [[ "${laststep}" -lt 40 ]]; then
doMessageDelay "Let's add our first repo to be mirrored"
if [[ -z "${localfqdn}" ]]; then
source "/etc/debmirrorman/settings.conf" || doError "Failed to read /etc/debmirrorman/settings.conf..."
fi
echo -n "What is the FQDN for the repo server you want to mirror? (Just press ENTER to skip this step) "
echo -en "What is the FQDN for the repo server you want to mirror?\n(Just press ENTER to skip this step) "
read -r remotefqdn
echo
if [[ -n "${remotefqdn}" ]]; then
[[ "${remotefqdn}" =~ ^([a-z0-9](-?[a-z0-9])*\.)+[a-z]{2,}$ ]] || doError "Not a valid FQDN..."
nslookup "${remotefqdn}" > /dev/null 2>&1 || doError "FQDN does not resolve to an IP address..."
echo -n "What is the name of the repo on ${remotefqdn} you want to mirror? "
echo -en "What is the name of the repo on ${remotefqdn} you want to mirror? "
read -r remoterepo
echo
[[ "${remoterepo}" =~ ^[a-z0-9]+([a-z0-9-]*[a-z0-9])?$ ]] || doError "Invalid repo name...\nMust use lowercase letter, digits and/or dash - (dash can not be the first or last character)..."
echo -n "What is the name you want to use for the repo on your local mirror server ${localfqdn}? (Press ENTER to use ${remoterepo}) "
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
echo
if [[ -z "${localrepo}" ]]; then
localrepo="${remoterepo}"
fi
[[ "${localrepo}" =~ ^[a-z0-9]+([a-z0-9-]*[a-z0-9])?$ ]] || doError "Invalid repo name...\nMust use lowercase letter, digits and/or dash - (dash can not be the first or last character)..."
echo -n "What is the name of the section(s) on ${remotefqdn}/${remoterepo} that you want to mirror? (Use a comma , as a delimeter if you want to use more than one - no spaces) "
echo -en "What is the name of the section(s) on ${remotefqdn}/${remoterepo}\nthat you want to mirror? (Use a comma , as a delimeter if you want to use more than one - no spaces) "
read -r section
echo
[[ "${section}" =~ ^([a-z0-9]+([a-z0-9-]*[a-z0-9])?)(,([a-z0-9]+([a-z0-9-]*[a-z0-9])?))*$ ]] || doError "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 -n "What is the name of the distribution(s) on ${remotefqdn}/${remoterepo} that you want to mirror? (Use a comma , as a delimeter if you want to use more than one - no spaces) "
echo -en "What is the name of the distribution(s) on ${remotefqdn}/${remoterepo}\nthat you want to mirror? (Use a comma , as a delimeter if you want to use more than one - no spaces) "
read -r distribution
echo
[[ "${distribution}" =~ ^([a-z0-9]+([a-z0-9-]*[a-z0-9])?)(,([a-z0-9]+([a-z0-9-]*[a-z0-9])?))*$ ]] || doError "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 -n "What hardware architecture(s) do you want to mirror? (Use a comma , as a delimeter if you want to use more than one - 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
echo
[[ "${architecture}" =~ ^([a-z0-9]+)(,[a-z0-9]+)*$ ]] || doError "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 -n "Must we use HTTPS for the remote repo? (Y/n) "
echo -en "Must we use HTTPS for the remote repo? (Y/n) "
read -r -n 1 method
echo
if [[ -z "${method}" || "${method,,}" == "y" ]]; then
@@ -153,7 +157,7 @@ if [[ "${laststep}" -lt 4 ]]; then
echo "Using HTTP..."
method="http"
fi
echo -n "If this repo requires a GPG key then paste the URL to download it, or press just ENTER if there is no GPG key. "
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
echo
if [[ -z "${keyringurl}" ]]; then
@@ -164,7 +168,7 @@ if [[ "${laststep}" -lt 4 ]]; then
curl -sSLo "/etc/debmirrorman/${localrepo}.gpg" "${keyringurl}" || doError "Failed to down ${keyringurl}..."
keyring=true
fi
echo -n "Do you want to mirror the Source data and files (y/N) "
echo -en "Do you want to mirror the Source data and files (y/N) "
read -r -n 1 sources
echo
if [[ -z "${sources}" || "${sources,,}" != "y" ]]; then
@@ -174,7 +178,7 @@ if [[ "${laststep}" -lt 4 ]]; then
echo "Including Source data..."
sources=true
fi
echo -n "Do you want to mirror the Debian Install data (normally only needed when mirroring the main Debian repos at deb.debian.org) (y/N) "
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
echo
if [[ -z "${debinst}" || "${debinst,,}" != "y" ]]; then
@@ -184,7 +188,7 @@ if [[ "${laststep}" -lt 4 ]]; then
echo "Including Debian Install data..."
debinst=true
fi
echo -n "Choose a memorable name that you can use to identify this repo in the future... "
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" || doError "Failed to write /etc/debmirrorman/settings.conf"
@@ -207,13 +211,13 @@ if [[ "${laststep}" -lt 4 ]]; then
echo "## This file was last updated on $(date)" >> "/etc/debmirrorman/${localrepo}.repo" || doError "Failed to write /etc/debmirrorman/${localrepo}.repo"
else
echo "Skipping..."
doNextStep
doNextStep 10
fi
doNextStep
doNextStep 10
fi
if [[ ${laststep} -lt 5 ]]; then
doMessageDelay "Step $((laststep+1)): Going to do a dry-run test on your first repo"
if [[ ${laststep} -lt 50 ]]; then
doMessageDelay "Going to do a dry-run test on your first repo"
if [[ -z "${localfqdn}" ]]; then
source "/etc/debmirrorman/settings.conf" || doError "Failed to read /etc/debmirrorman/settings.conf..."
[[ "${#localrepos[@]}" -gt 0 ]] || doError "No local repos found in /etc/debmirrorman/settings.conf..."
@@ -241,19 +245,23 @@ if [[ ${laststep} -lt 5 ]]; then
debmirror --host=${remotefqdn} --root=${remoterepo} --dist=${distribution} --section=${section} --arch=${architecture} --method=${method} ${sourcetag} --progress --dry-run /var/www/${localfqdn}/${localrepo} || doError "Dry run failed..."
fi
fi
doNextStep
doNextStep 10
fi
if [[ ${laststep} -lt 6 ]]; then
doMessageDelay "Step $((laststep+1)): Install is completed"
if [[ ${laststep} -lt 60 ]]; then
doMessageDelay "Install is completed"
echo
echo "Now you can use debmirrorman to sync your repos or to add/edit/remove repos."
echo
echo "Example:"
echo " debmirrorman run"
echo " This will sync all repos"
echo " This will sync all repos verbosely"
echo " debmirrorman run {localreponame}"
echo " This will sync just the repo called {localreponame}"
echo " This will sync just the repo called {localreponame} verbosely"
echo " debmirrorman silentrun"
echo " This will sync all repos quietly"
echo " debmirrorman silentrun {localreponame}"
echo " This will sync just the repo called {localreponame} quietly"
echo " debmirrorman dryrun {localreponame}"
echo " This will test the repo called {localreponame}"
echo " debmirrorman list"
@@ -265,24 +273,36 @@ if [[ ${laststep} -lt 6 ]]; then
echo " debmirrorman edit {localreponame}"
echo " This will allow you to edit the details for the repo called {localreponame}"
echo " debmirrorman remove {localreponame}"
echo " This will allow you to remove the repo, including all synced packages, for the repo called {localreponame}"
echo " This will allow you to remove the repo, including all synced packages, for"
echo " the repo called {localreponame}"
echo " debmirrorman usage"
echo " This will calculate how much storage space each repo is taking up, as well as give you a total of all repos"
echo " This will calculate how much storage space each repo is taking up, as well"
echo " as give you a total of all repos"
echo " debmirrorman usage {localreponame}"
echo " This will calculate how much storage space is taken up, itemized by distribution and section, for the repo called {localreponame}"
echo " This will calculate how much storage space is taken up, itemized by"
echo " distribution and section, for the repo called {localreponame}"
echo " debmirrorman help"
echo " This will display the help documentation"
echo " debmirrorman version"
echo " This will display the version number and let you know if there is an update"
echo " available"
echo " debmirrorman update"
echo " This will check if there is a newer version of DebMirror Manager and if so update the currently installed version with the newer version"
echo " This will check if there is a newer version of DebMirror Manager and if so"
echo " update the currently installed version with the newer version"
echo
echo "DebMirror Manager is released under the Gnu Public Lincense 3.0 and is Free to use, copy, study, modify and share."
echo "If you find DebMirror Manager to be useful, please consider making a donation at https://paypal.me/thisiszeev"
echo "My primary source of income is from donations by people like you... and it motivates me to keep developing more useful tools and scripts."
echo "DebMirror Manager is released under the Gnu Public License 3.0 and is Free to use,"
echo "copy, study, modify and share. If you find DebMirror Manager to be useful, please"
echo "consider making a donation at https://paypal.me/thisiszeev"
echo "My primary source of income is from donations by people like you... and it motivates"
echo "me to keep developing more useful tools and scripts."
echo " \$5 will buy me a cup of coffee"
echo " \$10 will buy me a nice burger"
echo " \$20 will buy me a bottle of wine"
echo "Anything above that will also be greatly appreciate..."
echo
echo "If you donate, or even if you just have a query, found a bug or need assistance, please message me on Reddit (u/thisiszeev)."
echo "Be patient if I do not reply promptly, I have been struggling with my health lately so I am not on Reddit as much as I would like."
echo "But I will reply as soon as I can..."
echo "If you donate, or even if you just have a query, found a bug or need assistance,"
echo "please message me on Reddit (u/thisiszeev). Be patient if I do not reply promptly,"
echo "I have been struggling with my health lately so I am not on Reddit as much as I would"
echo "like. But I will reply as soon as I can..."
doFinalStep
fi

Binary file not shown.

Binary file not shown.

Binary file not shown.

0
source/actions.lib.sh Normal file
View File

0
source/debmirrorman.sh Normal file
View File

0
source/functions.lib.sh Normal file
View File

0
source/vars.lib.sh Normal file
View File