-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi
More file actions
executable file
·220 lines (195 loc) · 8.86 KB
/
api
File metadata and controls
executable file
·220 lines (195 loc) · 8.86 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
219
220
#!/bin/bash
if [[ $(xrandr --current) =~ "connected primary" ]]; then
resolution=$(xrandr --current | grep " connected primary" | awk '{print $4}' | cut -d'+' -f1)
else
resolution=$(xrandr --current | grep " connected" | awk '{print $3}' | cut -d'+' -f1)
fi
horizontal=$(echo $resolution | cut -d'x' -f1)
vertical=$(echo $resolution | cut -d'x' -f2)
theme_get() {
website_file="etc/theme"
if [ -e "$website_file" ]; then
cat "$website_file"
else
echo ""
fi
}
theme=$(theme_get)
logo() {
echo """
██╗░░░░░██╗███╗░░██╗░██████╗████████╗░█████╗░██████╗░███████╗
██║░░░░░██║████╗░██║██╔════╝╚══██╔══╝██╔══██╗██╔══██╗██╔════╝
██║░░░░░██║██╔██╗██║╚█████╗░░░░██║░░░██║░░██║██████╔╝█████╗░░
██║░░░░░██║██║╚████║░╚═══██╗░░░██║░░░██║░░██║██╔══██╗██╔══╝░░
███████╗██║██║░╚███║██████╔╝░░░██║░░░╚█████╔╝██║░░██║███████╗
╚══════╝╚═╝╚═╝░░╚══╝╚═════╝░░░░╚═╝░░░░╚════╝░╚═╝░░╚═╝╚══════╝"""
}
# Function to install an app
install_app() {
local app_directory="$1"
local selected_app_name="$2"
local installed_file="$HOME/.linstore/installed"
local temp_script=$(mktemp)
if [ -e "$app_directory/install" ]; then
echo "cd \"$app_directory\" && chmod +x install && ./install && echo \"$selected_app_name\" >> \"$installed_file\" && echo \"$selected_app_name is installed\" && cat install > \"$HOME/.linstore/installscripts/${selected_app_name}\"" >"$temp_script"
else
local architecture=$(cat "$HOME/.linstore/architecture.txt")
local install_script="install-$architecture"
if [ -e "$app_directory/$install_script" ]; then
echo "cd \"$app_directory\" && chmod +x \"$install_script\" && ./\"$install_script\" && echo \"$selected_app_name\" >> \"$installed_file\" && echo \"$selected_app_name is installed\" && cat \"$install_script\" > \"$HOME/.linstore/installscripts/${selected_app_name}\"" >"$temp_script"
else
if [ -e "$app_directory/packages" ]; then
echo "cd \"$app_directory\" && sudo apt update && sudo apt install \$(cat \"$app_directory/packages\") && echo \"$selected_app_name\" >> \"$installed_file\" && echo \"$selected_app_name is installed\" && cat packages > \"$HOME/.linstore/installscripts/${selected_app_name}\"" >"$temp_script"
else
echo "./api error 'Installation script not found for this architecture.'"
fi
fi
fi
echo "x-terminal-emulator -e './api logo && ./api info \"Installing ${selected_app_name}\n\n\" && bash -c \"sudo echo && bash $temp_script\"'"
}
get_installed_apps_from_piapps() {
find "$HOME/pi-apps/data/status" -maxdepth 1 -type f -print0 | while IFS= read -r -d '' app; do
echo "\"$app\": $(cat "$app")"
done
}
open_app() {
local app_directory="$1"
if [ -e "$app_directory/open" ]; then
cat "$app_directory/open"
else
echo ""
fi
}
# Function to install an app
installation_script() {
local app_directory="$1"
local selected_app_name="$2"
local installed_file="$HOME/.linstore/installed"
if [ -e "$app_directory/install" ]; then
echo "install"
else
local architecture=$(cat "$HOME/.linstore/architecture.txt")
local install_script="install-$architecture"
if [ -e "$app_directory/$install_script" ]; then
echo "$install_script"
else
if [ -e "$app_directory/packages" ]; then
echo "packages"
else
echo "install"
fi
fi
fi
}
# Function to uninstall an app
uninstall_app() {
local app_directory="$1"
local selected_app_name="$2"
local uninstalled_file="$HOME/.linstore/uninstalled"
local temp_script=$(mktemp)
if [ -e "$app_directory/uninstall" ]; then
echo "cd \"$app_directory\" && chmod +x uninstall && ./uninstall && echo \"$selected_app_name has been uninstalled\"" >"$temp_script"
else
local architecture=$(cat "$HOME/.linstore/architecture.txt")
local uninstall_script="uninstall-$architecture"
if [ -e "$app_directory/$uninstall_script" ]; then
echo "cd \"$app_directory\" && chmod +x \"$uninstall_script\" && ./\"$uninstall_script\" && echo \"$selected_app_name has been uninstalled\"" >"$temp_script"
else
if [ -e "$app_directory/packages" ]; then
echo "cd \"$app_directory\" && sudo apt update && sudo apt remove \$(cat \"$app_directory/packages\") && echo \"$selected_app_name has been uninstalled\"" >"$temp_script"
else
echo "./api error 'Uninstallation script not found for this architecture.'" >"$temp_script"
fi
fi
fi
echo "x-terminal-emulator -e './api logo && ./api info \"Uninstalling ${selected_app_name}\n\n\" && sudo echo && bash \"$temp_script\"'"
}
# Function to search for apps
search_apps() {
x2=$((horizontal / 2 - 65))
y2=$((vertical / 2 - 320))
query=$(GTK_THEME="${theme}" yad --title="Search Apps" --borders=10 --center --text="Enter query:" --entry \
--button="Cancel!gtk-cancel":1 --button="Search!edit-find":0)
if [ -n "$query" ]; then
app_list=$(ls -w 1 ./apps | awk 'BEGIN {ORS="\n"} {print}')
num_apps=$(echo "$app_list" | wc -l)
num_apps=$((num_apps))
echo "$num_apps"
apps_found=()
for app in ./apps/*; do
app_name=$(basename "$app")
if [[ "${app_name,,}" == *"${query,,}"* ]]; then
app_icon="apps/$app_name/icon-24.png"
app_category_file="$app/category"
app_category=$(head -n 1 "$app_category_file")
apps_found+=("$app_icon" "$app_name" "in" "$app_category")
fi
done
if [ ${#apps_found[@]} -gt 0 ]; then
selected_category2=$(GTK_THEME="${theme}" yad --center --title="Search Results" --geometry=450x600+${x2}+${y2} \
--list --text="<big><b>Search Results for '${query}'</b></big>" --column="Icon:IMG" --column="App Name" \
--column="in" --column="Category" --no-headers "${apps_found[@]}" --button="Exit!gtk-cancel":1 --button="View App!edit-find":0 &)
if [ -n "$selected_category2" ]; then
echo "$(echo ${selected_category2} | awk -F"|" '{print $2}' | sed 's/|//g')" > /tmp/tmpname
./gui showdetails &
fi
else
GTK_THEME="${theme}" yad --center --title="Search Results" --geometry=450x600+${x2}+${y2} \
--text="<big><b>No apps found for '${query}'.</b></big>\nPlease try another query." --center \
--button="Retry!edit-find":1 --button="Exit!gtk-cancel":0
response=$?
if [ $response -eq 1 ]; then
./api search
fi
fi
fi
}
update() {
pkill -f "yad*"
./api info "Updating LinStore..."
curl -s -L https://raw.githubusercontent.com/techguy16/LinStore/main/install | bash
}
buildinfo() {
echo "Update/commit $(git rev-parse --short HEAD) (\"$(git log --pretty='format:%Creset%s' --no-merges -1)\" - $(git log -1 --pretty=format:%an))"
}
error() {
local msg
msg=$(printf "%s" "$*" | tr -d '\n' | sed 's/\\n/ /g')
printf '\033[1;41;97m ERROR:\033[0;41m %s \033[0m\n' "$msg" >&2
}
warning() {
local msg
msg=$(printf "%s" "$*" | tr -d '\n' | sed 's/\\n/ /g')
printf '\033[1;43;97m WARNING:\033[0;43m %s \033[0m\n' "$msg" >&2
}
information() {
local msg
msg=$(printf "%s" "$*" | tr -d '\n' | sed 's/\\n/ /g')
printf '\033[1;104;30m INFO:\033[0;104m %s \033[0m\n' "$msg" >&2
}
# Main logic to handle command line arguments
if [[ $1 == "search" ]]; then
search_apps
elif [[ $1 == "install" ]]; then
install_app "$2" "$3"
elif [[ $1 == "whatscript" ]]; then
installation_script "$2" "$3"
elif [[ $1 == "uninstall" ]]; then
uninstall_app "$2" "$3"
elif [[ $1 == "logo" ]]; then
logo
elif [[ $1 == "error" ]]; then
error "$2"
elif [[ $1 == "warning" ]]; then
warning "$2"
elif [[ $1 == "info" ]]; then
information "$2"
elif [[ $1 == "buildinfo" ]]; then
buildinfo
elif [[ $1 == "update" ]]; then
update
elif [[ $1 == "open" ]]; then
open_app "$2"
elif [[ $1 == "installed-piapps" ]]; then
get_installed_apps_from_piapps
fi