Skip to content

Commit

Permalink
Quote shell variables. Avoid wildcards.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rouven Spreckels committed Sep 20, 2019
1 parent d98ed4e commit 8ce9d01
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 53 deletions.
2 changes: 1 addition & 1 deletion debian/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*/10-huawei-wmi.rules
*/constants
*/available
*/privilege
*/reinstate
*/debian/huawei-wmi-privilege.service
Expand Down
16 changes: 8 additions & 8 deletions debian/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:;
2 changes: 1 addition & 1 deletion debian/huawei-wmi-1.1.0/debian/install
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions debian/huawei-wmi-1.1.0/debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -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#
7 changes: 4 additions & 3 deletions debian/huawei-wmi-1.1.0/debian/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion debian/huawei-wmi-1.1.0/debian/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -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#
6 changes: 3 additions & 3 deletions generic/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
30 changes: 30 additions & 0 deletions generic/huawei-wmi-1.1.0/available
Original file line number Diff line number Diff line change
@@ -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" ]
9 changes: 0 additions & 9 deletions generic/huawei-wmi-1.1.0/constants

This file was deleted.

26 changes: 6 additions & 20 deletions generic/huawei-wmi-1.1.0/privilege
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 4 additions & 4 deletions generic/huawei-wmi-1.1.0/reinstate
Original file line number Diff line number Diff line change
@@ -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")"

0 comments on commit 8ce9d01

Please sign in to comment.