Skip to content

Commit 2226dd5

Browse files
committed
Improved syntax and comments in a few shell scripts
1 parent 9b54999 commit 2226dd5

File tree

6 files changed

+49
-57
lines changed

6 files changed

+49
-57
lines changed

build/ReleaseManager/osg-release.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Buold the source tarball and upload it to the OSG library (now using osg-sw-subm
1313
1414
NOTE that when using this script you'll have to authenticate with the CILogon URL and insert the OSG PASSWORD (for AFS/Kerberos) and authenticate with the URL again."
1515

16-
[ "$1" == "-h" ] || [ "$1" == "--help" ] && { echo "$USAGE_STR"; exit 0; }
16+
[ "$1" = "-h" ] || [ "$1" = "--help" ] && { echo "$USAGE_STR"; exit 0; }
1717

1818
if [ $# -lt 3 ]; then
1919
echo "ERROR: Missing arguments 'tag', 'user', and 'krb_principal'"
@@ -46,7 +46,7 @@ archive_gwms() {
4646
cd $gwms_location
4747
git checkout $gwms_tag
4848
[ $? -ne 0 ] && { echo "ERROR: Failed to checkout $gwms_tag, aborting. Did you push your commit?"; exit 1; }
49-
local archive_tag
49+
# local archive_tag # uncomment for bash
5050
archive_tag="$gwms_tag"
5151
if [ -x ./build/bigfiles/bigfiles.sh ]; then
5252
# Add also uncommitted big files instead of links

creation/web_base/add_config_line.source

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ gconfig_get_toupper() {
4545

4646
# Check for Truth values (case insensitive) from gconfig_get: TRUE, T, YES, Y, 1 (or positive numbers)
4747
# Anything else, including empty is false
48+
# Use: if gconfig_get_bool KEY "$glidein_config"; then ....
4849
gconfig_get_bool() {
4950
local res
5051
# sed "s/[\"' \t\r\n]//g" not working on OS X, '\040\011\012\015' = ' '$'\t'$'\r'$'\n'

creation/web_base/check_blacklist.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ check_blacklist() {
3939
return 0
4040
}
4141

42-
main() {
42+
_main() {
4343
# Assume all functions exit on error
4444
config_file="$1"
4545
dir_id="$2"

creation/web_base/create_mapfile.sh

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,14 @@ exit_if_no_token(){
3535
}
3636

3737
get_proxy_fname() {
38-
local cert_fname="$1"
39-
if [ -z "$cert_fname" ]; then
40-
if [ -n "$X509_USER_PROXY" ]; then
41-
cert_fname="$X509_USER_PROXY"
42-
# Ignoring the file in /tmp, it may be confusing
43-
#else
44-
# cert_fname="/tmp/x509up_u`id -u`"
45-
fi
46-
fi
38+
# 1 - optional certificate file
39+
local cert_fname="${1:-$X509_USER_PROXY}"
40+
# Ignoring the file in /tmp, it may be confusing
41+
#if [ -z "$cert_fname" ]; then
42+
# cert_fname="/tmp/x509up_u`id -u`"
43+
#fi
4744
# should it control if the file exists?
48-
echo "Using proxy file $cert_fname (`[ -e "$cert_fname" ] && echo "OK" || echo "No file"`)" 1>&2
45+
echo "Using proxy file '$cert_fname' ($([ -e "$cert_fname" ] && echo "OK" || echo "No file"))" 1>&2
4946
echo "$cert_fname"
5047
}
5148

@@ -60,7 +57,7 @@ create_gridmapfile() {
6057
if ! id=$(voms-proxy-info -identity 2>/dev/null); then
6158
# "openssl x509 -noout -issuer .." works for proxies but may be a CA for certificates
6259
# did not find something to extract the identity, filtering manually
63-
cert_fname=$(get_proxy_fname)
60+
cert_fname=$(get_proxy_fname "")
6461
if [[ -z "$cert_fname" ]]; then
6562
ERROR="Cannot find the x509 proxy."
6663
return 1
@@ -88,35 +85,36 @@ create_gridmapfile() {
8885

8986
touch "$X509_GRIDMAP"
9087
if [ -e "$GLIDEIN_WORK_DIR/$EXPECTED_GRIDMAP_FNAME" ]; then
91-
lines=$(wc -l "$GLIDEIN_WORK_DIR/$EXPECTED_GRIDMAP_FNAME" |awk '{print $1}')
88+
lines=$(wc -l < "$GLIDEIN_WORK_DIR/$EXPECTED_GRIDMAP_FNAME")
9289
cat "$GLIDEIN_WORK_DIR/$EXPECTED_GRIDMAP_FNAME" >> "$X509_GRIDMAP"
9390
echo "Using factory main grid-mapfile ($lines)" 1>&2
9491
fi
9592
if [ -e "$GLIDEIN_ENTRY_WORK_DIR/$EXPECTED_GRIDMAP_FNAME" ]; then
96-
lines=$(wc -l "$GLIDEIN_ENTRY_WORK_DIR/$EXPECTED_GRIDMAP_FNAME" |awk '{print $1}')
93+
lines=$(wc -l < "$GLIDEIN_ENTRY_WORK_DIR/$EXPECTED_GRIDMAP_FNAME")
9794
cat "$GLIDEIN_ENTRY_WORK_DIR/$EXPECTED_GRIDMAP_FNAME" >> "$X509_GRIDMAP"
9895
echo "Using factory entry grid-mapfile ($lines)" 1>&2
9996
fi
10097
if [ -e "$GLIDECLIENT_WORK_DIR/$EXPECTED_GRIDMAP_FNAME" ]; then
101-
lines=$(wc -l "$GLIDECLIENT_WORK_DIR/$EXPECTED_GRIDMAP_FNAME" |awk '{print $1}')
98+
lines=$(wc -l < "$GLIDECLIENT_WORK_DIR/$EXPECTED_GRIDMAP_FNAME")
10299
cat "$GLIDECLIENT_WORK_DIR/$EXPECTED_GRIDMAP_FNAME" >> "$X509_GRIDMAP"
103100
echo "Using client main grid-mapfile ($lines)" 1>&2
104101
fi
105102
if [ -e "$GLIDECLIENT_GROUP_WORK_DIR/$EXPECTED_GRIDMAP_FNAME" ]; then
106-
lines=$(wc -l "$GLIDECLIENT_GROUP_WORK_DIR/$EXPECTED_GRIDMAP_FNAME" |awk '{print $1}')
103+
lines=$(wc -l < "$GLIDECLIENT_GROUP_WORK_DIR/$EXPECTED_GRIDMAP_FNAME")
107104
cat "$GLIDECLIENT_GROUP_WORK_DIR/$EXPECTED_GRIDMAP_FNAME" >> "$X509_GRIDMAP"
108105
echo "Using client group grid-mapfile ($lines)" 1>&2
109106
fi
110-
echo "\"$idp\"" condor >> "$X509_GRIDMAP"
111-
if [ $? -ne 0 ]; then
107+
if ! echo "\"$idp\"" condor >> "$X509_GRIDMAP"; then
112108
ERROR="Cannot add user identity to $X509_GRIDMAP!"
113109
return 1
114110
fi
115111
return 0
116112
}
117113

118114
extract_gridmap_DNs() {
119-
awk -F '"' '/CN/{dn=$2;if (dns=="") {dns=dn;} else {dns=dns "," dn}}END{print dns}' "$X509_GRIDMAP"
115+
if [[ -r "$X509_GRIDMAP" ]]; then
116+
awk -F '"' '/CN/{dn=$2;if (dns=="") {dns=dn;} else {dns=dns "," dn}}END{print dns}' "$X509_GRIDMAP"
117+
fi
120118
}
121119

122120
# create a condor_mapfile starting from a grid-mapfile
@@ -127,32 +125,33 @@ create_condormapfile() {
127125
# make sure there is nothing in place already
128126
rm -f "$X509_CONDORMAP"
129127
touch "$X509_CONDORMAP" && chmod go-wx "$X509_CONDORMAP" || { ERROR="Cannot create HTCSS map file '$X509_CONDORMAP'"; return 1; }
130-
# copy with formatting the glide-mapfile into condor_mapfile
128+
# copy with formatting the grid-mapfile into condor_mapfile
131129
# filter out lines starting with the comment (#)
132130
#grep -v "^[ ]*#" "$X509_GRIDMAP" | while read file
133-
while read line
134-
do
135-
if [[ -n "$line" ]]; then # ignore empty lines
136-
# split between DN and UID
137-
# keep the quotes in DN to not loose trailing spaces
138-
udn=$(echo "$line" |awk '{print substr($0,1,length($0)-length($NF)-1)}')
139-
uid=$(echo "$line" |awk '{print $NF}')
140-
141-
# encode for regexp
142-
edn_wq=$(echo "$udn" | sed 's/[^[:alnum:]]/\\\&/g')
143-
# remove backslashes from the first and last quote
144-
# and add begin and end matching chars
145-
e_dn=$(echo "$edn_wq" | awk '{print "\"^" substr(substr($0,3,length($0)-2),1,length($0)-4) "$\"" }')
146-
147-
echo "GSI $e_dn $uid" >> "$X509_CONDORMAP"
148-
if [ "$X509_SKIP_HOST_CHECK_DNS_REGEX" = "" ]; then
149-
X509_SKIP_HOST_CHECK_DNS_REGEX="$edn_wq"
150-
else
151-
X509_SKIP_HOST_CHECK_DNS_REGEX=$X509_SKIP_HOST_CHECK_DNS_REGEX\|$edn_wq
131+
if [[ -r "$X509_GRIDMAP" ]]; then
132+
while read line
133+
do
134+
if [[ -n "$line" ]]; then # ignore empty lines
135+
# split between DN and UID
136+
# keep the quotes in DN to not loose trailing spaces
137+
udn=$(echo "$line" |awk '{print substr($0,1,length($0)-length($NF)-1)}')
138+
uid=$(echo "$line" |awk '{print $NF}')
139+
140+
# encode for regexp
141+
edn_wq=$(echo "$udn" | sed 's/[^[:alnum:]]/\\\&/g')
142+
# remove backslashes from the first and last quote
143+
# and add begin and end matching chars
144+
e_dn=$(echo "$edn_wq" | awk '{print "\"^" substr(substr($0,3,length($0)-2),1,length($0)-4) "$\"" }')
145+
146+
echo "GSI $e_dn $uid" >> "$X509_CONDORMAP"
147+
if [ "$X509_SKIP_HOST_CHECK_DNS_REGEX" = "" ]; then
148+
X509_SKIP_HOST_CHECK_DNS_REGEX="$edn_wq"
149+
else
150+
X509_SKIP_HOST_CHECK_DNS_REGEX=$X509_SKIP_HOST_CHECK_DNS_REGEX\|$edn_wq
151+
fi
152152
fi
153-
fi
154-
done < <(grep -v "^[ ]*#" "$X509_GRIDMAP")
155-
153+
done < <(grep -v "^[ ]*#" "$X509_GRIDMAP")
154+
fi
156155
# add local user
157156
# and deny any other type of traffic
158157
cat << EOF >> "$X509_CONDORMAP"
@@ -199,8 +198,7 @@ if ! create_gridmapfile; then
199198
# TODO: check if it makes sense to continue w/ the rest, including defining X509... variables in glidein_config
200199
else
201200
#1. "$error_gen" -error "create_mapfile.sh" "WN_Resource" "$ERROR" "command" "$proxy_cmd"
202-
#2. "$error_gen" -error "create_mapfile.sh" "WN_Resource" "$ERROR" "command" "$proxy_cmd"
203-
#3. "$error_gen" -error "create_mapfile.sh" "WN_Resource" "$ERROR" "file" "$X509_GRIDMAP"
201+
#2. "$error_gen" -error "create_mapfile.sh" "WN_Resource" "$ERROR" "file" "$X509_GRIDMAP"
204202
"$error_gen" -error "create_mapfile.sh" "WN_Resource" "$ERROR" "command" "$proxy_cmd" "file" "$X509_GRIDMAP"
205203
exit 1
206204
fi

creation/web_base/get_id_selectors.source

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# SPDX-License-Identifier: Apache-2.0
55

66
# NOTE: any script that imports this script to use the functions defined must also import add_config_line.source
7+
# and define glidein_config
78

89
############################################
910
# Get entry/client/group work dir

creation/web_base/setup_network.sh

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
# SPDX-FileCopyrightText: 2009 Fermi Research Alliance, LLC
44
# SPDX-License-Identifier: Apache-2.0
55

6-
#
7-
# Project:
8-
# glideinWMS
9-
#
10-
# File Version:
11-
#
126
# Description:
137
# This script will setup the knobs that
148
# are related to network tuning, like incoming connections/firewalls
@@ -17,7 +11,7 @@
1711
glidein_config="$1"
1812
tmp_fname="${glidein_config}.$$.tmp"
1913

20-
function warn {
14+
warn() {
2115
echo "$(date)" "$@" 1>&2
2216
}
2317

@@ -34,8 +28,7 @@ condor_vars_file=$(gconfig_get CONDOR_VARS_FILE "$glidein_config")
3428
# check if it should use CCB
3529
##########################################################
3630
out_ccb_str="False"
37-
use_ccb=$(gconfig_get USE_CCB "$glidein_config")
38-
if [[ "$use_ccb" == "True" || "$use_ccb" == "TRUE" || "$use_ccb" == "T" || "$use_ccb" == "Yes" || "$use_ccb" == "Y" || "$use_ccb" == "1" ]]; then
31+
if gconfig_get_bool USE_CCB "$glidein_config"; then
3932
# ok, we need to define CCB variable
4033

4134
ccb_host=$(gconfig_get GLIDEIN_CCB "$glidein_config")
@@ -60,8 +53,7 @@ fi
6053
# check if it should use the shared_port_daemon
6154
##########################################################
6255
out_sharedp_str="False"
63-
use_sharedp=$(gconfig_get USE_SHARED_PORT "$glidein_config")
64-
if [[ "$use_sharedp" == "True" || "$use_sharedp" == "TRUE" || "$use_sharedp" == "T" || "$use_sharedp" == "Yes" || "$use_sharedp" == "Y" || "$use_sharedp" == "1" ]]; then
56+
if gconfig_get_bool USE_SHARED_PORT "$glidein_config"; then
6557
# ok, we need to enable the shared port
6658
daemon_list=$(gconfig_get DAEMON_LIST "$glidein_config")
6759
if [ -z "$daemon_list" ]; then

0 commit comments

Comments
 (0)