Skip to content

Commit b50a69c

Browse files
Multi-argument support for install.sh
Signed-off-by: Sai Charan Sunkara <[email protected]>
1 parent 95a85a8 commit b50a69c

File tree

1 file changed

+67
-14
lines changed

1 file changed

+67
-14
lines changed

mount-helper/install/install.sh

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,55 @@ declare -A region_map=(
6060
["br-sao"]="br-sao"
6161
["par"]="eu-fr2"
6262
["eu-fr2"]="eu-fr2"
63-
)
63+
)
64+
65+
ENVIRONMENT="prod" # prod | stage
66+
SKIP_UPDATE="false" # true | false
67+
TLS_FLAG="false" # true | false
68+
UNINSTALL_FLAG="false" # true | false
69+
STUNNEL_ENABLED=false # flipped true by --stunnel
70+
71+
parse_token() {
72+
case "$1" in
73+
stage|--env=stage) ENVIRONMENT="stage" ;;
74+
--env=prod) ENVIRONMENT="prod" ;;
75+
--update) SKIP_UPDATE="true" ;;
76+
--update-stage) ENVIRONMENT="stage"; SKIP_UPDATE="true" ;;
77+
--tls) TLS_FLAG="true" ;;
78+
--uninstall|--uninstall*) UNINSTALL_FLAG="true" ;;
79+
--stunnel) STUNNEL_ENABLED=true ;;
80+
region=*) : ;;
81+
"" ) : ;;
82+
*) : ;; # ignore unknowns
83+
esac
84+
}
85+
for tok in "$@"; do parse_token "$tok"; done
6486

87+
# Normalize legacy positional vars so the rest of the script keeps working.
88+
# Many checks key off INSTALL_ARG for "stage", "--update", "--update-stage".
89+
if [ "$UNINSTALL_FLAG" = "true" ]; then
90+
INSTALL_ARG="--uninstall"
91+
else
92+
if [[ "${1:-}" == region=* ]]; then
93+
: # leave INSTALL_ARG as-is (region=...)
94+
else
95+
if [ "$SKIP_UPDATE" = "true" ]; then
96+
if [ "$ENVIRONMENT" = "stage" ]; then
97+
INSTALL_ARG="--update-stage"
98+
else
99+
INSTALL_ARG="--update"
100+
fi
101+
else
102+
if [ "$ENVIRONMENT" = "stage" ]; then
103+
INSTALL_ARG="stage"
104+
fi
105+
fi
106+
fi
107+
fi
108+
109+
if [ "$TLS_FLAG" = "true" ]; then
110+
INSTALL_MOUNT_OPTION_ARG="--tls"
111+
fi
65112

66113
not_for_ppc () {
67114
echo $@ is not needed for PPC architechture since Ipsec is not supported. Silently ignoring.
@@ -568,9 +615,7 @@ init_mount_helper () {
568615
INSTALL_ARG=""
569616
fi
570617

571-
if [[ "$INSTALL_MOUNT_OPTION_ARG" == "stage" ]]; then
572-
exit_err "incorrect command, pass stage as first arg."
573-
fi
618+
# Accept 'stage' in any position; no error if it was passed as $2
574619
if [[ "$INSTALL_ARG" == "--tls" || "$INSTALL_MOUNT_OPTION_ARG" == "--tls" ]]; then
575620
check_tls_supported_linux_verion
576621
fi
@@ -582,6 +627,16 @@ init_mount_helper () {
582627
if [[ "$INSTALL_MOUNT_OPTION_ARG" == "--tls" ]]; then
583628
install_tls_certificates $CERT_PATH
584629
fi
630+
# If stunnel mode was selected, install it in stage too
631+
if [ "$STUNNEL_ENABLED" = "true" ]; then
632+
if [ -x "./install_stunnel.sh" ]; then
633+
echo "STUNNEL selected: installing stunnel (stage)..."
634+
./install_stunnel.sh install
635+
else
636+
echo "Error: install_stunnel.sh not found or not executable in current directory."
637+
exit 1
638+
fi
639+
fi
585640
exit_ok "Install completed ok"
586641
fi
587642

@@ -593,7 +648,7 @@ init_mount_helper () {
593648
INSTALL_ARG="metadata"
594649
fi
595650

596-
log "Installing certs for: $INSTALL_ARG"
651+
log "Installing certs for: $INSTALL_ARG"
597652
CERT_PATH="./certs/$INSTALL_ARG"
598653
if [ ! -d $CERT_PATH ]; then
599654
exit_err "$CERT_PATH cert folder does not exist"
@@ -604,7 +659,7 @@ init_mount_helper () {
604659
$SBIN_SCRIPT -INSTALL_ROOT_CERT $CERT_PATH
605660
check_result "Problem installing ssl certs"
606661
if [[ "$INSTALL_MOUNT_OPTION_ARG" == "--tls" ]]; then
607-
install_tls_certificates $CERT_PATH
662+
install_tls_certificates $CERT_PATH
608663
fi
609664
# Check if STUNNEL_ENABLED is set to true
610665
if [ "$STUNNEL_ENABLED" == "true" ]; then
@@ -623,15 +678,13 @@ init_mount_helper () {
623678

624679
# main starts here.
625680
#
626-
if [[ "$INSTALL_ARG" == "--stunnel" ]]; then
627-
STUNNEL_INSTALL_CMD="./install_stunnel.sh install"
628-
STUNNEL_ENABLED=true
681+
if [ "$STUNNEL_ENABLED" = "true" ]; then
682+
STUNNEL_INSTALL_CMD="./install_stunnel.sh install"
629683
else
630-
STUNNEL_INSTALL_CMD="echo skipping stunnel..."
631-
684+
STUNNEL_INSTALL_CMD=":"
685+
echo "skipping stunnel..."
632686
fi
633687

634-
635688
reject_ipsec && setup_share_config
636689

637690
if ( is_linux LINUX_UBUNTU || is_linux LINUX_DEBIAN ); then
@@ -698,7 +751,7 @@ if is_linux LINUX_RED_HAT; then
698751

699752
# Read the package list from the file
700753
packages=()
701-
while IFS= read -r line; do
754+
while IFS= read -r line; do
702755
packages+=("$line")
703756
done < "$PACKAGE_LIST_PATH"
704757

@@ -779,4 +832,4 @@ if is_linux LINUX_FEDORA; then
779832
fi;
780833

781834

782-
exit_err "IbmMountHelper Install not supported $NAME $VERSION"
835+
exit_err "IbmMountHelper Install not supported $NAME $VERSION"

0 commit comments

Comments
 (0)