save
This commit is contained in:
118
scripts/jade.sh
118
scripts/jade.sh
@@ -1,118 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# ---
|
||||
# @file_name: jade.sh
|
||||
# @version: 1.3.1
|
||||
# @description: Lazy script for modifying docker files
|
||||
# @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
|
||||
|
||||
# ---
|
||||
# @return_code: [2] Unable to source.
|
||||
# shellcheck disable=2015,1090,1091
|
||||
# ---
|
||||
setup() {
|
||||
declare script_dir; script_dir="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)"
|
||||
. "${script_dir}/../libs/libs_cradle.sh"
|
||||
declare -r conf="../config/jade.conf"
|
||||
[[ -f "${conf}" ]] && . "${conf}" || cradle::error 2 "unable to source '${conf}'"
|
||||
}
|
||||
|
||||
# ---
|
||||
# @return_code: [3] Download failed.
|
||||
# ---
|
||||
download_file() {
|
||||
scp -q "${REMOTE_HOST}:${REMOTE_PATH}" "$LOCAL_PATH" || cradle::error 3 'Download failed'
|
||||
cradle::info "Downloaded: $LOCAL_PATH"
|
||||
}
|
||||
|
||||
# ---
|
||||
# @return_code: [4] Local file missing.
|
||||
# @return_code: [5] Failed to create remote backup.
|
||||
# @return_code: [6] Upload failed.
|
||||
# ---
|
||||
upload_file() {
|
||||
[[ -f "$LOCAL_PATH" ]] || cradle::error 4 "Local file missing: $LOCAL_PATH"
|
||||
ssh -q "${REMOTE_HOST}" "[[ -f '${REMOTE_PATH}' ]] && cp -f '${REMOTE_PATH}' '${REMOTE_PATH}.bak'" || cradle::error 5 'Failed to create remote backup'
|
||||
scp -q "$LOCAL_PATH" "${REMOTE_HOST}:${REMOTE_PATH}" || cradle::error 6 'Upload failed'
|
||||
cradle::info "Uploaded: $LOCAL_PATH"
|
||||
cradle::info "Remote file backed up to: ${REMOTE_PATH}.bak"
|
||||
}
|
||||
|
||||
# ---
|
||||
# @return_code: [7] Editor command not found.
|
||||
# @return_code: [3] Download failed (inherited from download_file).
|
||||
# ---
|
||||
edit_file() {
|
||||
download_file
|
||||
if ! command -v "$EDITOR" >/dev/null; then
|
||||
cradle::error 7 "Editor not found: '$EDITOR'"
|
||||
fi
|
||||
"$EDITOR" "$LOCAL_PATH"
|
||||
}
|
||||
|
||||
# ---
|
||||
# @return_code: [6] Upload failed (inherited from upload_file).
|
||||
# @return_code: [8] Remote docker compose up failed.
|
||||
# ---
|
||||
upload_compose() {
|
||||
upload_file
|
||||
ssh -q "${REMOTE_HOST}" \
|
||||
"cd '$(dirname "$REMOTE_PATH")' && exec docker compose up -d --remove-orphans" \
|
||||
|| cradle::error 8 'Remote docker compose up failed'
|
||||
cradle::info 'Remote docker compose up -d completed'
|
||||
}
|
||||
|
||||
# ---
|
||||
# @return_code: [9] Remote docker compose down failed.
|
||||
# @return_code: [6] Upload failed (inherited from upload_file).
|
||||
# @return_code: [11] Remote docker compose up failed during restart.
|
||||
# ---
|
||||
upload_restart() {
|
||||
ssh -q "${REMOTE_HOST}" \
|
||||
"cd '$(dirname "$REMOTE_PATH")' && exec docker compose down" \
|
||||
|| cradle::error 9 'Remote docker compose down failed'
|
||||
upload_file
|
||||
ssh -q "${REMOTE_HOST}" \
|
||||
"cd '$(dirname "$REMOTE_PATH")' && exec docker compose up -d --remove-orphans" \
|
||||
|| cradle::error 11 'Remote docker compose up failed during restart'
|
||||
cradle::info 'Remote docker compose restart completed'
|
||||
}
|
||||
|
||||
# ---
|
||||
# @return_code: [10] Unknown command-line option.
|
||||
# @return_code: [12] Required tool 'scp' not found.
|
||||
# @return_code: [13] Required tool 'ssh' not found.
|
||||
# @return_code: [14] Unexpected execution mode.
|
||||
# @return_code: [N] Errors from called functions (e.g., download_file, upload_file, etc.).
|
||||
# ---
|
||||
main() {
|
||||
setup
|
||||
declare mode=''
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-d) mode='download' ; shift ;;
|
||||
-u) mode='upload' ; shift ;;
|
||||
-uc) mode='up' ; shift ;;
|
||||
-ur) mode='restart' ; shift ;;
|
||||
*) cradle::error 10 "Unknown option: $1 (use -d, -u, -uc, -ur)" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
command -v scp >/dev/null || cradle::error 12 "'scp' not found"
|
||||
command -v ssh >/dev/null || cradle::error 13 "'ssh' not found"
|
||||
|
||||
case "$mode" in
|
||||
download) download_file ;;
|
||||
upload) upload_file ;;
|
||||
up) upload_compose ;;
|
||||
restart) upload_restart ;;
|
||||
'') edit_file ;;
|
||||
*) cradle::error 14 "Unexpected mode: $mode" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
||||
139
scripts/jau.sh
139
scripts/jau.sh
@@ -1,139 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# ---
|
||||
# @file_name: jau.sh
|
||||
# @version: 1.0.0
|
||||
# @description: Full system update handler for Fedora-based systems with DNF and Flatpak
|
||||
# @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
|
||||
|
||||
# ---
|
||||
# @description: Perform initial setup checks. Verifies required base commands (dnf, sudo) are available.
|
||||
# @return_code: [2] Required tool 'sudo' not found.
|
||||
# @return_code: [3] Required tool 'dnf' not found.
|
||||
# shellcheck disable=1091
|
||||
# ---
|
||||
setup() {
|
||||
declare script_dir; script_dir="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)"
|
||||
. "${script_dir}/../libs/libs_cradle.sh"
|
||||
command -v sudo >/dev/null || cradle::error 2 "sudo not found"
|
||||
sudo sh -c 'command -v dnf >/dev/null' || cradle::error 3 "dnf not found (script requires a DNF-based system)"
|
||||
}
|
||||
|
||||
# ---
|
||||
# @description: Install package if missing.
|
||||
# @arg: $1 - The name of the package/command to check and install.
|
||||
# @return_code: [1] General cradle::error (inherits from set -e).
|
||||
# @return_code: [4] Failed to install the specified package.
|
||||
# ---
|
||||
install_if_missing() {
|
||||
declare pkg="$1"
|
||||
if ! command -v "$pkg" &>/dev/null; then
|
||||
cradle::info "Installing missing dependency: $pkg"
|
||||
sudo dnf install -y "$pkg" || cradle::error 4 "Failed to install $pkg"
|
||||
else
|
||||
cradle::info "Dependency satisfied: $pkg"
|
||||
fi
|
||||
}
|
||||
|
||||
# ---
|
||||
# @description: Refresh DNF cache and update all packages.
|
||||
# @return_code: [1] General cradle::error (inherits from set -e).
|
||||
# @return_code: [5] Failed to refresh DNF cache.
|
||||
# @return_code: [6] DNF update failed.
|
||||
# ---
|
||||
run_dnf_update() {
|
||||
cradle::info "Refreshing DNF cache..."
|
||||
sudo dnf -y makecache --refresh || cradle::error 5 "Failed to refresh DNF cache"
|
||||
|
||||
cradle::info "Updating all packages..."
|
||||
sudo dnf -y update || cradle::error 6 "DNF update failed"
|
||||
}
|
||||
|
||||
# ---
|
||||
# @description: Handle leftover RPM configuration files.
|
||||
# @return_code: [1] General cradle::error (inherits from set -e).
|
||||
# @return_code: [7] rpmconf execution failed.
|
||||
# ---
|
||||
handle_rpmconf() {
|
||||
if command -v rpmconf &>/dev/null; then
|
||||
cradle::info "Handling leftover RPM configuration files..."
|
||||
sudo rpmconf -a || cradle::error 7 "rpmconf execution failed"
|
||||
else
|
||||
cradle::info "rpmconf not available; skipping config file handling"
|
||||
fi
|
||||
}
|
||||
|
||||
# ---
|
||||
# @description: Install security updates if any exist.
|
||||
# @return_code: [1] General cradle::error (inherits from set -e).
|
||||
# @return_code: [8] Security update failed.
|
||||
# ---
|
||||
install_security_updates() {
|
||||
cradle::info "Checking for security updates..."
|
||||
# dnf check-update returns 100 if updates are available, 1 on error, 0 if not.
|
||||
# We only want to proceed if it returns 100 (success with updates) or 0 (no updates).
|
||||
# Using || true prevents set -e from triggering on exit code 100.
|
||||
if sudo dnf check-update --security &>/dev/null || [[ $? -eq 100 ]]; then
|
||||
cradle::info "Installing security updates..."
|
||||
sudo dnf -y update --security || cradle::error 8 "Security update failed"
|
||||
else
|
||||
cradle::info "No security updates available."
|
||||
fi
|
||||
}
|
||||
|
||||
# ---
|
||||
# @description: Remove unused packages and clean cache.
|
||||
# @return_code: [1] General cradle::error (inherits from set -e).
|
||||
# @return_code: [9] DNF autoremove failed.
|
||||
# @return_code: [10] DNF clean failed.
|
||||
# ---
|
||||
cleanup_packages() {
|
||||
cradle::info "Removing unused dependencies..."
|
||||
sudo dnf -y autoremove || cradle::error 9 "DNF autoremove failed"
|
||||
|
||||
cradle::info "Cleaning cached package data..."
|
||||
sudo dnf clean all || cradle::error 10 "DNF clean failed"
|
||||
}
|
||||
|
||||
# ---
|
||||
# @description: Update Flatpak applications and remove unused runtimes.
|
||||
# @return_code: [1] General cradle::error (inherits from set -e).
|
||||
# @return_code: [11] Flatpak update failed.
|
||||
# @return_code: [12] Flatpak cleanup failed.
|
||||
# ---
|
||||
update_flatpak() {
|
||||
if command -v flatpak &>/dev/null; then
|
||||
cradle::info "Updating Flatpak applications..."
|
||||
flatpak update -y || cradle::error 11 "Flatpak update failed"
|
||||
|
||||
cradle::info "Removing unused Flatpak runtimes..."
|
||||
flatpak uninstall --unused -y || cradle::error 12 "Flatpak cleanup failed"
|
||||
else
|
||||
cradle::info "Flatpak not installed; skipping Flatpak updates"
|
||||
fi
|
||||
}
|
||||
|
||||
# ---
|
||||
# @description: Main routine.
|
||||
# @arg: $@ - Command-line arguments (currently unused).
|
||||
# @return_code: [1] General cradle::error (inherits from set -e).
|
||||
# @return_code: [N] Errors from called functions (e.g., setup, install_if_missing, etc.).
|
||||
# ---
|
||||
main() {
|
||||
setup
|
||||
cradle::info "Starting system updates..."
|
||||
install_if_missing rpmconf
|
||||
install_if_missing flatpak
|
||||
run_dnf_update
|
||||
handle_rpmconf
|
||||
install_security_updates
|
||||
cleanup_packages
|
||||
update_flatpak
|
||||
cradle::info "System updates completed successfully."
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,66 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# ---
|
||||
# @file_name: pwgen.sh
|
||||
# @version: 1.0.1
|
||||
# @description: Generate a passphrase
|
||||
# @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 WORD_LIST='/usr/share/dict/japg.list'
|
||||
declare -gr DEFAULT_DELIM='-'
|
||||
declare -gi DEFAULT_WORDS=5
|
||||
|
||||
|
||||
# ---
|
||||
# @return_code: [2] Word-list file not found.
|
||||
# @return_code: [3] Required tool 'xclip' not found.
|
||||
# shellcheck disable=1091,1090
|
||||
# ---
|
||||
setup() {
|
||||
declare script_dir; script_dir="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)"
|
||||
. "${script_dir}/../libs/libs_cradle.sh"
|
||||
[[ -f "${WORD_LIST}" ]] || cradle::error 2 "Word-list not found: $WORD_LIST"
|
||||
command -v xclip >/dev/null || cradle::error 3 "xclip not found (install xclip)"
|
||||
}
|
||||
|
||||
# ---
|
||||
# @arg: $1 - Number of words (optional, defaults to DEFAULT_WORDS).
|
||||
# @arg: $2 - Delimiter (optional, defaults to DEFAULT_DELIM).
|
||||
# @return_code: [1] General cradle::error (inherits from set -e).
|
||||
# @return_code: [4] Invalid number of words provided.
|
||||
# @return_code: [2] Word-list not found (inherited from setup).
|
||||
# @return_code: [3] xclip not found (inherited from setup).
|
||||
# ---
|
||||
main() {
|
||||
setup
|
||||
|
||||
declare num_words="${1:-$DEFAULT_WORDS}"
|
||||
declare delim="${2:-$DEFAULT_DELIM}"
|
||||
|
||||
[[ "${num_words}" =~ ^[1-9][0-9]*$ ]] || cradle::error 4 "num_words must be a positive integer"
|
||||
|
||||
declare -a words
|
||||
mapfile -t words < <(shuf -n "$num_words" "$WORD_LIST") || cradle::error 1 "Failed to read words from list"
|
||||
|
||||
declare i
|
||||
for i in "${!words[@]}"; do
|
||||
words[i]="${words[i]^}"
|
||||
done
|
||||
|
||||
declare dig_idx=$(( RANDOM % num_words ))
|
||||
words[dig_idx]+=$(( RANDOM % 10 ))
|
||||
|
||||
declare pass
|
||||
IFS="$delim"
|
||||
printf -v pass '%s' "${words[*]}" || cradle::error 1 "Failed to construct passphrase"
|
||||
|
||||
printf '%s' "$pass" | xclip -selection clipboard || cradle::error 1 "Failed to copy passphrase to clipboard"
|
||||
cradle::info "Generated password: $pass"
|
||||
cradle::info "Password copied to clipboard."
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,32 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# ---
|
||||
# @file_name: rclone_mount.sh
|
||||
# @version: 1.0.0
|
||||
# @description: Lazy script for mounting rclone
|
||||
# @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
|
||||
|
||||
rclone_mount_koofr() {
|
||||
echo "Mounting koofr..."
|
||||
/usr/bin/rclone mount koofr: /home/jamie/dao/storage/koofr &
|
||||
}
|
||||
|
||||
rclone_mount_koofr_vault() {
|
||||
echo "Mounting vault..."
|
||||
/usr/bin/rclone mount koofr_vault: /home/jamie/dao/storage/vault &
|
||||
}
|
||||
|
||||
# ---
|
||||
# @return_code: [2] Failed to mount koofr to dir.
|
||||
# @return_code: [3] Failed to mount vault to dir.
|
||||
# ---
|
||||
main() {
|
||||
rclone_mount_koofr || { echo "[2] Failed to mount koofr."; exit 2; }
|
||||
rclone_mount_koofr_vault || { echo "[2] Failed to mount koofr vault."; exit 3; }
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user