ab-openldap update script
This commit is contained in:
		
							parent
							
								
									e930b28043
								
							
						
					
					
						commit
						ae64bb86b1
					
				
							
								
								
									
										125
									
								
								ab-openldap-update.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										125
									
								
								ab-openldap-update.sh
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,125 @@
 | 
				
			|||||||
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### update script for ab-openldap utility scripts
 | 
				
			||||||
 | 
					# version 1.0.0
 | 
				
			||||||
 | 
					# 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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# zero counters
 | 
				
			||||||
 | 
					updatesAvailable=0
 | 
				
			||||||
 | 
					downloadFailed=0
 | 
				
			||||||
 | 
					downloadSuccess=0
 | 
				
			||||||
 | 
					updateFailed=0
 | 
				
			||||||
 | 
					updateSuccess=0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# reference constants
 | 
				
			||||||
 | 
					containerName='ab-openldap'
 | 
				
			||||||
 | 
					server='https://git.asifbacchus.app/ab-docker/scripts/raw/branch/master/'
 | 
				
			||||||
 | 
					checksumFilename='checksums.sha256'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# files to update
 | 
				
			||||||
 | 
					localScriptName='update.sh'
 | 
				
			||||||
 | 
					repoScriptName="${containerName}-update.sh"
 | 
				
			||||||
 | 
					updateFiles="ab-openldap.sh ab-openldap.params.template ab-openldap-backup.sh ab-openldap-backup.params.template"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					printf "\n*** Updating %s container service scripts ***\n\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" files.sha256 | grep -o '^\S*' )
 | 
				
			||||||
 | 
					localScriptChecksum=$( sha256sum "$localScriptName" | grep -o '^\S*' )
 | 
				
			||||||
 | 
					if [ "$localScriptChecksum" = "$repoScriptChecksum" ]; then
 | 
				
			||||||
 | 
					    printf "[NONE]\n\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 "Checking '%s' for updates... " "$updateTarget"
 | 
				
			||||||
 | 
					    repoFile=$( grep "$updateTarget" files.sha256 | 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
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user