-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
164 lines (137 loc) · 4.28 KB
/
install
File metadata and controls
164 lines (137 loc) · 4.28 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
# --- 0. Self-Update Logic ---
if [ -d "$HOME/.sentinel/.git" ]; then
cd "$HOME/.sentinel"
git fetch --quiet
LOCAL=$(git rev-parse HEAD)
REMOTE=$(git rev-parse @{u})
if [ "$LOCAL" != "$REMOTE" ]; then
echo -e "\033[0;36m\033[1m:: Update Found! Syncing with GitHub...\033[0m"
git pull --quiet
echo ":: Update applied. Restarting script..."
exec "$0" "$@"
fi
fi
set -e
# --- Configuration ---
# Update this if your repo name differs
REPO_URL="https://github.com/CodeFXR/Sentinel.git"
INSTALL_DIR="$HOME/.sentinel"
ENTRY_MODULE="sentinel.py"
# --- Visual Styling ---
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
# Unknown Terminal Fix
if ! infocmp "$TERM" >/dev/null 2>&1; then
export TERM=xterm-256color
fi
OS="$(uname -s)"
case "${OS}" in
Linux*) OS_NAME=Linux;;
Darwin*) OS_NAME=Mac;;
*) OS_NAME="UNKNOWN:${OS}"
esac
# --- Header ---
clear
echo -e "${CYAN}${BOLD}"
echo " ____ __ _ __"
echo " / __/__ ___ / /_(_)__ ___ / /"
echo " _\ \/ -_) _ \/ __/ / _ \/ -_) /"
echo " /___/\__/_//_/\__/_/_//_/\__/_/"
echo -e "${NC}"
echo -e ":: Detected System: $OS_NAME"
spinner() {
local pid=$1
local delay=0.1
local spinstr='|/-'
while kill -0 "$pid" 2>/dev/null; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
}
# --- 1. Check Prerequisites ---
echo -e "${BOLD}:: Checking System...${NC}"
if ! command -v git &> /dev/null; then
echo -e " [!] Error: Git is not installed."
exit 1
fi
if ! command -v python3 &> /dev/null; then
echo -e " [!] Error: Python 3 is not installed."
exit 1
fi
# Optional: Check for smart card tools
if ! command -v pcscd &> /dev/null; then
echo -e " [!] Warning: 'pcscd' (Smart Card Service) not found. Functionality may be limited."
fi
echo -e " [OK] System tools ready."
echo ""
# --- 2. Download ---
if [ ! -d "$INSTALL_DIR" ]; then
echo -e "${BOLD}:: Downloading Sentinel...${NC}"
echo -n " [>] Cloning repository..."
git clone --quiet --depth 1 "$REPO_URL" "$INSTALL_DIR" > /dev/null 2>&1 &
spinner $!
echo -e " Done"
else
cd "$INSTALL_DIR"
git pull --quiet > /dev/null 2>&1
fi
cd "$INSTALL_DIR"
# --- 3. Setup Virtual Env ---
if [ ! -d ".venv" ]; then
echo ""
echo -e "${BOLD}:: Setting up Sandbox...${NC}"
echo -n " [>] Creating virtual environment..."
python3 -m venv .venv &
spinner $!
echo -e " Done"
fi
source .venv/bin/activate
echo -n " [>] Syncing dependencies..."
pip install --upgrade pip > /dev/null 2>&1
if [ -f "requirements.txt" ]; then
pip install -r requirements.txt > /dev/null 2>&1 &
spinner $!
echo -e " Done"
else
echo -e " [!] requirements.txt not found. Skipping."
fi
echo ""
# --- 4. Shell Shortcuts ---
echo -e "${BOLD}:: Finalizing...${NC}"
case "$SHELL" in
*/zsh) SHELL_CONFIG="$HOME/.zshrc" ;;
*/bash)
if [ -f "$HOME/.bash_profile" ]; then SHELL_CONFIG="$HOME/.bash_profile"; else SHELL_CONFIG="$HOME/.bashrc"; fi
;;
*/fish) SHELL_CONFIG="$HOME/.config/fish/config.fish" ;;
*) SHELL_CONFIG="$HOME/.profile" ;;
esac
if [ -f "$SHELL_CONFIG" ]; then
# Clean up old aliases
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' '/alias sentinel=/d' "$SHELL_CONFIG"
sed -i '' '/alias snl=/d' "$SHELL_CONFIG"
else
sed -i '/alias sentinel=/d' "$SHELL_CONFIG"
sed -i '/alias snl=/d' "$SHELL_CONFIG"
fi
# 1. Run in subshell so we don't change user's PWD
# 2. Call python directly on the script
CMD_STR="(cd $INSTALL_DIR && $INSTALL_DIR/.venv/bin/python $ENTRY_MODULE)"
echo "alias sentinel="$CMD_STR"" >> "$SHELL_CONFIG"
echo "alias snl="$CMD_STR"" >> "$SHELL_CONFIG"
echo -e " [OK] Aliases added to ${CYAN}$SHELL_CONFIG${NC}"
else
echo -e " [!] Shell config not found. Add alias manually."
fi
echo -e "${CYAN}===================================================${NC}"
echo -e "${BOLD} SENTINEL IS READY${NC}"
echo -e "${CYAN}===================================================${NC}"
echo -e "1. Restart your terminal."
echo -e "2. Launch with: ${BOLD}${CYAN}snl${NC} or ${BOLD}${CYAN}sentinel${NC}"