Skip to content

Commit

Permalink
Auto-commit: 0 added, 10 modified, 0 deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
4ndr0666 committed Jan 18, 2025
1 parent 5e5ffe8 commit 6f24f5b
Show file tree
Hide file tree
Showing 11 changed files with 451 additions and 95 deletions.
17 changes: 9 additions & 8 deletions 4ndr0tools/4ndr0install/4ndr0666install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ fi
if [ -n "$SUDO_USER" ]; then
INVOKING_USER="$SUDO_USER"
USER_HOME=$(getent passwd "$SUDO_USER" | cut -d: -f6)
export INVOKING_USER
export USER_HOME
else
echo "Error: Unable to determine the invoking user's home directory."
exit 1
Expand Down Expand Up @@ -60,7 +58,7 @@ declare -A REQUIRED_DEPENDENCIES=(
["nvim"]="neovim,official"
["bat"]="bat,official"
["meld"]="meld,official"
["gh"]="github-cli,official"
["gh"]="gh,official"
["delta"]="git-delta,AUR"
["lsd"]="lsd,AUR"
["eza"]="eza,AUR"
Expand Down Expand Up @@ -573,11 +571,14 @@ run_external_script() {
local script_name="$1"
local script_path="$SCRIPT_DIR/$script_name"
if [[ -x "$script_path" ]]; then
sudo -u "$INVOKING_USER" "$script_path" || {
log_message "Error executing $script_name."
whiptail --msgbox "Error executing $script_name." 8 45
return 1
}
sudo -u "$INVOKING_USER" env "XDG_CONFIG_HOME=$XDG_CONFIG_HOME" \
"XDG_DATA_HOME=$XDG_DATA_HOME" "XDG_CACHE_HOME=$XDG_CACHE_HOME" \
"XDG_STATE_HOME=$XDG_STATE_HOME" "GNUPGHOME=$GNUPGHOME" \
"$script_path" || {
log_message "Error executing $script_name."
whiptail --msgbox "Error executing $script_name." 8 45
return 1
}
log_message "$script_name executed successfully."
whiptail --msgbox "$script_name executed successfully!" 8 45
else
Expand Down
20 changes: 19 additions & 1 deletion 4ndr0tools/4ndr0install/backup_verification.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@

# --- // Backup Verification Script ---

# --- // Environment Variables:
if [ -n "$SUDO_USER" ]; then
INVOKING_USER="$SUDO_USER"
USER_HOME=$(getent passwd "$SUDO_USER" | cut -d: -f6)
else
echo "Error: Unable to determine the invoking user's home directory."
exit 1
fi

export XDG_CONFIG_HOME="$USER_HOME/.config"
export XDG_DATA_HOME="$USER_HOME/.local/share"
export XDG_CACHE_HOME="$USER_HOME/.cache"
export XDG_STATE_HOME="$USER_HOME/.local/state"
export GNUPGHOME="$XDG_DATA_HOME/gnupg"

# --- // Logging:
LOG_DIR="${XDG_DATA_HOME}/logs/"
LOG_FILE="$LOG_DIR/backup_verification.log"
Expand All @@ -27,7 +42,10 @@ verify_backup() {
exit 1
fi

shopt -s nullglob
local backups=("$recovery_dir"/*.tar.gz)
shopt -u nullglob

if [ ${#backups[@]} -eq 0 ]; then
log_message "No backup files found in $recovery_dir."
whiptail --title "Verification Error" --msgbox "No backup files found in $recovery_dir." 8 60
Expand All @@ -41,7 +59,7 @@ verify_backup() {

for backup in "${backups[@]}"; do
for key in "${!expected_backups[@]}"; do
if [[ "$backup" == *"${key}_backup_"* ]]; then
if [[ "$(basename "$backup")" == "${key}_backup_"*".tar.gz" ]]; then
expected_backups["$key"]=""
fi
done
Expand Down
15 changes: 15 additions & 0 deletions 4ndr0tools/4ndr0install/hideapps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@

# --- // Hide Applications Script ---

# --- // Environment Variables:
if [ -n "$SUDO_USER" ]; then
INVOKING_USER="$SUDO_USER"
USER_HOME=$(getent passwd "$SUDO_USER" | cut -d: -f6)
else
echo "Error: Unable to determine the invoking user's home directory."
exit 1
fi

export XDG_CONFIG_HOME="$USER_HOME/.config"
export XDG_DATA_HOME="$USER_HOME/.local/share"
export XDG_CACHE_HOME="$USER_HOME/.cache"
export XDG_STATE_HOME="$USER_HOME/.local/state"
export GNUPGHOME="$XDG_DATA_HOME/gnupg"

# --- // Logging:
LOG_DIR="${XDG_DATA_HOME}/logs/"
LOG_FILE="$LOG_DIR/hideapps.log"
Expand Down
101 changes: 45 additions & 56 deletions 4ndr0tools/4ndr0install/homemanager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@

# --- // Home Manager Script ---

# --- // Environment Variables:
if [ -n "$SUDO_USER" ]; then
INVOKING_USER="$SUDO_USER"
USER_HOME=$(getent passwd "$SUDO_USER" | cut -d: -f6)
else
echo "Error: Unable to determine the invoking user's home directory."
exit 1
fi

export XDG_CONFIG_HOME="$USER_HOME/.config"
export XDG_DATA_HOME="$USER_HOME/.local/share"
export XDG_CACHE_HOME="$USER_HOME/.cache"
export XDG_STATE_HOME="$USER_HOME/.local/state"
export GNUPGHOME="$XDG_DATA_HOME/gnupg"

# --- // Logging:
LOG_DIR="${XDG_DATA_HOME}/logs/"
LOG_FILE="$LOG_DIR/home_manager.log"
Expand Down Expand Up @@ -49,71 +64,43 @@ create_backup() {
local timestamp
timestamp="$(date -u "+%Y-%m-%d_%H.%M%p")"
local tarball_name="etc_backup_$timestamp.tar.gz"
local target_list=(
"arch-release" "audit" "avahi" "borgmatic" "binfmt.d" "conf.d" "cron.d" "cron.daily"
"cron.deny" "cron.hourly" "cron.monthly" "cron.weekly" "crontab" "default" "depmod.d"
"dhcpd.conf" "dnsmasq.conf" "drbl" "environment" "fstab" "group" "grub.d" "gshadow"
"gss" "gssproxy" "gtk-2.0" "gtk-3.0" "host.conf" "hostname" "hosts" "ipsec.conf"
"ipsec.d" "iptables" "iscsi" "ld.so.conf" "ld.so.conf.d" "libaudit" "locale.conf"
"locale.gen" "makepkg.conf" "mkepkg.config.d" "mkinitcpio.conf" "mkinitcpio.conf.d"
"modprobe.d" "modules-load.d" "nanorc" "netconfig" "NetworkManager" "nfs.conf"
"nfsmount.conf" "nftables" "nsswitch.conf" "nvme" "openvpn" "pacman.conf" "pacman.d"
"pam.d" "paru.conf" "passwd" "pinentry" "pipewire" "plymouth" "polkit-1" "powerpill"
"profile" "profile.d" "pulse" "reflector-simple-tool.conf" "reflector-simple.conf"
"resolv.conf" "resolv.conf.expressvpn-orig" "screenrc" "sddm.conf" "sddm.conf.d"
"security" "services" "skel" "ssh" "sudo.conf" "sudoers" "sysctl.d" "systemd"
"timeshift" "timeshift-autosnap.conf" "tmpfiles.d" "udev" "udisks2" "ufw"
"vconsole.conf" "wpa_supplicant" "X11" "xdg" "zsh"
)

# Create the temporary backup directory if it doesn't exist
[ ! -d "$backup_dir" ] && mkdir -p "$backup_dir"

# Total number of items to backup
local total_items=${#target_list[@]}
local current_item=0
# Create the backup directory
mkdir -p "$backup_dir"

# Create a progress bar using whiptail
{
for item in "${target_list[@]}"; do
current_item=$((current_item + 1))
if [[ -e "/etc/$item" ]]; then
rsync -a --ignore-existing --ignore-times --update --recursive "/etc/$item" "$backup_dir" || log_action "Failed to copy /etc/$item"
fi
local progress=$((current_item * 100 / total_items))
echo $progress
done
} | whiptail --gauge "Backing up files..." 6 50 0

# Ensure the recovery directory exists
[ ! -d "$recover_dir" ] && mkdir -p "$recover_dir"

# Check if a tarball with the same name already exists and version it
if [[ -f "$recover_dir/$tarball_name" ]]; then
local counter=1
while [[ -f "$recover_dir/${tarball_name%.tar.gz}_v$counter.tar.gz" ]]; do
counter=$((counter + 1))
done
tarball_name="${tarball_name%.tar.gz}_v$counter.tar.gz"
log_action "Existing tarball found. Creating versioned tarball: $tarball_name"
fi
# Rsync the /etc directory to the backup directory
log_action "Starting rsync of /etc to $backup_dir..."
rsync -a --delete /etc/ "$backup_dir/etc/" || {
log_action "Failed to rsync /etc to $backup_dir."
exit 1
}
log_action "/etc successfully rsynced to $backup_dir/etc/."

# Create a tarball of the backup directory
tar -czf "$recover_dir/$tarball_name" -C "$backup_dir" . || { log_action "Failed to create tarball."; exit 1; }
# Create the tarball
log_action "Creating tarball $tarball_name..."
tar -czf "$recover_dir/$tarball_name" -C "$backup_dir" etc || {
log_action "Failed to create tarball $tarball_name."
exit 1
}
log_action "Tarball $tarball_name created successfully."

# Clean up the temporary directory
rm -rf "$backup_dir" || log_action "Failed to clean up temporary backup directory."
# Clean up the backup directory
rm -rf "$backup_dir" || log_action "Failed to clean up $backup_dir."

# Lock the recovery tarball
chattr +i "$recover_dir/$tarball_name" || { log_action "Failed to lock the tarball."; exit 1; }
# Lock the tarball
chattr +i "$recover_dir/$tarball_name" || {
log_action "Failed to lock the tarball $tarball_name."
exit 1
}
log_action "Tarball $tarball_name locked successfully."

# Add lock and unlock aliases to shell configuration files
# Add lock and unlock aliases
add_aliases

# Notify the user
local notification="Backup acquired and secured.\n\nUsage:\n lock <path> # Lock a file or directory\n unlock <path> # Unlock a file or directory\n\nLocation: $recover_dir"
whiptail --title "Asset: /etc" --msgbox "$notification" 12 70
log_action "Backup created and secured at $recover_dir/$tarball_name"
whiptail --title "Recovery Directory" --msgbox "$notification" 12 70
log_action "Backup created and secured at $recover_dir/$tarball_name."
}

# Function to restore from a backup and compare using meld
Expand All @@ -126,8 +113,10 @@ restore_backup() {
exit 1
fi

shopt -s nullglob
# List available backups
local backups=("$recover_dir"/*.tar.gz)
shopt -u nullglob
if [ ${#backups[@]} -eq 0 ]; then
log_action "No backups found in $recover_dir."
exit 1
Expand Down Expand Up @@ -221,7 +210,7 @@ main() {
show_help
;;
*)
log_action "Unrecognized option: $1"
echo "Error: Unrecognized command '$1'"
show_help
exit 1
;;
Expand Down
15 changes: 15 additions & 0 deletions 4ndr0tools/4ndr0install/makegrub-btrfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@

# --- // Make GRUB Btrfs Configuration Script ---

# --- // Environment Variables:
if [ -n "$SUDO_USER" ]; then
INVOKING_USER="$SUDO_USER"
USER_HOME=$(getent passwd "$SUDO_USER" | cut -d: -f6)
else
echo "Error: Unable to determine the invoking user's home directory."
exit 1
fi

export XDG_CONFIG_HOME="$USER_HOME/.config"
export XDG_DATA_HOME="$USER_HOME/.local/share"
export XDG_CACHE_HOME="$USER_HOME/.cache"
export XDG_STATE_HOME="$USER_HOME/.local/state"
export GNUPGHOME="$XDG_DATA_HOME/gnupg"

# --- // Logging:
LOG_DIR="${XDG_DATA_HOME}/logs/"
LOG_FILE="$LOG_DIR/makegrub-btrfs.log"
Expand Down
15 changes: 15 additions & 0 deletions 4ndr0tools/4ndr0install/makegrub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@

# --- // Make GRUB Configuration Script ---

# --- // Environment Variables:
if [ -n "$SUDO_USER" ]; then
INVOKING_USER="$SUDO_USER"
USER_HOME=$(getent passwd "$SUDO_USER" | cut -d: -f6)
else
echo "Error: Unable to determine the invoking user's home directory."
exit 1
fi

export XDG_CONFIG_HOME="$USER_HOME/.config"
export XDG_DATA_HOME="$USER_HOME/.local/share"
export XDG_CACHE_HOME="$USER_HOME/.cache"
export XDG_STATE_HOME="$USER_HOME/.local/state"
export GNUPGHOME="$XDG_DATA_HOME/gnupg"

# --- // Logging:
LOG_DIR="${XDG_DATA_HOME}/logs/"
LOG_FILE="$LOG_DIR/makegrub.log"
Expand Down
Loading

0 comments on commit 6f24f5b

Please sign in to comment.