Merge pull request #713 from darko-poljak/shellcheck-files-scripts
shellcheck on /files/ scripts.
This commit is contained in:
commit
5e99219ea5
10 changed files with 115 additions and 91 deletions
|
@ -31,9 +31,11 @@
|
||||||
### END INIT INFO
|
### END INIT INFO
|
||||||
|
|
||||||
if [ -f "/etc/default/consul" ]; then
|
if [ -f "/etc/default/consul" ]; then
|
||||||
|
# shellcheck disable=SC1091
|
||||||
. /etc/default/consul
|
. /etc/default/consul
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# shellcheck disable=SC1091
|
||||||
. /lib/lsb/init-functions
|
. /lib/lsb/init-functions
|
||||||
|
|
||||||
NAME=consul
|
NAME=consul
|
||||||
|
|
|
@ -11,49 +11,52 @@
|
||||||
# pidfile: /var/run/consul/pidfile
|
# pidfile: /var/run/consul/pidfile
|
||||||
|
|
||||||
# Source function library.
|
# Source function library.
|
||||||
|
|
||||||
|
# shellcheck disable=SC1091
|
||||||
. /etc/init.d/functions
|
. /etc/init.d/functions
|
||||||
NAME=consul
|
NAME=consul
|
||||||
CONSUL=/usr/local/bin/consul
|
CONSUL=/usr/local/bin/consul
|
||||||
CONFIG=/etc/$NAME/conf.d
|
CONFIG="/etc/$NAME/conf.d"
|
||||||
PID_FILE=/var/run/$NAME/pidfile
|
PID_FILE="/var/run/$NAME/pidfile"
|
||||||
LOG_FILE=/var/log/$NAME
|
LOG_FILE="/var/log/$NAME"
|
||||||
|
|
||||||
[ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
|
# shellcheck disable=SC1090
|
||||||
export GOMAXPROCS=${GOMAXPROCS:-2}
|
[ -e "/etc/sysconfig/$NAME" ] && . "/etc/sysconfig/$NAME"
|
||||||
|
export GOMAXPROCS="${GOMAXPROCS:-2}"
|
||||||
|
|
||||||
mkdir -p /var/run/$NAME
|
mkdir -p "/var/run/$NAME"
|
||||||
chown consul:consul /var/run/$NAME
|
chown consul:consul "/var/run/$NAME"
|
||||||
chmod 2770 /var/run/$NAME
|
chmod 2770 "/var/run/$NAME"
|
||||||
|
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
echo -n "Starting $NAME: "
|
printf "Starting %s: " "$NAME"
|
||||||
daemon --user=consul \
|
daemon --user=consul \
|
||||||
--pidfile="$PID_FILE" \
|
--pidfile="$PID_FILE" \
|
||||||
"$CONSUL" agent -pid-file="$PID_FILE" -config-dir "$CONFIG" >> "$LOG_FILE" &
|
"$CONSUL" agent -pid-file="$PID_FILE" -config-dir "$CONFIG" >> "$LOG_FILE" &
|
||||||
retcode=$?
|
retcode=$?
|
||||||
touch /var/lock/subsys/$NAME
|
touch "/var/lock/subsys/$NAME"
|
||||||
return $retcode
|
return "$retcode"
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
echo -n "Shutting down $NAME: "
|
printf "Shutting down %s: " "$NAME"
|
||||||
killproc -p "$PID_FILE" $NAME
|
killproc -p "$PID_FILE" "$NAME"
|
||||||
retcode=$?
|
retcode=$?
|
||||||
rm -f /var/lock/subsys/$NAME
|
rm -f "/var/lock/subsys/$NAME"
|
||||||
return $retcode
|
return "$retcode"
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
if $(status -p "$PID_FILE" $NAME >/dev/null); then
|
if status -p "$PID_FILE" "$NAME" >/dev/null; then
|
||||||
echo "$NAME already running"
|
echo "$NAME already running"
|
||||||
else
|
else
|
||||||
start
|
start
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
if $(status -p "$PID_FILE" $NAME >/dev/null); then
|
if status -p "$PID_FILE" "$NAME" >/dev/null; then
|
||||||
stop
|
stop
|
||||||
else
|
else
|
||||||
echo "$NAME not running"
|
echo "$NAME not running"
|
||||||
|
@ -63,25 +66,25 @@ case "$1" in
|
||||||
"$CONSUL" info
|
"$CONSUL" info
|
||||||
;;
|
;;
|
||||||
status)
|
status)
|
||||||
status -p "$PID_FILE" $NAME
|
status -p "$PID_FILE" "$NAME"
|
||||||
exit $?
|
exit $?
|
||||||
;;
|
;;
|
||||||
restart)
|
restart)
|
||||||
if $(status -p "$PID_FILE" $NAME >/dev/null); then
|
if status -p "$PID_FILE" "$NAME" >/dev/null; then
|
||||||
stop
|
stop
|
||||||
fi
|
fi
|
||||||
start
|
start
|
||||||
;;
|
;;
|
||||||
reload)
|
reload)
|
||||||
if $(status -p "$PID_FILE" $NAME >/dev/null); then
|
if status -p "$PID_FILE" "$NAME" >/dev/null; then
|
||||||
kill -HUP `cat $PID_FILE`
|
kill -HUP "$(cat "$PID_FILE")"
|
||||||
else
|
else
|
||||||
echo "$NAME not running"
|
echo "$NAME not running"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
condrestart)
|
condrestart)
|
||||||
if [ -f /var/lock/subsys/$NAME ]; then
|
if [ -f "/var/lock/subsys/$NAME" ]; then
|
||||||
if $(status -p "$PID_FILE" $NAME >/dev/null); then
|
if status -p "$PID_FILE" "$NAME" >/dev/null; then
|
||||||
stop
|
stop
|
||||||
fi
|
fi
|
||||||
start
|
start
|
||||||
|
|
|
@ -10,72 +10,75 @@
|
||||||
# pidfile: /var/run/consul-template/pidfile
|
# pidfile: /var/run/consul-template/pidfile
|
||||||
|
|
||||||
# Source function library.
|
# Source function library.
|
||||||
|
|
||||||
|
# shellcheck disable=SC1091
|
||||||
. /etc/init.d/functions
|
. /etc/init.d/functions
|
||||||
NAME=consul-template
|
NAME=consul-template
|
||||||
CONSUL_TEMPLATE=/usr/local/bin/consul-template
|
CONSUL_TEMPLATE=/usr/local/bin/consul-template
|
||||||
CONFIG=/etc/$NAME/conf.d
|
CONFIG="/etc/$NAME/conf.d"
|
||||||
PID_FILE=/var/run/$NAME/pidfile
|
PID_FILE="/var/run/$NAME/pidfile"
|
||||||
LOG_FILE=/var/log/$NAME
|
LOG_FILE="/var/log/$NAME"
|
||||||
|
|
||||||
[ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
|
# shellcheck disable=SC1090
|
||||||
export CONSUL_TEMPLATE_LOG=${CONSUL_TEMPLATE_LOG:-info}
|
[ -e "/etc/sysconfig/$NAME" ] && . "/etc/sysconfig/$NAME"
|
||||||
export GOMAXPROCS=${GOMAXPROCS:-2}
|
export CONSUL_TEMPLATE_LOG="${CONSUL_TEMPLATE_LOG:-info}"
|
||||||
|
export GOMAXPROCS="${GOMAXPROCS:-2}"
|
||||||
|
|
||||||
mkdir -p /var/run/$NAME
|
mkdir -p "/var/run/$NAME"
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
echo -n "Starting $NAME: "
|
printf "Starting %s: " "$NAME"
|
||||||
daemon --pidfile="$PID_FILE" \
|
daemon --pidfile="$PID_FILE" \
|
||||||
"$CONSUL_TEMPLATE" -config "$CONFIG" >> "$LOG_FILE" 2>&1 &
|
"$CONSUL_TEMPLATE" -config "$CONFIG" >> "$LOG_FILE" 2>&1 &
|
||||||
echo $! > "$PID_FILE"
|
echo "$!" > "$PID_FILE"
|
||||||
retcode=$?
|
retcode=$?
|
||||||
touch /var/lock/subsys/$NAME
|
touch "/var/lock/subsys/$NAME"
|
||||||
return $retcode
|
return "$retcode"
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
echo -n "Shutting down $NAME: "
|
printf "Shutting down %s: " "$NAME"
|
||||||
killproc -p $PID_FILE $CONSUL_TEMPLATE
|
killproc -p "$PID_FILE" "$CONSUL_TEMPLATE"
|
||||||
retcode=$?
|
retcode=$?
|
||||||
rm -f /var/lock/subsys/$NAME
|
rm -f "/var/lock/subsys/$NAME"
|
||||||
return $retcode
|
return "$retcode"
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
if $(status -p "$PID_FILE" $NAME >/dev/null); then
|
if status -p "$PID_FILE" "$NAME" >/dev/null; then
|
||||||
echo "$NAME already running"
|
echo "$NAME already running"
|
||||||
else
|
else
|
||||||
start
|
start
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
if $(status -p "$PID_FILE" $NAME >/dev/null); then
|
if status -p "$PID_FILE" "$NAME" >/dev/null; then
|
||||||
stop
|
stop
|
||||||
else
|
else
|
||||||
echo "$NAME not running"
|
echo "$NAME not running"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
status)
|
status)
|
||||||
status -p "$PID_FILE" $NAME
|
status -p "$PID_FILE" "$NAME"
|
||||||
exit $?
|
exit $?
|
||||||
;;
|
;;
|
||||||
restart)
|
restart)
|
||||||
if $(status -p "$PID_FILE" $NAME >/dev/null); then
|
if status -p "$PID_FILE" "$NAME" >/dev/null; then
|
||||||
stop
|
stop
|
||||||
fi
|
fi
|
||||||
start
|
start
|
||||||
;;
|
;;
|
||||||
reload)
|
reload)
|
||||||
if $(status -p "$PID_FILE" $NAME >/dev/null); then
|
if status -p "$PID_FILE" "$NAME" >/dev/null; then
|
||||||
kill -HUP `cat $PID_FILE`
|
kill -HUP "$(cat "$PID_FILE")"
|
||||||
else
|
else
|
||||||
echo "$NAME not running"
|
echo "$NAME not running"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
condrestart)
|
condrestart)
|
||||||
if [ -f /var/lock/subsys/$NAME ]; then
|
if [ -f "/var/lock/subsys/$NAME" ]; then
|
||||||
if $(status -p "$PID_FILE" $NAME >/dev/null); then
|
if status -p "$PID_FILE" "$NAME" >/dev/null; then
|
||||||
stop
|
stop
|
||||||
fi
|
fi
|
||||||
start
|
start
|
||||||
|
|
|
@ -23,9 +23,9 @@ fi
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
echo -n "Starting daemontools: "
|
printf "Starting daemontools: "
|
||||||
if [ ! `pidof svscan` ]; then
|
if ! pidof svscan > /dev/null 2>&1; then
|
||||||
echo -n "svscan "
|
printf "svscan "
|
||||||
env - PATH="$PATH" svscan /service 2>&1 | setuidgid daemon multilog t /var/log/svscan &
|
env - PATH="$PATH" svscan /service 2>&1 | setuidgid daemon multilog t /var/log/svscan &
|
||||||
echo "."
|
echo "."
|
||||||
else
|
else
|
||||||
|
@ -33,23 +33,28 @@ case "$1" in
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
echo -n "Stopping daemontools: "
|
printf "Stopping daemontools: "
|
||||||
if [ `pidof svscan` ]; then
|
pids="$(pidof svscan)"
|
||||||
echo -n "svscan"
|
if [ -n "${pids}" ]
|
||||||
while [ `pidof svscan` ]; do
|
then
|
||||||
kill `pidof svscan`
|
printf "svscan"
|
||||||
echo -n "."
|
while [ -n "${pids}" ]
|
||||||
|
do
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
kill ${pids}
|
||||||
|
printf "."
|
||||||
|
pids="$(pidof svscan)"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
echo -n " services"
|
printf " services"
|
||||||
for i in `ls -d /service/*`; do
|
for i in /service/*; do
|
||||||
svc -dx $i
|
svc -dx "$i"
|
||||||
echo -n "."
|
printf "."
|
||||||
done
|
done
|
||||||
echo -n " logging "
|
printf " logging "
|
||||||
for i in `ls -d /service/*/log`; do
|
for i in /service/*/log; do
|
||||||
svc -dx $i
|
svc -dx "$i"
|
||||||
echo -n "."
|
printf "."
|
||||||
done
|
done
|
||||||
echo ""
|
echo ""
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -37,10 +37,12 @@ code="$(echo "$@" | sed "s|$target_host:|$target_host:$chroot|g")"
|
||||||
|
|
||||||
log "target_host: $target_host"
|
log "target_host: $target_host"
|
||||||
log "chroot: $chroot"
|
log "chroot: $chroot"
|
||||||
log "@: $@"
|
log "@: $*"
|
||||||
log "code: $code"
|
log "code: $code"
|
||||||
|
|
||||||
# copy files into chroot
|
# copy files into chroot
|
||||||
|
# __default_remote_copy and code should be split
|
||||||
|
# shellcheck disable=SC2086
|
||||||
$__default_remote_copy $code
|
$__default_remote_copy $code
|
||||||
|
|
||||||
log "-----"
|
log "-----"
|
||||||
|
|
|
@ -36,14 +36,17 @@ shift
|
||||||
|
|
||||||
# escape ' with '"'"'
|
# escape ' with '"'"'
|
||||||
code="$(echo "$@" | sed -e "s/'/'\"'\"'/g")"
|
code="$(echo "$@" | sed -e "s/'/'\"'\"'/g")"
|
||||||
|
# shellcheck disable=SC2089
|
||||||
code="chroot $chroot sh -e -c '$code'"
|
code="chroot $chroot sh -e -c '$code'"
|
||||||
|
|
||||||
log "target_host: $target_host"
|
log "target_host: $target_host"
|
||||||
log "chroot: $chroot"
|
log "chroot: $chroot"
|
||||||
log "@: $@"
|
log "@: $*"
|
||||||
log "code: $code"
|
log "code: $code"
|
||||||
|
|
||||||
# Run the code
|
# Run the code
|
||||||
$__default_remote_exec $target_host $code
|
# __default_remote_exec and code should be split
|
||||||
|
# shellcheck disable=SC2086,SC2090
|
||||||
|
$__default_remote_exec "$target_host" $code
|
||||||
|
|
||||||
log "-----"
|
log "-----"
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
echo "[__install_partition_msdos_apply] $@" >&2
|
echo "[__install_partition_msdos_apply] $*" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
debug() {
|
debug() {
|
||||||
#echo "[__install_partition_msdos_apply] $@" >&2
|
#echo "[__install_partition_msdos_apply] $*" >&2
|
||||||
:
|
:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +14,7 @@ fdisk_command() {
|
||||||
cmd="$2"
|
cmd="$2"
|
||||||
|
|
||||||
debug fdisk_command "running fdisk command '${cmd}' on device ${device}"
|
debug fdisk_command "running fdisk command '${cmd}' on device ${device}"
|
||||||
printf "${cmd}\nw\n" | fdisk -c -u "$device"
|
printf '%s\nw\n' "${cmd}" | fdisk -c -u "$device"
|
||||||
ret=$?
|
ret=$?
|
||||||
# give disk some time
|
# give disk some time
|
||||||
sleep 1
|
sleep 1
|
||||||
|
@ -23,14 +25,14 @@ create_disklabel() {
|
||||||
device=$1
|
device=$1
|
||||||
|
|
||||||
debug create_disklabel "creating new msdos disklabel"
|
debug create_disklabel "creating new msdos disklabel"
|
||||||
fdisk_command ${device} "o"
|
fdisk_command "${device}" "o"
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle_bootable() {
|
toggle_bootable() {
|
||||||
device="$1"
|
device="$1"
|
||||||
minor="$2"
|
minor="$2"
|
||||||
fdisk_command ${device} "a\n${minor}\n"
|
fdisk_command "${device}" "a\\n${minor}\\n"
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,28 +43,28 @@ create_partition() {
|
||||||
type="$4"
|
type="$4"
|
||||||
primary_count="$5"
|
primary_count="$5"
|
||||||
|
|
||||||
if [ "$type" = "extended" -o "$type" = "5" ]; then
|
if [ "$type" = "extended" ] || [ "$type" = "5" ]; then
|
||||||
# Extended partition
|
# Extended partition
|
||||||
primary_extended="e\n"
|
primary_extended='e\n'
|
||||||
first_minor="${minor}\n"
|
first_minor="${minor}\\n"
|
||||||
[ "${minor}" = "4" ] && first_minor=""
|
[ "${minor}" = "4" ] && first_minor=""
|
||||||
type_minor="${minor}\n"
|
type_minor="${minor}\\n"
|
||||||
[ "${minor}" = "1" ] && type_minor=""
|
[ "${minor}" = "1" ] && type_minor=""
|
||||||
type="5"
|
type="5"
|
||||||
elif [ "${minor}" -lt "5" ]; then
|
elif [ "${minor}" -lt "5" ]; then
|
||||||
primary_extended="p\n"
|
primary_extended='p\n'
|
||||||
first_minor="${minor}\n"
|
first_minor="${minor}\\n"
|
||||||
[ "${minor}" = "4" ] && first_minor=""
|
[ "${minor}" = "4" ] && first_minor=""
|
||||||
type_minor="${minor}\n"
|
type_minor="${minor}\\n"
|
||||||
[ "${minor}" = "1" ] && type_minor=""
|
[ "${minor}" = "1" ] && type_minor=""
|
||||||
else
|
else
|
||||||
# Logical partitions
|
# Logical partitions
|
||||||
first_minor="${minor}\n"
|
first_minor="${minor}\\n"
|
||||||
type_minor="${minor}\n"
|
type_minor="${minor}\\n"
|
||||||
primary_extended="l\n"
|
primary_extended='l\n'
|
||||||
[ "$primary_count" -gt "3" ] && primary_extended=""
|
[ "$primary_count" -gt "3" ] && primary_extended=""
|
||||||
fi
|
fi
|
||||||
[ -n "${size}" ] && size="+${size}M"
|
[ -n "${size}" ] && size="+${size}M"
|
||||||
fdisk_command ${device} "n\n${primary_extended}${first_minor}\n${size}\nt\n${type_minor}${type}\n"
|
fdisk_command "${device}" "n\\n${primary_extended}${first_minor}\\n${size}\\nt\\n${type_minor}${type}\\n"
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,15 @@ case $1 in
|
||||||
iptables-save > "$status"
|
iptables-save > "$status"
|
||||||
|
|
||||||
# Apply our ruleset
|
# Apply our ruleset
|
||||||
cd "$basedir"
|
cd "$basedir" || exit
|
||||||
count="$(ls -1 | wc -l)"
|
count="$(find . ! -name . -prune | wc -l)"
|
||||||
|
|
||||||
# Only do something if there are rules
|
# Only do something if there are rules
|
||||||
if [ "$count" -ge 1 ]; then
|
if [ "$count" -ge 1 ]; then
|
||||||
for rule in *; do
|
for rule in *; do
|
||||||
echo "Applying iptables rule $rule ..."
|
echo "Applying iptables rule $rule ..."
|
||||||
|
# Rule should be split.
|
||||||
|
# shellcheck disable=SC2046
|
||||||
iptables $(cat "$rule")
|
iptables $(cat "$rule")
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,19 +1,21 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
export key="$(cat "$__object/parameter/key" 2>/dev/null \
|
key="$(cat "$__object/parameter/key" 2>/dev/null \
|
||||||
|| echo "$__object_id")"
|
|| echo "$__object_id")"
|
||||||
export state="$(cat "$__object/parameter/state")"
|
state="$(cat "$__object/parameter/state")"
|
||||||
|
|
||||||
file="$(cat "$__object/parameter/file")"
|
file="$(cat "$__object/parameter/file")"
|
||||||
|
|
||||||
export delimiter="$(cat "$__object/parameter/delimiter")"
|
delimiter="$(cat "$__object/parameter/delimiter")"
|
||||||
export value="$(cat "$__object/parameter/value" 2>/dev/null \
|
value="$(cat "$__object/parameter/value" 2>/dev/null \
|
||||||
|| echo "__CDIST_NOTSET__")"
|
|| echo "__CDIST_NOTSET__")"
|
||||||
|
export key state delimiter value
|
||||||
if [ -f "$__object/parameter/exact_delimiter" ]; then
|
if [ -f "$__object/parameter/exact_delimiter" ]; then
|
||||||
export exact_delimiter=1
|
exact_delimiter=1
|
||||||
else
|
else
|
||||||
export exact_delimiter=0
|
exact_delimiter=0
|
||||||
fi
|
fi
|
||||||
|
export exact_delimiter
|
||||||
|
|
||||||
tmpfile=$(mktemp "${file}.cdist.XXXXXXXXXX")
|
tmpfile=$(mktemp "${file}.cdist.XXXXXXXXXX")
|
||||||
# preserve ownership and permissions by copying existing file over tmpfile
|
# preserve ownership and permissions by copying existing file over tmpfile
|
||||||
|
|
|
@ -43,7 +43,7 @@ for key in baseurl gpgkey; do
|
||||||
if [ -f "$__object/parameter/$key" ]; then
|
if [ -f "$__object/parameter/$key" ]; then
|
||||||
printf '%s=' "$key"
|
printf '%s=' "$key"
|
||||||
prefix=''
|
prefix=''
|
||||||
while read line; do
|
while read -r line; do
|
||||||
printf '%s%s\n' "$prefix" "$line"
|
printf '%s%s\n' "$prefix" "$line"
|
||||||
prefix=' '
|
prefix=' '
|
||||||
done < "$__object/parameter/$key"
|
done < "$__object/parameter/$key"
|
||||||
|
|
Loading…
Reference in a new issue