mirror of
				https://github.com/mail-in-a-box/mailinabox.git
				synced 2025-10-30 18:50:53 +00:00 
			
		
		
		
	shellcheck improvements
This commit is contained in:
		
							parent
							
								
									f3bd2d9d42
								
							
						
					
					
						commit
						f123787dc6
					
				| @ -19,12 +19,12 @@ if [ -z "$TAG" ]; then | |||||||
| 	# want to display in status checks. | 	# want to display in status checks. | ||||||
| 	# | 	# | ||||||
| 	# Allow point-release versions of the major releases, e.g. 22.04.1 is OK. | 	# Allow point-release versions of the major releases, e.g. 22.04.1 is OK. | ||||||
| 	UBUNTU_VERSION=$( lsb_release -d | sed 's/.*:\s*//' | sed 's/\([0-9]*\.[0-9]*\)\.[0-9]/\1/' )" | 	UBUNTU_VERSION=$( lsb_release -d | sed 's/.*:\s*//' | sed 's/\([0-9]*\.[0-9]*\)\.[0-9]/\1/' ) | ||||||
| 	if [ "$UBUNTU_VERSION" == "Ubuntu 22.04 LTS" ]; then | 	if [[ "$UBUNTU_VERSION" == "Ubuntu 22.04 LTS" ]]; then | ||||||
| 		# This machine is running Ubuntu 22.04, which is supported by | 		# This machine is running Ubuntu 22.04, which is supported by | ||||||
| 		# Mail-in-a-Box versions 60 and later. | 		# Mail-in-a-Box versions 60 and later. | ||||||
| 		TAG=v60 | 		TAG=v60 | ||||||
| 	elif [ "$UBUNTU_VERSION" == "Ubuntu 18.04 LTS" ]; then | 	elif [[ "$UBUNTU_VERSION" == "Ubuntu 18.04 LTS" ]]; then | ||||||
| 		# This machine is running Ubuntu 18.04, which is supported by | 		# This machine is running Ubuntu 18.04, which is supported by | ||||||
| 		# Mail-in-a-Box versions 0.40 through 5x. | 		# Mail-in-a-Box versions 0.40 through 5x. | ||||||
| 		echo "Support is ending for Ubuntu 18.04." | 		echo "Support is ending for Ubuntu 18.04." | ||||||
| @ -32,7 +32,7 @@ if [ -z "$TAG" ]; then | |||||||
| 		echo "a new machine running Ubuntu 22.04. See:" | 		echo "a new machine running Ubuntu 22.04. See:" | ||||||
| 		echo "https://mailinabox.email/maintenance.html#upgrade" | 		echo "https://mailinabox.email/maintenance.html#upgrade" | ||||||
| 		TAG=v57a | 		TAG=v57a | ||||||
| 	elif [ "$UBUNTU_VERSION" == "Ubuntu 14.04 LTS" ]; then | 	elif [[ "$UBUNTU_VERSION" == "Ubuntu 14.04 LTS" ]]; then | ||||||
| 		# This machine is running Ubuntu 14.04, which is supported by | 		# This machine is running Ubuntu 14.04, which is supported by | ||||||
| 		# Mail-in-a-Box versions 1 through v0.30. | 		# Mail-in-a-Box versions 1 through v0.30. | ||||||
| 		echo "Ubuntu 14.04 is no longer supported." | 		echo "Ubuntu 14.04 is no longer supported." | ||||||
| @ -51,7 +51,7 @@ if [[ $EUID -ne 0 ]]; then | |||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| # Clone the Mail-in-a-Box repository if it doesn't exist. | # Clone the Mail-in-a-Box repository if it doesn't exist. | ||||||
| if [ ! -d $HOME/mailinabox ]; then | if [[ ! -d "$HOME/mailinabox" ]]; then | ||||||
| 	if [ ! -f /usr/bin/git ]; then | 	if [ ! -f /usr/bin/git ]; then | ||||||
| 		echo Installing git . . . | 		echo Installing git . . . | ||||||
| 		apt-get -q -q update | 		apt-get -q -q update | ||||||
| @ -59,22 +59,22 @@ if [ ! -d $HOME/mailinabox ]; then | |||||||
| 		echo | 		echo | ||||||
| 	fi | 	fi | ||||||
| 
 | 
 | ||||||
| 	echo Downloading Mail-in-a-Box $TAG. . . | 	echo "Downloading Mail-in-a-Box $TAG . . ." | ||||||
| 	git clone \ | 	git clone \ | ||||||
| 		-b $TAG --depth 1 \ | 		-b $TAG --depth 1 \ | ||||||
| 		https://github.com/mail-in-a-box/mailinabox \ | 		https://github.com/mail-in-a-box/mailinabox \ | ||||||
| 		$HOME/mailinabox \ | 		"$HOME/mailinabox" \ | ||||||
| 		< /dev/null 2> /dev/null | 		< /dev/null 2> /dev/null | ||||||
| 
 | 
 | ||||||
| 	echo | 	echo | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| # Change directory to it. | # Change directory to it. | ||||||
| cd $HOME/mailinabox | cd "$HOME/mailinabox" || exit | ||||||
| 
 | 
 | ||||||
| # Update it. | # Update it. | ||||||
| if [ "$TAG" != $(git describe) ]; then | if [[ "$TAG" != $(git describe) ]]; then | ||||||
| 	echo Updating Mail-in-a-Box to $TAG . . . | 	echo "Updating Mail-in-a-Box to $TAG . . ." | ||||||
| 	git fetch --depth 1 --force --prune origin tag $TAG | 	git fetch --depth 1 --force --prune origin tag $TAG | ||||||
| 	if ! git checkout -q $TAG; then | 	if ! git checkout -q $TAG; then | ||||||
| 		echo "Update failed. Did you modify something in $(pwd)?" | 		echo "Update failed. Did you modify something in $(pwd)?" | ||||||
|  | |||||||
| @ -6,6 +6,7 @@ | |||||||
| # | # | ||||||
| # The DNS configuration for DKIM is done in the management daemon. | # The DNS configuration for DKIM is done in the management daemon. | ||||||
| 
 | 
 | ||||||
|  | # shellcheck source=./functions.sh | ||||||
| source setup/functions.sh # load our functions | source setup/functions.sh # load our functions | ||||||
| source /etc/mailinabox.conf # load global vars | source /etc/mailinabox.conf # load global vars | ||||||
| 
 | 
 | ||||||
| @ -15,7 +16,7 @@ apt_install opendkim opendkim-tools opendmarc | |||||||
| 
 | 
 | ||||||
| # Make sure configuration directories exist. | # Make sure configuration directories exist. | ||||||
| mkdir -p /etc/opendkim; | mkdir -p /etc/opendkim; | ||||||
| mkdir -p $STORAGE_ROOT/mail/dkim | mkdir -p "$STORAGE_ROOT/mail/dkim" | ||||||
| 
 | 
 | ||||||
| # Used in InternalHosts and ExternalIgnoreList configuration directives. | # Used in InternalHosts and ExternalIgnoreList configuration directives. | ||||||
| # Not quite sure why. | # Not quite sure why. | ||||||
| @ -52,13 +53,13 @@ fi | |||||||
| # A 1024-bit key is seen as a minimum standard by several providers | # A 1024-bit key is seen as a minimum standard by several providers | ||||||
| # such as Google. But they and others use a 2048 bit key, so we'll | # such as Google. But they and others use a 2048 bit key, so we'll | ||||||
| # do the same. Keys beyond 2048 bits may exceed DNS record limits. | # do the same. Keys beyond 2048 bits may exceed DNS record limits. | ||||||
| if [ ! -f "$STORAGE_ROOT/mail/dkim/mail.private" ]; then | if [[ ! -f "$STORAGE_ROOT/mail/dkim/mail.private" ]]; then | ||||||
| 	opendkim-genkey -b 2048 -r -s mail -D $STORAGE_ROOT/mail/dkim | 	opendkim-genkey -b 2048 -r -s mail -D "$STORAGE_ROOT/mail/dkim" | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| # Ensure files are owned by the opendkim user and are private otherwise. | # Ensure files are owned by the opendkim user and are private otherwise. | ||||||
| chown -R opendkim:opendkim $STORAGE_ROOT/mail/dkim | chown -R opendkim:opendkim "$STORAGE_ROOT/mail/dkim" | ||||||
| chmod go-rwx $STORAGE_ROOT/mail/dkim | chmod go-rwx "$STORAGE_ROOT/mail/dkim" | ||||||
| 
 | 
 | ||||||
| tools/editconf.py /etc/opendmarc.conf -s \ | tools/editconf.py /etc/opendmarc.conf -s \ | ||||||
| 	"Syslog=true" \ | 	"Syslog=true" \ | ||||||
|  | |||||||
| @ -28,13 +28,13 @@ function hide_output { | |||||||
| 		echo | 		echo | ||||||
| 		echo FAILED: "$@" | 		echo FAILED: "$@" | ||||||
| 		echo ----------------------------------------- | 		echo ----------------------------------------- | ||||||
| 		cat $OUTPUT | 		cat "$OUTPUT" | ||||||
| 		echo ----------------------------------------- | 		echo ----------------------------------------- | ||||||
| 		exit $E | 		exit $E | ||||||
| 	fi | 	fi | ||||||
| 
 | 
 | ||||||
| 	# Remove temporary file. | 	# Remove temporary file. | ||||||
| 	rm -f $OUTPUT | 	rm -f "$OUTPUT" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function apt_get_quiet { | function apt_get_quiet { | ||||||
| @ -78,7 +78,7 @@ function get_publicip_from_web_service { | |||||||
| 	# | 	# | ||||||
| 	# Pass '4' or '6' as an argument to this function to specify | 	# Pass '4' or '6' as an argument to this function to specify | ||||||
| 	# what type of address to get (IPv4, IPv6). | 	# what type of address to get (IPv4, IPv6). | ||||||
| 	curl -$1 --fail --silent --max-time 15 icanhazip.com 2>/dev/null || /bin/true | 	curl -"$1" --fail --silent --max-time 15 icanhazip.com 2>/dev/null || /bin/true | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function get_default_privateip { | function get_default_privateip { | ||||||
| @ -121,19 +121,19 @@ function get_default_privateip { | |||||||
| 	if [ "$1" == "6" ]; then target=2001:4860:4860::8888; fi | 	if [ "$1" == "6" ]; then target=2001:4860:4860::8888; fi | ||||||
| 
 | 
 | ||||||
| 	# Get the route information. | 	# Get the route information. | ||||||
| 	route=$(ip -$1 -o route get $target 2>/dev/null | grep -v unreachable) | 	route=$(ip -"$1" -o route get $target 2>/dev/null | grep -v unreachable) | ||||||
| 
 | 
 | ||||||
| 	# Parse the address out of the route information. | 	# Parse the address out of the route information. | ||||||
| 	address=$(echo $route | sed "s/.* src \([^ ]*\).*/\1/") | 	address=$(echo "$route" | sed "s/.* src \([^ ]*\).*/\1/") | ||||||
| 
 | 
 | ||||||
| 	if [[ "$1" == "6" && $address == fe80:* ]]; then | 	if [[ "$1" == "6" && $address == fe80:* ]]; then | ||||||
| 		# For IPv6 link-local addresses, parse the interface out | 		# For IPv6 link-local addresses, parse the interface out | ||||||
| 		# of the route information and append it with a '%'. | 		# of the route information and append it with a '%'. | ||||||
| 		interface=$(echo $route | sed "s/.* dev \([^ ]*\).*/\1/") | 		interface=$(echo "$route" | sed "s/.* dev \([^ ]*\).*/\1/") | ||||||
| 		address=$address%$interface | 		address=$address%$interface | ||||||
| 	fi | 	fi | ||||||
| 
 | 
 | ||||||
| 	echo $address | 	echo "$address" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function ufw_allow { | function ufw_allow { | ||||||
| @ -151,7 +151,7 @@ function ufw_limit { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function restart_service { | function restart_service { | ||||||
| 	hide_output service $1 restart | 	hide_output service "$1" restart | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ## Dialog Functions ## | ## Dialog Functions ## | ||||||
| @ -180,7 +180,7 @@ function input_menu { | |||||||
| 	declare -n result_code=$4_EXITCODE | 	declare -n result_code=$4_EXITCODE | ||||||
| 	local IFS=^$'\n' | 	local IFS=^$'\n' | ||||||
| 	set +e | 	set +e | ||||||
| 	result=$(dialog --stdout --title "$1" --menu "$2" 0 0 0 $3) | 	result=$(dialog --stdout --title "$1" --menu "$2" 0 0 0 "$3") | ||||||
| 	result_code=$? | 	result_code=$? | ||||||
| 	set -e | 	set -e | ||||||
| } | } | ||||||
| @ -192,17 +192,17 @@ function wget_verify { | |||||||
| 	HASH=$2 | 	HASH=$2 | ||||||
| 	DEST=$3 | 	DEST=$3 | ||||||
| 	CHECKSUM="$HASH  $DEST" | 	CHECKSUM="$HASH  $DEST" | ||||||
| 	rm -f $DEST | 	rm -f "$DEST" | ||||||
| 	hide_output wget -O $DEST $URL | 	hide_output wget -O "$DEST" "$URL" | ||||||
| 	if ! echo "$CHECKSUM" | sha1sum --check --strict > /dev/null; then | 	if ! echo "$CHECKSUM" | sha1sum --check --strict > /dev/null; then | ||||||
| 		echo "------------------------------------------------------------" | 		echo "------------------------------------------------------------" | ||||||
| 		echo "Download of $URL did not match expected checksum." | 		echo "Download of $URL did not match expected checksum." | ||||||
| 		echo "Found:" | 		echo "Found:" | ||||||
| 		sha1sum $DEST | 		sha1sum "$DEST" | ||||||
| 		echo | 		echo | ||||||
| 		echo "Expected:" | 		echo "Expected:" | ||||||
| 		echo "$CHECKSUM" | 		echo "$CHECKSUM" | ||||||
| 		rm -f $DEST | 		rm -f "$DEST" | ||||||
| 		exit 1 | 		exit 1 | ||||||
| 	fi | 	fi | ||||||
| } | } | ||||||
| @ -218,9 +218,9 @@ function git_clone { | |||||||
| 	SUBDIR=$3 | 	SUBDIR=$3 | ||||||
| 	TARGETPATH=$4 | 	TARGETPATH=$4 | ||||||
| 	TMPPATH=/tmp/git-clone-$$ | 	TMPPATH=/tmp/git-clone-$$ | ||||||
| 	rm -rf $TMPPATH $TARGETPATH | 	rm -rf "$TMPPATH" "$TARGETPATH" | ||||||
| 	git clone -q $REPO $TMPPATH || exit 1 | 	git clone -q "$REPO" "$TMPPATH" || exit 1 | ||||||
| 	(cd $TMPPATH; git checkout -q $TREEISH;) || exit 1 | 	(cd "$TMPPATH" && git checkout -q "$TREEISH") || exit 1 | ||||||
| 	mv $TMPPATH/$SUBDIR $TARGETPATH | 	mv "$TMPPATH/$SUBDIR" "$TARGETPATH" | ||||||
| 	rm -rf $TMPPATH | 	rm -rf "$TMPPATH" | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user