#!/bin/sh # # bkctld is a shell script to create and manage a backup server which will # handle the backup of many servers (clients). # # Authors: Victor Laborie # Jérémy Lecour # Benoît Série # Gregory Colpart # Romain Dessort # Tristan Pilat # Licence: AGPLv3 # set -u [ "$(id -u)" -ne 0 ] && error "You need to be root to run ${0} !" basedir=$(dirname "$0") if [ "${basedir}" = "/usr/local/sbin" ] && [ -d "/usr/local/lib/bkctld" ]; then LIBDIR='/usr/local/lib/bkctld' elif [ "${basedir}" = "/usr/sbin" ] && [ -d "/usr/lib/bkctld" ]; then LIBDIR='/usr/lib/bkctld' elif [ -d './lib' ]; then LIBDIR='lib' else error "Failed to find a suitable lib directory for bkctld." fi # shellcheck source=lib/includes . "${LIBDIR}/includes" subcommand="${1:-}" jail_name="${2:-}" option="${3:-}" if [ ! -x "${LIBDIR}/bkctld-${subcommand}" ]; then "${LIBDIR}/bkctld-help" && exit 1 fi case "${subcommand}" in "inc" | "rm" | "check" | "stats" | "help" | "list") "${LIBDIR}/bkctld-${subcommand}" ;; "init" | "is-on") "${LIBDIR}/bkctld-${subcommand}" "${jail_name}" ;; "key" | "port" | "ip") "${LIBDIR}/bkctld-${subcommand}" "${jail_name}" "${option}" ;; "start" | "stop" | "reload" | "restart" | "sync" | "update" | "remove" | "firewall") if [ "${jail_name}" = "all" ]; then "${LIBDIR}/bkctld-list" | xargs --no-run-if-empty --max-args=1 --max-procs=0 "${LIBDIR}/bkctld-${subcommand}" else "${LIBDIR}/bkctld-${subcommand}" "${jail_name}" fi ;; "status") if [ "${jail_name}" = "all" ] || [ -z "${jail_name}" ]; then "${LIBDIR}/bkctld-list" | xargs --no-run-if-empty --max-args=1 "${LIBDIR}/bkctld-${subcommand}" else "${LIBDIR}/bkctld-${subcommand}" "${jail_name}" fi ;; esac