From 8ce9d010eecc1ca58a3af595fc754cfdf91bc8cd Mon Sep 17 00:00:00 2001 From: Rouven Spreckels Date: Fri, 20 Sep 2019 13:58:17 +0200 Subject: [PATCH] Quote shell variables. Avoid wildcards. --- debian/.gitignore | 2 +- debian/Makefile | 16 ++++++------- debian/huawei-wmi-1.1.0/debian/install | 2 +- debian/huawei-wmi-1.1.0/debian/postinst | 7 +++--- debian/huawei-wmi-1.1.0/debian/postrm | 7 +++--- debian/huawei-wmi-1.1.0/debian/preinst | 2 +- generic/Makefile | 6 ++--- generic/huawei-wmi-1.1.0/available | 30 +++++++++++++++++++++++++ generic/huawei-wmi-1.1.0/constants | 9 -------- generic/huawei-wmi-1.1.0/privilege | 26 +++++---------------- generic/huawei-wmi-1.1.0/reinstate | 8 +++---- 11 files changed, 62 insertions(+), 53 deletions(-) create mode 100755 generic/huawei-wmi-1.1.0/available delete mode 100755 generic/huawei-wmi-1.1.0/constants diff --git a/debian/.gitignore b/debian/.gitignore index 6819140..8f80e1d 100644 --- a/debian/.gitignore +++ b/debian/.gitignore @@ -1,5 +1,5 @@ */10-huawei-wmi.rules -*/constants +*/available */privilege */reinstate */debian/huawei-wmi-privilege.service diff --git a/debian/Makefile b/debian/Makefile index 4e0615b..df5db4d 100644 --- a/debian/Makefile +++ b/debian/Makefile @@ -51,7 +51,7 @@ translate: CPY := $(SRC)10-huawei-wmi.rules CPY += $(SRC)debian/huawei-wmi-privilege.service CPY += $(SRC)debian/huawei-wmi-reinstate.service -CPY += $(SRC)constants +CPY += $(SRC)available CPY += $(SRC)privilege CPY += $(SRC)reinstate @@ -62,21 +62,21 @@ $(DEB): $(CPY) $(shell find $(SRC) | grep -vFf .gitignore) lintian $(DEB) $(SRC)10-huawei-wmi.rules: $(GEN)10-huawei-wmi.rules - cp -a $< $@ + cp --archive $< $@ $(SRC)debian/huawei-wmi-privilege.service: $(GEN)huawei-wmi-privilege.service - cp -a $< $@ + cp --archive $< $@ $(SRC)debian/huawei-wmi-reinstate.service: $(GEN)huawei-wmi-reinstate.service - cp -a $< $@ + cp --archive $< $@ -$(SRC)constants: $(GEN)constants - cp -a $< $@ +$(SRC)available: $(GEN)available + cp --archive $< $@ $(SRC)privilege: $(GEN)privilege - cp -a $< $@ + cp --archive $< $@ $(SRC)reinstate: $(GEN)reinstate - cp -a $< $@ + cp --archive $< $@ Makefile:; diff --git a/debian/huawei-wmi-1.1.0/debian/install b/debian/huawei-wmi-1.1.0/debian/install index 1f9a03f..60f5c99 100644 --- a/debian/huawei-wmi-1.1.0/debian/install +++ b/debian/huawei-wmi-1.1.0/debian/install @@ -1,4 +1,4 @@ 10-huawei-wmi.rules lib/udev/rules.d -constants usr/lib/huawei-wmi +available usr/lib/huawei-wmi privilege usr/lib/huawei-wmi reinstate usr/lib/huawei-wmi diff --git a/debian/huawei-wmi-1.1.0/debian/postinst b/debian/huawei-wmi-1.1.0/debian/postinst index aaa648f..354a564 100644 --- a/debian/huawei-wmi-1.1.0/debian/postinst +++ b/debian/huawei-wmi-1.1.0/debian/postinst @@ -13,11 +13,12 @@ then groupadd --system huawei-wmi 2> /dev/null || true for user in $users do - usermod --append --groups huawei-wmi "$user" + usermod --append --groups huawei-wmi -- "$user" done - mkdir --parents --mode=02775 $DEF - chgrp huawei-wmi $DEF + mkdir --parents "$DEF" + chmod g+s "$DEF" + chgrp huawei-wmi "$DEF" fi #DEBHELPER# diff --git a/debian/huawei-wmi-1.1.0/debian/postrm b/debian/huawei-wmi-1.1.0/debian/postrm index 0ed1c63..8377181 100644 --- a/debian/huawei-wmi-1.1.0/debian/postrm +++ b/debian/huawei-wmi-1.1.0/debian/postrm @@ -3,11 +3,12 @@ #DEBHELPER# DEF=/etc/default/huawei-wmi/ -CCT=charge*_thresholds +CCT=charge_control_thresholds +DCT=charge_thresholds if [ "$1" = purge ] then - rm --force $DEF$CCT - rmdir $DEF 2> /dev/null || true + rm --force -- "$DEF$CCT" "$DEF$DCT" + rmdir -- "$DEF" 2> /dev/null || true groupdel huawei-wmi 2> /dev/null || true fi diff --git a/debian/huawei-wmi-1.1.0/debian/preinst b/debian/huawei-wmi-1.1.0/debian/preinst index eff0adc..1f2bccd 100644 --- a/debian/huawei-wmi-1.1.0/debian/preinst +++ b/debian/huawei-wmi-1.1.0/debian/preinst @@ -4,7 +4,7 @@ DEF=/etc/default/huawei-wmi/ if [ "$1" = upgrade ] then - rm --force ${DEF}README.md + rm --force -- "${DEF}README.md" fi #DEBHELPER# diff --git a/generic/Makefile b/generic/Makefile index 423bc15..fae026f 100644 --- a/generic/Makefile +++ b/generic/Makefile @@ -21,7 +21,7 @@ all: install: users groupadd --system huawei-wmi 2> /dev/null || true for user in $$(cat $<); do \ - usermod --append --groups huawei-wmi "$$user"; \ + usermod --append --groups huawei-wmi -- "$$user"; \ done install -d $(DEF) chmod g+s $(DEF) @@ -30,7 +30,7 @@ install: users install $(SRC)huawei-wmi-privilege.service $(SYSTEMD) install $(SRC)huawei-wmi-reinstate.service $(SYSTEMD) install -d $(LIB) - install $(SRC)constants $(LIB) + install $(SRC)available $(LIB) install $(SRC)privilege $(LIB) install $(SRC)reinstate $(LIB) systemctl daemon-reload @@ -56,7 +56,7 @@ remove: rm --force $(UDEV)10-huawei-wmi.rules rm --force $(SYSTEMD)huawei-wmi-privilege.service rm --force $(SYSTEMD)huawei-wmi-reinstate.service - rm --force $(LIB)constants + rm --force $(LIB)available rm --force $(LIB)privilege rm --force $(LIB)reinstate rmdir $(LIB) || true diff --git a/generic/huawei-wmi-1.1.0/available b/generic/huawei-wmi-1.1.0/available new file mode 100755 index 0000000..d2107cd --- /dev/null +++ b/generic/huawei-wmi-1.1.0/available @@ -0,0 +1,30 @@ +#! /bin/sh -e + +readonly DEF=/etc/default/huawei-wmi/ +readonly WMI=/sys/devices/platform/huawei-wmi/ + +readonly CCT=charge_control_thresholds +readonly DCT=charge_thresholds +readonly FLS=fn_lock_state + +available() { + [ \( -e "$WMI$CCT" -o -e "$WMI$DCT" \) -a -e "$WMI$FLS" ] +} + +available || sleep 1 +available || { + echo No Huawei WMI available >&2 + exit 1 +} + +for wmi_xct in "$WMI$CCT" "$WMI$DCT" +do + if [ -e "$wmi_xct" ] + then + readonly cct=$(basename "$wmi_xct") + else + readonly dct=$(basename "$wmi_xct") + fi +done + +[ "$cct" -a "$dct" -a "$cct" != "$dct" ] diff --git a/generic/huawei-wmi-1.1.0/constants b/generic/huawei-wmi-1.1.0/constants deleted file mode 100755 index aec1ca3..0000000 --- a/generic/huawei-wmi-1.1.0/constants +++ /dev/null @@ -1,9 +0,0 @@ -#! /bin/sh -e - -readonly DEF=/etc/default/huawei-wmi/ -readonly WMI=/sys/devices/platform/huawei-wmi/ - -readonly CCT=charge*_thresholds -readonly FLS=fn_lock_state - -export DEF WMI CCT FLS diff --git a/generic/huawei-wmi-1.1.0/privilege b/generic/huawei-wmi-1.1.0/privilege index df01f91..1006f65 100755 --- a/generic/huawei-wmi-1.1.0/privilege +++ b/generic/huawei-wmi-1.1.0/privilege @@ -1,25 +1,11 @@ #! /bin/sh -e -. /usr/lib/huawei-wmi/constants +. /usr/lib/huawei-wmi/available -[ -e $WMI$CCT -a -e $WMI$FLS ] || sleep 1 +[ -e "$DEF$dct" ] && mv --force -- "$DEF$dct" "$DEF$cct" -[ -e $WMI$CCT -a -e $WMI$FLS ] || { - echo >&2 "No Huawei WMI available" - exit 1 -} +[ -e "$DEF$cct" ] || cp -- "$WMI$cct" "$DEF" +chmod g=u -- "$DEF$cct" -if [ -e $DEF$CCT ] -then - wmi_cct=$(basename $WMI$CCT) - for def_cct in $DEF$CCT - do - [ $(basename $def_cct) = $wmi_cct ] || mv --force $def_cct $DEF$wmi_cct - done -else - cp $WMI$CCT $DEF - chmod g=u $DEF$CCT -fi - -chgrp huawei-wmi $WMI$CCT $WMI$FLS -chmod g=u $WMI$CCT $WMI$FLS +chgrp huawei-wmi -- "$WMI$cct" "$WMI$FLS" +chmod g=u -- "$WMI$cct" "$WMI$FLS" diff --git a/generic/huawei-wmi-1.1.0/reinstate b/generic/huawei-wmi-1.1.0/reinstate index 9decd4f..7713f88 100755 --- a/generic/huawei-wmi-1.1.0/reinstate +++ b/generic/huawei-wmi-1.1.0/reinstate @@ -1,7 +1,7 @@ #! /bin/sh -e -. /usr/lib/huawei-wmi/constants +. /usr/lib/huawei-wmi/available -echo Old charge control thresholds $(cat $WMI$CCT) -cp $DEF$CCT $WMI -echo New charge control thresholds $(cat $WMI$CCT) +echo Old battery charge-thresholds "$(cat -- "$WMI$cct")" +cp -- "$DEF$cct" "$WMI" +echo New battery charge-thresholds "$(cat -- "$WMI$cct")"