Skip to content

Commit 431a6bc

Browse files
author
Debdut Chakraborty
committed
Using function for detected_distro instead of an associative array.
1 parent 124d9a1 commit 431a6bc

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

common-functions/main.sh

+32-18
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@
3333
###########################################################
3434
# System
3535
###########################################################
36-
function debian_upgrade {
36+
debian_upgrade () {
3737
printf "Running initial updates - This will take a while...\n"
38-
DEBIAN_FRONTEND=noninteractive apt-get -y upgrade >/dev/null
38+
(
39+
export DEBIAN_FRONTEND=noninteractive
40+
apt-get update >/dev/null && >/dev/null apt upgrade -y
41+
)
3942
}
40-
function system_update {
41-
case "${detected_distro[family]}" in
43+
system_update () {
44+
case "`detected_distro family`" in
4245
'debian')
4346
# Force IPv4 and noninteractive upgrade after script runs to prevent
4447
# breaking nf_conntrack
@@ -51,13 +54,13 @@ function system_update {
5154
# Run initial updates for RedHat-based systems, quietly
5255
# Also, add the 'epel-release' repository to yum
5356
printf "Running initial updates - This will take a while...\n"
54-
yum --quiet -y update >/dev/null
55-
yum --quiet -y install epel-release >/dev/null
56-
yum --quiet repolist
57+
dnf --quiet -y update >/dev/null
58+
dnf --quiet -y install epel-release >/dev/null
59+
dnf --quiet repolist
5760
;;
5861
esac
5962
}
60-
function system_primary_ip {
63+
system_primary_ip () {
6164
local ip_address="$(ip a | awk '/inet / {print $2}')"
6265
echo $ip_address | cut -d' ' -f 2 | cut -d/ -f 1
6366
}
@@ -115,7 +118,7 @@ detect_distro() {
115118
' /etc/os-release`"
116119

117120
local version="`awk -F= '
118-
$1 ~ /VERSION_ID/ {
121+
$1 ~ /^VERSION_ID$/ {
119122
$2=gensub(/^"(.+)"/, "\\1", 1, $2);
120123
print $2
121124
}
@@ -862,15 +865,26 @@ function certbot_ssl {
862865
# OS Detection Stuff
863866
###########################################################
864867
# Store detected distribution information in a globally-scoped Associative Array
865-
readonly dist="$(detect_distro 'distro')"
866-
readonly fam="$(detect_distro 'family')"
867-
readonly -A detected_distro="(
868-
[distro]="${dist,,}" \
869-
[family]="${fam,,}" \
870-
[version]="$(detect_distro 'version')"
871-
[version_major]="$(detect_distro 'version' | cut -d. -f1)"
872-
[version_minor]="$(detect_distro 'version' | cut -d. -f2)"
873-
)"
868+
readonly distro="`detect_distro 'distro' | tr [:upper:] [:lower:]`"
869+
readonly family="`detect_distro 'family' | tr [:upper:] [:lower:]`"
870+
readonly version="`detect_dstro 'version'`"
871+
readonly version_major="`echo $version | cut -d. -f1`"
872+
readonly version_minor="`echo $version | cut -d. -f2`"
873+
874+
detected_distro(){
875+
eval echo \$$1
876+
}
877+
878+
# CAN'T USE ASSOCIATIVE ARRAYS IN POSIX SH
879+
880+
# readonly -A detected_distro="(
881+
# [distro]="${dist,,}" \
882+
# [family]="${fam,,}" \
883+
# [version]="$(detect_distro 'version')"
884+
# [version_major]="$(detect_distro 'version' | cut -d. -f1)"
885+
# [version_minor]="$(detect_distro 'version' | cut -d. -f2)"
886+
# )"
887+
874888
###########################################################
875889
# Other functions
876890
###########################################################

0 commit comments

Comments
 (0)