Skip to content

Commit e373861

Browse files
authored
avoid "install /dev/stdin" (#94)
1 parent 7b1de34 commit e373861

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

debian/rules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ override_dh_auto_install:
1919
install -D "$$BOUNCER" -t "debian/$$PKG/usr/bin/"; \
2020
install -D "scripts/_bouncer.sh" -t "debian/$$PKG/usr/lib/$$PKG/"; \
2121
install -D "config/$$BOUNCER.yaml" "debian/$$PKG/etc/crowdsec/bouncers/$$BOUNCER.yaml"; \
22-
BIN="/usr/bin/$$BOUNCER" CFG="/etc/crowdsec/bouncers" envsubst '$$BIN $$CFG' < "config/$$BOUNCER.service" | install -D /dev/stdin "debian/$$PKG/lib/systemd/system/$$BOUNCER.service"; \
22+
BIN="/usr/bin/$$BOUNCER" CFG="/etc/crowdsec/bouncers" envsubst '$$BIN $$CFG' < "config/$$BOUNCER.service" > "debian/$$PKG/lib/systemd/system/$$BOUNCER.service"
2323
mkdir -p "debian/$$PKG/usr/lib/$$PKG/lua"; \
2424
mkdir -p "debian/$$PKG/usr/share/doc/$$PKG/examples"; \
2525
install -D "config/crowdsec.cfg" -t "debian/$$PKG/usr/share/doc/$$PKG/examples/"; \

rpm/SPECS/crowdsec-haproxy-spoa-bouncer.spec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ install -m 600 -D config/%{binary_name}.yaml %{buildroot}/etc/crowdsec/bouncers/
4141
install -m 600 -D scripts/_bouncer.sh %{buildroot}/usr/lib/%{name}/_bouncer.sh
4242
install -m 644 -D config/crowdsec.cfg %{buildroot}/%{_docdir}/%{name}/examples/crowdsec.cfg
4343
install -m 644 -D config/haproxy.cfg %{buildroot}/%{_docdir}/%{name}/examples/haproxy.cfg
44-
BIN=%{_bindir}/%{binary_name} CFG=/etc/crowdsec/bouncers envsubst '$BIN $CFG' < config/%{binary_name}.service | install -m 0644 -D /dev/stdin %{buildroot}%{_unitdir}/%{binary_name}.service
44+
mkdir -p %{buildroot}%{_unitdir}
45+
BIN=%{_bindir}/%{binary_name} CFG=/etc/crowdsec/bouncers envsubst '$BIN $CFG' < config/%{binary_name}.service > %{buildroot}%{_unitdir}/%{binary_name}.service
4546
install -D lua/crowdsec.lua %{buildroot}/usr/lib/%{name}/lua/crowdsec.lua
4647
install -D lua/utils.lua %{buildroot}/usr/lib/%{name}/lua/utils.lua
4748
install -D lua/template.lua %{buildroot}/usr/lib/%{name}/lua/template.lua

scripts/_bouncer.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ BOUNCER_PREFIX=$(echo "$BOUNCER" | sed 's/crowdsec-/cs-/g')
1616
# some environment variables with the functions. It's a matter of
1717
# readability balance between shorter vs cleaner code.
1818

19-
if [ ! -t 0 ]; then
19+
if [ -n "${NO_COLOR-}" ] || [ ! -t 1 ]; then
2020
# terminal is not interactive; no colors
2121
FG_RED=""
2222
FG_GREEN=""
2323
FG_YELLOW=""
2424
FG_CYAN=""
2525
RESET=""
26-
elif tput sgr0 >/dev/null 2>&1; then
26+
elif [ -n "${TERM-}" ] && tput sgr0 >/dev/null 2>&1; then
2727
# terminfo
2828
FG_RED=$(tput setaf 1)
2929
FG_GREEN=$(tput setaf 2)
@@ -124,9 +124,8 @@ set_config_var_value() {
124124
fi
125125

126126
before=$(cat "$CONFIG")
127-
echo "$before" |
128-
env "$varname=$value" envsubst "\$$varname" |
129-
install -m 0600 /dev/stdin "$CONFIG"
127+
(umask 177 && echo "$before" | \
128+
env "$varname=$value" envsubst "\$$varname" >"$CONFIG")
130129
}
131130

132131
set_api_key() {

scripts/install.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ gen_apikey() {
2626

2727
gen_config_file() {
2828
# shellcheck disable=SC2016
29-
API_KEY=${API_KEY} envsubst '$API_KEY' <"./config/$CONFIG_FILE" | \
30-
install -D -m 0600 /dev/stdin "$CONFIG"
29+
(umask 177 && API_KEY="$API_KEY" envsubst '$API_KEY' <"./config/$CONFIG_FILE" > "$CONFIG")
3130
}
3231

3332
install_bouncer() {
@@ -41,7 +40,7 @@ install_bouncer() {
4140
fi
4241
msg info "Installing $BOUNCER"
4342
install -v -m 0755 -D "$BIN_PATH" "$BIN_PATH_INSTALLED"
44-
install -D -m 0600 "./config/$CONFIG_FILE" "$CONFIG"
43+
mkdir -p "$(dirname "$CONFIG")"
4544
# shellcheck disable=SC2016
4645
CFG=${CONFIG_DIR} BIN=${BIN_PATH_INSTALLED} envsubst '$CFG $BIN' <"./config/$SERVICE" >"$SYSTEMD_PATH_FILE"
4746
systemctl daemon-reload

0 commit comments

Comments
 (0)