-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
218 lines (189 loc) · 10.1 KB
/
install.sh
File metadata and controls
218 lines (189 loc) · 10.1 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env bash
# DaemonIQ installer — silent, single command
#
# Recommended:
# curl -fsSL https://raw.githubusercontent.com/JayRaj21/DaemonIQ/master/install.sh | bash
#
# Local install (files already downloaded):
# bash install.sh
set -euo pipefail
PRODUCT="DaemonIQ"
CLI="daemoniq"
DAEMON_LABEL="daemoniq-demon"
BASE_URL="https://raw.githubusercontent.com/JayRaj21/DaemonIQ/master"
R='\033[0m'; BOLD='\033[1m'; DIM='\033[2m'
GREEN='\033[38;5;82m'; YELLOW='\033[38;5;220m'
RED='\033[38;5;196m'; CYAN='\033[38;5;51m'
ok() { echo -e " ${GREEN}✓${R} $*"; }
warn() { echo -e " ${YELLOW}⚠${R} $*"; }
err() { echo -e " ${RED}✗${R} $*"; }
info() { echo -e " ${DIM}$*${R}"; }
hdr() { echo -e "\n${CYAN}${BOLD}── $* ${R}"; }
INSTALL_DIR="$HOME/.${DAEMON_LABEL}"
BIN_DIR="$HOME/.local/bin"
LAUNCHER="$BIN_DIR/${CLI}"
# ── Banner ────────────────────────────────────────────────────────────────────
echo -e "${RED}${BOLD}"
echo ' ██████╗ █████╗ ███████╗███╗ ███╗ ██████╗ ███╗ ██╗██████╗ ██████╗ '
echo ' ██╔══██╗██╔══██╗██╔════╝████╗ ████║██╔═══██╗████╗ ██║╚═██╔═╝██╔═══██╗ '
echo ' ██║ ██║███████║█████╗ ██╔████╔██║██║ ██║██╔██╗ ██║ ██║ ██║ ██║ '
echo ' ██║ ██║██╔══██║██╔══╝ ██║╚██╔╝██║██║ ██║██║╚██╗██║ ██║ ██║▄▄ ██║ '
echo ' ██████╔╝██║ ██║███████╗██║ ╚═╝ ██║╚██████╔╝██║ ╚████║██████╗╚██████╔╝ '
echo ' ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═════╝ ╚══▀▀═╝ '
echo -e "${R}${DIM} * Linux Troubleshooting Assistant *${R}"
echo ""
# ══════════════════════════════════════════════════════════════════════════════
# 1 — Python check
# ══════════════════════════════════════════════════════════════════════════════
hdr "Checking requirements"
if ! command -v python3 &>/dev/null; then
err "Python 3 is not installed."
echo ""
echo " Install it first:"
echo " sudo apt install python3 ← Ubuntu / Debian / Mint"
echo " sudo dnf install python3 ← Fedora"
echo " sudo pacman -S python ← Arch"
echo ""
exit 1
fi
PYMAJ=$(python3 -c "import sys; print(sys.version_info.major)")
PYMIN=$(python3 -c "import sys; print(sys.version_info.minor)")
PYVER="${PYMAJ}.${PYMIN}"
if [ "$PYMAJ" -lt 3 ] || { [ "$PYMAJ" -eq 3 ] && [ "$PYMIN" -lt 8 ]; }; then
err "Python $PYVER found — ${PRODUCT} requires Python 3.8+."
exit 1
fi
ok "Python $PYVER"
# ══════════════════════════════════════════════════════════════════════════════
# 2 — Download or copy scripts
# ══════════════════════════════════════════════════════════════════════════════
hdr "Installing ${PRODUCT}"
mkdir -p "$INSTALL_DIR" "$BIN_DIR"
INSTALLER_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-install.sh}")" 2>/dev/null && pwd || echo ".")"
SCRIPTS=("daemoniq-imp.py" "daemoniq-sovereign.py")
INSTALLED=0
_download() {
local file="$1" dest="$2"
if command -v curl &>/dev/null; then
curl -fsSL "$BASE_URL/$file" -o "$dest" 2>/dev/null
elif command -v wget &>/dev/null; then
wget -q "$BASE_URL/$file" -O "$dest" 2>/dev/null
else
return 1
fi
}
for script in "${SCRIPTS[@]}"; do
LOCAL=""
for candidate in "$INSTALLER_DIR/$script" "./$script" "$HOME/Downloads/$script"; do
if [ -f "$candidate" ]; then LOCAL="$candidate"; break; fi
done
if [ -n "$LOCAL" ]; then
cp "$LOCAL" "$INSTALL_DIR/$script"
chmod +x "$INSTALL_DIR/$script"
ok "Installed $script"
INSTALLED=$((INSTALLED + 1))
elif _download "$script" "$INSTALL_DIR/$script"; then
chmod +x "$INSTALL_DIR/$script"
ok "Downloaded $script"
INSTALLED=$((INSTALLED + 1))
else
warn "Could not get $script — skipping"
fi
done
if [ "$INSTALLED" -eq 0 ]; then
err "No scripts could be installed."
echo " Place the script files next to install.sh, or check your internet connection."
exit 1
fi
# ══════════════════════════════════════════════════════════════════════════════
# 3 — Create the launcher
# ══════════════════════════════════════════════════════════════════════════════
cat > "$LAUNCHER" << LAUNCHER_EOF
#!/usr/bin/env bash
INSTALL_DIR="\$HOME/.${DAEMON_LABEL}"
CONFIG="\$INSTALL_DIR/config.json"
# First run — no config yet, launch setup wizard
if [ ! -f "\$CONFIG" ] && [[ "\${1:-}" != "setup" ]] && [[ "\${1:-}" != "_daemon_bg" ]] && [[ "\${1:-}" != "_daemon_fg" ]]; then
exec python3 "\$INSTALL_DIR/daemoniq-imp.py" setup
fi
# Read active script from config
ACTIVE=\$(python3 -c "
import json
try: print(json.load(open('\$CONFIG')).get('active_script','daemoniq-imp.py'))
except: print('daemoniq-imp.py')
" 2>/dev/null || echo "daemoniq-imp.py")
SCRIPT="\$INSTALL_DIR/\$ACTIVE"
[ ! -f "\$SCRIPT" ] && { echo "Error: \$SCRIPT not found. Run: ${CLI} setup"; exit 1; }
exec python3 "\$SCRIPT" "\$@"
LAUNCHER_EOF
chmod +x "$LAUNCHER"
ok "Created 'daemoniq' command"
# ══════════════════════════════════════════════════════════════════════════════
# 4 — PATH (silent — no prompt)
# ══════════════════════════════════════════════════════════════════════════════
hdr "Configuring PATH"
SHELL_RC=""
case "${SHELL:-}" in
*/zsh) SHELL_RC="$HOME/.zshrc" ;;
*/fish) SHELL_RC="$HOME/.config/fish/config.fish" ;;
*) SHELL_RC="$HOME/.bashrc" ;;
esac
if [[ ":${PATH}:" == *":${BIN_DIR}:"* ]]; then
ok "Already in PATH"
else
if [ -n "$SHELL_RC" ] && ! grep -q "local/bin" "$SHELL_RC" 2>/dev/null; then
if [[ "${SHELL:-}" == */fish ]]; then
echo 'fish_add_path $HOME/.local/bin' >> "$SHELL_RC"
else
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$SHELL_RC"
fi
fi
export PATH="$BIN_DIR:$PATH"
ok "Added ~/.local/bin to PATH in ${SHELL_RC##*/}"
fi
# ══════════════════════════════════════════════════════════════════════════════
# 5 — Auto-start on login (one optional question)
# ══════════════════════════════════════════════════════════════════════════════
if command -v systemctl &>/dev/null && [ "${EUID:-$(id -u)}" -ne 0 ]; then
hdr "Auto-start on login (optional)"
read -r -p " Start DaemonIQ automatically when you log in? [y/n] " ans
if [[ "${ans:-}" =~ ^[Yy]$ ]]; then
SVCDIR="$HOME/.config/systemd/user"
mkdir -p "$SVCDIR"
{
echo "[Unit]"
echo "Description=${PRODUCT} Troubleshooting Daemon"
echo "After=network.target"
echo ""
echo "[Service]"
echo "Type=forking"
echo "ExecStart=${LAUNCHER} _daemon_bg"
echo "PIDFile=/tmp/${DAEMON_LABEL}.pid"
echo "Restart=on-failure"
echo "RestartSec=5"
echo "EnvironmentFile=-%h/.${DAEMON_LABEL}/env"
echo ""
echo "[Install]"
echo "WantedBy=default.target"
} > "$SVCDIR/${DAEMON_LABEL}.service"
systemctl --user daemon-reload
systemctl --user enable "${DAEMON_LABEL}.service" 2>/dev/null || true
ok "Auto-start enabled"
else
info "Skipped — DaemonIQ starts on demand when you run it."
fi
fi
# ══════════════════════════════════════════════════════════════════════════════
# Done
# ══════════════════════════════════════════════════════════════════════════════
echo ""
echo -e "${GREEN}${BOLD} ✓ DaemonIQ installed!${R}"
echo ""
# Add to PATH for this session so we can run setup immediately
export PATH="$BIN_DIR:$PATH"
echo -e " Starting setup wizard...${R}"
echo ""
python3 "$INSTALL_DIR/daemoniq-imp.py" setup
echo ""
echo -e "${GREEN}${BOLD} Ready. Run ${CYAN}daemoniq${GREEN} in a new terminal to start.${R}"
echo ""