-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreinstall.sh
More file actions
executable file
·148 lines (126 loc) · 4.66 KB
/
reinstall.sh
File metadata and controls
executable file
·148 lines (126 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env bash
###############################################################################
# SENTINEL – Framework reinstaller
# -----------------------------------------------
# Hardened edition • v2.3.0 • 2025-05-16
# Fully reinstalls SENTINEL after cleaning any previous installation
###############################################################################
set -euo pipefail
# Colour helpers
c_red=$'\033[1;31m'; c_green=$'\033[1;32m'; c_yellow=$'\033[1;33m'; c_blue=$'\033[1;34m'; c_reset=$'\033[0m'
# Logging functions
log() { printf '[%(%F %T)T] %b\n' -1 "$*"; }
step() { log "${c_blue}==>${c_reset} $*"; }
ok() { log "${c_green}✔${c_reset} $*"; }
warn() { log "${c_yellow}⚠${c_reset} $*"; }
fail() { log "${c_red}✖${c_reset} $*"; exit 1; }
# Define paths
STATE_FILE="${HOME}/install.state"
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
# Get confirmation
step "This will completely remove and reinstall SENTINEL"
warn "This will remove your current SENTINEL installation and settings."
read -p "Are you sure you want to reinstall SENTINEL? [y/N]: " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
fail "Reinstallation cancelled by user."
fi
# Create backup of current setup
step "Creating backup of current setup"
BACKUP_DIR="${HOME}/sentinel_backup_$(date +%Y%m%d%H%M%S)"
mkdir -p "$BACKUP_DIR"
# Check for old sentinel home directory (legacy)
if [[ -d "${HOME}/.sentinel" ]]; then
cp -r "${HOME}/.sentinel" "${BACKUP_DIR}/"
ok "Legacy SENTINEL home directory backed up to ${BACKUP_DIR}"
fi
# Back up key SENTINEL files from HOME
for file in blesh_loader.sh bashrc.postcustom; do
if [[ -f "${HOME}/${file}" ]]; then
cp "${HOME}/${file}" "${BACKUP_DIR}/"
ok "${file} backed up to ${BACKUP_DIR}"
fi
done
for dir in bash_aliases.d bash_completion.d bash_functions.d contrib logs autocomplete bash_modules.d venv; do
if [[ -d "${HOME}/${dir}" ]]; then
cp -r "${HOME}/${dir}" "${BACKUP_DIR}/"
ok "${dir} backed up to ${BACKUP_DIR}"
fi
done
for file in .bashrc .bash_modules .bash_aliases .bash_completion .bash_functions; do
if [[ -f "${HOME}/${file}" ]]; then
cp "${HOME}/${file}" "${BACKUP_DIR}/"
ok "${file} backed up to ${BACKUP_DIR}"
fi
done
# Verify installation script exists
if [[ ! -f "${SCRIPT_DIR}/install.sh" ]]; then
fail "Install script not found: ${SCRIPT_DIR}/install.sh"
fi
# Remove existing installation
step "Removing existing SENTINEL installation files"
# Remove old sentinel directory if it exists (legacy)
if [[ -d "${HOME}/.sentinel" ]]; then
rm -rf "${HOME}/.sentinel"
ok "Removed legacy ${HOME}/.sentinel directory"
fi
# Remove specific SENTINEL files from HOME
for file in blesh_loader.sh bashrc.postcustom install.state; do
if [[ -f "${HOME}/${file}" ]]; then
rm -f "${HOME}/${file}"
ok "Removed ${HOME}/${file}"
fi
done
# Remove SENTINEL directories
for dir in autocomplete bash_modules.d logs; do
if [[ -d "${HOME}/${dir}" ]]; then
rm -rf "${HOME}/${dir}"
ok "Removed ${HOME}/${dir}"
fi
done
# Remove venv directory if it exists
if [[ -d "${HOME}/venv" ]]; then
read -p "Remove Python virtual environment at ${HOME}/venv? [y/N]: " confirm_venv
if [[ "$confirm_venv" =~ ^[Yy]$ ]]; then
rm -rf "${HOME}/venv"
ok "Removed Python virtual environment"
else
warn "Keeping Python virtual environment at ${HOME}/venv"
fi
fi
# Remove modular directories
for dir in bash_aliases.d bash_completion.d bash_functions.d contrib; do
if [[ -d "${HOME}/${dir}" ]]; then
read -p "Remove ${HOME}/${dir}? [y/N]: " confirm_dir
if [[ "$confirm_dir" =~ ^[Yy]$ ]]; then
rm -rf "${HOME}/${dir}"
ok "Removed ${HOME}/${dir}"
else
warn "Keeping ${HOME}/${dir} (may contain old files)"
fi
fi
done
# Clean up BLE.sh installation
if [[ -d "${HOME}/.local/share/blesh" ]]; then
rm -rf "${HOME}/.local/share/blesh"
ok "Removed BLE.sh installation"
fi
if [[ -d "${HOME}/.cache/blesh" ]]; then
rm -rf "${HOME}/.cache/blesh"
ok "Removed BLE.sh cache"
fi
# Run the installer
step "Running SENTINEL installer"
bash "${SCRIPT_DIR}/install.sh"
# Verify installation
step "Verifying installation"
if [[ -f "${HOME}/bashrc.postcustom" ]]; then
ok "SENTINEL installation verified"
else
fail "Installation verification failed"
fi
# Final message
echo
ok "SENTINEL has been successfully reinstalled!"
echo "• Open a new terminal OR run: source '${HOME}/bashrc.postcustom'"
echo "• Verify with: @autocomplete status"
echo "• A backup of your previous installation is available at: ${BACKUP_DIR}"