-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi
executable file
·123 lines (109 loc) · 5.22 KB
/
api
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
#!/bin/bash
# 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"
echo "x-terminal-emulator -e 'bash -c \"sudo echo && bash $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"
echo "x-terminal-emulator -e 'bash -c \"sudo echo && bash $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"
echo "x-terminal-emulator -e 'bash -c \"sudo echo && bash $temp_script\"'"
else
echo "echo 'Installation script not found for this architecture.'"
fi
fi
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 "echo 'Uninstallation script not found for this architecture.'" >"$temp_script"
fi
fi
fi
echo "x-terminal-emulator -e 'sudo echo && bash \"$temp_script\"'"
}
# Function to search for apps
search_apps() {
query=$(GTK_THEME="${theme}" yad --title="Search Apps" --text="Enter app name:" --entry)
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")
fi
done
if [ ${#apps_found[@]} -gt 0 ]; then
selected_category2=$(GTK_THEME="${theme}" yad --title="Search Results for ${query}" --width=400 --height=300 --list --column="Icon:IMG" --column="App Name" "${apps_found[@]}" --borders=10)
if [ -n "$selected_category2" ]; then
echo "$(echo ${selected_category2} | sed 's/|//g')" > /tmp/tmpname
./gui showdetails
fi
else
GTK_THEME="${theme}" yad --title="Search Results for ${query}" --width=300 --height=100 --text="No apps found for '${query}'.\nPlease try another query." --borders=10 --button="OK:0" --center
fi
fi
}
# 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"
fi