This repository was archived by the owner on Jan 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-manager.sh
More file actions
88 lines (69 loc) · 2.54 KB
/
app-manager.sh
File metadata and controls
88 lines (69 loc) · 2.54 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
#!/bin/bash
MENU_JSON="$HOME/t41launcher/menu.json"
APPS_DIR="$HOME/t41launcher/apps"
REPO_JSON="https://raw.githubusercontent.com/nebuff/t41launcher/refs/heads/main/apps/apps.json"
mkdir -p "$APPS_DIR"
add_app() {
app_data=$(curl -fsSL "$REPO_JSON")
if [ -z "$app_data" ]; then
dialog --msgbox "Failed to retrieve app list." 6 40
return
fi
mapfile -t app_names < <(echo "$app_data" | jq -r '.[].name')
mapfile -t descriptions < <(echo "$app_data" | jq -r '.[].description')
menu_items=()
for i in "${!app_names[@]}"; do
menu_items+=("${app_names[$i]}" "${descriptions[$i]}")
done
selected_app=$(dialog --menu "Available Apps:" 20 60 15 "${menu_items[@]}" 3>&1 1>&2 2>&3)
[ $? -ne 0 ] && return
app_entry=$(echo "$app_data" | jq -c --arg sel "$selected_app" '.[] | select(.name == $sel)')
app_url=$(echo "$app_entry" | jq -r '.file')
script_name=$(basename "$app_url")
local_path="$APPS_DIR/$script_name"
curl -fsSL "$app_url" -o "$local_path"
chmod +x "$local_path"
# Construct new menu entry
new_entry=$(echo "$app_entry" | jq --arg cmd "bash $local_path" 'del(.file) | .command = $cmd')
# Check if the app already exists in menu.json
if jq -e ".[] | select(.name == \"$selected_app\")" "$MENU_JSON" > /dev/null; then
dialog --msgbox "App already exists in menu.json." 6 40
return
fi
tmp_file=$(mktemp)
jq --argjson entry "$new_entry" '. + [ $entry ]' "$MENU_JSON" > "$tmp_file" && mv "$tmp_file" "$MENU_JSON"
dialog --msgbox "$selected_app installed and added to launcher." 6 50
}
list_apps() {
mapfile -t apps < <(ls "$APPS_DIR")
dialog --msgbox "Installed Apps:\n\n${apps[*]}" 20 50
}
delete_app() {
mapfile -t apps < <(ls "$APPS_DIR")
[ ${#apps[@]} -eq 0 ] && dialog --msgbox "No apps installed." 6 40 && return
menu_items=()
for app in "${apps[@]}"; do
menu_items+=("$app" "Remove $app")
done
selected=$(dialog --menu "Remove which app?" 20 60 15 "${menu_items[@]}" 3>&1 1>&2 2>&3)
[ $? -ne 0 ] && return
rm -f "$APPS_DIR/$selected"
jq "map(select(.name != \"$selected\"))" "$MENU_JSON" > /tmp/menu_tmp.json && mv /tmp/menu_tmp.json "$MENU_JSON"
dialog --msgbox "$selected removed from system and menu." 6 40
}
while true; do
choice=$(dialog --backtitle "T41 Launcher App Manager" --title "App Manager" \
--menu "Select an option:" 15 50 6 \
1 "Add App from GitHub" \
2 "List Installed Apps" \
3 "Delete App" \
4 "Exit" \
3>&1 1>&2 2>&3)
case $choice in
1) add_app ;;
2) list_apps ;;
3) delete_app ;;
*) break ;;
esac
done
clear