forked from Botspot/pi-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload
executable file
·155 lines (134 loc) · 4.16 KB
/
preload
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
#!/bin/bash
#this generates a yad-friendly app list. This is run every time the gui script is executed.
#if this script detects nothing has changed since last run, then it will echo back the app list that was generated last time.
DIRECTORY="$(readlink -f "$(dirname "$0")")"
function error {
echo -e "\e[91m$1\e[39m" 1>&2
exit 1
}
#determine if host system is 64 bit arm64 or 32 bit armhf
if [ ! -z "$(file "$(readlink -f "/sbin/init")" | grep 64)" ];then
arch=64
elif [ ! -z "$(file "$(readlink -f "/sbin/init")" | grep 32)" ];then
arch=32
else
error "Failed to detect OS CPU architecture! Something is very wrong."
fi
#yad or xlunch format
format="$1"
if [ -z "$format" ];then
format=yad
fi
mkdir -p "${DIRECTORY}/data/preload"
mktimestamps() {
#these directories are checked for changes
checkdirs="${DIRECTORY}/apps
${DIRECTORY}/data/settings
${DIRECTORY}/data/status"
timestamps=''
PREIFS="$IFS"
IFS=$'\n'
for dir in $checkdirs
do
timestamps="$timestamps
${dir}/$(ls -t "$dir" | head -n1)
$(stat -c %Y "${dir}/$(ls -t "$dir" | head -n1)")"
done
IFS="$PREIFS"
#remove first empty newline
timestamps="${timestamps:1}"
}
reloadlist=0
if [ -f "${DIRECTORY}/data/preload/timestamps" ];then
#get modified timestamps for directories
mktimestamps
if [ "$timestamps" == "$(cat "${DIRECTORY}/data/preload/timestamps")" ];then
#if current timestamps and saved timestamps match, then don't reload the list
reloadlist=0
echo "Timestamps match." 1>&2
else
#timestamps don't match, so reload the list
reloadlist=1
echo "Timestamps don"\'"t match" 1>&2
fi
else
#timestamp file not found
reloadlist=1
fi
if [ ! -f "${DIRECTORY}/data/preload/LIST" ];then
echo "list file does not exist." 1>&2
reloadlist=1
fi
if [ $reloadlist == 1 ];then
echo "Generating list..." 1>&2
#get list of apps ----------------------------------- and exclude apps mentioned in hidelist file
APPS="$(echo "$(ls "${DIRECTORY}/apps")" | grep -vxE "$(cat "${DIRECTORY}/data/hidelist" | tr '\n' '|')")"
#APPS="$(echo "$(ls "${DIRECTORY}/apps")")"
#remove apps that are not compatible with OS architecture
PREIFS="$IFS"
IFS=$'\n'
for i in $APPS
do
#if install script doesn't exist -------------------- and if os-specific install script doesn't exist, then...
if [ ! -f "${DIRECTORY}/apps/${i}/install" ] && [ ! -f "${DIRECTORY}/apps/${i}/install-${arch}" ];then
#...remove the app from the list
echo "Removing $i from the list because it is not compatible with your ${arch}-bit OS." 1>&2
APPS="$(echo "$APPS" | grep -vx "$i")"
fi
done
IFS="$PREIFS"
#shuffle the list if enabled
if [ "$(cat "${DIRECTORY}/data/settings/Shuffle App list")" == 'Yes' ];then
APPS="$(echo "$APPS" | shuf)"
fi
if [ "$format" == yad ];then
PREIFS="$IFS"
IFS=$'\n'
LIST=''
for i in $APPS
do
LIST="$LIST$(echo "${DIRECTORY}/icons/$(cat "${DIRECTORY}/data/status/${i}" 2>/dev/null || echo "none").png")
${DIRECTORY}/apps/${i}/icon-24.png
$i
"\("$(cat "${DIRECTORY}/data/status/${i}" 2>/dev/null || echo "uninstalled")"\)" $(echo "$(cat "${DIRECTORY}/apps/${i}/description" || echo "Description unavailable")" | head -n1)
"
done
IFS="$PREIFS"
elif [ "$format" == xlunch ];then
PREIFS="$IFS"
IFS=$'\n'
LIST=''
for i in $APPS
do
LIST="$LIST
${i} "\("$(cat "${DIRECTORY}/data/status/${i}" 2>/dev/null || echo "uninstalled")"\)";${DIRECTORY}/apps/${i}/icon-64.png;${i}"
done
IFS="$PREIFS"
fi
LIST="$(echo -e "$LIST")"
#save entire list string to file for future use
echo "$LIST" > "${DIRECTORY}/data/preload/LIST"
export CACHED_LIST="$LIST"
#save timestamps to file too
mktimestamps
echo "$timestamps" > "${DIRECTORY}/data/preload/timestamps"
else
if [ -z "$CACHED_LIST" ];then
echo "Reading list file..." 1>&2
LIST="$(cat "${DIRECTORY}/data/preload/LIST")"
export CACHED_LIST="$LIST"
else
echo "Reading list variable..." 1>&2
LIST="$CACHED_LIST"
fi
fi
(#put icons in cache
PREIFS="$IFS"
IFS=$'\n'
for icon in $(echo "$LIST" | grep icon-24)
do
cat "$icon" 1>/dev/null
#echo "Putting $icon in cache..." 1>&2
done
IFS="$PREIFS" ) &
echo "$LIST"