blob: bd40554c0acbe748b70d994c685732e130bede1c [file] [log] [blame]
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +01001#!/bin/bash
Jon West1c44e902021-04-01 19:29:47 -04002#~ set -e
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +01003
Jon West9fd0d662021-04-01 16:07:30 -04004RED='\033[0;31m'
5GREEN='\033[0;32m'
6YELLOW='\033[0;33m'
7LT_BLUE='\033[0;34m'
8
9NC='\033[0m' # No Color
10
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +010011repo="https://f-droid.org/repo/"
Jon West0d65aa82021-04-04 19:55:11 -040012repo2="https://bubu1.eu/fdroid/repo/"
13repo3="https://fdroid.tetaneutral.net/fdroid/repo/"
14repo4="https://mirror.cyberbits.eu/fdroid/repo/"
15repo5="https://ftp.fau.de/fdroid/repo/"
16repo6="https://ftp.osuosl.org/pub/fdroid/repo/"
17repo7="https://mirror.scd31.com/fdroid/repo/"
18repo8="https://plug-mirror.rcac.purdue.edu/fdroid/repo/"
19repo9="https://mirrors.tuna.tsinghua.edu.cn/fdroid/repo/"
20repo10="https://mirrors.nju.edu.cn/fdroid/repo/"
21repo11="https://mirror.kumi.systems/fdroid/repo/"
22repo12="https://ftp.lysator.liu.se/pub/fdroid/repo/"
23repo13="https://mirror.librelabucm.org/fdroid/repo/"
24
25microg="https://microg.org/fdroid/repo"
26microg_dir="tmp/microg"
27
28nanolx="https://nanolx.org/fdroid/repo"
29nanolx_dir="tmp/nanolx"
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +010030
Jon West6969cea2021-05-02 12:18:10 -040031newpipe="https://archive.newpipe.net/fdroid/repo/"
32newpipe_dir="tmp/newpipe"
33
Jon West81cd34f2021-04-01 19:30:33 -040034# Device type selection
Jon West3ac1d3e2021-04-24 18:38:42 -040035if [ "$1" == "" ]; then
Jon West81cd34f2021-04-01 19:30:33 -040036PS3='Which device type do you plan on building?: '
Jon West0d65aa82021-04-04 19:55:11 -040037echo -e ${YELLOW}"(default is 'ABI:x86_64 & ABI2:x86')"
Jon West81cd34f2021-04-01 19:30:33 -040038TMOUT=10
39options=("ABI:x86_64 & ABI2:x86"
40 "ABI:arm64-v8a & ABI2:armeabi-v7a")
Jon West0d65aa82021-04-04 19:55:11 -040041echo -e "Timeout in $TMOUT sec."${NC}
Jon West81cd34f2021-04-01 19:30:33 -040042select opt in "${options[@]}"
43do
44 case $opt in
45 "ABI:x86_64 & ABI2:x86")
46 echo "you chose choice $REPLY which is $opt"
47 MAIN_ARCH="x86_64"
48 SUB_ARCH="x86"
49 break
50 ;;
51 "ABI:arm64-v8a & ABI2:armeabi-v7a")
52 echo "you chose choice $REPLY which is $opt"
53 MAIN_ARCH="arm64-v8a"
54 SUB_ARCH="armeabi-v7a"
55 break
56 ;;
57 *) echo "invalid option $REPLY";;
58 esac
59done
60if [ "$opt" == "" ]; then
61 MAIN_ARCH="x86_64"
62 SUB_ARCH="x86"
63fi
Jon West3ac1d3e2021-04-24 18:38:42 -040064fi
65
66if [ "$1" == "1" ]; then
67 echo "ABI:x86_64 & ABI2:x86 was preselected"
68 MAIN_ARCH="x86_64"
69 SUB_ARCH="x86"
70fi
71if [ "$1" == "2" ]; then
72 echo "ABI:arm64-v8a & ABI2:armeabi-v7a was preselected"
73 MAIN_ARCH="arm64-v8a"
74 SUB_ARCH="armeabi-v7a"
75fi
Jon West1c44e902021-04-01 19:29:47 -040076
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +010077addCopy() {
Pierre-Hugues Husson16644af2020-04-05 16:08:40 +020078 addition=""
Jon West1c44e902021-04-01 19:29:47 -040079 if [ "$native" != "" ]
80 then
81 unzip bin/$1 "lib/*"
82 if [ "$native" == "$MAIN_ARCH" ];then
83 addition="
84LOCAL_PREBUILT_JNI_LIBS := \\
Jon West3ac1d3e2021-04-24 18:38:42 -040085$(unzip -olv bin/$1 |grep -v Stored |sed -nE 's;.*(lib/'"$MAIN_ARCH"'/.*);\t\1 \\;p')
Jon West1c44e902021-04-01 19:29:47 -040086 "
87 fi
88 if [ "$native" == "$SUB_ARCH" ];then
89 addition="
90LOCAL_MULTILIB := 32
91LOCAL_PREBUILT_JNI_LIBS := \\
Jon West3ac1d3e2021-04-24 18:38:42 -040092$(unzip -olv bin/$1 |grep -v Stored |sed -nE 's;.*(lib/'"$SUB_ARCH"'/.*);\t\1 \\;p')
Jon West1c44e902021-04-01 19:29:47 -040093 "
94 fi
95 fi
Pierre-Hugues Hussone1b56f52020-11-03 18:15:49 +010096 if [ "$2" == com.google.android.gms ] || [ "$2" == com.android.vending ] ;then
97 addition="LOCAL_PRIVILEGED_MODULE := true"
98 fi
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +010099cat >> Android.mk <<EOF
100include \$(CLEAR_VARS)
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +0100101LOCAL_MODULE := $2
102LOCAL_MODULE_TAGS := optional
103LOCAL_SRC_FILES := bin/$1
104LOCAL_MODULE_CLASS := APPS
Pierre-Hugues Hussonea4517b2017-12-04 16:45:04 +0100105LOCAL_CERTIFICATE := PRESIGNED
Pierre-Hugues Husson3811d162017-12-04 23:07:00 +0100106LOCAL_OVERRIDES_PACKAGES := $3
Pierre-Hugues Husson16644af2020-04-05 16:08:40 +0200107$addition
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +0100108include \$(BUILD_PREBUILT)
Pierre-Hugues Husson5250fdd2017-12-04 22:18:22 +0100109
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +0100110EOF
111echo -e "\t$2 \\" >> apps.mk
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100112}
113
Jon West9fd0d662021-04-01 16:07:30 -0400114echo -e "${LT_BLUE}# Setting Up${NC}"
Pierre-Hugues Husson16644af2020-04-05 16:08:40 +0200115rm -Rf apps.mk lib
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +0100116cat > Android.mk <<EOF
117LOCAL_PATH := \$(my-dir)
118
119EOF
120echo -e 'PRODUCT_PACKAGES += \\' > apps.mk
121
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100122mkdir -p bin
Pierre-Hugues Hussone1b56f52020-11-03 18:15:49 +0100123
Pierre-Hugues Husson5250fdd2017-12-04 22:18:22 +0100124#downloadFromFdroid packageName overrides
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100125downloadFromFdroid() {
126 mkdir -p tmp
Pierre-Hugues Hussone1b56f52020-11-03 18:15:49 +0100127 [ "$oldRepo" != "$repo" ] && rm -f tmp/index.xml
128 oldRepo="$repo"
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100129 if [ ! -f tmp/index.xml ];then
130 #TODO: Check security keys
Jon West0d65aa82021-04-04 19:55:11 -0400131 failed_count=0
132 array=( $repo $repo2 $repo3 $repo4 $repo5 $repo6 $repo7 $repo8 $repo9 $repo10 $repo11 $repo12 $repo13 )
133 for url in $repo $repo2 $repo3 $repo4 $repo5 $repo6 $repo7 $repo8 $repo9 $repo10 $repo11 $repo12 $repo13 ; do
134 echo -e "${GREEN}# Trying: $url ${NC}"
135 if wget --connect-timeout=10 --tries=2 ${url}index.jar -O tmp/index.jar; then
136 unzip -p tmp/index.jar index.xml > tmp/index.xml
137 echo -e "${GREEN}# Downloaded from $url ${NC}"
138 failed=
139 repo=${url}
140 passed=true
141 break
142 elif [ "$failed" ]; then
143 echo -e "${YELLOW}# $url broken ${NC}"
144 failed=true
145 failed_count=$((failed_count+1))
146 else
147 echo -e "${YELLOW}# $url failed ${NC}"
148 failed=true
149 failed_count=$((failed_count+1))
150 fi
151
152 done
153 echo -e "${Yellow}# Total mirrors: ${#array[@]} ${NC}"
154 echo -e "${RED}# Failed $failed_count mirrors ${NC}"
155 if [ "$failed_count" == "${#array[@]}" ]; then
156 echo -e "${RED}# Failed too many mirrors: $failed_count ${NC}"
157 exit
158
159 fi
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100160 fi
Jon West1c44e902021-04-01 19:29:47 -0400161
162 index=1
163 apk="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./apkname tmp/index.xml)"
164 native="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./nativecode tmp/index.xml)"
165 if [ "$native" != "" ]
166 then
167 index=1
168 while true
169 do
170 apk="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./apkname tmp/index.xml)"
171 native="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./nativecode tmp/index.xml)"
172 if [ "$native" != "" ] && [ "$(echo $native | grep $MAIN_ARCH)" != "" ]
173 then
174 native=$MAIN_ARCH
175 echo -e "${YELLOW}# native is $native ${NC}"
176 break
177 fi
178 if [ "$native" == "" ]
179 then
180 echo -e "${YELLOW}# native is blank or $native ${NC}"
181 break
182 fi
183 index=$((index + 1))
184 done
185 if [ "$native" != "$MAIN_ARCH" ]
186 then
187 index=1
188 while true
189 do
190 apk="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./apkname tmp/index.xml)"
191 native="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./nativecode tmp/index.xml)"
192 if [ "$native" != "" ] && [ "$(echo $native | grep $SUB_ARCH)" != "" ]
193 then
194 native=$SUB_ARCH
195 echo -e "${YELLOW}# native is $native ${NC}"
196 break
197 fi
198 index=$((index + 1))
199 done
200 if [ "$native" != "$SUB_ARCH" ]
201 then
202 echo -e "${RED} $1 is not available in $MAIN_ARCH nor $SUB_ARCH ${NC}"
203 exit 1
204 fi
205 fi
206 fi
paledega6303e2a2020-03-02 09:39:50 +0300207 if [ ! -f bin/$apk ];then
208 while ! wget --connect-timeout=10 $repo/$apk -O bin/$apk;do sleep 1;done
Jon Wested6857b2021-04-01 16:37:30 -0400209 else
210 echo -e "${GREEN}# Already grabbed $apk ${NC}"
paledega6303e2a2020-03-02 09:39:50 +0300211 fi
Pierre-Hugues Husson5250fdd2017-12-04 22:18:22 +0100212 addCopy $apk $1 "$2"
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100213}
Jon West1c44e902021-04-01 19:29:47 -0400214
Jon West0d65aa82021-04-04 19:55:11 -0400215downloadStuff() {
216 what="$1"
217 where="$2"
218
219 while ! wget --connect-timeout=10 --tries=2 "$what" -O "$where";do sleep 1;done
220}
221
222#downloadFromRepo repo repo_dir packageName overrides
223downloadFromRepo() {
224 repo="$1"
225 repo_dir="$2"
226 package="$3"
227 overrides="$4"
228
229 mkdir -p "$repo_dir"
230 if [ ! -f "$repo_dir"/index.xml ];then
231 downloadStuff "$repo"/index.jar "$repo_dir"/index.jar
232 unzip -p "$repo_dir"/index.jar index.xml > "$repo_dir"/index.xml
233 fi
234
235 marketvercode="$(xmlstarlet sel -t -m '//application[id="'"$package"'"]' -v ./marketvercode "$repo_dir"/index.xml || true)"
236 apk="$(xmlstarlet sel -t -m '//application[id="'"$package"'"]/package[versioncode="'"$marketvercode"'"]' -v ./apkname "$repo_dir"/index.xml || xmlstarlet sel -t -m '//application[id="'"$package"'"]/package[1]' -v ./apkname "$repo_dir"/index.xml)"
237 downloadStuff "$repo"/"$apk" bin/"$apk"
238
239 addCopy "$apk" "$package" "$overrides"
240}
241
242
Jon West9fd0d662021-04-01 16:07:30 -0400243echo -e "${YELLOW}# grabbing F-Droid Apps${NC}"
Jon West311f0ca2021-04-01 15:42:33 -0400244# Terminal Emulator
Jon West6969cea2021-05-02 12:18:10 -0400245#~ downloadFromFdroid com.termoneplus
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100246#Navigation
Jon West6969cea2021-05-02 12:18:10 -0400247#~ downloadFromFdroid net.osmand.plus
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100248#Calendar
Jon Wested6857b2021-04-01 16:37:30 -0400249downloadFromFdroid ws.xsoh.etar "Calendar"
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100250#Pdf viewer
Jon West6969cea2021-05-02 12:18:10 -0400251#~ downloadFromFdroid com.artifex.mupdf.viewer.app
Unknown2974a752020-11-07 20:18:09 -0500252# Aurora App Store
Pierre-Hugues Husson06683c22020-03-31 23:16:24 +0200253downloadFromFdroid com.aurora.store
Pierre-Hugues Hussonb7a5f4a2017-12-04 17:07:27 +0100254#Mail client
Jon West6656cb52021-04-25 11:08:08 -0400255#~ downloadFromFdroid com.fsck.k9 "Email"
Pierre-Hugues Hussone46e3702018-06-04 21:19:57 +0200256#Calendar/Contacts sync
Pierre-Hugues Husson06683c22020-03-31 23:16:24 +0200257downloadFromFdroid com.etesync.syncadapter
Pierre-Hugues Husson06683c22020-03-31 23:16:24 +0200258# Todo lists
Jon West6969cea2021-05-02 12:18:10 -0400259#~ downloadFromFdroid org.tasks
Unknown2974a752020-11-07 20:18:09 -0500260#Fake assistant that research on duckduckgo
261downloadFromFdroid co.pxhouse.sas
262# Gallery App
263downloadFromFdroid com.simplemobiletools.gallery.pro "Photos Gallery Gallery2"
264# Aurora Fdroid
265downloadFromFdroid com.aurora.adroid
Jon Wested6857b2021-04-01 16:37:30 -0400266# F-Droid App Store
267#~ downloadFromFdroid org.fdroid.fdroid
Jon West1c44e902021-04-01 19:29:47 -0400268#fdroid extension
Jon West3ac1d3e2021-04-24 18:38:42 -0400269downloadFromFdroid org.fdroid.fdroid.privileged
q0kHaN77f09432019-11-11 12:36:35 +0000270#Phonograph
Jon West6969cea2021-05-02 12:18:10 -0400271#~ downloadFromFdroid com.kabouzeid.gramophone "Eleven"
kisekinopureya6a3d0362020-01-19 21:35:08 +0300272#Alarmio
Jon West6969cea2021-05-02 12:18:10 -0400273#~ downloadFromFdroid me.jfenn.alarmio "GoogleClock DeskClock"
kisekinopureya13634d72019-12-12 01:23:53 +0300274#Mozilla Nlp
kisekinopureyae47d0882020-01-19 21:44:48 +0300275downloadFromFdroid org.microg.nlp.backend.ichnaea
kisekinopureyabb4217d2019-12-10 20:47:31 +0300276#Nominatim Nlp
277downloadFromFdroid org.microg.nlp.backend.nominatim
Jon Westddb6a382021-04-01 15:43:49 -0400278# EtchDroid USB Writer
Jon West6969cea2021-05-02 12:18:10 -0400279#~ downloadFromFdroid eu.depau.etchdroid
280# NewPipe (outdated)
Jon Westdd1770f2021-04-04 19:54:58 -0400281downloadFromFdroid org.schabi.newpipe
Pierre-Hugues Hussonb7a5f4a2017-12-04 17:07:27 +0100282
Jon West3ac1d3e2021-04-24 18:38:42 -0400283# Astian Apps
284# Midori Browser
285downloadFromFdroid org.midorinext.android "Browser2 QuickSearchBox"
286# Astian Spika
287# downloadFromFdroid org.astianspika.android
288# Astian Cloud
289# downloadFromFdroid org.astiancloud.android
290# Astian VPN
291# downloadFromFdroid org.astianvpn.android
292
kisekinopureyabb4217d2019-12-10 20:47:31 +0300293#Web browser
Unknown2974a752020-11-07 20:18:09 -0500294#~ downloadFromFdroid org.mozilla.fennec_fdroid "Browser2 QuickSearchBox"
Jon West6969cea2021-05-02 12:18:10 -0400295#icecat
296#~ downloadFromFdroid org.gnu.icecat "Browser2 QuickSearchBox"
Unknown2974a752020-11-07 20:18:09 -0500297#Public transportation
298#~ downloadFromFdroid de.grobox.liberario
299#Ciphered Instant Messaging
300#downloadFromFdroid im.vector.alpha
301#Nextcloud client
302#~ downloadFromFdroid com.nextcloud.client
303# Social Media Apps
Unknowna0b877c2020-11-07 19:48:33 -0500304#~ downloadFromFdroid org.mariotaku.twidere
305#~ downloadFromFdroid com.pitchedapps.frost
306#~ downloadFromFdroid com.keylesspalace.tusky
paledega6303e2a2020-03-02 09:39:50 +0300307
Jon West9fd0d662021-04-01 16:07:30 -0400308echo -e "${YELLOW}# grabbing MicroG Apps${NC}"
Jon West0d65aa82021-04-04 19:55:11 -0400309downloadFromRepo "$microg" "$microg_dir" com.google.android.gms
310downloadFromRepo "$microg" "$microg_dir" com.google.android.gsf
311downloadFromRepo "$microg" "$microg_dir" com.android.vending "Google Play Store"
312downloadFromRepo "$microg" "$microg_dir" org.microg.gms.droidguard
Pierre-Hugues Hussone1b56f52020-11-03 18:15:49 +0100313
Jon West9fd0d662021-04-01 16:07:30 -0400314echo -e "${YELLOW}# grabbing NanoLX Apps${NC}"
Jon West0d65aa82021-04-04 19:55:11 -0400315downloadFromRepo "$nanolx" "$nanolx_dir" is.xyz.mpv
Unknown2974a752020-11-07 20:18:09 -0500316
Jon West6969cea2021-05-02 12:18:10 -0400317#~ echo -e "${YELLOW}# grabbing NewPipe ${NC}"
318#~ downloadFromRepo "$newpipe" "$newpipe_dir" org.schabi.newpip
319
Jon West9fd0d662021-04-01 16:07:30 -0400320echo -e "${LT_BLUE}# finishing up apps.mk${NC}"
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +0100321echo >> apps.mk
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100322
Jon West9fd0d662021-04-01 16:07:30 -0400323echo -e "${YELLOW}# Cleaning up${NC}"
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100324rm -Rf tmp
Jon West9fd0d662021-04-01 16:07:30 -0400325
326echo -e "${GREEN}# DONE${NC}"