init
This commit is contained in:
commit
b4cdb80b5c
137 changed files with 6383 additions and 0 deletions
53
local-bin/.local/bin/dbeaver-backup.sh
Executable file
53
local-bin/.local/bin/dbeaver-backup.sh
Executable file
|
@ -0,0 +1,53 @@
|
|||
#!/bin/bash
|
||||
|
||||
# DBeaver Profile Backup Script
|
||||
# This script creates a backup of DBeaver profiles and configurations
|
||||
|
||||
# Configuration variables - modify as needed
|
||||
BACKUP_DIR="/home/forbi/Sync/Backups"
|
||||
HOSTNAME=$(hostname)
|
||||
BACKUP_FILE="dbeaver_backup_${HOSTNAME}.tar.gz"
|
||||
LOG_FILE="$BACKUP_DIR/dbeaver_backup_log.txt"
|
||||
|
||||
# DBeaver configuration location
|
||||
DBEAVER_DATA="$HOME/.local/share/DBeaverData" # Contains drivers, workspace, and secure storage
|
||||
|
||||
# Create backup directory if it doesn't exist
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
# Start logging
|
||||
echo "===== DBeaver Backup Started at $(date) =====" >>"$LOG_FILE"
|
||||
|
||||
# Check if DBeaver configuration exists
|
||||
if [ ! -d "$DBEAVER_DATA" ]; then
|
||||
echo "Error: DBeaver configuration not found at $DBEAVER_DATA. Please make sure DBeaver is installed and has been run at least once." | tee -a "$LOG_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create temporary directory for backup
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
echo "Created temporary directory: $TEMP_DIR" >>"$LOG_FILE"
|
||||
|
||||
# Copy DBeaver data to temporary directory
|
||||
echo "Copying DBeaver data from $DBEAVER_DATA..." >>"$LOG_FILE"
|
||||
cp -r "$DBEAVER_DATA" "$TEMP_DIR/"
|
||||
|
||||
# Create compressed archive
|
||||
echo "Creating backup archive..." >>"$LOG_FILE"
|
||||
tar -czf "$BACKUP_DIR/$BACKUP_FILE" -C "$TEMP_DIR" .
|
||||
BACKUP_RESULT=$?
|
||||
|
||||
# Clean up temporary directory
|
||||
echo "Cleaning up temporary files..." >>"$LOG_FILE"
|
||||
rm -rf "$TEMP_DIR"
|
||||
|
||||
# Check if backup was successful
|
||||
if [ $BACKUP_RESULT -eq 0 ]; then
|
||||
echo "Backup completed successfully: $BACKUP_DIR/$BACKUP_FILE" | tee -a "$LOG_FILE"
|
||||
echo "Backup size: $(du -h "$BACKUP_DIR/$BACKUP_FILE" | cut -f1)" | tee -a "$LOG_FILE"
|
||||
echo "Keeping only the latest backup for this PC ($HOSTNAME)" >>"$LOG_FILE"
|
||||
else
|
||||
echo "Error: Backup failed with exit code $BACKUP_RESULT" | tee -a "$LOG_FILE"
|
||||
fi
|
||||
|
||||
echo "===== DBeaver Backup Finished at $(date) =====" >>"$LOG_FILE"
|
72
local-bin/.local/bin/dbeaver-restore.sh
Executable file
72
local-bin/.local/bin/dbeaver-restore.sh
Executable file
|
@ -0,0 +1,72 @@
|
|||
#!/bin/bash
|
||||
# DBeaver Profile Restore Script
|
||||
# This script restores a DBeaver backup created with the backup script
|
||||
|
||||
# Configuration variables - modify as needed
|
||||
BACKUP_DIR="/home/forbi/Sync/Backups"
|
||||
HOSTNAME=main
|
||||
BACKUP_FILE="dbeaver_backup_${HOSTNAME}.tar.gz"
|
||||
LOG_FILE="$BACKUP_DIR/dbeaver_restore_log.txt"
|
||||
|
||||
# DBeaver configuration location
|
||||
DBEAVER_DATA="$HOME/.local/share/DBeaverData"
|
||||
|
||||
# Start logging
|
||||
echo "===== DBeaver Restore Started at $(date) =====" >>"$LOG_FILE"
|
||||
|
||||
# Check if backup file exists
|
||||
if [ ! -f "$BACKUP_DIR/$BACKUP_FILE" ]; then
|
||||
echo "Error: Backup file not found at $BACKUP_DIR/$BACKUP_FILE" | tee -a "$LOG_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if DBeaver data directory exists and create backup if it does
|
||||
if [ -d "$DBEAVER_DATA" ]; then
|
||||
echo "DBeaver data directory exists. Creating backup before restoration..." | tee -a "$LOG_FILE"
|
||||
TEMP_BACKUP="${DBEAVER_DATA}_backup_$(date +%Y%m%d_%H%M%S)"
|
||||
mv "$DBEAVER_DATA" "$TEMP_BACKUP"
|
||||
echo "Original data backed up to: $TEMP_BACKUP" | tee -a "$LOG_FILE"
|
||||
fi
|
||||
|
||||
# Create temporary directory for extraction
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
echo "Created temporary directory for extraction: $TEMP_DIR" >>"$LOG_FILE"
|
||||
|
||||
# Extract backup file
|
||||
echo "Extracting backup archive..." | tee -a "$LOG_FILE"
|
||||
tar -xzf "$BACKUP_DIR/$BACKUP_FILE" -C "$TEMP_DIR"
|
||||
EXTRACT_RESULT=$?
|
||||
|
||||
if [ $EXTRACT_RESULT -ne 0 ]; then
|
||||
echo "Error: Failed to extract backup with exit code $EXTRACT_RESULT" | tee -a "$LOG_FILE"
|
||||
rm -rf "$TEMP_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create target directory if it doesn't exist
|
||||
mkdir -p "$(dirname "$DBEAVER_DATA")"
|
||||
|
||||
# Copy extracted content to DBeaver data directory
|
||||
echo "Restoring DBeaver data to $DBEAVER_DATA..." | tee -a "$LOG_FILE"
|
||||
cp -r "$TEMP_DIR/DBeaverData" "$(dirname "$DBEAVER_DATA")/"
|
||||
RESTORE_RESULT=$?
|
||||
|
||||
# Clean up temporary directory
|
||||
echo "Cleaning up temporary files..." >>"$LOG_FILE"
|
||||
rm -rf "$TEMP_DIR"
|
||||
|
||||
# Check if restore was successful
|
||||
if [ $RESTORE_RESULT -eq 0 ]; then
|
||||
echo "Restore completed successfully to: $DBEAVER_DATA" | tee -a "$LOG_FILE"
|
||||
echo "You may need to restart DBeaver for changes to take effect." | tee -a "$LOG_FILE"
|
||||
else
|
||||
echo "Error: Restore failed with exit code $RESTORE_RESULT" | tee -a "$LOG_FILE"
|
||||
if [ -d "$TEMP_BACKUP" ]; then
|
||||
echo "Attempting to restore original data from backup..." | tee -a "$LOG_FILE"
|
||||
rm -rf "$DBEAVER_DATA"
|
||||
mv "$TEMP_BACKUP" "$DBEAVER_DATA"
|
||||
echo "Original data restored from backup." | tee -a "$LOG_FILE"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "===== DBeaver Restore Finished at $(date) =====" >>"$LOG_FILE"
|
237
local-bin/.local/bin/maintenance.sh
Executable file
237
local-bin/.local/bin/maintenance.sh
Executable file
|
@ -0,0 +1,237 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Make sure we're running as root or with sudo
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
gum style --foreground 196 --bold "This script must be run as root or with sudo"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if gum is installed
|
||||
if ! command -v gum &>/dev/null; then
|
||||
echo "This script uses gum for a nice interface."
|
||||
echo "Please install gum first: pacman -S gum"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Function to print section headers
|
||||
print_section() {
|
||||
gum style --border normal --border-foreground 39 --margin "1" --padding "0 2" --bold "$1"
|
||||
}
|
||||
|
||||
# Function to print tasks
|
||||
print_task() {
|
||||
echo "→ $1..."
|
||||
}
|
||||
|
||||
# Function to print success messages
|
||||
print_success() {
|
||||
gum style --foreground 46 "✓ $1"
|
||||
}
|
||||
|
||||
# Function to print warning messages
|
||||
print_warning() {
|
||||
gum style --foreground 226 "⚠ $1"
|
||||
}
|
||||
|
||||
# Starting message
|
||||
# Starting message
|
||||
echo "=== Arch Linux System Maintenance ==="
|
||||
|
||||
# Update the system
|
||||
print_section "Updating System"
|
||||
|
||||
# Sync package database
|
||||
print_task "Synchronizing package databases"
|
||||
pacman -Sy
|
||||
print_success "Package databases synchronized"
|
||||
|
||||
# Clean package caches
|
||||
print_section "Cleaning Package Caches"
|
||||
|
||||
# Clean pacman cache
|
||||
print_task "Cleaning pacman cache"
|
||||
pacman -Sc --noconfirm
|
||||
print_success "Pacman cache cleaned"
|
||||
|
||||
# Clean AUR cache if paru is installed
|
||||
if command -v paru &>/dev/null; then
|
||||
print_task "Cleaning paru cache"
|
||||
paru -Sc --noconfirm
|
||||
print_success "Paru cache cleaned"
|
||||
else
|
||||
print_warning "paru not found. Skipping AUR cache cleanup."
|
||||
fi
|
||||
|
||||
# Remove orphaned packages
|
||||
print_section "Removing Orphaned Packages"
|
||||
print_task "Finding orphaned packages"
|
||||
ORPHANS=$(pacman -Qtdq)
|
||||
if [ -n "$ORPHANS" ]; then
|
||||
echo "Found orphaned packages:"
|
||||
echo "$ORPHANS"
|
||||
|
||||
print_task "Removing orphaned packages"
|
||||
pacman -Rns $(pacman -Qtdq) --noconfirm
|
||||
print_success "Orphaned packages removed"
|
||||
else
|
||||
print_success "No orphaned packages found"
|
||||
fi
|
||||
|
||||
# Clean user cache directory
|
||||
print_section "Cleaning User Cache Directory"
|
||||
|
||||
# Get current user's username
|
||||
CURRENT_USER=$(logname 2>/dev/null || echo $SUDO_USER)
|
||||
|
||||
# If we still don't have a username, try to get it from /home
|
||||
if [ -z "$CURRENT_USER" ]; then
|
||||
CURRENT_USER=$(ls -la /home | grep -v "\.\." | grep -v "total" | awk '{print $9}' | head -1)
|
||||
fi
|
||||
|
||||
echo "Cleaning cache for user: $CURRENT_USER"
|
||||
|
||||
# Create a backup directory
|
||||
BACKUP_DIR="/home/$CURRENT_USER/.cache_backup_$(date +%Y%m%d)"
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
chown $CURRENT_USER:$CURRENT_USER "$BACKUP_DIR"
|
||||
|
||||
# User cache directory
|
||||
USER_CACHE="/home/$CURRENT_USER/.cache"
|
||||
|
||||
if [ -d "$USER_CACHE" ]; then
|
||||
# Firefox cache
|
||||
if [ -d "$USER_CACHE/mozilla" ]; then
|
||||
print_task "Backing up Firefox cache metadata"
|
||||
cp -r "$USER_CACHE/mozilla" "$BACKUP_DIR/"
|
||||
print_task "Cleaning Firefox cache"
|
||||
find "$USER_CACHE/mozilla" -type f -name "*.sqlite" -exec sqlite3 {} "VACUUM;" \;
|
||||
fi
|
||||
|
||||
# Chrome/Chromium cache
|
||||
for chrome_dir in "$USER_CACHE/google-chrome" "$USER_CACHE/chromium"; do
|
||||
if [ -d "$chrome_dir" ]; then
|
||||
print_task "Backing up Chrome/Chromium cache metadata"
|
||||
mkdir -p "$BACKUP_DIR/$(basename $chrome_dir)"
|
||||
cp -r "$chrome_dir/Default/Preferences" "$BACKUP_DIR/$(basename $chrome_dir)/" 2>/dev/null
|
||||
print_task "Cleaning Chrome/Chromium cache"
|
||||
rm -rf "$chrome_dir/Default/Cache" "$chrome_dir/Default/Code Cache" 2>/dev/null
|
||||
fi
|
||||
done
|
||||
|
||||
# Clean thumbnail cache
|
||||
if [ -d "$USER_CACHE/thumbnails" ]; then
|
||||
print_task "Cleaning thumbnail cache"
|
||||
rm -rf "$USER_CACHE/thumbnails/*" 2>/dev/null
|
||||
fi
|
||||
|
||||
# General cache cleanup (but preserve important files)
|
||||
print_task "Cleaning general cache files"
|
||||
find "$USER_CACHE" -type f -atime +30 -not -path "*/mozilla/*" -not -path "*/chromium/*" -not -path "*/google-chrome/*" -delete 2>/dev/null
|
||||
|
||||
print_success "Cache cleaned for user $CURRENT_USER"
|
||||
else
|
||||
print_warning "Cache directory not found for user $CURRENT_USER"
|
||||
fi
|
||||
|
||||
# Clean system journals
|
||||
print_section "Cleaning System Journals"
|
||||
print_task "Rotating and cleaning journal logs"
|
||||
journalctl --vacuum-time=2weeks
|
||||
print_success "Journal logs cleaned (kept last 2 weeks)"
|
||||
|
||||
# Reset failed services
|
||||
print_section "Resetting Failed Systemd Units"
|
||||
print_task "Checking for failed systemd units"
|
||||
FAILED_UNITS=$(systemctl --failed --no-legend | awk '{print $1}')
|
||||
if [ -n "$FAILED_UNITS" ]; then
|
||||
echo "Failed units found:"
|
||||
echo "$FAILED_UNITS"
|
||||
fi
|
||||
print_task "Clearing failed systemd units"
|
||||
systemctl reset-failed
|
||||
print_success "Failed systemd units cleared"
|
||||
|
||||
# Clean temporary files
|
||||
print_section "Cleaning Temporary Files"
|
||||
print_task "Removing temporary files"
|
||||
rm -rf /tmp/* /var/tmp/* 2>/dev/null
|
||||
print_success "Temporary files removed"
|
||||
|
||||
# Update file database
|
||||
print_section "Updating File Database"
|
||||
if command -v updatedb &>/dev/null; then
|
||||
print_task "Updating file database for locate command"
|
||||
updatedb
|
||||
print_success "File database updated"
|
||||
else
|
||||
print_warning "updatedb not found. Skipping file database update."
|
||||
fi
|
||||
|
||||
# Check for and install security updates
|
||||
print_section "Security Updates Check"
|
||||
print_task "Checking for security updates"
|
||||
SECURITY_UPDATES=$(pacman -Qu | grep -i "security")
|
||||
if [ -n "$SECURITY_UPDATES" ]; then
|
||||
echo "Security updates available:"
|
||||
echo "$SECURITY_UPDATES"
|
||||
|
||||
print_task "Installing security updates"
|
||||
pacman -S --needed $(echo "$SECURITY_UPDATES" | awk '{print $1}') --noconfirm
|
||||
print_success "Security updates installed"
|
||||
else
|
||||
print_success "No security updates needed"
|
||||
fi
|
||||
|
||||
# Check for pacman database errors
|
||||
print_section "Checking Pacman Database"
|
||||
print_task "Verifying package database integrity"
|
||||
if command -v paccheck &>/dev/null; then
|
||||
paccheck --md5sum --quiet
|
||||
print_success "Pacman database check complete"
|
||||
else
|
||||
print_warning "paccheck not found. Consider installing pacutils package."
|
||||
fi
|
||||
|
||||
# Cleanup pacnew/pacsave files
|
||||
print_section "Configuration File Management"
|
||||
print_task "Checking for .pacnew and .pacsave files"
|
||||
PACFILES=$(find /etc -name "*.pacnew" -o -name "*.pacsave" 2>/dev/null)
|
||||
if [ -n "$PACFILES" ]; then
|
||||
echo "Found the following .pacnew/.pacsave files:"
|
||||
echo "$PACFILES"
|
||||
|
||||
print_warning "You may want to merge these configuration files"
|
||||
echo "Use 'pacdiff' to help manage these files (install pacdiff from pacman-contrib)"
|
||||
else
|
||||
print_success "No .pacnew or .pacsave files found"
|
||||
fi
|
||||
|
||||
# System status
|
||||
print_section "System Status"
|
||||
|
||||
# Disk usage with duf
|
||||
print_task "Checking disk usage"
|
||||
if command -v duf &>/dev/null; then
|
||||
duf --only local
|
||||
else
|
||||
print_warning "duf not found. Using df instead. Consider installing duf for better disk usage display."
|
||||
df -h | grep -v "tmpfs" | grep -v "udev"
|
||||
fi
|
||||
|
||||
# Memory usage
|
||||
echo "Memory usage:"
|
||||
free -h
|
||||
|
||||
# Find large files
|
||||
echo "Large files (>100MB) in your home directory:"
|
||||
find /home/$(logname 2>/dev/null || echo $SUDO_USER) -type f -size +100M -exec ls -lh {} \; 2>/dev/null | sort -k5hr | head -n 10
|
||||
|
||||
# Final summary
|
||||
print_section "Maintenance Complete"
|
||||
echo "System maintenance tasks completed successfully"
|
||||
echo "Remember to periodically run additional manual maintenance tasks:"
|
||||
echo "- Check for broken symlinks: find /usr /etc -xtype l -print"
|
||||
echo "- Run a SMART disk check: smartctl -a /dev/sdX (install smartmontools)"
|
||||
echo "- Check systemd boot time: systemd-analyze"
|
||||
|
||||
exit 0
|
25
local-bin/.local/bin/rmq-passwd
Executable file
25
local-bin/.local/bin/rmq-passwd
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/bin/sh
|
||||
|
||||
PREFIX="oc-"
|
||||
SUFFIX="-eks-cluster"
|
||||
FINAL=""
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
context="$PREFIX$1$SUFFIX"
|
||||
current_context=$(kubectl config current-context)
|
||||
|
||||
kubectl config use-context $context >/dev/null
|
||||
kubectl config set-context --current --namespace=oc-app >/dev/null
|
||||
|
||||
# is second argument provided then silent exit
|
||||
password=$(kubectl get secret oc-secrets -o jsonpath="{.data.rabbit_passwd}" | base64 --decode)
|
||||
|
||||
printf "$password" | wl-copy
|
||||
# printf "$password" | xsel --clipboard
|
||||
|
||||
# reset context
|
||||
kubectl config use-context $current_context >/dev/null
|
||||
kubectl config set-context --current --namespace=oc-app >/dev/null
|
Loading…
Add table
Add a link
Reference in a new issue