#!/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 if [ "$(id -u)" -ne 0 ]; then echo "You need to be root to run ${0} !" >&2 exit 1 fi 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 echo "Failed to find a suitable lib directory for bkctld." >&2 exit 1 fi # shellcheck source=lib/includes . "${LIBDIR}/includes" subcommand="${1:-}" case "${subcommand}" in "inc" | "rm" | "check" | "stats" | "help" | "list") "${LIBDIR}/bkctld-${subcommand}" ;; "check-incs") option="${2:-}" if [ "${option}" = "all" ] || [ -z "${option}" ]; then "${LIBDIR}/bkctld-check-incs" elif [ "${option}" = "last" ]; then "${LIBDIR}/bkctld-check-last-incs" else "${LIBDIR}/bkctld-help" exit 1 fi ;; "init" | "is-on") jail_name="${2:-}" "${LIBDIR}/bkctld-${subcommand}" "${jail_name}" ;; "key" | "port" | "ip") jail_name="${2:-}" option="${3:-}" "${LIBDIR}/bkctld-${subcommand}" "${jail_name}" "${option}" ;; "start" | "stop" | "reload" | "restart" | "sync" | "update" | "remove" | "firewall") jail_name="${2:-}" 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") jail_name="${2:-}" 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 ;; *) "${LIBDIR}/bkctld-help" exit 1 ;; esac