Skip to content

Commit cd50c74

Browse files
authored
A bit of cleanup (#338)
* Print exact command in debug message when not dryrun * Make default graphics config more readable * Don't ask for DRYRUN output VERBOSE=3 already shows the container environment variables and command. * Refactor container security flags * Use getenforce to check if SELinux is active
1 parent 2ed245f commit cd50c74

2 files changed

Lines changed: 41 additions & 33 deletions

File tree

β€Ž.github/ISSUE_TEMPLATE/help.yamlβ€Ž

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ body:
1313
options:
1414
- label: I have given details of my install including Distribution, Wayland/ XOrg, Parameters Used, echo $XAUTHORITY, etc.
1515
required: true
16-
- label: I have provided logs showing any errors, if available (use `VERBOSITY=3 ZWIFT_FG=1 zwift` and `DRYRUN=1 zwift`)
16+
- label: I have provided logs showing any errors, if available (use `VERBOSITY=3 ZWIFT_FG=1 zwift`)
1717
required: true
1818
- label: I have filled out the issue template to the best of my ability.
1919
required: true
@@ -31,17 +31,9 @@ body:
3131
label: Zwift Logs
3232
description: The output of launching zwift.
3333
value: |
34-
- Zwift foreground logs:
35-
3634
```text
3735
Place VERBOSITY=3 ZWIFT_FG=1 zwift output here
3836
```
39-
40-
- Zwift dry run logs:
41-
42-
```text
43-
Place DRYRUN=1 zwift output here
44-
```
4537
validations:
4638
required: true
4739
- type: textarea

β€Žsrc/zwift.shβ€Ž

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,18 @@ if [[ ${ZWIFT_OVERRIDE_GRAPHICS} -eq 1 ]]; then
425425
zwift_graphics_config="${zwift_user_graphics_config}"
426426
# Create graphics.txt file if it does not exist.
427427
elif [[ ! -f ${zwift_graphics_config} ]]; then
428-
echo -e "res 1920x1080(0x)\nsres 2048x2048\nset gSSAO=1\nset gFXAA=1\nset gSunRays=1\nset gHeadlight=1\nset gFoliagePercent=1.0\nset gSimpleReflections=0\nset gLODBias=0\nset gShowFPS=0" > "${zwift_graphics_config}"
428+
{
429+
echo "res 1920x1080(0x)"
430+
echo "sres 2048x2048"
431+
echo "set gSSAO=1"
432+
echo "set gFXAA=1"
433+
echo "set gSunRays=1"
434+
echo "set gHeadlight=1"
435+
echo "set gFoliagePercent=1.0"
436+
echo "set gSimpleReflections=0"
437+
echo "set gLODBias=0"
438+
echo "set gShowFPS=0"
439+
} > "${zwift_graphics_config}"
429440
msgbox warning "Created ${zwift_graphics_config} with default values, edit this file to tweak the zwift graphics settings" 0
430441
fi
431442

@@ -461,27 +472,22 @@ else
461472
container_args+=(-d)
462473
fi
463474

464-
# Setup container security flags
465475
# Detect if SELinux is actively enforcing
466-
_selinux_enforcing() {
467-
local enforce_file=/sys/fs/selinux/enforce
468-
if [[ -f ${enforce_file} ]]; then
469-
[[ $(< "${enforce_file}") == "1" ]]
470-
else
471-
return 1
472-
fi
476+
is_selinux_active() {
477+
local enforcing
478+
command_exists getenforce && enforcing="$(getenforce)" && [[ ${enforcing} == "Enforcing" ]]
473479
}
474480

475481
# Setup container security flags
476-
if [[ ${PRIVILEGED_CONTAINER:-0} -eq 1 ]]; then
477-
# Explicit opt-in to privileged mode
478-
container_args+=(--privileged --security-opt label=disable) # privileged container, less secure
479-
elif _selinux_enforcing; then
480-
# SELinux is active, use label-based security
481-
container_args+=(--security-opt label=type:container_runtime_t) # more secure
482+
if [[ ${PRIVILEGED_CONTAINER} -eq 1 ]]; then
483+
msgbox warning "PRIVILEGED_CONTAINER is set, running container in privileged mode"
484+
container_args+=(--privileged --security-opt label=disable)
485+
elif is_selinux_active; then
486+
msgbox info "SELinux is active, using secure container flags"
487+
container_args+=(--security-opt label=type:container_runtime_t)
482488
else
483-
# Not SELinux (e.g. AppArmor/none), default to privileged for GPU compatibility
484-
container_args+=(--privileged --security-opt label=disable) # privileged container, less secure
489+
msgbox warning "Not using SELinux, running container in privileged mode to be able to access the GPU"
490+
container_args+=(--privileged --security-opt label=disable)
485491
fi
486492

487493
# Append extra arguments provided by user
@@ -670,19 +676,29 @@ fi
670676
declare -a container_command
671677
container_command=("${CONTAINER_TOOL}" run "${container_args[@]}" "${IMAGE}:${VERSION}" "${entrypoint_args[@]}")
672678

673-
# DRYRUN: print the exact command that would be executed, then exit
674-
if [[ ${DRYRUN} -eq 1 ]]; then
675-
msgbox ok "DRYRUN:"
676-
msgbox ok "environment variables (${container_env_file}):"
679+
# Print the exact command that would be executed
680+
681+
print_container_command() {
682+
local msg_type="${1:?}"
683+
684+
msgbox "${msg_type}" "environment variables (${container_env_file}):"
677685
for env_var in "${container_env_vars[@]}"; do
678686
env_var="${env_var//\\/\\\\}" # escape backslashes
679687
env_var="${env_var//ZWIFT_USERNAME=*/ZWIFT_USERNAME=πŸ’œπŸ’œπŸ’œπŸ’œπŸ’œπŸ’œ}" # redact username
680688
env_var="${env_var//ZWIFT_PASSWORD=*/ZWIFT_PASSWORD=πŸ’œπŸ’œπŸ’œπŸ’œπŸ’œπŸ’œ}" # redact password
681-
msgbox ok " β€’ ${env_var}"
689+
msgbox "${msg_type}" " β€’ ${env_var}"
682690
done
683-
msgbox ok "${CONTAINER_TOOL} command:"
684-
msgbox ok " $(printf '%q ' "${container_command[@]}")"
691+
msgbox "${msg_type}" "${CONTAINER_TOOL} command:"
692+
msgbox "${msg_type}" " $(printf '%q ' "${container_command[@]}")"
693+
}
694+
695+
if [[ ${DRYRUN} -eq 1 ]]; then
696+
msgbox ok "DRYRUN:"
697+
print_container_command ok
685698
exit 0
699+
else
700+
msgbox debug "Starting ${CONTAINER_TOOL} container with the following arguments:"
701+
print_container_command debug
686702
fi
687703

688704
# Create a volume if not already exists, this is done now as

0 commit comments

Comments
Β (0)