-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-termux-widget.sh
More file actions
182 lines (163 loc) Β· 6.75 KB
/
Copy pathsetup-termux-widget.sh
File metadata and controls
182 lines (163 loc) Β· 6.75 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
#!/usr/bin/env bash
# IsotopeAI β Termux Widget shortcut installer
# Creates home-screen buttons in ~/.shortcuts/ and ~/.shortcuts/tasks/
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Usage: bash setup-termux-widget.sh
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
set -euo pipefail
info() { printf '%s\n' "$*"; }
warn() { printf 'WARN: %s\n' "$*" >&2; }
if [ -z "${TERMUX_VERSION:-}" ] && ! printf '%s' "${PREFIX:-}" | grep -q 'com.termux'; then
warn "Termux not detected. This script is for Android Termux only."
warn "Continuing anyway β run on Android Termux for full functionality."
fi
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ISO_HOME="$HOME/.isotope"
LOG_DIR="$ISO_HOME/logs"
SHORTCUT_DIR="$HOME/.shortcuts"
TASKS_DIR="$HOME/.shortcuts/tasks"
mkdir -p "$ISO_HOME" "$LOG_DIR" "$SHORTCUT_DIR" "$TASKS_DIR"
printf '%s\n' "$PROJECT_DIR" > "$ISO_HOME/project-path"
# Resolve the isotope command at setup time and embed it in shortcuts.
# Widget launches don't always inherit the interactive PATH.
PREFIX_BIN_ISO="${PREFIX:-/data/data/com.termux/files/usr}/bin/isotope"
TERMUX_BIN_ISO="/data/data/com.termux/files/usr/bin/isotope"
if [ -x "$PREFIX_BIN_ISO" ]; then
GLOBAL_ISO="$PREFIX_BIN_ISO"
elif [ -x "$TERMUX_BIN_ISO" ]; then
GLOBAL_ISO="$TERMUX_BIN_ISO"
elif command -v isotope >/dev/null 2>&1 && [ -x "$(command -v isotope)" ]; then
GLOBAL_ISO="$(command -v isotope)"
else
GLOBAL_ISO=""
fi
# ββ write a foreground shortcut (opens Termux terminal window) βββββββββββββββββ
make_shortcut() {
local name="$1"
local iso_cmd="$2"
local file="$SHORTCUT_DIR/$name"
cat > "$file" <<SHORTCUT
#!/usr/bin/env bash
# IsotopeAI widget: $name β isotope $iso_cmd
ISO_HOME="\$HOME/.isotope"
LOG_DIR="\$ISO_HOME/logs"
PROJECT_PATH_FILE="\$ISO_HOME/project-path"
PROJECT_DIR=""
[ -f "\$PROJECT_PATH_FILE" ] && PROJECT_DIR="\$(sed -n '1p' "\$PROJECT_PATH_FILE")"
mkdir -p "\$LOG_DIR"
run_isotope() {
if [ -x "$TERMUX_BIN_ISO" ]; then
"$TERMUX_BIN_ISO" $iso_cmd 2>&1 | tee -a "\$LOG_DIR/widget-$name.log"
return \${PIPESTATUS[0]}
fi
if [ -n "$GLOBAL_ISO" ] && [ -x "$GLOBAL_ISO" ]; then
"$GLOBAL_ISO" $iso_cmd 2>&1 | tee -a "\$LOG_DIR/widget-$name.log"
return \${PIPESTATUS[0]}
fi
if [ -n "\$PROJECT_DIR" ] && [ -x "\$PROJECT_DIR/bin/isotope" ]; then
ISOTOPE_PROJECT_DIR="\$PROJECT_DIR" "\$PROJECT_DIR/bin/isotope" $iso_cmd 2>&1 | tee -a "\$LOG_DIR/widget-$name.log"
return \${PIPESTATUS[0]}
fi
printf '%s\n' "IsotopeAI command not found. Run: bash setup.sh"
return 1
}
run_isotope
SHORTCUT
chmod +x "$file"
}
# ββ write a background task shortcut (no terminal window) βββββββββββββββββββββ
make_task() {
local name="$1"
local iso_cmd="$2"
local file="$TASKS_DIR/$name"
cat > "$file" <<TASK
#!/usr/bin/env bash
# IsotopeAI background task: $name β isotope $iso_cmd
ISO_HOME="\$HOME/.isotope"
LOG_DIR="\$ISO_HOME/logs"
PROJECT_PATH_FILE="\$ISO_HOME/project-path"
PROJECT_DIR=""
[ -f "\$PROJECT_PATH_FILE" ] && PROJECT_DIR="\$(sed -n '1p' "\$PROJECT_PATH_FILE")"
mkdir -p "\$LOG_DIR"
run_isotope() {
if [ -x "$TERMUX_BIN_ISO" ]; then
"$TERMUX_BIN_ISO" $iso_cmd >> "\$LOG_DIR/widget-$name.log" 2>&1
return \$?
fi
if [ -n "$GLOBAL_ISO" ] && [ -x "$GLOBAL_ISO" ]; then
"$GLOBAL_ISO" $iso_cmd >> "\$LOG_DIR/widget-$name.log" 2>&1
return \$?
fi
if [ -n "\$PROJECT_DIR" ] && [ -x "\$PROJECT_DIR/bin/isotope" ]; then
ISOTOPE_PROJECT_DIR="\$PROJECT_DIR" "\$PROJECT_DIR/bin/isotope" $iso_cmd >> "\$LOG_DIR/widget-$name.log" 2>&1
return \$?
fi
printf '%s\n' "IsotopeAI command not found. Run: bash setup.sh" >> "\$LOG_DIR/widget-$name.log"
return 1
}
run_isotope
TASK
chmod +x "$file"
}
# ββ create all shortcuts βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Foreground shortcuts (open a Termux terminal window β user sees output)
make_shortcut isotope-start start
make_shortcut isotope-stop stop
make_shortcut isotope-restart restart
make_shortcut isotope-update update
make_shortcut isotope-open open
make_shortcut isotope-doctor doctor
make_shortcut isotope-status status
make_shortcut isotope-logs logs
make_shortcut isotope-repair repair
make_shortcut isotope-reinstall-widgets reinstall-widgets
# Background task shortcuts (no terminal window β silent background operation)
# Use these for actions that should run without opening Termux
make_task isotope-stop-bg stop
make_task isotope-restart-bg restart
# ββ report ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
info ""
info "Termux Widget shortcuts installed in: $SHORTCUT_DIR"
info ""
info "Foreground shortcuts (open terminal):"
for name in isotope-start isotope-stop isotope-restart isotope-update \
isotope-open isotope-doctor isotope-status isotope-logs \
isotope-repair isotope-reinstall-widgets; do
if [ -x "$SHORTCUT_DIR/$name" ]; then
info " β
$name"
else
warn " β $name (failed to create)"
fi
done
info ""
info "Background task shortcuts (silent, no terminal):"
for name in isotope-stop-bg isotope-restart-bg; do
if [ -x "$TASKS_DIR/$name" ]; then
info " β
$name"
else
warn " β $name (failed to create)"
fi
done
if [ -x "$TERMUX_BIN_ISO" ]; then
info ""
info "Global command: $TERMUX_BIN_ISO (embedded in shortcuts)"
elif [ -n "$GLOBAL_ISO" ]; then
info ""
info "Global command: $GLOBAL_ISO (embedded in shortcuts)"
else
warn ""
warn "Global isotope command not found."
warn "Shortcuts will fall back to $PROJECT_DIR/bin/isotope"
warn "Run bash setup.sh to install the global command."
fi
info ""
info "Add buttons to your Android home screen:"
info " 1. Install Termux:Widget from F-Droid or GitHub (same source as Termux)."
info " 2. Long press the Android home screen."
info " 3. Tap Widgets β scroll to Termux Widget."
info " 4. Tap the widget and choose a shortcut:"
info " β’ isotope-start β start server + open browser"
info " β’ isotope-update β pull latest version"
info " β’ isotope-open β open in browser"
info " β’ isotope-doctor β check everything"
info " β’ isotope-repair β fix dependencies"