forked from hansemro/hyakvnc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
hyakvnc
executable file
·1850 lines (1640 loc) · 61.5 KB
/
hyakvnc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/env bash
# hyakvnc - A script to launch VNC sessions on Hyak
# Check Bash version greater than 4:
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
echo "Requires Bash version > 4.x"
exit 1
fi
# Check Bash version 4.4 or greater:
case "${BASH_VERSION:-0}" in
4*) if [[ "${BASH_VERSINFO[1]:-0}" -lt 4 ]]; then
echo "Requires Bash version > 4.x"
exit 1
fi ;;
*) ;;
esac
# Only enable these shell behaviours if we're not being sourced
if ! (return 0 2>/dev/null); then
[[ -n "${XDEBUG:-}" ]] && set -x # %% Set XDEBUG to print commands as they are executed
set -o pipefail # Use last non-zero exit code in a pipeline
set -o errtrace # Ensure the error trap handler is inherited
# set -o errexit # Exit on error
# shopt -qs inherit_errexit # Ensure subshells exit on error
fi
# # Preferences and settings:
HYAKVNC_VERSION="0.3.1"
# ## App preferences:
HYAKVNC_DIR="${HYAKVNC_DIR:-${HOME}/.hyakvnc}" # %% Local directory to store application data (default: `$HOME/.hyakvnc`)
HYAKVNC_CONFIG_FILE="${HYAKVNC_DIR}/hyakvnc-config.env" # %% Configuration file to use (default: `$HYAKVNC_DIR/hyakvnc-config.env`)
# hyakvnc_load_config()
# Load the hyakvnc configuration from the config file
# This is high up in the file so that settings can be overridden by the user's config
# Arguments: None
function hyakvnc_load_config {
[[ -r "${HYAKVNC_CONFIG_FILE:-}" ]] || return 0 # Return if config file doesn't exist
# Read each line of the parsed config file and export the variable:
while IFS=$'\n' read -r line; do
# Get the variable name by removing everything after the equals sign. Uses nameref to allow indirect assignment (see https://gnu.org/software/bash/manual/html_node/Shell-Parameters.html):
declare -n varref="${line%%=*}"
# Evaluate the right-hand side of the equals sign:
varref="$(bash --restricted --posix -c "echo ${line#*=}" || true)"
# Export the variable:
export "${!varref}"
# If DEBUG is not 0, print the variable:
[[ "${DEBUG:-0}" != 0 ]] && echo "Loaded variable from \"CONFIG_FILE\": ${!varref}=(${varref})" >&2
done < <(sed -E 's/^\s*//; /^[^#=]+=.*/!d; s/^([^=\s]+)\s+=/\1=/;' "${HYAKVNC_CONFIG_FILE}" || true) # Parse config file, ignoring comments and blank lines, removing leading whitespace, and removing whitespace before (but not after) the equals sign
}
# Load config if not sourced:
if ! (return 0 2>/dev/null); then
hyakvnc_load_config
fi
HYAKVNC_REPO_DIR="${HYAKVNC_REPO_DIR:-${HYAKVNC_DIR}/hyakvnc}" # Local directory to store git repository (default: `$HYAKVNC_DIR/hyakvnc`)
HYAKVNC_CHECK_UPDATE_FREQUENCY="${HYAKVNC_CHECK_UPDATE_FREQUENCY:-0}" # %% How often to check for updates in `[d]`ays or `[m]`inutes (default: `0` for every time. Use `1d` for daily, `10m` for every 10 minutes, etc. `-1` to disable.)
HYAKVNC_LOG_FILE="${HYAKVNC_LOG_FILE:-${HYAKVNC_DIR}/hyakvnc.log}" # %% Log file to use (default: `$HYAKVNC_DIR/hyakvnc.log`)
HYAKVNC_LOG_LEVEL="${HYAKVNC_LOG_LEVEL:-INFO}" # %% Log level to use for interactive output (default: `INFO`)
HYAKVNC_LOG_FILE_LEVEL="${HYAKVNC_LOG_FILE_LEVEL:-DEBUG}" # %% Log level to use for log file output (default: `DEBUG`)
HYAKVNC_SSH_HOST="${HYAKVNC_SSH_HOST:-klone.hyak.uw.edu}" # %% Default SSH host to use for connection strings (default: `klone.hyak.uw.edu`)
HYAKVNC_DEFAULT_TIMEOUT="${HYAKVNC_DEFAULT_TIMEOUT:-30}" # %% Seconds to wait for most commands to complete before timing out (default: `30`)
# ## VNC preferences:
HYAKVNC_VNC_PASSWORD="${HYAKVNC_VNC_PASSWORD:-password}" # %% Password to use for new VNC sessions (default: `password`)
HYAKVNC_VNC_DISPLAY="${HYAKVNC_VNC_DISPLAY:-:10}" # %% VNC display to use (default: `:1`)
HYAKVNC_MACOS_VNC_VIEWER_BUNDLEIDS="${HYAKVNC_MACOS_VNC_VIEWER_BUNDLEIDS:-com.turbovnc.vncviewer.VncViewer com.turbovnc.vncviewer}" # macOS bundle identifiers for VNC viewer executables (default: `com.turbovnc.vncviewer com.realvnc.vncviewer com.tigervnc.vncviewer`)
# ## Apptainer preferences:
HYAKVNC_APPTAINER_CONTAINERS_DIR="${HYAKVNC_APPTAINER_CONTAINERS_DIR:-}" # %% Directory to look for apptainer containers (default: (none))
HYAKVNC_APPTAINER_GHCR_ORAS_PRELOAD="${HYAKVNC_APPTAINER_GHCR_ORAS_PRELOAD:-1}" # %% Whether to preload SIF files from the ORAS GitHub Container Registry (default: `0`)
HYAKVNC_APPTAINER_BIN="${HYAKVNC_APPTAINER_BIN:-apptainer}" # %% Name of apptainer binary (default: `apptainer`)
HYAKVNC_APPTAINER_CONTAINER="${HYAKVNC_APPTAINER_CONTAINER:-}" # %% Path to container image to use (default: (none; set by `--container` option))
HYAKVNC_APPTAINER_APP_VNCSERVER="${HYAKVNC_APPTAINER_APP_VNCSERVER:-vncserver}" # %% Name of app in the container that starts the VNC session (default: `vncserver`)
HYAKVNC_APPTAINER_APP_VNCKILL="${HYAKVNC_APPTAINER_APP_VNCKILL:-vnckill}" # %% Name of app that cleanly stops the VNC session in the container (default: `vnckill`)
HYAKVNC_APPTAINER_WRITABLE_TMPFS="${HYAKVNC_APPTAINER_WRITABLE_TMPFS:-${APPTAINER_WRITABLE_TMPFS:-1}}" # %% Whether to use a writable tmpfs for the container (default: `1`)
HYAKVNC_APPTAINER_CLEANENV="${HYAKVNC_APPTAINER_CLEANENV:-${APPTAINER_CLEANENV:-1}}" # %% Whether to use a clean environment for the container (default: `1`)
HYAKVNC_APPTAINER_ADD_BINDPATHS="${HYAKVNC_APPTAINER_ADD_BINDPATHS:-}" # %% Bind paths to add to the container (default: (none))
HYAKVNC_APPTAINER_ADD_ENVVARS="${HYAKVNC_APPTAINER_ADD_ENVVARS:-}" # %% Environment variables to add to before invoking apptainer (default: (none))
HYAKVNC_APPTAINER_ADD_ARGS="${HYAKVNC_APPTAINER_ADD_ARGS:-}" # %% Additional arguments to give apptainer (default: (none))
# ## Slurm preferences:
HYAKVNC_SLURM_JOB_PREFIX="${HYAKVNC_SLURM_JOB_PREFIX:-hyakvnc-}" # %% Prefix to use for hyakvnc SLURM job names (default: `hyakvnc-`)
HYAKVNC_SLURM_SUBMIT_TIMEOUT="${HYAKVNC_SLURM_SUBMIT_TIMEOUT:-120}" # %% Seconds after submitting job to wait for the job to start before timing out (default: `120`)
HYAKVNC_SLURM_OUTPUT_DIR="${HYAKVNC_SLURM_OUTPUT_DIR:-${HYAKVNC_DIR}/slurm-output}" # %% Directory to store SLURM output files (default: `$HYAKVNC_DIR/slurm-output`)
HYAKVNC_SLURM_OUTPUT="${HYAKVNC_SLURM_OUTPUT:-${SBATCH_OUTPUT:-${HYAKVNC_SLURM_OUTPUT_DIR}/job-%j.out}}" # %% Where to send SLURM job output (default: `$HYAKVNC_SLURM_OUTPUT_DIR/job-%j.out`)
HYAKVNC_SLURM_JOB_NAME="${HYAKVNC_SLURM_JOB_NAME:-${SBATCH_JOB_NAME:-}}" # %% What to name the launched SLURM job (default: (set according to container name))
HYAKVNC_SLURM_ACCOUNT="${HYAKVNC_SLURM_ACCOUNT:-${SBATCH_ACCOUNT:-}}" # %% Slurm account to use (default: (autodetected))
HYAKVNC_SLURM_PARTITION="${HYAKVNC_SLURM_PARTITION:-${SBATCH_PARTITION:-}}" # %% Slurm partition to use (default: (autodetected))
HYAKVNC_SLURM_CLUSTER="${HYAKVNC_SLURM_CLUSTER:-${SBATCH_CLUSTERS:-}}" # %% Slurm cluster to use (default: (autodetected))
HYAKVNC_SLURM_GPUS="${HYAKVNC_SLURM_GPUS:-${SBATCH_GPUS:-}}" # %% Number of GPUs to request (default: (none))
HYAKVNC_SLURM_MEM="${HYAKVNC_SLURM_MEM:-${SBATCH_MEM:-4G}}" # %% Amount of memory to request, in [M]egabytes or [G]igabytes (default: `4G`)
HYAKVNC_SLURM_CPUS="${HYAKVNC_SLURM_CPUS:-4}" # %% Number of CPUs to request (default: `4`)
HYAKVNC_SLURM_TIMELIMIT="${HYAKVNC_SLURM_TIMELIMIT:-${SBATCH_TIMELIMIT:-12:00:00}}" # %% Time limit for SLURM job (default: `12:00:00`)
# # Global variables (using CamelCase):
declare -a Launched_JobIDs # Declare array of launched jobs
Launched_JobIDs=() # Array of launched jobs
# ## Log levels for log() function:
declare -A Log_Levels Log_Level_Colors # Declare Log_Levels and Log_Level_Colors arrays
Log_Levels=(["OFF"]=0 ["FATAL"]=1 ["ERROR"]=2 ["WARN"]=3 ["INFO"]=4 ["DEBUG"]=5 ["TRACE"]=6 ["ALL"]=100)
Log_Level_Colors=(["FATAL"]=5 ["ERROR"]=1 ["WARN"]=3 ["INFO"]=4 ["DEBUG"]=6 ["TRACE"]=2)
# # Utility functions
# check_log_level()
# Check if the current log level is high enough to log a message
# Arguments: <level>
function check_log_level {
local level levelno refloglevel refloglevelno
level="${1:-INFO}"
refloglevel="${2:-${HYAKVNC_LOG_LEVEL:-INFO}}"
[[ -z "${levelno:=${Log_Levels[${level}]}}" ]] && {
echo >&2 "log(): Unknown log level: ${level}"
return 1
}
[[ -z "${refloglevelno:=${Log_Levels[${refloglevel}]}}" ]] && {
echo >&2 "log() Unknown log level: ${refloglevel}"
return 1
}
[[ "${levelno}" -lt "${refloglevelno}" ]] && return 1
return 0
}
# log()
# Log a message to the stderr and the log file if the log level is high enough
# Arguments: <level> <message>
# <level> is the log level, e.g. INFO, WARN, ERROR, etc. (default: INFO)
# <message> is the message to log (default: empty string)
#
# Environment variables:
# $HYAKVNC_LOG_LEVEL - The log level to use for interactive output (default: INFO)
# $HYAKVNC_LOG_FILE - The log file to use (default: $HYAKVNC_DIR/hyakvnc.log)
# $HYAKVNC_LOG_FILE_LEVEL - The log level to use for log file output (default: DEBUG)
function log {
local level levelno colorno curlevelno curlogfilelevelno funcname logfilefuncname curloglevel curlogfilelevel
[[ $# -lt 1 ]] && return 1
level="${1:-}"
shift
[[ -z "${level}" ]] && {
echo >&2 "log(): No log level set"
return 1
}
[[ -z "${levelno:=${Log_Levels[${level}]}}" ]] && {
echo >&2 "log(): Unknown log level: ${level}"
return 1
}
curloglevel="${HYAKVNC_LOG_LEVEL:-INFO}" && curlogfilelevel="${HYAKVNC_LOG_FILE_LEVEL:-DEBUG}"
[[ -z "${curlevelno:=${Log_Levels[${curloglevel}]}}" ]] && {
echo >&2 "log() Unknown interactive log level: ${curloglevel}"
return 1
}
[[ -z "${curlogfilelevelno:=${Log_Levels[${curlogfilelevel}]}}" ]] && {
echo >&2 "log() Unknown logfile log level: ${curloglevel}"
return 1
}
colorno="${Log_Level_Colors[${level}]}"
[[ "${levelno}" -ge "${Log_Levels[DEBUG]}" ]] && funcname=" ${FUNCNAME[1]}() - " || funcname=" "
[[ "${curlogfilelevelno}" -ge "${Log_Levels[DEBUG]}" ]] && logfilefuncname="${FUNCNAME[1]}() - " || logfilefuncname=" "
if [[ "${curlevelno}" -ge "${levelno}" ]]; then
# If we're in a terminal, use colors:
tput setaf "${colorno:-}" 2>/dev/null
echo "${level:-}:${funcname:-}${*:-}" >&2
tput sgr0 2>/dev/null
fi
if [[ "${curlogfilelevelno}" -ge "${levelno}" ]]; then
echo "${level}:${logfilefuncname}${*:-}" >>"${HYAKVNC_LOG_FILE:-/dev/null}"
fi
}
# ## Update functions:
# hyakvnc_pull_updates()
# Pull updates from the hyakvnc git repository
# Arguments: None
# Returns: 0 if successfuly updated, 1 if not or if an error occurred
function hyakvnc_pull_updates() {
local cur_branch
[[ -z "${HYAKVNC_REPO_DIR:-}" ]] && {
log ERROR "HYAKVNC_REPO_DIR is not set. Can't pull updates."
return 1
}
cur_branch="$(git -C "${HYAKVNC_REPO_DIR}" branch --show-current 2>&1 || true)"
[[ -z "${cur_branch}" ]] && {
log ERROR "Couldn't determine current branch. Can't pull updates."
return 1
}
[[ "${cur_branch}" != "main" ]] && {
log WARN "Current branch is ${cur_branch}, not main. Be warned that this branch may not be up to date."
}
log INFO "Updating hyakvnc..."
git -C "${HYAKVNC_REPO_DIR}" pull --quiet origin "${cur_branch}" || {
log WARN "Couldn't apply updates"
return 0
}
log INFO "Successfully updated hyakvnc."
return 0
}
# hyakvnc_check_updates()
# Check if a hyakvnc update is available
# Arguments: None
# Returns: 0 if an update is available, 1 if none or if an error occurred
function hyakvnc_check_updates {
log DEBUG "Checking for updates... "
# Check if git is installed:
check_command git ERROR || return 1
# Check if git is available and that the git directory is a valid git repository:
git -C "${HYAKVNC_REPO_DIR}" tag >/dev/null 2>&1 || {
log DEBUG "Configured git directory ${HYAKVNC_REPO_DIR} doesn't seem to be a valid git repository. Can't check for updates"
return 1
}
local cur_branch
cur_branch="$(git -C "${HYAKVNC_REPO_DIR}" branch --show-current 2>&1 || true)"
[[ -z "${cur_branch}" ]] && {
log ERROR "Couldn't determine current branch. Can't pull updates."
return 1
}
[[ "${cur_branch}" != "main" ]] && {
log WARN "Current branch is ${cur_branch}, not main. Be warned that this branch may not be up to date."
}
local cur_date
cur_date="$(git -C "${HYAKVNC_REPO_DIR}" show -s --format=%cd --date=human-local "${cur_branch}" || echo ???)"
log INFO "The installed version was published ${cur_date}"
touch "${HYAKVNC_REPO_DIR}/.last_update_check"
# Get hash of local HEAD:
if [[ "$(git -C "${HYAKVNC_REPO_DIR}" rev-parse "${cur_branch}" || true)" == "$(git -C "${HYAKVNC_REPO_DIR}" ls-remote --heads --refs origin "${cur_branch}" | cut -f1 || true)" ]]; then
log INFO "hyakvnc is up to date."
return 1
fi
git -C "${HYAKVNC_REPO_DIR}" fetch --quiet origin "${cur_branch}" || {
log DEBUG "Failed to fetch from remote"
return 1
}
local nchanges
nchanges="$(git -C "${HYAKVNC_REPO_DIR}" rev-list HEAD...origin/"${cur_branch}" --count || echo 0)"
if [[ "${nchanges}" -gt 0 ]]; then
local new_date
new_date="$(git -C "${HYAKVNC_REPO_DIR}" show -s --format=%cd --date=human-local origin/"${cur_branch}" || echo ???)"
log INFO "Found ${nchanges} updates. Most recent: ${new_date}"
return 0
fi
return 1
}
# hyakvnc_autoupdate()
# Unless updates were checked recenetly per $HYAKVNC_CHECK_UPDATE_FREQUENCY,
# check if a hyakvnc update is available. If running interactively, prompt
# to apply update (or disable prompt in the future). If not running interactively,
# apply the update.
# Arguments: None
# Returns: 0 if an update is available and the user wants to update, 1 if none or if an error occurred
function hyakvnc_autoupdate {
if [[ "${HYAKVNC_CHECK_UPDATE_FREQUENCY:-0}" == "-1" ]]; then
log DEBUG "Skipping update check"
return 1
fi
if [[ "${HYAKVNC_CHECK_UPDATE_FREQUENCY:-0}" != "0" ]]; then
local update_frequency_unit="${HYAKVNC_CHECK_UPDATE_FREQUENCY:0-1}"
local update_frequency_value="${HYAKVNC_CHECK_UPDATE_FREQUENCY:0:-1}"
local find_m_arg=()
case "${update_frequency_unit:=d}" in
d)
find_m_arg+=(-mtime "+${update_frequency_value:=0}")
;;
m)
find_m_arg+=(-mmin "+${update_frequency_value:=0}")
;;
*)
log ERROR "Invalid update frequency unit: ${update_frequency_unit}. Please use [d]ays or [m]inutes."
return 1
;;
esac
log DEBUG "Checking if ${HYAKVNC_REPO_DIR}/.last_update_check is older than ${update_frequency_value}${update_frequency_unit}..."
if [[ -r "${HYAKVNC_REPO_DIR}/.last_update_check" ]] && [[ -z $(find "${HYAKVNC_REPO_DIR}/.last_update_check" -type f "${find_m_arg[@]}" -print || true) ]]; then
log DEBUG "Skipping update check because the last check was less than ${update_frequency_value}${update_frequency_unit} ago."
return 1
fi
log DEBUG "Checking for updates because the last check was more than ${update_frequency_value}${update_frequency_unit} ago."
fi
hyakvnc_check_updates || {
log DEBUG "No updates found."
return 1
}
if [[ -t 0 ]]; then # Check if we're running interactively
while true; do # Ask user if they want to update
local choice
read -r -p "Would you like to update hyakvnc? [y/n] [x to disable]: " choice
case "${choice}" in
y | Y | yes | Yes)
log INFO "Updating hyakvnc..."
hyakvnc_pull_updates || {
log WARN "Didn't update hyakvnc"
return 1
}
log INFO "Successfully updated hyakvnc. Restarting..."
echo
exec "${0}" "${@}" # Restart hyakvnc
;;
n | N | no | No)
log INFO "Not updating hyakvnc"
return 1
;;
x | X)
log INFO "Disabling update checks"
export HYAKVNC_CHECK_UPDATE_FREQUENCY="-1"
if [[ -n "${HYAKVNC_CONFIG_FILE:-}" ]]; then
touch "${HYAKVNC_CONFIG_FILE}" && echo 'HYAKVNC_CHECK_UPDATE_FREQUENCY=-1' >>"${HYAKVNC_CONFIG_FILE}"
log INFO "Set HYAKVNC_CHECK_UPDATE_FREQUENCY=-1 in ${HYAKVNC_CONFIG_FILE}"
fi
return 1
;;
*)
echo "Please enter y, n, or x"
;;
esac
done
else
hyakvnc_pull_updates || {
log INFO "Didn't update hyakvnc"
return 1
}
fi
return 0
}
# ## General utility functions:
# check_command()
# Check if a command is available
# Arguments:
# - <command> - The command to check
# - <loglevel> <message> - Passed to log if the command is not available (optional)
function check_command {
if [[ -z "${1:-}" ]] || ! command -v "${1}" >/dev/null 2>&1; then
[[ $# -gt 1 ]] && log "${@:2}"
return 1
fi
return 0
}
# ## SLURM utility functons:
# check_slurm_running {
# Check if SLURM is running
# Arguments: None
function check_slurm_running {
sinfo >/dev/null 2>&1 || return 1
}
# expand_slurm_node_range()
# Expand a SLURM node range to a list of nodes
# Arguments: <node range>
function expand_slurm_node_range {
[[ -z "${1:-}" ]] && return 1
result=$(scontrol show hostnames --oneliner "${1}" | grep -oE '^.+$' | tr ' ' '\n') || return 1
echo "${result}" && return 0
}
# get_slurm_job_info()
# Get info about a SLURM job, given a list of job IDs
# Arguments: <user> [<jobid>]
function get_slurm_job_info {
[[ $# -eq 0 ]] && {
log ERROR "User or Job ID must be specified"
return 1
}
local user="${1:-${USER:-}}"
[[ -z "${user}" ]] && {
log ERROR "User must be specified"
return 1
}
shift
local squeue_format_fields='%i %j %a %P %u %T %M %l %C %m %D %N'
squeue_format_fields="${squeue_format_fields// /\t}" # Replace spaces with tab
local squeue_args=(--noheader --user "${user}" --format "${squeue_format_fields}")
local jobids="${*:-}"
if [[ -n "${jobids}" ]]; then
jobids="${jobids//,/ }" # Replace commas with spaces
squeue_args+=(--job "${jobids}")
fi
squeue "${squeue_args[@]}"
}
# get_squeue_job_status()
# Get the status of a SLURM job, given a job ID
# Arguments: <jobid>
function get_squeue_job_status {
local jobid="${1:-}"
[[ -z "${jobid}" ]] && {
log ERROR "Job ID must be specified"
return 1
}
squeue -j "${1}" -h -o '%T' || {
log ERROR "Failed to get status for job ${jobid}"
return 1
}
}
# get_slurm_hyak_qos()
# Return the correct QOS on Hyak for the given partition on hyak
# Arguments: <partition>
function get_slurm_hyak_qos {
# Logic copied from hyakalloc's hyakqos.py:QosResource.__init__():
local qos_name qos_suffix
qos_name="${1:-}"
[[ -z "${qos_name:-}" ]] && return 1
if [[ "${qos_name}" == *-* ]]; then
qos_suffix="${qos_name#*-}" # Extract portion after the first "-"
if [[ "${qos_suffix}" == *mem ]]; then
echo "compute-${qos_suffix}"
else
echo "${qos_suffix}"
fi
else
echo "compute"
fi
}
# hyakvnc_config_init()
# Initialize the hyakvnc configuration
# Arguments: None
function hyakvnc_config_init {
mkdir -p "${HYAKVNC_DIR}/jobs" "${HYAKVNC_SLURM_OUTPUT_DIR}" || {
log ERROR "Failed to create HYAKVNC jobs directory ${HYAKVNC_DIR}/jobs"
return 1
}
mkdir -p "${HYAKVNC_SLURM_OUTPUT_DIR}" || {
log ERROR "Failed to create HYAKVNC jobs directory ${HYAKVNC_DIR}/jobs"
return 1
}
if ! check_command squeue; then
log ERROR "SLURM is not installed! Can't initialize configuration."
return 1
fi
# Set default SLURM cluster, accont, and partition if empty:
if [[ -z "${HYAKVNC_SLURM_CLUSTER}" ]]; then
HYAKVNC_SLURM_CLUSTER="$(sacctmgr show cluster -nPs format=Cluster)" || {
log ERROR "Failed to get default SLURM account"
return 1
}
fi
export SBATCH_CLUSTERS="${HYAKVNC_SLURM_CLUSTER:-}" && log TRACE "Set SBATCH_CLUSTERS to ${SBATCH_CLUSTERS}"
if [[ -z "${HYAKVNC_SLURM_ACCOUNT}" ]]; then
# Get the default account for the cluster. Uses grep to get first non-whitespace line:
HYAKVNC_SLURM_ACCOUNT=$(sacctmgr show user -nPs "${USER}" format=defaultaccount where cluster="${HYAKVNC_SLURM_CLUSTER}" | grep -o -m 1 -E '\S+') || {
log ERROR "Failed to get default account"
return 1
}
fi
export SBATCH_ACCOUNT="${HYAKVNC_SLURM_ACCOUNT:-}" && log TRACE "Set SBATCH_ACCOUNT to ${SBATCH_ACCOUNT}"
if [[ -z "${HYAKVNC_SLURM_PARTITION:-}" ]]; then
HYAKVNC_SLURM_PARTITION=$(sacctmgr show -nPs user "${USER}" format=qos where account="${HYAKVNC_SLURM_ACCOUNT}" cluster="${HYAKVNC_SLURM_CLUSTER}" | grep -o -m 1 -E '\S+') || {
log ERROR "Failed to get SLURM partitions for user ${USER} on account ${HYAKVNC_SLURM_ACCOUNT} on cluster ${HYAKVNC_SLURM_CLUSTER}"
return 1
}
# Get the first partition:
HYAKVNC_SLURM_PARTITION="${HYAKVNC_SLURM_PARTITION%%,*}"
[[ -z "${HYAKVNC_SLURM_PARTITION}" ]] && {
log ERROR "Failed to get default SLURM partition"
return 1
}
HYAKVNC_SLURM_PARTITION=$(get_slurm_hyak_qos "${HYAKVNC_SLURM_PARTITION}") || {
log ERROR "Failed to get SLURM partition for ${HYAKVNC_SLURM_PARTITION}"
return 1
}
fi
export SBATCH_PARTITION="${HYAKVNC_SLURM_PARTITION:-}" && log TRACE "Set SBATCH_PARTITION to ${SBATCH_PARTITION}"
# shellcheck disable=SC2046
export $(compgen -v HYAKVNC_) # Export all HYAKVNC_ variables
}
# stop_hyakvnc_session()
# Stop a Hyak VNC session, given a job ID
# Arguments: <jobid> [ -c | --cancel ] [ --no-rm ]
function stop_hyakvnc_session {
local jobid should_cancel no_rm
while true; do
case ${1:-} in
-c | --cancel)
shift
should_cancel=1
;;
--no-rm) # Don't remove the job directory
shift
no_rm=1
;;
*)
jobid="${1:-}"
break
;;
esac
done
[[ -z "${jobid}" ]] && {
log ERROR "Job ID must be specified"
return 1
}
log DEBUG "Stopping VNC session for job ${jobid}"
local jobdir pid tmpdirname
jobdir="${HYAKVNC_DIR}/jobs/${jobid}"
if [[ -d "${jobdir}" ]]; then
local pidfile
for pidfile in "${jobdir}/vnc/"*"${HYAKVNC_VNC_DISPLAY}".pid; do
if [[ -r "${pidfile:-}" ]]; then
read -r pid <"${pidfile}"
[[ -z "${pid:-}" ]] && {
log WARN "Failed to get pid from ${pidfile}"
break
}
srun --jobid "${jobid}" kill "${pid}" || log WARN "srun failed to stop VNC process for job ${jobid} with pid ${pid}"
break
fi
done
if [[ -r "${jobdir}/tmpdirname" ]]; then
read -r tmpdirname <"${pidfile}"
[[ -z "${tmpdirname}" ]] && log WARN "Failed to get tmpdirname from ${jobdir}/tmpdirname"
srun --quiet --jobid "${jobid}" rm -rf "${tmpdirname}" || log WARN "Failed to remove container /tmp directory at ${tmpdirname} job ${jobid}"
fi
[[ -n "${no_rm}" ]] || rm -rf "${jobdir}" && log DEBUG "Removed VNC directory ${jobdir}"
else
log WARN "Job directory ${jobdir} does not exist"
fi
if [[ -n "${should_cancel}" ]]; then
log INFO "Cancelling job ${jobid}"
sleep 1 # Wait for VNC process to exit
scancel --full "${jobid}" || log ERROR "scancel failed to cancel job ${jobid}"
fi
return 0
}
# print_connection_info()
# Print connection instructions for a job, given job ID
# Arguments: -j | --jobid <jobid> (required) [ -p | --viewer-port <viewer_port> ] [ -n |--node <node> ] [ -s | --ssh-host <ssh_host> ]
#
# The generated connection string should look like this, depending on the the OS:
# ssh -f -L 6111:'/mmfs1/home/altan/.hyakvnc/jobs/14930429/socket.uds' -J altan@klone.hyak.uw.edu altan@g3071 sleep 10; vncviewer localhost:6111
function print_connection_info {
local jobid jobdir node socket_path viewer_port launch_hostname ssh_host
viewer_port="${HYAKVNC_LOCALHOST_PORT:-5901}"
ssh_host="${HYAKVNC_SSH_HOST:-klone.hyak.uw.edu}"
# Parse arguments:
while true; do
case ${1:-} in
-j | --jobid)
shift
jobid="${1:-}"
shift
;;
-p | --viewer-port)
shift
viewer_port="${1:-viewer_port}"
shift
;;
-n | --node)
shift
node="${1:-}"
shift
;;
-s | --ssh-host)
shift
ssh_host="${1:-}"
shift
;;
-*)
log ERROR "Unknown option for print_connection_info: ${1:-}\n"
return 1
;;
*)
break
;;
esac
done
# Check arguments:
[[ -z "${jobid}" ]] && {
log ERROR "Job ID must be specified"
return 1
}
[[ -z "${viewer_port}" ]] && {
log ERROR "Viewer port must be specified"
return 1
}
[[ -z "${ssh_host}" ]] && {
log ERROR "SSH host must be specified"
return 1
}
# Check that the job directory exists
[[ -d "${jobdir:=${HYAKVNC_DIR}/jobs/${jobid}}" ]] || {
log ERROR "Job directory ${jobdir} does not exist"
return 1
}
[[ -e "${socket_path:=${HYAKVNC_DIR}/jobs/${jobid}/vnc/socket.uds}" ]] || {
log ERROR "Socket file ${socket_path} does not exist"
return 1
}
[[ -S "${socket_path}" ]] || {
log ERROR "Socket file ${socket_path} is not a socket"
return 1
}
[[ -n "${node}" ]] || node=$(squeue -h -j "${jobid}" -o '%N' | grep -o -m 1 -E '\S+') || log DEBUG "Failed to get node for job ${jobid} from squeue"
if [[ -r "${HYAKVNC_DIR}/jobs/${jobid}/vnc/hostname" ]] && launch_hostname=$(cat "${HYAKVNC_DIR}/jobs/${jobid}/vnc/hostname" 2>/dev/null || true) && [[ -n "${launch_hostname:-}" ]]; then
[[ "${node}" = "${launch_hostname}" ]] || log WARN "Node for ${jobid} from hostname file (${HYAKVNC_DIR}/jobs/${jobid}/vnc/hostname) (${launch_hostname:-}) does not match node from squeue (${node}). Was the job restarted?"
[[ -z "${node}" ]] && {
log DEBUG "Node for ${jobid} from squeue is blank. Setting to ${launch_hostname}"
node="${launch_hostname}"
}
else
log WARN "Failed to get originally launched node for job ${jobid} from ${HYAKVNC_DIR}/jobs/${jobid}/hostname"
fi
[[ -z "${node}" ]] && {
log ERROR "No node identified for job ${jobid}"
return 1
}
local ssh_args
ssh_args=()
ssh_args+=("-o StrictHostKeyChecking=no")
ssh_args+=("-L" "${viewer_port}:${socket_path}")
ssh_args+=("-J" "${USER}@${HYAKVNC_SSH_HOST}")
ssh_args+=("${USER}@${node}")
# Print connection instruction header:
cat <<EOF
==========
Copy and paste these instructions into a command line terminal on your local machine to connect to the VNC session.
You may need to install a VNC client if you don't already have one.
NOTE: If you receive an error that looks like "Permission denied (publickey,gssapi-keyex,gssapi-with-mic)", you don't have an SSH key set up. See https://hyak.uw.edu/docs/setup/intracluster-keys for more information. To set this up quickly on Linux, macOS, or Windows (WSL2/Cygwin), open a new terminal window on your machine and enter the following 2 commands before you try again:
[ ! -r ~/.ssh/id_rsa ] && ssh-keygen -t rsa -b 4096 -N '' -C "${USER}@uw.edu" -f ~/.ssh/id_rsa
ssh-copy-id -o StrictHostKeyChecking=no ${USER}@klone.hyak.uw.edu
---------
EOF
# Print connection instructions for each operating system:
echo "LINUX TERMINAL (bash/zsh):"
echo "ssh -f ${ssh_args[*]} sleep 20 && vncviewer localhost:${viewer_port} || xdg-open vnc://localhost:${viewer_port} || echo 'No VNC viewer found. Please install one or try entering the connection information manually.'"
echo
echo "MACOS TERMINAL"
printf "ssh -f %s sleep 20 && " "${ssh_args[*]}"
# Print a command to open a VNC viewer for each bundle ID:
for bundleid in ${HYAKVNC_MACOS_VNC_VIEWER_BUNDLEIDS}; do
printf "open -b %s --args localhost:%s 2>/dev/null || " "${bundleid}" "${viewer_port}"
done
# Try default VNC viewer built into macOS:
printf "open vnc://localhost:%s 2>/dev/null || " "${viewer_port}"
# And finally, print a command to warn the user if no VNC viewer was found:
printf "echo 'No VNC viewer found. Please install one or try entering the connection information manually.'\n"
echo
echo "WINDOWS"
echo "ssh -f ${ssh_args[*]} sleep 20 && cmd.exe /c cmd /c \"\$(cmd.exe /c where \"C:\Program Files\TurboVNC;C:\Program Files (x86)\TurboVNC:vncviewerw.bat\")\" localhost:${viewer_port} || echo 'No VNC viewer found. Please install one or try entering the connection information manually.'"
echo
echo "=========="
}
# cleanup_launched_jobs_and_exit()
# Cancel any jobs that were launched and exit
function cleanup_launched_jobs_and_exit {
local jobdir jobid
log WARN "Interrupted. Cleaning up and exiting!"
# Cancel any jobs that were launched:
for jobid in "${Launched_JobIDs[@]}"; do
jobdir="${HYAKVNC_DIR}/jobs/${jobid}"
log WARN "Cancelling launched job ${jobid}"
scancel "${jobid}" || log ERROR "scancel failed to cancel job ${jobid}"
[[ -d "${jobdir}" ]] && rm -rf "${jobdir}" && log DEBUG "Removed job directory ${jobdir}"
done
kill -TERM %tail 2>/dev/null # Stop following the SLURM log file
trap - SIGINT SIGTERM SIGHUP SIGABRT SIGQUIT ERR EXIT # Remove traps
exit 1
}
# # Apptainer utility functions:
# ghcr_get_oras_sif()
# Get a GitHub Container Registry token for a given repository
# Arguments:
# - url: URL to download from (required)
# - output_path: Directory or path to save the image to (optional)
# Returns: 0 if successful, 1 if not or if an error occurred
# Prints: The token to stdout
function ghcr_get_oras_sif {
check_command curl || return 1 # Check if curl is installed
check_command python3 || return 1 # Check if python3 is installed
local url output_path
[[ -z "${url:=${1:-}}" ]] && {
log ERROR "URL must be specified"
return 1
}
output_path="${2:-./}" # Optionally set the output file
[[ -d "${output_path}" ]] && [[ ! -w "${output_path}" ]] && {
log ERROR "Output directory \"${output_path}\" is not writable"
return 1
}
# Check that the URL is an ORAS GitHub Container Registry URL:
local address image_ref repo image_tag
case "${url}" in
oras://ghcr.io/*)
address="${url#oras://}"
image_ref="${address#ghcr.io/}"
repo="${image_ref%%:*}"
[[ -z "${repo}" ]] && {
log ERROR "Failed to parse repository from URL \"${url}\""
return 1
}
[[ ${image_ref} == *:* ]] && image_tag="${image_ref##*:}"
image_tag="${image_tag:-latest}"
;;
*) # Not a GitHub Container Registry URL
log ERROR "URL \"${url}\" is not a GitHub Container Registry URL for an ORAS image"
return 1
;;
esac
# Get a token for the repository (required to get the manifest, but freely available by this request):
# Uses curl to get the token, then python to parse the JSON response
local repo_token
repo_token="$(curl -sSL "https://ghcr.io/token?scope=repository:${repo}:pull&service=ghcr.io" | python3 -I -c 'import sys,json; print(json.load(sys.stdin)["token"])' 2>/dev/null || true)"
[[ -z "${repo_token}" ]] && {
log ERROR "Failed to get token for repository ${repo}"
return 1
}
# Request the manifest for the image tag:
local manifest
manifest="$(curl -sSL \
-H "Accept: application/vnd.oci.image.manifest.v1+json" \
-H "Authorization: Bearer ${repo_token}" \
"https://ghcr.io/v2/${repo}/manifests/${image_tag}" \
2>/dev/null || true)"
[[ -z "${manifest}" ]] && {
log ERROR "Failed to get manifest for repository ${repo}"
return 1
}
local image_sha256
image_sha256="$(echo "${manifest}" | python3 -I -c \
'import sys, json; s=[ x for x in json.load(sys.stdin)["layers"] if x.get("mediaType", "") == "application/vnd.sylabs.sif.layer.v1.sif" and x.get("digest", "").startswith("sha256")]; sys.exit(1) if len(s) != 1 else print(s[0]["digest"])' \
2>/dev/null || true)"
[[ -z "${image_sha256:-}" ]] && {
log ERROR "Failed to get image info for repository ${repo}"
return 1
}
[[ -d "${output_path}" ]] && output_path="${output_path}/${image_sha256}" # Append the image SHA256 to the output path if it's a directory
if [[ -r "${output_path}" ]]; then
log DEBUG "Image already exists at ${output_path}"
if check_command sha256sum; then
if sha256sum --quiet --status --ignore-missing --check <(echo "${image_sha256##sha256:}" "${output_path}"); then
log DEBUG "Image at ${output_path} matches expected SHA256 ${image_sha256}"
echo "${output_path}"
return 0
else
log DEBUG "Image at ${output_path} does not match expected SHA256 ${image_sha256}. Will redownload and overwrite."
fi
fi
fi
# Download the image:
local image_url
image_url="https://ghcr.io/v2/${repo}/blobs/${image_sha256}"
curl --progress -fSL -H "Authorization: Bearer ${repo_token}" -o "${output_path}" "${image_url}" || {
log ERROR "Failed to download image from ${image_url} to ${output_path}"
rm -f "${output_path}" && log DEBUG "Removed output file at ${output_path}" # Remove the file if it exists
return 1
}
chmod +x "${output_path}"
log DEBUG "Downloaded image to ${output_path}"
echo "${output_path}"
return 0
}
# # Commands
# ## Command: create
# help_create()
function help_create {
cat <<EOF
Create a VNC session on Hyak
Usage: hyakvnc create [create options...] -c <container> [extra args to pass to apptainer...]
Description:
Create a VNC session on Hyak.
Options:
-h, --help Show this help message and exit
-c, --container Path to container image (required)
-A, --account Slurm account to use (default: ${HYAKVNC_SLURM_ACCOUNT})
-p, --partition Slurm partition to use (default: ${HYAKVNC_SLURM_PARTITION})
-C, --cpus Number of CPUs to request (default: ${HYAKVNC_SLURM_CPUS})
-m, --mem Amount of memory to request (default: ${HYAKVNC_SLURM_MEM})
-t, --timelimit Slurm timelimit to use (default: ${HYAKVNC_SLURM_TIMELIMIT})
-g, --gpus Number of GPUs to request (default: ${HYAKVNC_SLURM_GPUS})
Advanced options:
--no-ghcr-oras-preload Don't preload ORAS GitHub Container Registry images
Extra arguments:
Any extra arguments will be passed to apptainer run.
See 'apptainer run --help' for more information.
Examples:
# Create a VNC session using the container ~/containers/mycontainer.sif
hyakvnc create -c ~/containers/mycontainer.sif
# Create a VNC session using the URL for a container:
hyakvnc create -c oras://ghcr.io/maouw/hyakvnc_apptainer/hyakvnc-vncserver-ubuntu22.04:latest
# Use the SLURM account escience, the partition gpu-a40, 4 CPUs, 1GB of memory, 1 GPU, and 1 hour of time:
hyakvnc create -c ~/containers/mycontainer.sif -A escience -p gpu-a40 -C 4 -m 1G -t 1:00:00 -g 1
EOF
}
# cmd_create()
function cmd_create {
local apptainer_start_args=()
local sbatch_args=(--parsable)
local container_basename container_name start tailpid
# <TODO> If a job ID was specified, don't launch a new job
# <TODO> If a job ID was specified, check that the job exists and is running
# Parse arguments:
while true; do
case ${1:-} in
-h | --help)
help_create
return 0
;;
-d | --debug) # Debug mode
shift
export HYAKVNC_LOG_LEVEL="DEBUG"
;;
-c | --container)
shift
[[ -z "${1:-}" ]] && {
log ERROR "-c | --container requires a non-empty option argument"
exit 1
}
export HYAKVNC_APPTAINER_CONTAINER="${1:-}"
shift
;;
-A | --account)
[[ -z "${1:-}" ]] && {
log ERROR "-A | --account requires a non-empty option argument"
exit 1
}
shift
export HYAKVNC_SLURM_ACCOUNT="${1:-}"
shift
;;
-p | --partition)
shift
[[ -z "${1:-}" ]] && {
log ERROR "-p | --partition requires a non-empty option argument"
exit 1
}
export HYAKVNC_SLURM_PARTITION="${1:-}"
shift
;;
-C | --cpus)
shift
[[ -z "${1:-}" ]] && {
log ERROR "--cpus requires a non-empty option argument"
exit 1
}
export HYAKVNC_SLURM_CPUS="${1:-}"
shift
;;
-m | --mem)
shift
[[ -z "${1:-}" ]] && {
log ERROR "--mem requires a non-empty option argument"
exit 1
}
export HYAKVNC_SLURM_MEM="${1:-}"
shift
;;
-t | --timelimit)
shift
[[ -z "${1:-}" ]] && {
log ERROR "--mem requires a non-empty option argument"
exit 1
}
export HYAKVNC_SLURM_TIMELIMIT="${1:-}"
shift
;;
-g | --gpus)
shift
[[ -z "${1:-}" ]] && {
log ERROR "--mem requires a non-empty option argument"
exit 1
}
export HYAKVNC_SLURM_GPUS="${1:-}"
shift
;;
--no-ghcr-oras-preload) # Don't preload ORAS GitHub Container Registry images
shift
export HYAKVNC_APPTAINER_GHCR_ORAS_PRELOAD=0
;;
--) # Args to pass to Apptainer
shift
if [[ -z "${HYAKVNC_APPTAINER_ADD_ARGS:-}" ]]; then
export HYAKVNC_APPTAINER_ADD_ARGS="${HYAKVNC_APPTAINER_ADD_ARGS:-} ${*:-}"
else
export HYAKVNC_APPTAINER_ADD_ARGS="${*:-}"
fi
break
;;
-*)
log ERROR "Unknown option: ${1:-}\n"
exit 1
;;
*)
break
;;
esac
done
# Check that container is specified:
[[ -z "${HYAKVNC_APPTAINER_CONTAINER}" ]] && {
log ERROR "Container image must be specified"
exit 1
}
container_basename="$(basename "${HYAKVNC_APPTAINER_CONTAINER}")"
if case "${HYAKVNC_APPTAINER_CONTAINER}" in library://* | docker://* | shub://* | oras://* | http://* | https://*) true ;; *) false ;; esac then
log DEBUG "Container image ${HYAKVNC_APPTAINER_CONTAINER} is a URL"
# Add a tag if none is specified:
[[ "${container_basename}" =~ .*:.* ]] || HYAKVNC_APPTAINER_CONTAINER="${HYAKVNC_APPTAINER_CONTAINER}:latest"
else
# Check that container is specified
[[ ! -e "${HYAKVNC_APPTAINER_CONTAINER:-}" ]] && {
log ERROR "Container image at ${HYAKVNC_APPTAINER_CONTAINER} does not exist "
exit 1
}
# Check that the container is readable:
[[ ! -r "${HYAKVNC_APPTAINER_CONTAINER:-}" ]] && {
log ERROR "Container image ${HYAKVNC_APPTAINER_CONTAINER} is not readable"
exit 1
}
fi
[[ -z "${container_basename}" ]] && {
log ERROR "Failed to get container basename from ${HYAKVNC_APPTAINER_CONTAINER}"
exit 1
}
container_name="${container_basename//\.@(sif|simg|img|sqsh)/}"
[[ -z "${container_name}" ]] && {
log ERROR "Failed to get container name from ${container_basename}"