Files
dotfiles/env/.local/scripts/kanatactl
Michael Housh b87348da96 feat: Adds firewalld to system run and setup script.
feat: Move dotfiles location and update the appropriate environment variables.
2025-10-15 08:40:02 -04:00

93 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
set -o nounset
set -o pipefail
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
THIS_FILE=${BASH_SOURCE[0]}
LOG_LABEL=$(basename "$THIS_FILE")
THIS=${THIS:-$LOG_LABEL}
LOG_FILE=${LOG_FILE:-"$LOG_LABEL.log"}
XDG_DATA_HOME=${XDG_DATA_HOME:-"$HOME/.local/share"}
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-"$HOME/.config"}
DEV_ENV=${DEV_ENV:-""}
KBD=${KBD:-""} # Keyboard config to use, either "voyager" or "macbook"
usage() {
cat <<EOF
Manages kanata qmk keyboard program, which needs to be built locally. Currently the linux builds
are only for x86. Also manages the kanata systemd service.
USAGE:
$ $THIS <command> <flags>
FLAGS:
-h | --help: Show this help page.
COMMANDS:
config: Commands for the kanata keyboard configuration file(s).
service: Commands for the kanata systemd service.
pkg: Commands for the kanata package.
bootstrap: Bootstrap a new machine, performs installation, enables, and starts kanata systemd service.
logs: View the log file.
Run "$THIS <command> --help" for more information about a command.
EOF
}
# Logging utility function, use in place of echo.
log() {
logging log --source "$THIS_FILE" "$@"
}
# Bootstrap a new machine, by building and installing the kanata executable,
# installing the systemd service files, and enable / start the service.
bootstrap() {
log "Bootstrapping new system..."
$THIS_FILE pkg install
$THIS_FILE service install
$THIS_FILE service enable
$THIS_FILE service start
}
################################################################################
# MAIN
################################################################################
# Setup logging file and label.
source "$SCRIPTS/hypr/logging"
setup-logging "$LOG_FILE" "$LOG_LABEL"
while [[ $# -gt 0 ]]; do
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
usage && exit 0
elif [[ $1 == "bootstrap" ]]; then
bootstrap && exit 0
elif [[ $1 == "config" ]]; then
shift
THIS="$THIS config" $SCRIPTS/utils/kanatactl/config "$@"
exit $?
elif [[ $1 == "service" ]]; then
shift
THIS="$THIS service" $SCRIPTS/utils/kanatactl/service "$@"
exit $?
elif [[ $1 == "pkg" ]]; then
shift
THIS="$THIS pkg" $SCRIPTS/utils/kanatactl/pkg "$@"
exit $?
elif [[ $1 == "logs" ]]; then
bat ${LOG_DIR:-/tmp/logs}/$LOG_FILE && exit 0
elif [[ $1 == "update" ]]; then
install_or_update "Updating" && exit 0
else
break
fi
done
# If we've made it here, then we didn't handle the command.
usage && exit 1