Files
dao_hades/archive/install_cradle.sh
Jamie Albert e5d26bd32b Lazy commit
2025-11-06 02:30:35 +00:00

98 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# ---
# @file_name: install_cradle.sh
# @version: 1.0.0
# @description: Install local scripts
# @author: Jamie Albert (empty_produce)
# @author_contact: <mailto:empty.produce@flatmail.me>
# @license: GNU Affero General Public License v3.0 (Included in LICENSE)
# Copyright (C) 2025, Jamie Albert
# ---
set -euo pipefail
declare -gr INSTALL_DIR="/usr/local/bin"
declare -g SCRIPTS_DIR; SCRIPTS_DIR="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)/scripts"
declare -g CONFIG_DIR; CONFIG_DIR="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)/config"
declare -g DICT_DIR; DICT_DIR="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)/dict"
declare -ga TOOLS=("pwgen.sh" "jade.sh" "jau.sh" "rclone_mount.sh")
declare -gr JADE_CONFIG_DIR="/usr/local/etc/jade.sh"
# ---
# @return_code: [2] Scripts directory not found.
# @return_code: [3] Config directory not found.
# @return_code: [4] Dict directory not found.
# shellcheck disable=1090,1091
# ---
setup() {
. /usr/local/share/dao/libs/libs_dao.sh
[[ -d $INSTALL_DIR ]] || sudo mkdir -p "$INSTALL_DIR" || dao::error 1 "Failed to create installation directory $INSTALL_DIR"
[[ -d "${SCRIPTS_DIR}" ]] || dao::error 2 "Scripts directory not found: ${SCRIPTS_DIR}"
[[ -d "${CONFIG_DIR}" ]] || dao::error 3 "Config directory not found: ${CONFIG_DIR}"
[[ -d "${DICT_DIR}" ]] || dao::error 4 "Dict directory not found: ${DICT_DIR}"
}
# ---
# @arg: $1 - The name of the tool/script to install.
# @return_code: [1] General dao::error (inherits from set -e).
# @return_code: [5] Source file not found.
# @return_code: [6] Copy failed for the tool.
# @return_code: [7] chmod failed for the tool.
# @return_code: [8] Failed to create jade config directory.
# @return_code: [9] Failed to copy config for jade.sh.
# @return_code: [10] Config template not found for jade.sh.
# @return_code: [11] Copy failed for pwgen.list.
# ---
install_tool() {
declare tool="$1"
declare src_path
src_path=$(realpath "${SCRIPTS_DIR}/${tool}")
[[ -f $src_path ]] || dao::error 5 "Source file not found: $tool"
sudo rm -f "${INSTALL_DIR}/${tool}"
sudo ln -s "$src_path" "$INSTALL_DIR/" || dao::error 6 "Copy failed for $tool"
sudo chmod 755 "$INSTALL_DIR/$tool" || dao::error 7 "chmod failed for $tool"
dao::info "Installed: $INSTALL_DIR/$tool"
case ${tool} in
pwgen.sh)
declare dict_src="${DICT_DIR}/pwgen.list"
if [[ -f "${dict_src}" ]]; then
sudo rm -f /usr/share/dict/pwgen.list
sudo ln -s "${dict_src}" /usr/share/dict/ || dao::error 11 "Copy failed for pwgen.list"
dao::info "Installed /usr/share/dict/pwgen.list"
else
dao::warn "Dict file not found at '${dict_src}', skipping installation of /usr/share/dict/pwgen.list"
fi
;;
jade.sh)
declare jade_config_src="${CONFIG_DIR}/jade.conf"
declare jade_config_dest="${JADE_CONFIG_DIR}/jade.conf"
if [[ -f "${jade_config_src}" ]]; then
if [[ ! -f "${jade_config_dest}" ]]; then
sudo mkdir -p "${JADE_CONFIG_DIR}" || dao::error 8 "Failed to create jade config directory"
sudo rm -f "${jade_config_dest}"
sudo ln -s "${jade_config_src}" "${jade_config_dest}" || dao::error 9 "Failed to copy config for jade.sh"
dao::info "Installed ${jade_config_dest} - manually set variables within this file."
else
dao::info "${jade_config_dest} already exists, not overwriting."
fi
else
dao::error 10 "Config template not found: '${jade_config_src}'"
fi
;;
esac
}
main() {
setup
declare tool
for tool in "${TOOLS[@]}"; do
install_tool "$tool"
done
dao::info "All tools installed successfully."
}
main "$@"