79 lines
1.4 KiB
Bash
Executable file
79 lines
1.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
# CONSTANTS
|
|
readonly PKGVER="1.0.0"
|
|
readonly LICENSE="GNU AGPLv3"
|
|
readonly ROOTPATH="$(dirname $(readlink -f $0))"
|
|
readonly MOTD_DIR="./etc/motd.d"
|
|
readonly MOTD_FILE="./etc/motd"
|
|
|
|
# VARIABLES
|
|
declare dryrun=false
|
|
|
|
function usage() {
|
|
echo -e "usage: $(basename ${0}) <operation>
|
|
operations:
|
|
$(basename ${0}) {-h --help}
|
|
$(basename ${0}) {-V --version}
|
|
$(basename ${0}) {-n --dryrun}"
|
|
}
|
|
|
|
function version() {
|
|
echo -e "Generate MOTD v${PKGVER}
|
|
Copyright (C) 2023 Noveria Network
|
|
|
|
This program may be freely redistributed under
|
|
the terms of the ${LICENSE}"
|
|
}
|
|
|
|
##
|
|
# SCRIPT START
|
|
##
|
|
|
|
OPT_SHORT="hVn"
|
|
OPT_LONG="help,version,dryrun"
|
|
|
|
TEMP=$(getopt -o ${OPT_SHORT} --long ${OPT_LONG} -n $(basename ${0}) -- "$@")
|
|
if [ "$?" != 0 ]; then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
eval set -- "$TEMP"
|
|
|
|
while true; do
|
|
case "$1" in
|
|
-h|--help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
-V|--version)
|
|
version
|
|
exit 0
|
|
;;
|
|
-n|--dryrun)
|
|
dryrun=true
|
|
;;
|
|
--)
|
|
shift
|
|
break
|
|
;;
|
|
*)
|
|
log w "$1 is not a valid parameter. Please refer to '$(basename ${0}) -h' for help!"
|
|
break
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if [[ -f "$MOTD_FILE" ]] && [[ "$dryrun" == false ]]; then
|
|
rm -f "$MOTD_FILE"
|
|
fi
|
|
|
|
for motdfile in $(find $MOTD_DIR -type f -name *.motd); do
|
|
if [[ "$dryrun" == false ]]; then
|
|
cat $motdfile >> "$MOTD_FILE"
|
|
else
|
|
cat $motdfile
|
|
fi
|
|
done
|