Compare commits

...

82 Commits

Author SHA1 Message Date
Asif Bacchus 0f53e1b39f moved to ab-openldap repo 2020-09-15 23:30:34 -06:00
Asif Bacchus 1e9ab5fc45 update comment header blocks 2020-09-15 23:27:09 -06:00
Asif Bacchus a8f70e892c update checksums 2020-09-15 23:20:45 -06:00
Asif Bacchus 65cebd4845 display failures iff greater than 0 2020-09-15 23:20:05 -06:00
Asif Bacchus d3eab06714 remove extraneous linebreaks 2020-09-15 23:11:52 -06:00
Asif Bacchus ca82b501cb update checksums 2020-09-15 00:42:18 -06:00
Asif Bacchus c80374f971 unquote dummy var to allow splitting 2020-09-15 00:40:55 -06:00
Asif Bacchus b81619376a add extra linebreak after results 2020-09-15 00:39:24 -06:00
Asif Bacchus 733168e4b6 update checksums 2020-09-15 00:32:43 -06:00
Asif Bacchus 3d9c1728a1 fix cmd typo 2020-09-15 00:31:29 -06:00
Asif Bacchus 2427aa628b update checksums 2020-09-15 00:07:49 -06:00
Asif Bacchus 5478ac1565 remove unused colours 2020-09-14 23:53:46 -06:00
Asif Bacchus 809c04b4b3 format text output 2020-09-14 23:50:04 -06:00
Asif Bacchus 81e0a6d91a add yellow text colour 2020-09-14 23:42:39 -06:00
Asif Bacchus 514e24664c use func: consoleError to display error 2020-09-14 23:36:34 -06:00
Asif Bacchus 34d57d4553 add error display function 2020-09-14 23:36:17 -06:00
Asif Bacchus 394487fadb add text formatting presets 2020-09-14 23:36:03 -06:00
Asif Bacchus 0a032cdae1 supress docker update output 2020-09-14 23:21:37 -06:00
Asif Bacchus b4f8834d51 rename update script 2020-09-14 23:18:53 -06:00
Asif Bacchus 3bc3683b11 partial rewrite of script and new update location 2020-09-14 23:18:28 -06:00
Asif Bacchus edf6a13e38 match container version, rename backup script 2020-09-14 16:33:55 -06:00
Asif Bacchus 368f4bb5fc fixed typo 2020-09-14 16:29:53 -06:00
Asif Bacchus c9adb535b2 fix incorrect form of its 2020-09-14 16:25:05 -06:00
Asif Bacchus edba57caaf update params template and move mailserver stuff 2020-09-14 16:21:58 -06:00
Asif Bacchus b23afe500d add mailserver option handling 2020-09-14 16:07:42 -06:00
Asif Bacchus f74879e834 update help with mailserver options 2020-09-14 16:04:19 -06:00
Asif Bacchus 8772fc0a44 update ignored files 2020-09-14 15:57:15 -06:00
Asif Bacchus 05775ea3c7 dynamically change params filename to match script 2020-09-14 15:55:29 -06:00
Asif Bacchus 3c4b743ee3 update version to match new features in container 2020-09-14 14:29:33 -06:00
Asif Bacchus 823c7b098c update checksums 2020-03-15 01:08:28 -06:00
Asif Bacchus 8347b89725 bump versions to 3.2 2020-03-15 01:07:41 -06:00
Asif Bacchus 0f3f012fd7 re-add clean operation 2020-03-15 01:05:59 -06:00
Asif Bacchus cee70f7ed8 update checksums 2020-03-14 19:31:21 -06:00
Asif Bacchus 15130b87ba cleanup script spacing and bump version number 2020-03-14 19:29:59 -06:00
Asif Bacchus 4298c0c0c6 move TLS file existance check 2020-03-14 19:16:15 -06:00
Asif Bacchus c23c60e16b remove 'clean' from help 2020-03-14 19:12:53 -06:00
Asif Bacchus d733687742 remove 'clean' option from script 2020-03-14 19:12:04 -06:00
Asif Bacchus 7a58e1b513 display confirmation loop err in red 2020-03-14 19:11:56 -06:00
Asif Bacchus 17dda2504d use 'force' on all docker related removals 2020-03-14 17:44:20 -06:00
Asif Bacchus 1108797ac2 clean up script spacing for easier reading 2020-03-14 17:40:57 -06:00
Asif Bacchus c6723b6c54 replace confirmation loops with func prompt_yn 2020-03-14 17:37:54 -06:00
Asif Bacchus a77b73e835 create and use func consoleError 2020-03-14 17:33:52 -06:00
Asif Bacchus 30bb38672b add note about where volume names are sourced 2020-03-14 17:31:48 -06:00
Asif Bacchus 0cc46e187c func textblock, update and use in help 2020-03-14 00:40:28 -06:00
Asif Bacchus b6fc492881 move error codes to end of file 2020-03-13 23:48:25 -06:00
Asif Bacchus 80ee3c7a3d match script to container version 2020-03-13 23:42:14 -06:00
Asif Bacchus 98b44dd63c update in-script help with removeTLS info 2020-03-13 23:41:44 -06:00
Asif Bacchus b033828165 get full path to restored cn config file 2020-03-13 23:33:08 -06:00
Asif Bacchus d7d7f1eae1 remove TLS entries from extracted backup files 2020-03-13 20:28:41 -06:00
Asif Bacchus 8126efc7e1 fix possible double-backslash on outputLocation 2020-03-13 20:03:36 -06:00
Asif Bacchus 85b02e8821 set vars and switches for removing TLS operation 2020-03-13 20:01:50 -06:00
Asif Bacchus 0246568a6c fix possible double-backslash on outputLocation 2020-03-13 19:58:39 -06:00
Asif Bacchus 974e5e06f5 update checksums 2020-03-13 11:47:20 -06:00
Asif Bacchus 091edf2323 Merge branch 'master' of https://git.asifbacchus.app/ab-docker/scripts 2020-03-13 11:45:57 -06:00
Asif Bacchus 198cfaf916 version tag script files, update checksums 2020-03-13 11:44:14 -06:00
Asif Bacchus b8ccfdca98 delete own checksum -- makes no sense 2020-03-13 04:58:23 -06:00
Asif Bacchus 3fe8bde320 update readme 2020-03-13 03:42:53 -06:00
Asif Bacchus bdf2a4f55f reorganized repo 2020-03-13 03:34:47 -06:00
Asif Bacchus ab048e2069 update directory organization
Renamed backup script, added files to update script and regenerated
checksums
2020-03-13 03:32:09 -06:00
Asif Bacchus 3b87ce0661 fix missing printf 2020-03-13 03:31:08 -06:00
Asif Bacchus 79458aa416 fix missing printf statement 2020-03-13 03:28:03 -06:00
Asif Bacchus 66c27ccd73 delete old checksum file 2020-03-13 03:23:22 -06:00
Asif Bacchus f7cfc4d9e3 create checksum file 2020-03-13 03:23:03 -06:00
Asif Bacchus 27c013ecd2 rename for easier use 2020-03-13 03:22:12 -06:00
Asif Bacchus 430af57512 update as per template changes 2020-03-13 03:21:53 -06:00
Asif Bacchus 49b7d15d43 update server path for new repo structure 2020-03-13 03:21:20 -06:00
Asif Bacchus 901f856402 update header comment and root check output 2020-03-13 03:15:53 -06:00
Asif Bacchus 7fb4423026 move ab-openldap scripts to subdirectory 2020-03-13 03:13:53 -06:00
Asif Bacchus 69a7114ac6 add container update 2020-03-13 03:12:47 -06:00
Asif Bacchus 9680c93574 check if user is root or in docker group 2020-03-13 03:08:06 -06:00
Asif Bacchus 860cc1408f clean-up output spacing for readability 2020-03-13 02:45:05 -06:00
Asif Bacchus 50a1f35c37 clean-up output spacing for readability 2020-03-13 02:44:00 -06:00
Asif Bacchus e6a4659b51 fix wrong checksum filename 2020-03-13 02:40:46 -06:00
Asif Bacchus 10e4ffc90d fix wrong checksum filename 2020-03-13 02:39:37 -06:00
Asif Bacchus 41fe77b92d fix formatting 2020-03-13 02:37:17 -06:00
Asif Bacchus ddb0c65eae make executable 2020-03-13 02:37:12 -06:00
Asif Bacchus 7b1c660224 update checksums for ab-openldap files 2020-03-13 02:33:29 -06:00
Asif Bacchus ae64bb86b1 ab-openldap update script 2020-03-13 02:31:05 -06:00
Asif Bacchus e930b28043 rename ab-openldap backup script files 2020-03-13 02:30:55 -06:00
Asif Bacchus ffd336e218 update ab-openldap scripts 2020-03-13 02:28:00 -06:00
Asif Bacchus 220f0bdd23 repo script name dynamically based on container 2020-03-13 02:24:27 -06:00
Asif Bacchus ce3c8e9c8c update script template file 2020-03-13 02:21:59 -06:00
12 changed files with 157 additions and 375 deletions
+1
View File
@@ -74,3 +74,4 @@
.gitattributes export-ignore
.gitignore export-ignore
.vscode export-ignore
+4
View File
@@ -3,4 +3,8 @@
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/numbered-bookmarks.json
*.code-workspace
# ignore params files
*.params
+3
View File
@@ -0,0 +1,3 @@
{
"bookmarks": []
}
+5 -1
View File
@@ -1,3 +1,7 @@
# AB-Docker Convenience Scripts
POSIX-shell scripts meant to make launching AB-Docker containers easier. See relevant container repos for information on how to use each script. The most updated version of each script will be in the container's git repo but are mirrored here for simplicity in distribution where only the script is needed as opposed to Dockerfiles, etc.
POSIX-shell scripts meant to make launching AB-Docker containers easier. See relevant container repos for information on how to use each script.
## Organization
Each container has it's own subdirectory within this repo for it's associated utility scripts. Each subdirectory has a *checksums.sha256* which allows the *update.sh* script to automate pulling the latest versions.
-73
View File
@@ -1,73 +0,0 @@
#
## openldap environment variables
#
### Usage
#
# ***VERY IMPORTANT! DO NOT PUT QUOTES AROUND VALUES IN THIS FILE!!!***
# incorrect: ORG_NAME="MyOrganization"
# correct: ORG_NAME=MyOrganization
#
# Instead of typing a myriad of "-e ...", you can fill them all out in this
# file and then use "--env-file ab-openldap.params" to tell docker to source
# it's variables from here. You can also combine both methods if you like.
# Most important, if you're using the convenience script, it draws all info from
# this file!
#
# You should probably protect this file via file permissions since it likely
# will contain things like passwords! Suggest restricting it to root only
# ex: chown root:root ab-openldap.parms && chmod 600 ab-openldap.parms
###
### Your timezone (https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
TZ=Area/Location
### First user account (will be added to Organization DIT 'manager' role)
USER=admin
USER_PASS=admin
USER_FIRSTNAME=admin
USER_LASTNAME=admin
### Your Organization domain and name
# domain in standard (dotted) format -- not LDAP format
DOMAIN=mydomain.net
# Org name: suggest using [A-Z][a-z][0-9][-_] ONLY. Avoid spaces.
ORG_NAME=MyOrganization
### Your 'directory browser' user
BROWSER_USER=ldapbind
BROWSER_PASS=ldapbind
### Anonymous binding (enabled by default)
ANONYMOUS_BINDING=yes
### Location of your TLS files
# Note: This section is only automated if using the script file to start the
# container. If you are starting it manually and using '--env-file', you still
# have to manually bind-mount these files using '-v source:/certs/dest.file:ro'.
#
# If you're bind-mounting symlinks, remember that you have to fully expand them
# or Docker will try to bind the link instead of the target! This is most
# common with Let's Encrypt.
#
# Example that does not work (binding directory instead of files):
# /etc/letsencrypt/live/mydomain.net:/certs:ro
# This will end up copying the symlinks themselves and, since the targets are
# not available to the container, it doesn't work!
# Example of the right way (bind actual files):
# /etc/letsencrypt/live/mydomain.net/privkey.pem:/certs/privkey.pem:ro
###
#TLS_CERT=/etc/letsencrypt/live/mydomain.net/fullchain.pem
#TLS_KEY=/etc/letsencrypt/live/mydomain.net/privkey.pem
#TLS_CHAIN=/etc/letsencrypt/live/mydomain.net/chain.pem
# The container will generate Diffie-Hellman parameters automatically the first
# time it's launched with TLS certificates defined.
### Custom LDIFs
# Path to any custom LDIFs you want applied to the container. Leave this line/
# variable commented-out if you don't have any LDIFs to apply.
# MY_LDIF=/path/to/my/LDIFs
#EOF
-300
View File
@@ -1,300 +0,0 @@
#!/bin/sh
#
### start openldap container using params file variables
#
# error code reference:
# 0: exited normally, no errors
# 1: unknown startup option passed to script
# 2: current user is unauthorized to operate docker
# 3: 'params' file not found in same directory as script
# 5: specified TLS-related files (cert, key or chain) not found
# text formatting presets
cyan=$(tput setaf 6)
err=$(tput bold)$(tput setaf 1)
magenta=$(tput setaf 5)
norm=$(tput sgr0)
red=$(tput setaf 1)
yellow=$(tput setaf 3)
### parameter defaults
clean=false
container_name="ab-openldap"
remove=0
shell=false
scriptHelp () {
printf "\n${magenta}%80s\n" | tr " " "-"
printf "${norm}This is a simple helper script so you can avoid lengthy typing when working\n"
printf "with the openLDAP container. The script reads the contents of 'ab-openldap.params'\n"
printf "and constructs various 'docker run' commands based on that file. The biggest\n"
printf "timesaver is working with certificates. If they are specified in the '.params',\n"
printf "the script will automatically bind-mount them so openLDAP starts in 'TLS\n"
printf "required' mode.\n\n"
printf "If you run the script with no parameters, it will execute the container\n"
printf "'normally': Run in detached mode with openLDAP automatically launched and\n"
printf "logging to stdout. If you specified certificates, openLDAP will require a TLS\n"
printf "connection. All modes of operation allow you to enter the container and\n"
printf "connect directly using UNIX sockets also.\n"
printf "Containers run in SHELL mode are ALWAYS removed upon exit as they are meant for\n"
printf "testing only. By default, containers run without '--rm' will be restarted\n"
printf "automatically unless they are manually stopped via 'docker stop...'\n\n"
printf "${magenta}The script has the following parameters:\n"
printf "${cyan}(parameter in cyan) ${yellow}(default in yellow)${norm}\n\n"
printf "${cyan}-n|--name${norm}\n"
printf "Change the name of the container. This is cosmetic and does not affect\n"
printf "operation in any way.\n"
printf "${yellow}(ab-openldap)${norm}\n\n"
printf "${cyan}--rm|--remove${norm}\n"
printf "Automatically remove the container and volume (unless data is written) after it\n"
printf "is exited.\n"
printf "${yellow}(off: do not destroy container when stopped)${norm}\n\n"
printf "${cyan}-s|--shell${norm}\n"
printf "Enter the container using an interactive POSIX shell. This happens after\n"
printf "startup operations but *before* openLDAP (slapd) is actually started. This is\n"
printf "a great way to see configuration changes possibly stopping openLDAP from\n"
printf "starting. You can combine this with '--rm' for easy configuration checks.\n"
printf "${yellow}(off: run in detached mode)${norm}\n\n"
printf "${cyan}--clean${norm}\n"
printf "This option will stop ALL running openLDAP containers *AND DESTROY ALL\n"
printf "VOLUMES*. This is meant to give you a 'clean start' if you've made\n"
printf "configuration changes, etc.\n\n"
printf "${yellow}More information can be found at:\n"
printf "https://git.asifbacchus.app/ab-docker/openldap/wiki\n"
printf "${magenta}%80s\n\n" | tr " " "-"
exit 0
}
### pre-requisite checks
# is user root or in the docker group?
if [ ! "$( id -u )" -eq 0 ]; then
if ! id -Gn | grep docker > /dev/null; then
printf "${err}\nYou must either be root or in the 'docker' group to run this script since you must be able to actually start the container! Exiting.\n${norm}"
exit 2
fi
fi
# does the params file exist?
if [ ! -f "./ab-openldap.params" ]; then
printf "${err}\nCannot find 'ab-openldap.params' file in the same directory as this script. Exiting.\n${norm}"
exit 3
fi
# read .params file
. ./ab-openldap.params
# check for certs if using TLS
if [ "$TLS_CERT" ]; then
if [ ! -f "$TLS_CERT" ]; then
printf "${err}\nCannot find specified TLS certificate file. Exiting.${norm}\n"
exit 5
fi
if [ ! -f "$TLS_KEY" ]; then
printf "${err}\nCannot find specified TLS private key file. Exiting.${norm}\n"
exit 5
fi
if [ ! -f "$TLS_CHAIN" ]; then
printf "${err}\nCannot find specified TLS certificate chain file. Exiting.${norm}\n"
exit 5
fi
fi
# process startup parameters
while [ $# -gt 0 ]; do
case "$1" in
-h|-\?|--help)
# display help
scriptHelp
exit 0
;;
--rm|--remove)
# remove container on exit
remove=1
;;
-s|--shell)
# start shell instead of default CMD
shell=true
;;
--clean)
# stop if necessary, delete volumes
clean=true
;;
-n|--name)
# container name
if [ -z "$2" ]; then
printf "${err}\nNo container name specified. Exiting.\n${norm}"
exit 1
fi
container_name="$2"
shift
;;
*)
printf "${err}\nUnknown option: %s\n" "$1"
printf "Use '--help' for valid options.\n\n${norm}"
exit 1
;;
esac
shift
done
# cleanup any running containers and volumes
if [ $clean = true ]; then
# get all ab-openldap containers
containers=$(docker ps -a --no-trunc --filter "label=org.label-schema.name=ab-openldap" --format "{{ .Names }}")
# check for null value -- no containers to remove
if [ -z "$containers" ]; then
printf "${err}No openldap containers to remove. Exiting.${norm}\n\n"
exit 0
fi
# iterate containers, stop them and remove straggling volumes
set -- dummy $containers
shift
for container; do
printf "\n${cyan}Found %s -- processing:${norm}\n" ${container}
volume=$(docker inspect --format '{{ range .Mounts }}{{ if eq .Destination "/var/openldap/data" }}{{ .Name }}{{ end }}{{ end }}' ${container})
printf "\t${red}Stopping container...${norm}\n"
docker stop ${container} > /dev/null 2>&1
printf "\t${red}Removing container...${norm}\n"
docker rm ${container} > /dev/null 2>&1
printf "\t${red}Removing volume...${norm}\n"
docker volume rm ${volume} > /dev/null 2>&1
printf "${cyan}...done${norm}\n"
done
# run without TLS
elif [ -z "$TLS_CERT" ]; then
if [ $shell = true ]; then
# exec shell
printf "${cyan}\nRunning SHELL on %s...${norm}\n" "$container_name"
if [ -d "$MY_LDIF" ]; then
# bind-mount custom LDIFs if specified
docker run --rm -it --name ${container_name} \
--env-file ab-openldap.params \
-v "$MY_LDIF":/etc/openldap/customLDIF \
-p 389:389 -p 636:636 \
docker.asifbacchus.app/ldap/ab-openldap:latest /bin/sh
else
docker run --rm -it --name ${container_name} \
--env-file ab-openldap.params \
-p 389:389 -p 636:636 \
docker.asifbacchus.app/ldap/ab-openldap:latest /bin/sh
fi
else
# exec normally
printf "${cyan}\nRunning OPENLDAP on %s...${norm}\n" "$container_name"
if [ "$remove" -eq 1 ]; then
if [ -d "$MY_LDIF" ]; then
# bind-mount custom LDIFs if specified
docker run --rm -d --name ${container_name} \
--env-file ab-openldap.params \
-v "$MY_LDIF":/etc/openldap/customLDIF \
-p 389:389 -p 636:636 \
docker.asifbacchus.app/ldap/ab-openldap:latest
else
docker run --rm -d --name ${container_name} \
--env-file ab-openldap.params \
-p 389:389 -p 636:636 \
docker.asifbacchus.app/ldap/ab-openldap:latest
fi
else
if [ -d "$MY_LDIF" ]; then
# bind-mount custom LDIFs if specified
docker run -d --name ${container_name} \
--env-file ab-openldap.params \
-v "$MY_LDIF":/etc/openldap/customLDIF \
-p 389:389 -p 636:636 \
--restart unless-stopped \
docker.asifbacchus.app/ldap/ab-openldap:latest
else
docker run -d --name ${container_name} \
--env-file ab-openldap.params \
-p 389:389 -p 636:636 \
--restart unless-stopped \
docker.asifbacchus.app/ldap/ab-openldap:latest
fi
fi
fi
# run with TLS
elif [ "$TLS_CERT" ] && [ "$TLS_KEY" ] && [ "$TLS_CHAIN" ]; then
if [ $shell = true ]; then
# exec shell
printf "${cyan}\nRunning SHELL on %s (TLS)...${norm}\n" "$container_name"
if [ -d "$MY_LDIF" ]; then
# bind-mount custom LDIFs if specified
docker run --rm -it --name ${container_name} \
--env-file ab-openldap.params \
-v "$MY_LDIF":/etc/openldap/customLDIF \
-v "$TLS_CERT":/certs/fullchain.pem:ro \
-v "$TLS_KEY":/certs/privkey.pem:ro \
-v "$TLS_CHAIN":/certs/chain.pem:ro \
-p 389:389 -p 636:636 \
docker.asifbacchus.app/ldap/ab-openldap:latest /bin/sh
else
docker run --rm -it --name ${container_name} \
--env-file ab-openldap.params \
-v "$TLS_CERT":/certs/fullchain.pem:ro \
-v "$TLS_KEY":/certs/privkey.pem:ro \
-v "$TLS_CHAIN":/certs/chain.pem:ro \
-p 389:389 -p 636:636 \
docker.asifbacchus.app/ldap/ab-openldap:latest /bin/sh
fi
else
# exec normally
printf "${cyan}\nRunning OPENLDAP on %s (TLS)...${norm}\n" "$container_name"
if [ "$remove" -eq 1 ]; then
if [ -d "$MY_LDIF" ]; then
# bind-mount custom LDIFs if specified
docker run --rm -d --name ${container_name} \
--env-file ab-openldap.params \
-v "$MY_LDIF":/etc/openldap/customLDIF \
-v "$TLS_CERT":/certs/fullchain.pem:ro \
-v "$TLS_KEY":/certs/privkey.pem:ro \
-v "$TLS_CHAIN":/certs/chain.pem:ro \
-p 389:389 -p 636:636 \
docker.asifbacchus.app/ldap/ab-openldap:latest
else
docker run --rm -d --name ${container_name} \
--env-file ab-openldap.params \
-v "$TLS_CERT":/certs/fullchain.pem:ro \
-v "$TLS_KEY":/certs/privkey.pem:ro \
-v "$TLS_CHAIN":/certs/chain.pem:ro \
-p 389:389 -p 636:636 \
docker.asifbacchus.app/ldap/ab-openldap:latest
fi
else
if [ -d "$MY_LDIF" ]; then
# bind-mount custom LDIFs if specified
docker run -d --name ${container_name} \
--env-file ab-openldap.params \
-v "$MY_LDIF":/etc/openldap/customLDIF \
-v "$TLS_CERT":/certs/fullchain.pem:ro \
-v "$TLS_KEY":/certs/privkey.pem:ro \
-v "$TLS_CHAIN":/certs/chain.pem:ro \
-p 389:389 -p 636:636 \
--restart unless-stopped \
docker.asifbacchus.app/ldap/ab-openldap:latest
else
docker run -d --name ${container_name} \
--env-file ab-openldap.params \
-v "$TLS_CERT":/certs/fullchain.pem:ro \
-v "$TLS_KEY":/certs/privkey.pem:ro \
-v "$TLS_CHAIN":/certs/chain.pem:ro \
-p 389:389 -p 636:636 \
--restart unless-stopped \
docker.asifbacchus.app/ldap/ab-openldap:latest
fi
fi
fi
fi
### exit gracefully
exit 0
-1
View File
@@ -1 +0,0 @@
# checksums for scripts and parameter files
+144
View File
@@ -0,0 +1,144 @@
#!/bin/sh
### update script for <ab-container> container and utility scripts
# version x.y.z
# script by Asif Bacchus
# usage of this script is subject to the license terms found at:
# https://git.asifbacchus.app/ab-docker/scripts/LICENSE
### pre-requisites
# check if wget is installed
if ! command -v wget > /dev/null 2>&1; then
printf "\nSorry, this script requires that 'wget' is installed in order to automatically update files.\nExiting.\n\n"
exit 1
fi
# is user root or in the docker group?
if [ ! "$( id -u )" -eq 0 ]; then
if ! id -Gn | grep docker > /dev/null; then
consoleError '1' "You must either be root or in the 'docker' group to pull container updates."
fi
fi
# zero counters
updatesAvailable=0
downloadFailed=0
downloadSuccess=0
updateFailed=0
updateSuccess=0
# reference constants
containerName=''
containerUpdatePath='docker.asifbacchus.app/...:latest'
server="https://git.asifbacchus.app/ab-docker/scripts/raw/branch/master/$containerName/"
checksumFilename='checksums.sha256'
# files to update
localScriptName='update.sh'
repoScriptName='update.sh'
updateFiles=""
### update container
printf "\n*** Updating %s container and service scripts ***\n\n" "$containerName"
printf "Updating container:\n"
if ! docker pull "$containerUpdatePath"; then
printf "There was an error updating the container. Try again later.\n\n"
exit 1
else
printf "Container updated!\n"
fi
### update scripts
printf "Updating %s service scripts\n" "$containerName"
## download latest checksums
printf "Getting latest checksums from ab-git server... "
if ! wget --quiet --tries=3 --timeout=10 -N "${server}${checksumFilename}"; then
printf "[ERROR]\n"
printf "Unable to download checksums from ab-git server. Try again later.\n\n"
exit 1
else
printf "[OK]\n"
fi
## check for updates to this script
printf "Checking for updates to this script... "
repoScriptChecksum=$( grep "$repoScriptName" "$checksumFilename" | grep -o '^\S*' )
localScriptChecksum=$( sha256sum "$localScriptName" | grep -o '^\S*' )
if [ "$localScriptChecksum" = "$repoScriptChecksum" ]; then
printf "[NONE]\n"
else
# download updated script
if ! wget --quiet --tries=3 --timeout=10 -O $localScriptName "${server}${repoScriptName}"; then
printf "[ERROR]\n"
printf "Unable to download script update. Try again later.\n\n"
exit 1
else
# verify download
localScriptChecksum=$( sha256sum "$localScriptName" | grep -o '^\S*' )
if ! [ "$localScriptChecksum" = "$repoScriptChecksum" ]; then
printf "[ERROR]\n"
printf "Unable to verify checksum of updated script. Try again later.\n\n"
else
printf "[UPDATED]\n\n"
printf "*** This script has been updated. Please re-run it to load the updated version of this file. ***\n\n"
exit 0
fi
fi
fi
## update files
set -- dummy $updateFiles
shift
for file; do
updateTarget="$file"
printf "\nChecking '%s' for updates... " "$updateTarget"
repoFile=$( grep "$updateTarget" "$checksumFilename" | grep -o '^\S*' )
if [ -f "$file" ]; then
localFile=$( sha256sum "$updateTarget" | grep -o '^\S*' )
else
localFile=0
fi
if ! [ "$localFile" = "$repoFile" ]; then
printf "[AVAILABLE]\n"
updatesAvailable=$((updatesAvailable+1))
# download update
printf "Downloading updated '%s'... " "$updateTarget"
# specify a name here instead of using the server name so that wget
# overwrites the file
if ! wget --quiet --tries=3 --timeout=10 -O "$updateTarget" "${server}${updateTarget}"; then
printf "[ERROR]\n"
downloadFailed=$((downloadFailed+1))
else
printf "[OK]\n"
downloadSuccess=$((downloadSuccess+1))
# verify download
printf "Verifying '%s'... " "$updateTarget"
localFile=$( sha256sum "$updateTarget" | grep -o '^\S*' )
if ! [ "$localFile" = "$repoFile" ]; then
printf "[INVALID]\n"
updateFailed=$((updateFailed+1))
else
printf "[OK]\n"
updateSuccess=$((updateSuccess+1))
fi
fi
else
printf "[NONE]\n"
fi
done
### display results
printf "\nResults:\n"
printf "\tUpdates: %s available\n" "$updatesAvailable"
printf "\tDownloads: %s successful, %s failed\n" "$downloadSuccess" "$downloadFailed"
printf "\tUpdates: %s applied, %s failed\n" "$updateSuccess" "$updateFailed"
exit 0