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