Fix shellcheck warnings

This commit is contained in:
Victor LABORIE 2017-07-19 14:02:49 +02:00
parent b8e4c3f11b
commit 8ac454dae0

38
bkctld
View file

@ -75,8 +75,8 @@ get_key() {
get_ip() { get_ip() {
jail=$1 jail=$1
for allow in $(grep -E "^AllowUsers" ${JAILDIR}/$jail/${SSHD_CONFIG}|grep -Eo "root@[^ ]+"); do grep -E "^AllowUsers" "${JAILDIR}/$jail/${SSHD_CONFIG}"|grep -Eo "root@[^ ]+"| while read allow; do
echo $allow|cut -d'@' -f2 echo "$allow"|cut -d'@' -f2
done done
} }
@ -97,7 +97,7 @@ set_port() {
jail=$1 jail=$1
port=$2 port=$2
if [ "$port" = "auto" ]; then if [ "$port" = "auto" ]; then
port=$(grep -h Port ${JAILDIR}/*/${SSHD_CONFIG} 2>/dev/null | grep -Eo [0-9]+ | sort -n | tail -1) port=$(grep -h Port ${JAILDIR}/*/${SSHD_CONFIG} 2>/dev/null | grep -Eo "[0-9]+" | sort -n | tail -1)
port=$((port+1)) port=$((port+1))
if [ ! $port -gt 1 ]; then if [ ! $port -gt 1 ]; then
port=2222 port=2222
@ -210,7 +210,8 @@ sub_init() {
fi fi
echo "Create jail $jail :" echo "Create jail $jail :"
rootdir_inode=$(stat --format=%i $(dirname $JAILDIR)) rootdir=$(dirname "$JAILDIR")
rootdir_inode=$(stat --format=%i "$rootdir")
jaildir_inode=$(stat --format=%i $JAILDIR) jaildir_inode=$(stat --format=%i $JAILDIR)
if [ "$rootdir_inode" -eq 256 ] || [ "$jaildir_inode" -eq 256 ]; then if [ "$rootdir_inode" -eq 256 ] || [ "$jaildir_inode" -eq 256 ]; then
/sbin/btrfs subvolume create ${JAILDIR}/${jail} /sbin/btrfs subvolume create ${JAILDIR}/${jail}
@ -263,7 +264,8 @@ sub_remove() {
rm -rf ${JAILDIR}/${jail} rm -rf ${JAILDIR}/${jail}
fi fi
if [ -d ${INCDIR}/${jail} ]; then if [ -d ${INCDIR}/${jail} ]; then
for inc in $(ls ${INCDIR}/${jail}); do incs=$(ls ${INCDIR}/${jail})
for inc in $incs; do
inc_inode=$(stat --format=%i ${INCDIR}/${jail}/$inc) inc_inode=$(stat --format=%i ${INCDIR}/${jail}/$inc)
if [ "$inc_inode" -eq 256 ]; then if [ "$inc_inode" -eq 256 ]; then
/sbin/btrfs subvolume delete ${INCDIR}/${jail}/${inc} /sbin/btrfs subvolume delete ${INCDIR}/${jail}/${inc}
@ -409,7 +411,8 @@ sub_sync() {
sub_inc() { sub_inc() {
date=$(date +"%Y-%m-%d-%H") date=$(date +"%Y-%m-%d-%H")
incs_logs="" incs_logs=""
for jail in $(ls -1 $JAILDIR); do jails=$(ls $JAILDIR)
for jail in $jails; do
inc="${INCDIR}/${jail}/${date}" inc="${INCDIR}/${jail}/${date}"
mkdir -p ${INCDIR}/${jail} mkdir -p ${INCDIR}/${jail}
if [ ! -d "${inc}" ]; then if [ ! -d "${inc}" ]; then
@ -421,9 +424,9 @@ sub_inc() {
cp -alx ${JAILDIR}/${jail}/ $inc cp -alx ${JAILDIR}/${jail}/ $inc
fi fi
end=$(date +"%H:%M:%S") end=$(date +"%H:%M:%S")
inc_log=$(echo "Create $date inc of $jail (Start at $start / End at $end)") inc_log="Create $date inc of $jail (Start at $start / End at $end)"
echo "${inc_log}" echo "${inc_log}"
incs_logs=$(echo "${incs_logs}"; echo "${inc_log}") incs_logs="${incs_logs} ${inc_log}"
else else
echo "Inc $date of $jail already exist !" >&2 echo "Inc $date of $jail already exist !" >&2
fi fi
@ -455,8 +458,9 @@ sub_rm() {
fi fi
echo $$ > $pidfile echo $$ > $pidfile
rms_logs="" rms_logs=""
for jail in $( ls -1 $JAILDIR ); do jails=$(ls $JAILDIR)
incs=$(ls -1 ${INCDIR}/$jail) for jail in $jails; do
incs=$(ls ${INCDIR}/$jail)
if [ -f ${CONFDIR}/$jail ]; then if [ -f ${CONFDIR}/$jail ]; then
keepfile="${CONFDIR}/.keep-${jail}" keepfile="${CONFDIR}/.keep-${jail}"
while read j; do while read j; do
@ -498,16 +502,16 @@ log() {
shift shift
tty -s tty -s
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
sub_${subcommand} $@ 2>&1 | tee -a $logfile sub_${subcommand} "$@" 2>&1 | tee -a $logfile
else else
sub_${subcommand} $@ 2>&1 >> $logfile sub_${subcommand} "$@" > $logfile 2>&1
fi fi
} }
## main function : check usage and valid params ## main function : check usage and valid params
main() { main() {
if [ $(id -u) != 0 ]; then if [ "$(id -u)" -ne 0 ]; then
echo "Error, you need to be root to run $0 !" >&2 echo "Error, you need to be root to run $0 !" >&2
exit 1 exit 1
fi fi
@ -549,7 +553,8 @@ main() {
"start" | "stop" | "reload" | "restart" | "sync" | "update" | "remove") "start" | "stop" | "reload" | "restart" | "sync" | "update" | "remove")
if [ -n "${jail}" ]; then if [ -n "${jail}" ]; then
if [ "${jail}" = "all" ]; then if [ "${jail}" = "all" ]; then
for jail in $(ls $JAILDIR); do jails=$(ls $JAILDIR)
for jail in $jails; do
case $subcommand in case $subcommand in
"start") "start")
if ! ( check_jail_on $jail ); then if ! ( check_jail_on $jail ); then
@ -588,11 +593,12 @@ main() {
;; ;;
"status") "status")
if [ -z "${jail}" ]; then if [ -z "${jail}" ]; then
for jail in $(ls $JAILDIR); do jails=$(ls $JAILDIR)
for jail in $jails; do
sub_$subcommand $jail sub_$subcommand $jail
done done
else else
sub_$subcommand $jail sub_$subcommand $jail
fi fi
;; ;;
*) *)