16
16
#
17
17
18
18
19
+ exec 42> /dev/null
20
+
21
+ base_toolbox_command=$( basename " $0 " 2>&42 )
22
+
19
23
source /etc/os-release
20
24
release=$VERSION_ID
21
25
@@ -70,7 +74,7 @@ spinner_start()
70
74
fi
71
75
72
76
if ! touch " $directory /spinner-start" 2>&42 ; then
73
- echo " $0 : unable to start spinner: spinner start file couldn't be created"
77
+ echo " $base_toolbox_command : unable to start spinner: spinner start file couldn't be created"
74
78
return 1
75
79
fi
76
80
@@ -98,7 +102,7 @@ spinner_start()
98
102
tput cnorm 2>&42
99
103
100
104
if ! touch " $directory /spinner-stop" 2>&42 ; then
101
- echo " $0 : unable to stop spinner: spinner stop file couldn't be created"
105
+ echo " $base_toolbox_command : unable to stop spinner: spinner stop file couldn't be created"
102
106
fi
103
107
) &
104
108
@@ -112,7 +116,7 @@ spinner_stop()
112
116
directory=" $1 "
113
117
114
118
if ! rm " $directory /spinner-start" 2>&42 ; then
115
- echo " $0 : unable to stop spinner: spinner start file couldn't be removed"
119
+ echo " $base_toolbox_command : unable to stop spinner: spinner start file couldn't be removed"
116
120
return
117
121
fi
118
122
@@ -138,7 +142,7 @@ configure_working_container()
138
142
if ! $prefix_sudo buildah run $working_container_name -- \
139
143
sh -c ' rmdir /home && mkdir -m 0755 -p /var/home && ln -s var/home /home' 2>&42 ; then
140
144
$prefix_sudo buildah rm $working_container_name > /dev/null 2>&42
141
- echo " $0 : failed to make /home a symlink"
145
+ echo " $base_toolbox_command : failed to make /home a symlink"
142
146
return 1
143
147
fi
144
148
fi
@@ -151,52 +155,52 @@ configure_working_container()
151
155
--groups wheel \
152
156
$USER \
153
157
> /dev/null 2>&42 ; then
154
- echo " $0 : failed to create user $USER with UID $UID "
158
+ echo " $base_toolbox_command : failed to create user $USER with UID $UID "
155
159
return 1
156
160
fi
157
161
158
162
if ! $prefix_sudo buildah run $working_container_name -- passwd -d $USER > /dev/null 2>&42 ; then
159
- echo " $0 : failed to remove password for user $USER "
163
+ echo " $base_toolbox_command : failed to remove password for user $USER "
160
164
return 1
161
165
fi
162
166
163
167
if ! $prefix_sudo buildah run $working_container_name -- passwd -d root > /dev/null 2>&42 ; then
164
- echo " $0 : failed to remove password for user root"
168
+ echo " $base_toolbox_command : failed to remove password for user root"
165
169
return 1
166
170
fi
167
171
168
172
if ! $prefix_sudo buildah config --volume $HOME $working_container_name > /dev/null 2>&42 ; then
169
- echo " $0 : failed to configure volume for $HOME "
173
+ echo " $base_toolbox_command : failed to configure volume for $HOME "
170
174
return 1
171
175
fi
172
176
173
177
if ! $prefix_sudo buildah config --volume $XDG_RUNTIME_DIR $working_container_name > /dev/null 2>&42 ; then
174
- echo " $0 : failed to configure volume for $XDG_RUNTIME_DIR "
178
+ echo " $base_toolbox_command : failed to configure volume for $XDG_RUNTIME_DIR "
175
179
return 1
176
180
fi
177
181
178
182
if ! $prefix_sudo buildah config --volume $dbus_system_bus_path $working_container_name > /dev/null 2>&42 ; then
179
- echo " $0 : failed to configure volume for $dbus_system_bus_path "
183
+ echo " $base_toolbox_command : failed to configure volume for $dbus_system_bus_path "
180
184
return 1
181
185
fi
182
186
183
187
if ! $prefix_sudo buildah config --volume /dev/dri $working_container_name > /dev/null 2>&42 ; then
184
- echo " $0 : failed to configure volume for /dev/dri"
188
+ echo " $base_toolbox_command : failed to configure volume for /dev/dri"
185
189
return 1
186
190
fi
187
191
188
192
if ! $prefix_sudo buildah config --volume /dev/fuse $working_container_name > /dev/null 2>&42 ; then
189
- echo " $0 : failed to configure volume for /dev/fuse"
193
+ echo " $base_toolbox_command : failed to configure volume for /dev/fuse"
190
194
return 1
191
195
fi
192
196
193
197
if ! $prefix_sudo buildah config --user $USER $working_container_name > /dev/null 2>&42 ; then
194
- echo " $0 : failed to configure the default user as $USER "
198
+ echo " $base_toolbox_command : failed to configure the default user as $USER "
195
199
return 1
196
200
fi
197
201
198
202
if ! $prefix_sudo buildah config --workingdir $HOME $working_container_name > /dev/null 2>&42 ; then
199
- echo " $0 : failed to configure the initial working directory to $HOME "
203
+ echo " $base_toolbox_command : failed to configure the initial working directory to $HOME "
200
204
return 1
201
205
fi
202
206
@@ -216,24 +220,24 @@ create()
216
220
dbus_system_bus_path=$( echo $dbus_system_bus_address | cut --delimiter = --fields 2 2>&42 )
217
221
dbus_system_bus_path=$( readlink --canonicalize $dbus_system_bus_path 2>&42 )
218
222
219
- echo " $0 : checking if image $toolbox_image already exists" >&42
223
+ echo " $base_toolbox_command : checking if image $toolbox_image already exists" >&42
220
224
221
225
if ! $prefix_sudo buildah inspect --type image $toolbox_image > /dev/null 2>&42 ; then
222
- echo " $0 : trying to create working container $working_container_name " >&42
223
- echo " $0 : looking for image localhost/$base_toolbox_image " >&42
226
+ echo " $base_toolbox_command : trying to create working container $working_container_name " >&42
227
+ echo " $base_toolbox_command : looking for image localhost/$base_toolbox_image " >&42
224
228
225
229
if ! $prefix_sudo buildah from \
226
230
--name $working_container_name \
227
231
localhost/$base_toolbox_image > /dev/null 2>&42 ; then
228
- echo " $0 : looking for image $registry /$fgc /$base_toolbox_image " >&42
232
+ echo " $base_toolbox_command : looking for image $registry /$fgc /$base_toolbox_image " >&42
229
233
230
234
if spinner_directory=$( mktemp --directory --tmpdir fedora-toolbox-spinner-XXXXXXXXXX 2>&42 ) ; then
231
- spinner_message=" $0 : pulling from $registry : "
235
+ spinner_message=" $base_toolbox_command : pulling from $registry : "
232
236
if ! spinner_start " $spinner_directory " " $spinner_message " ; then
233
237
spinner_directory=" "
234
238
fi
235
239
else
236
- echo " $0 : unable to start spinner: spinner directory not created"
240
+ echo " $base_toolbox_command : unable to start spinner: spinner directory not created"
237
241
spinner_directory=" "
238
242
fi
239
243
@@ -247,20 +251,20 @@ create()
247
251
fi
248
252
249
253
if [ $ret_val -ne 0 ]; then
250
- echo " $0 : failed to create working container"
254
+ echo " $base_toolbox_command : failed to create working container"
251
255
exit 1
252
256
fi
253
257
fi
254
258
255
- echo " $0 : trying to configure working container $working_container_name " >&42
259
+ echo " $base_toolbox_command : trying to configure working container $working_container_name " >&42
256
260
257
261
if spinner_directory=$( mktemp --directory --tmpdir fedora-toolbox-spinner-XXXXXXXXXX 2>&42 ) ; then
258
- spinner_message=" $0 : configuring working container: "
262
+ spinner_message=" $base_toolbox_command : configuring working container: "
259
263
if ! spinner_start " $spinner_directory " " $spinner_message " ; then
260
264
spinner_directory=" "
261
265
fi
262
266
else
263
- echo " $0 : unable to start spinner: spinner directory not created"
267
+ echo " $base_toolbox_command : unable to start spinner: spinner directory not created"
264
268
spinner_directory=" "
265
269
fi
266
270
@@ -276,15 +280,15 @@ create()
276
280
exit 1
277
281
fi
278
282
279
- echo " $0 : trying to create image $toolbox_image " >&42
283
+ echo " $base_toolbox_command : trying to create image $toolbox_image " >&42
280
284
281
285
if spinner_directory=$( mktemp --directory --tmpdir fedora-toolbox-spinner-XXXXXXXXXX 2>&42 ) ; then
282
- spinner_message=" $0 : creating image $toolbox_image : "
286
+ spinner_message=" $base_toolbox_command : creating image $toolbox_image : "
283
287
if ! spinner_start " $spinner_directory " " $spinner_message " ; then
284
288
spinner_directory=" "
285
289
fi
286
290
else
287
- echo " $0 : unable to start spinner: spinner directory not created"
291
+ echo " $base_toolbox_command : unable to start spinner: spinner directory not created"
288
292
spinner_directory=" "
289
293
fi
290
294
@@ -297,17 +301,17 @@ create()
297
301
298
302
if [ $ret_val -ne 0 ]; then
299
303
$prefix_sudo buildah rm $working_container_name > /dev/null 2>&42
300
- echo " $0 : failed to create image $toolbox_image "
304
+ echo " $base_toolbox_command : failed to create image $toolbox_image "
301
305
exit 1
302
306
fi
303
307
304
- echo " $0 : created image $toolbox_image " >&42
308
+ echo " $base_toolbox_command : created image $toolbox_image " >&42
305
309
fi
306
310
307
- echo " $0 : checking if container $toolbox_container already exists" >&42
311
+ echo " $base_toolbox_command : checking if container $toolbox_container already exists" >&42
308
312
309
313
if $prefix_sudo podman inspect --type container $toolbox_container > /dev/null 2>&42 ; then
310
- echo " $0 : container $toolbox_container already exists"
314
+ echo " $base_toolbox_command : container $toolbox_container already exists"
311
315
exit 1
312
316
fi
313
317
@@ -320,15 +324,15 @@ create()
320
324
max_minus_uid=$(( max_uid_count - UID))
321
325
uid_plus_one=$(( UID + 1 ))
322
326
323
- echo " $0 : trying to create container $toolbox_container " >&42
327
+ echo " $base_toolbox_command : trying to create container $toolbox_container " >&42
324
328
325
329
if spinner_directory=$( mktemp --directory --tmpdir fedora-toolbox-spinner-XXXXXXXXXX 2>&42 ) ; then
326
- spinner_message=" $0 : creating container $toolbox_container : "
330
+ spinner_message=" $base_toolbox_command : creating container $toolbox_container : "
327
331
if ! spinner_start " $spinner_directory " " $spinner_message " ; then
328
332
spinner_directory=" "
329
333
fi
330
334
else
331
- echo " $0 : unable to start spinner: spinner directory not created"
335
+ echo " $base_toolbox_command : unable to start spinner: spinner directory not created"
332
336
spinner_directory=" "
333
337
fi
334
338
@@ -359,38 +363,38 @@ create()
359
363
fi
360
364
361
365
if [ $ret_val -ne 0 ]; then
362
- echo " $0 : failed to create container $toolbox_container "
366
+ echo " $base_toolbox_command : failed to create container $toolbox_container "
363
367
exit 1
364
368
fi
365
369
366
- echo " $0 : created container $toolbox_container " >&42
370
+ echo " $base_toolbox_command : created container $toolbox_container " >&42
367
371
)
368
372
369
373
370
374
enter ()
371
375
(
372
376
shell_to_exec=/bin/bash
373
377
374
- echo " $0 : trying to start container $toolbox_container " >&42
378
+ echo " $base_toolbox_command : trying to start container $toolbox_container " >&42
375
379
376
380
if ! $prefix_sudo podman start $toolbox_container > /dev/null 2>&42 ; then
377
- echo " $0 : failed to start container $toolbox_container "
381
+ echo " $base_toolbox_command : failed to start container $toolbox_container "
378
382
exit 1
379
383
fi
380
384
381
385
if [ " $DBUS_SYSTEM_BUS_ADDRESS " != " " ]; then
382
386
set_dbus_system_bus_address=" --env DBUS_SYSTEM_BUS_ADDRESS=$DBUS_SYSTEM_BUS_ADDRESS "
383
387
fi
384
388
385
- echo " $0 : looking for $SHELL in container $toolbox_container " >&42
389
+ echo " $base_toolbox_command : looking for $SHELL in container $toolbox_container " >&42
386
390
387
391
if $prefix_sudo podman exec $toolbox_container test -f $SHELL 2>&42 ; then
388
392
shell_to_exec=$SHELL
389
393
else
390
- echo " $0 : $SHELL not found in $toolbox_container ; using $shell_to_exec instead" >&42
394
+ echo " $base_toolbox_command : $SHELL not found in $toolbox_container ; using $shell_to_exec instead" >&42
391
395
fi
392
396
393
- echo " $0 : trying to exec $shell_to_exec in container $toolbox_container " >&42
397
+ echo " $base_toolbox_command : trying to exec $shell_to_exec in container $toolbox_container " >&42
394
398
395
399
$prefix_sudo podman exec \
396
400
--env COLORTERM=$COLORTERM \
@@ -474,17 +478,17 @@ list_containers()
474
478
exit_if_extra_operand ()
475
479
{
476
480
if [ " $1 " != " " ]; then
477
- echo " $0 : extra operand '$1 '"
478
- echo " Try '$0 --help' for more information."
481
+ echo " $base_toolbox_command : extra operand '$1 '"
482
+ echo " Try '$base_toolbox_command --help' for more information."
479
483
exit 1
480
484
fi
481
485
}
482
486
483
487
484
488
exit_if_unrecognized_option ()
485
489
{
486
- echo " $0 : unrecognized option '$1 '"
487
- echo " Try '$0 --help' for more information."
490
+ echo " $base_toolbox_command : unrecognized option '$1 '"
491
+ echo " Try '$base_toolbox_command --help' for more information."
488
492
exit 1
489
493
}
490
494
@@ -506,15 +510,13 @@ usage()
506
510
}
507
511
508
512
509
- exec 42> /dev/null
510
-
511
513
while has_prefix " $1 " -; do
512
514
case $1 in
513
515
--container )
514
516
shift
515
517
if [ " $1 " = " " ]; then
516
- echo " $0 : missing argument for '--container'"
517
- echo " Try '$0 --help' for more information."
518
+ echo " $base_toolbox_command : missing argument for '--container'"
519
+ echo " Try '$base_toolbox_command --help' for more information."
518
520
exit 1
519
521
fi
520
522
toolbox_container=$1
@@ -526,19 +528,19 @@ while has_prefix "$1" -; do
526
528
--release )
527
529
shift
528
530
if [ " $1 " = " " ]; then
529
- echo " $0 : missing argument for '--release'"
530
- echo " Try '$0 --help' for more information."
531
+ echo " $base_toolbox_command : missing argument for '--release'"
532
+ echo " Try '$base_toolbox_command --help' for more information."
531
533
exit 1
532
534
fi
533
535
arg=$( echo $1 | sed ' s/^F\|^f//' 2>&42 )
534
536
if ! is_integer $arg ; then
535
- echo " $0 : invalid argument for '--release'"
536
- echo " Try '$0 --help' for more information."
537
+ echo " $base_toolbox_command : invalid argument for '--release'"
538
+ echo " Try '$base_toolbox_command --help' for more information."
537
539
exit 1
538
540
fi
539
541
if [ $arg -le 0 2>&42 ]; then
540
- echo " $0 : invalid argument for '--release'"
541
- echo " Try '$0 --help' for more information."
542
+ echo " $base_toolbox_command : invalid argument for '--release'"
543
+ echo " Try '$base_toolbox_command --help' for more information."
542
544
exit 1
543
545
fi
544
546
release=$arg
@@ -562,8 +564,8 @@ base_toolbox_image="fedora-toolbox:$release"
562
564
toolbox_image=" fedora-toolbox-$USER :$release "
563
565
564
566
if [ " $1 " = " " ]; then
565
- echo " $0 : missing command"
566
- echo " Try '$0 --help' for more information."
567
+ echo " $base_toolbox_command : missing command"
568
+ echo " Try '$base_toolbox_command --help' for more information."
567
569
exit 1
568
570
fi
569
571
@@ -580,8 +582,8 @@ case $op in
580
582
--image )
581
583
shift
582
584
if [ " $1 " = " " ]; then
583
- echo " $0 : missing argument for '--image'"
584
- echo " Try '$0 --help' for more information."
585
+ echo " $base_toolbox_command : missing argument for '--image'"
586
+ echo " Try '$base_toolbox_command --help' for more information."
585
587
exit 1
586
588
fi
587
589
toolbox_image=$1
@@ -635,7 +637,7 @@ case $op in
635
637
exit
636
638
;;
637
639
* )
638
- echo " $0 : unrecognized command '$op '"
639
- echo " Try '$0 --help' for more information."
640
+ echo " $base_toolbox_command : unrecognized command '$op '"
641
+ echo " Try '$base_toolbox_command --help' for more information."
640
642
exit 1
641
643
esac
0 commit comments