Skip to content

Commit

Permalink
scripts/chwd: Fix issues with escaping when executing hooks
Browse files Browse the repository at this point in the history
Signed-off-by: Vasiliy Stelmachenok <[email protected]>
  • Loading branch information
ventureoo committed Jan 3, 2025
1 parent a53630b commit 0ae2918
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
14 changes: 7 additions & 7 deletions profiles/pci/graphic_drivers/profiles.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ post_install = """
device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)"
if ((device_type >= 8 && device_type <= 11)); then
# nvidia-powerd is not supported by Turing GPUs
if ! lspci -d "10de:*:030x" -vm | grep -q 'Device:\tTU.*'; then
if ! lspci -d "10de:*:030x" -vm | grep -q 'Device:\\tTU.*'; then
systemctl enable nvidia-powerd
fi
systemctl enable switcheroo-control
Expand Down Expand Up @@ -99,7 +99,7 @@ conditional_packages = """
# Trying to determine the laptop
device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)"
if [[ "$device_type" -ge 8 && "$device_type" -le 11 ]]; then
if ((device_type >= 8 && device_type <= 11)); then
packages+=" nvidia-prime switcheroo-control"
fi
Expand Down Expand Up @@ -258,14 +258,14 @@ device_ids = "*"
priority = 5
packages = 'virtualbox-guest-utils xf86-video-vmware open-vm-tools xf86-input-vmmouse spice-vdagent qemu-guest-agent vulkan-virtio gtkmm3'
post_install = """
if [[ "$(systemd-detect-virt)" == "oracle" ]]; then
if [ "$(systemd-detect-virt)" = "oracle" ]; then
# Virtualbox detected
# Load kernel modules and sync clock
systemctl enable --now --no-block vboxservice.service
else
if [[ "$(systemd-detect-virt)" == "vmware" ]]; then
if [ "$(systemd-detect-virt)" = "vmware" ]; then
# Vmware detected
systemctl enable --now --no-block vmtoolsd.service
else
Expand All @@ -276,17 +276,17 @@ EOF
mkinitcpio -P
fi
fi
if [[ -e /etc/gdm/custom.conf ]]; then
if [ -e /etc/gdm/custom.conf ]; then
sed -i -e 's|#WaylandEnable=false|WaylandEnable=false|g' /etc/gdm/custom.conf
fi"""
pre_remove = """
rm -f /etc/mkinitcpio.conf.d/10-chwd.conf
"""
post_remove = """
if [[ "$(systemd-detect-virt)" == "oracle" ]]; then
if [ "$(systemd-detect-virt)" = "oracle" ]; then
# Virtualbox detected
systemctl disable --now vboxservice.service
elif [[ "$(systemd-detect-virt)" == "vmware" ]]; then
elif [ "$(systemd-detect-virt)" = "vmware" ]; then
# Vmware detected
systemctl disable --now vmtoolsd.service
fi"""
27 changes: 17 additions & 10 deletions scripts/chwd
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
--]]
local pacman, pmconfig, pmroot, cachedir, sync

local function printf(s, ...)
print(s:format(...))
end

local function die(err, ...)
print(err:format(...))
printf(err, ...)
os.exit(1)
end

Expand Down Expand Up @@ -124,17 +128,20 @@ local function exec_hook(hook)
return
end

if hook ~= "" then
local handle, errmsg = io.popen(("/bin/bash -c '%s'"):format(hook), "r")
if hook == "" then
return
end

if handle then
local output = handle:read('*all')
handle:close()
return output
else
print(("ERROR: Unkown shell invocation error for %s hook: %s"):format(hook, errmsg))
end
local handle, errmsg = io.popen(hook, "r")

if not handle then
printf("ERROR: Unknown shell invocation error for %s hook: %s", hook, errmsg)
return
end

local output = handle:read("*a")
handle:close()
return output
end

local function escape_pattern(text)
Expand Down

0 comments on commit 0ae2918

Please sign in to comment.