Skip to content

Commit 8550285

Browse files
committed
fix shellcheck
1 parent 49816d0 commit 8550285

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

lib/os-utils.sh

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,39 @@ function get_uid_from_username() {
3232

3333
if [ "$l_username" == "none" ]; then
3434
echo ""
35-
return $SUCCESS
35+
return "$SUCCESS"
3636
fi
3737

3838
local l_uid
3939
l_uid=$(id -u "$l_username" 2>/dev/null)
4040

4141
if [ -z "$l_uid" ]; then
4242
echo "ERROR: User \"$l_username\" not found"
43-
return $FAILURE
43+
return "$FAILURE"
4444
fi
4545

4646
echo "$l_uid"
47-
return $SUCCESS
47+
return "$SUCCESS"
4848
}
4949

5050
function get_gid_from_groupname() {
5151
local l_groupname=$1
5252

5353
if [ "$l_groupname" == "none" ]; then
5454
echo ""
55-
return $SUCCESS
55+
return "$SUCCESS"
5656
fi
5757

5858
local l_gid
5959
l_gid=$(getent group "$l_groupname" | cut -d: -f3)
6060

6161
if [ -z "$l_gid" ]; then
6262
echo "ERROR: Group \"$l_groupname\" not found"
63-
return $FAILURE
63+
return "$FAILURE"
6464
fi
6565

6666
echo "$l_gid"
67-
return $SUCCESS
67+
return "$SUCCESS"
6868
}
6969

7070
function build_mount_options() {
@@ -79,19 +79,19 @@ function build_mount_options() {
7979
# Get UID from username
8080
if [ "$l_owner_user" != "none" ]; then
8181
l_uid=$(get_uid_from_username "$l_owner_user")
82-
if [ $? -ne $SUCCESS ]; then
82+
if [ $? -ne "$SUCCESS" ]; then
8383
echo "$l_uid" # Print error message
84-
return $FAILURE
84+
return "$FAILURE"
8585
fi
8686
l_final_options="uid=$l_uid"
8787
fi
8888

8989
# Get GID from groupname
9090
if [ "$l_owner_group" != "none" ]; then
9191
l_gid=$(get_gid_from_groupname "$l_owner_group")
92-
if [ $? -ne $SUCCESS ]; then
92+
if [ $? -ne "$SUCCESS" ]; then
9393
echo "$l_gid" # Print error message
94-
return $FAILURE
94+
return "$FAILURE"
9595
fi
9696

9797
if [ -n "$l_final_options" ]; then
@@ -116,7 +116,7 @@ function build_mount_options() {
116116
fi
117117

118118
echo "$l_final_options"
119-
return $SUCCESS
119+
return "$SUCCESS"
120120
}
121121

122122
# -----------------------------------------------------------------------------
@@ -127,14 +127,14 @@ function stop_service() {
127127
local l_service=$1
128128

129129
if [ "$l_service" == "none" ]; then
130-
return $SUCCESS
130+
return "$SUCCESS"
131131
fi
132132

133133
echo "Stopping \"$l_service\" service..."
134134
if systemctl is-active --quiet "$l_service"; then
135135
if ! systemctl stop "$l_service"; then
136136
echo "WARNING: Failed to stop service \"$l_service\""
137-
return $FAILURE
137+
return "$FAILURE"
138138
fi
139139
echo -e "Done\n"
140140
else
@@ -146,16 +146,16 @@ function start_service() {
146146
local l_service=$1
147147

148148
if [ "$l_service" == "none" ]; then
149-
return $SUCCESS
149+
return "$SUCCESS"
150150
fi
151151

152152
echo "Starting \"$l_service\" service..."
153153
if systemctl is-active --quiet "$l_service"; then
154-
echo -e "Service \"$l_service\" active. Skipping.\n"
154+
echo -e "Service \"$l_service\" active. Skipping.\\n"
155155
else
156156
if ! systemctl start "$l_service"; then
157157
echo "ERROR: Failed to start service \"$l_service\""
158-
return $FAILURE
158+
return "$FAILURE"
159159
fi
160160
echo -e "Done\n"
161161
fi

lib/storage.sh

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ function wait_for_device() {
4646

4747
for i in {1..5}; do
4848
if [ -e "/dev/disk/by-uuid/$l_device_uuid" ]; then
49-
return $SUCCESS
49+
return "$SUCCESS"
5050
else
5151
echo "Waiting for device $l_device_uuid... ${i}s"
5252
sleep 1
5353
fi
5454
done
5555

5656
echo "ERROR: Device \"$l_device_uuid\" is not available."
57-
return $FAILURE
57+
return "$FAILURE"
5858
}
5959

6060
# -----------------------------------------------------------------------------
@@ -66,11 +66,11 @@ function verify_lvm() {
6666
local l_lvm_group=$2
6767

6868
if lvdisplay "$l_lvm_group/$l_lvm_name" >/dev/null 2>&1; then
69-
return $SUCCESS
69+
return "$SUCCESS"
7070
fi
7171

7272
echo "ERROR: Logical volume \"$l_lvm_name\" is not available."
73-
return $FAILURE
73+
return "$FAILURE"
7474
}
7575

7676
function lvm_is_active() {
@@ -79,9 +79,9 @@ function lvm_is_active() {
7979

8080
# Use lvs to check if volume is active (more reliable than parsing lvdisplay)
8181
if lvs --noheadings -o lv_active "$l_lvm_group/$l_lvm_name" 2>/dev/null | grep -q "active"; then
82-
return $SUCCESS
82+
return "$SUCCESS"
8383
else
84-
return $FAILURE
84+
return "$FAILURE"
8585
fi
8686
}
8787

@@ -90,7 +90,7 @@ function activate_lvm() {
9090
local l_lvm_group=$2
9191

9292
if [ "$l_lvm_name" == "none" ] || [ "$l_lvm_group" == "none" ]; then
93-
return $SUCCESS
93+
return "$SUCCESS"
9494
fi
9595

9696
verify_lvm "$l_lvm_name" "$l_lvm_group"
@@ -100,7 +100,7 @@ function activate_lvm() {
100100
echo "Activating $l_lvm_name..."
101101
if ! lvchange -ay "$l_lvm_group/$l_lvm_name"; then
102102
echo "ERROR: Failed to activate LVM logical volume \"$l_lvm_group/$l_lvm_name\""
103-
return $FAILURE
103+
return "$FAILURE"
104104
fi
105105
echo -e "Done\n"
106106
fi
@@ -111,7 +111,7 @@ function deactivate_lvm() {
111111
local l_lvm_group=$2
112112

113113
if [ "$l_lvm_name" == "none" ] || [ "$l_lvm_group" == "none" ]; then
114-
return $SUCCESS
114+
return "$SUCCESS"
115115
fi
116116

117117
verify_lvm "$l_lvm_name" "$l_lvm_group"
@@ -120,7 +120,7 @@ function deactivate_lvm() {
120120
echo "Deactivating $l_lvm_name..."
121121
if ! lvchange -an "$l_lvm_group/$l_lvm_name"; then
122122
echo "WARNING: Failed to deactivate LVM logical volume \"$l_lvm_group/$l_lvm_name\""
123-
return $FAILURE
123+
return "$FAILURE"
124124
fi
125125
echo -e "Done\n"
126126
else
@@ -140,13 +140,13 @@ function unlock_device() {
140140

141141
if [ "$l_device_uuid" == "none" ] || [ "$l_mapper" == "none" ]; then
142142
echo -e "Device not configured (device_uuid=\"$l_device_uuid\"; mapper=\"$l_mapper\"). Skipping.\n"
143-
return $SUCCESS
143+
return "$SUCCESS"
144144
fi
145145

146146
# Check if already unlocked
147147
if cryptsetup status "$l_mapper" >/dev/null 2>&1; then
148148
echo -e "Partition \"$l_mapper\" unlocked. Skipping.\n"
149-
return $SUCCESS
149+
return "$SUCCESS"
150150
fi
151151

152152
echo "Unlocking $l_mapper ($l_encryption_type)..."
@@ -160,30 +160,30 @@ function unlock_device() {
160160
if [ "$l_key_file" != "none" ] && [ -f "$l_key_file" ]; then
161161
if ! cryptsetup open --type bitlk "$l_device_path" "$l_mapper" --key-file="$l_key_file"; then
162162
echo "ERROR: Failed to unlock BitLocker device \"$l_device_uuid\" as \"$l_mapper\" using key file"
163-
return $FAILURE
163+
return "$FAILURE"
164164
fi
165165
else
166166
if ! cryptsetup open --type bitlk "$l_device_path" "$l_mapper"; then
167167
echo "ERROR: Failed to unlock BitLocker device \"$l_device_uuid\" as \"$l_mapper\" with interactive password"
168-
return $FAILURE
168+
return "$FAILURE"
169169
fi
170170
fi
171171
elif [ "$l_encryption_type" == "luks" ]; then
172172
# LUKS support
173173
if [ "$l_key_file" != "none" ] && [ -f "$l_key_file" ]; then
174174
if ! cryptsetup open --type luks "$l_device_path" "$l_mapper" --key-file="$l_key_file"; then
175175
echo "ERROR: Failed to unlock LUKS device \"$l_device_uuid\" as \"$l_mapper\" using key file"
176-
return $FAILURE
176+
return "$FAILURE"
177177
fi
178178
else
179179
if ! cryptsetup open --type luks "$l_device_path" "$l_mapper"; then
180180
echo "ERROR: Failed to unlock LUKS device \"$l_device_uuid\" as \"$l_mapper\" with interactive password"
181-
return $FAILURE
181+
return "$FAILURE"
182182
fi
183183
fi
184184
else
185185
echo "ERROR: Unsupported encryption type \"$l_encryption_type\" for device \"$l_mapper\""
186-
return $FAILURE
186+
return "$FAILURE"
187187
fi
188188

189189
echo -e "Done\n"
@@ -194,14 +194,14 @@ function lock_device() {
194194
local l_encryption_type=${2:-luks}
195195

196196
if [ "$l_mapper" == "none" ]; then
197-
return $SUCCESS
197+
return "$SUCCESS"
198198
fi
199199

200200
if cryptsetup status "$l_mapper" >/dev/null 2>&1; then
201201
echo "Locking $l_mapper ($l_encryption_type)..."
202202
if ! cryptsetup close "$l_mapper"; then
203203
echo "WARNING: Failed to lock device \"$l_mapper\""
204-
return $FAILURE
204+
return "$FAILURE"
205205
fi
206206
echo -e "Done\n"
207207
else
@@ -220,22 +220,22 @@ function mount_device() {
220220

221221
if [ "$l_mapper" == "none" ] || [ "$l_mount" == "none" ]; then
222222
echo -e "Mount not configured (mapper=\"$l_mapper\"; mount_point=\"$l_mount\"). Skipping.\n"
223-
return $SUCCESS
223+
return "$SUCCESS"
224224
elif mountpoint -q "/mnt/$l_mount"; then
225225
echo -e "Mountpoint \"$l_mount\" mounted. Skipping.\n"
226226
else
227227
# Check if mapper device exists before attempting mount
228228
if [ ! -e "/dev/mapper/$l_mapper" ]; then
229229
echo -e "Mapper device \"/dev/mapper/$l_mapper\" does not exist. Skipping mount.\n"
230-
return $SUCCESS
230+
return "$SUCCESS"
231231
fi
232232

233233
echo "Mounting $l_mount..."
234234
mkdir -p "/mnt/$l_mount"
235235

236236
if ! mount -o "$l_mount_options" "/dev/mapper/$l_mapper" "/mnt/$l_mount"; then
237237
echo "ERROR: Failed to mount \"/dev/mapper/$l_mapper\" to \"/mnt/$l_mount\""
238-
return $FAILURE
238+
return "$FAILURE"
239239
fi
240240
echo -e "Done\n"
241241
fi
@@ -245,14 +245,14 @@ function unmount_device() {
245245
local l_mount=$1
246246

247247
if [ "$l_mount" == "none" ]; then
248-
return $SUCCESS
248+
return "$SUCCESS"
249249
fi
250250

251251
if mountpoint -q "/mnt/$l_mount"; then
252252
echo "Unmounting $l_mount..."
253253
if ! umount "/mnt/$l_mount"; then
254254
echo "WARNING: Failed to unmount \"/mnt/$l_mount\""
255-
return $FAILURE
255+
return "$FAILURE"
256256
else
257257
echo -e "Done\n"
258258
fi
@@ -271,7 +271,7 @@ function mount_network_path() {
271271
local l_additional_options=$7
272272

273273
if [ "$l_protocol" == "none" ]; then
274-
return $SUCCESS
274+
return "$SUCCESS"
275275
fi
276276

277277
if mountpoint -q "/mnt/$l_mount_path"; then
@@ -283,9 +283,9 @@ function mount_network_path() {
283283
# Build mount options from username/groupname
284284
local l_mount_options
285285
l_mount_options=$(build_mount_options "$l_owner_user" "$l_owner_group" "$l_additional_options")
286-
if [ $? -ne $SUCCESS ]; then
286+
if [ $? -ne "$SUCCESS" ]; then
287287
echo "$l_mount_options" # Print error message
288-
return $FAILURE
288+
return "$FAILURE"
289289
fi
290290

291291
# Prepend credentials if provided
@@ -295,7 +295,7 @@ function mount_network_path() {
295295

296296
if ! mount -t "$l_protocol" -o "$l_mount_options" "$l_network_path" "/mnt/$l_mount_path"; then
297297
echo "ERROR: Failed to mount network path \"$l_network_path\" to \"/mnt/$l_mount_path\""
298-
return $FAILURE
298+
return "$FAILURE"
299299
fi
300300
echo -e "Done\n"
301301
fi

0 commit comments

Comments
 (0)