blob: ba57cf9e7acb2b35f2ed3d17f7ddee6bfb3fcc22 [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"
Jon Weste8209292021-05-31 17:16:19 -040040 "ABI:arm64-v8a & ABI2:armeabi-v7a"
41 "ABI:x86")
Jon West0d65aa82021-04-04 19:55:11 -040042echo -e "Timeout in $TMOUT sec."${NC}
Jon West81cd34f2021-04-01 19:30:33 -040043select opt in "${options[@]}"
44do
45 case $opt in
46 "ABI:x86_64 & ABI2:x86")
47 echo "you chose choice $REPLY which is $opt"
48 MAIN_ARCH="x86_64"
49 SUB_ARCH="x86"
50 break
51 ;;
52 "ABI:arm64-v8a & ABI2:armeabi-v7a")
53 echo "you chose choice $REPLY which is $opt"
54 MAIN_ARCH="arm64-v8a"
55 SUB_ARCH="armeabi-v7a"
56 break
57 ;;
Jon Weste8209292021-05-31 17:16:19 -040058 "ABI:x86")
59 echo "you chose choice $REPLY which is $opt"
60 MAIN_ARCH="x86"
61 break
62 ;;
Jon West81cd34f2021-04-01 19:30:33 -040063 *) echo "invalid option $REPLY";;
64 esac
65done
66if [ "$opt" == "" ]; then
67 MAIN_ARCH="x86_64"
68 SUB_ARCH="x86"
69fi
Jon West3ac1d3e2021-04-24 18:38:42 -040070fi
71
72if [ "$1" == "1" ]; then
73 echo "ABI:x86_64 & ABI2:x86 was preselected"
74 MAIN_ARCH="x86_64"
75 SUB_ARCH="x86"
76fi
77if [ "$1" == "2" ]; then
78 echo "ABI:arm64-v8a & ABI2:armeabi-v7a was preselected"
79 MAIN_ARCH="arm64-v8a"
80 SUB_ARCH="armeabi-v7a"
81fi
Jon Weste8209292021-05-31 17:16:19 -040082if [ "$1" == "3" ]; then
83 echo "ABI:x86 & ABI2:x86 was preselected"
84 MAIN_ARCH="x86"
85fi
Jon West1c44e902021-04-01 19:29:47 -040086
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +010087addCopy() {
Pierre-Hugues Husson16644af2020-04-05 16:08:40 +020088 addition=""
Jon West1c44e902021-04-01 19:29:47 -040089 if [ "$native" != "" ]
90 then
91 unzip bin/$1 "lib/*"
92 if [ "$native" == "$MAIN_ARCH" ];then
93 addition="
94LOCAL_PREBUILT_JNI_LIBS := \\
Jon West3ac1d3e2021-04-24 18:38:42 -040095$(unzip -olv bin/$1 |grep -v Stored |sed -nE 's;.*(lib/'"$MAIN_ARCH"'/.*);\t\1 \\;p')
Jon West1c44e902021-04-01 19:29:47 -040096 "
97 fi
98 if [ "$native" == "$SUB_ARCH" ];then
99 addition="
100LOCAL_MULTILIB := 32
101LOCAL_PREBUILT_JNI_LIBS := \\
Jon West3ac1d3e2021-04-24 18:38:42 -0400102$(unzip -olv bin/$1 |grep -v Stored |sed -nE 's;.*(lib/'"$SUB_ARCH"'/.*);\t\1 \\;p')
Jon West1c44e902021-04-01 19:29:47 -0400103 "
104 fi
105 fi
Pierre-Hugues Hussone1b56f52020-11-03 18:15:49 +0100106 if [ "$2" == com.google.android.gms ] || [ "$2" == com.android.vending ] ;then
107 addition="LOCAL_PRIVILEGED_MODULE := true"
108 fi
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +0100109cat >> Android.mk <<EOF
110include \$(CLEAR_VARS)
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +0100111LOCAL_MODULE := $2
112LOCAL_MODULE_TAGS := optional
113LOCAL_SRC_FILES := bin/$1
114LOCAL_MODULE_CLASS := APPS
Pierre-Hugues Hussonea4517b2017-12-04 16:45:04 +0100115LOCAL_CERTIFICATE := PRESIGNED
Pierre-Hugues Husson3811d162017-12-04 23:07:00 +0100116LOCAL_OVERRIDES_PACKAGES := $3
Pierre-Hugues Husson16644af2020-04-05 16:08:40 +0200117$addition
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +0100118include \$(BUILD_PREBUILT)
Pierre-Hugues Husson5250fdd2017-12-04 22:18:22 +0100119
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +0100120EOF
121echo -e "\t$2 \\" >> apps.mk
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100122}
123
Jon West9fd0d662021-04-01 16:07:30 -0400124echo -e "${LT_BLUE}# Setting Up${NC}"
Pierre-Hugues Husson16644af2020-04-05 16:08:40 +0200125rm -Rf apps.mk lib
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +0100126cat > Android.mk <<EOF
127LOCAL_PATH := \$(my-dir)
128
129EOF
130echo -e 'PRODUCT_PACKAGES += \\' > apps.mk
131
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100132mkdir -p bin
Pierre-Hugues Hussone1b56f52020-11-03 18:15:49 +0100133
Pierre-Hugues Husson5250fdd2017-12-04 22:18:22 +0100134#downloadFromFdroid packageName overrides
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100135downloadFromFdroid() {
136 mkdir -p tmp
Pierre-Hugues Hussone1b56f52020-11-03 18:15:49 +0100137 [ "$oldRepo" != "$repo" ] && rm -f tmp/index.xml
138 oldRepo="$repo"
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100139 if [ ! -f tmp/index.xml ];then
140 #TODO: Check security keys
Jon West0d65aa82021-04-04 19:55:11 -0400141 failed_count=0
142 array=( $repo $repo2 $repo3 $repo4 $repo5 $repo6 $repo7 $repo8 $repo9 $repo10 $repo11 $repo12 $repo13 )
143 for url in $repo $repo2 $repo3 $repo4 $repo5 $repo6 $repo7 $repo8 $repo9 $repo10 $repo11 $repo12 $repo13 ; do
144 echo -e "${GREEN}# Trying: $url ${NC}"
145 if wget --connect-timeout=10 --tries=2 ${url}index.jar -O tmp/index.jar; then
146 unzip -p tmp/index.jar index.xml > tmp/index.xml
147 echo -e "${GREEN}# Downloaded from $url ${NC}"
148 failed=
149 repo=${url}
150 passed=true
151 break
152 elif [ "$failed" ]; then
153 echo -e "${YELLOW}# $url broken ${NC}"
154 failed=true
155 failed_count=$((failed_count+1))
156 else
157 echo -e "${YELLOW}# $url failed ${NC}"
158 failed=true
159 failed_count=$((failed_count+1))
160 fi
161
162 done
163 echo -e "${Yellow}# Total mirrors: ${#array[@]} ${NC}"
164 echo -e "${RED}# Failed $failed_count mirrors ${NC}"
165 if [ "$failed_count" == "${#array[@]}" ]; then
166 echo -e "${RED}# Failed too many mirrors: $failed_count ${NC}"
167 exit
168
169 fi
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100170 fi
Jon West1c44e902021-04-01 19:29:47 -0400171
172 index=1
173 apk="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./apkname tmp/index.xml)"
174 native="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./nativecode tmp/index.xml)"
175 if [ "$native" != "" ]
176 then
177 index=1
178 while true
179 do
180 apk="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./apkname tmp/index.xml)"
181 native="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./nativecode tmp/index.xml)"
182 if [ "$native" != "" ] && [ "$(echo $native | grep $MAIN_ARCH)" != "" ]
183 then
184 native=$MAIN_ARCH
185 echo -e "${YELLOW}# native is $native ${NC}"
186 break
187 fi
188 if [ "$native" == "" ]
189 then
190 echo -e "${YELLOW}# native is blank or $native ${NC}"
191 break
192 fi
193 index=$((index + 1))
194 done
195 if [ "$native" != "$MAIN_ARCH" ]
196 then
197 index=1
198 while true
199 do
200 apk="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./apkname tmp/index.xml)"
201 native="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./nativecode tmp/index.xml)"
202 if [ "$native" != "" ] && [ "$(echo $native | grep $SUB_ARCH)" != "" ]
203 then
204 native=$SUB_ARCH
205 echo -e "${YELLOW}# native is $native ${NC}"
206 break
207 fi
208 index=$((index + 1))
209 done
210 if [ "$native" != "$SUB_ARCH" ]
211 then
212 echo -e "${RED} $1 is not available in $MAIN_ARCH nor $SUB_ARCH ${NC}"
213 exit 1
214 fi
215 fi
216 fi
paledega6303e2a2020-03-02 09:39:50 +0300217 if [ ! -f bin/$apk ];then
218 while ! wget --connect-timeout=10 $repo/$apk -O bin/$apk;do sleep 1;done
Jon Wested6857b2021-04-01 16:37:30 -0400219 else
220 echo -e "${GREEN}# Already grabbed $apk ${NC}"
paledega6303e2a2020-03-02 09:39:50 +0300221 fi
Pierre-Hugues Husson5250fdd2017-12-04 22:18:22 +0100222 addCopy $apk $1 "$2"
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100223}
Jon West1c44e902021-04-01 19:29:47 -0400224
Jon West0d65aa82021-04-04 19:55:11 -0400225downloadStuff() {
226 what="$1"
227 where="$2"
228
229 while ! wget --connect-timeout=10 --tries=2 "$what" -O "$where";do sleep 1;done
230}
231
232#downloadFromRepo repo repo_dir packageName overrides
233downloadFromRepo() {
234 repo="$1"
235 repo_dir="$2"
236 package="$3"
237 overrides="$4"
238
239 mkdir -p "$repo_dir"
240 if [ ! -f "$repo_dir"/index.xml ];then
241 downloadStuff "$repo"/index.jar "$repo_dir"/index.jar
242 unzip -p "$repo_dir"/index.jar index.xml > "$repo_dir"/index.xml
243 fi
244
245 marketvercode="$(xmlstarlet sel -t -m '//application[id="'"$package"'"]' -v ./marketvercode "$repo_dir"/index.xml || true)"
246 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)"
247 downloadStuff "$repo"/"$apk" bin/"$apk"
248
249 addCopy "$apk" "$package" "$overrides"
250}
251
252
Jon West9fd0d662021-04-01 16:07:30 -0400253echo -e "${YELLOW}# grabbing F-Droid Apps${NC}"
Jon West311f0ca2021-04-01 15:42:33 -0400254# Terminal Emulator
Jon West6969cea2021-05-02 12:18:10 -0400255#~ downloadFromFdroid com.termoneplus
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100256#Navigation
Jon West6969cea2021-05-02 12:18:10 -0400257#~ downloadFromFdroid net.osmand.plus
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100258#Calendar
Jon Wested6857b2021-04-01 16:37:30 -0400259downloadFromFdroid ws.xsoh.etar "Calendar"
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100260#Pdf viewer
Jon West6969cea2021-05-02 12:18:10 -0400261#~ downloadFromFdroid com.artifex.mupdf.viewer.app
Unknown2974a752020-11-07 20:18:09 -0500262# Aurora App Store
Pierre-Hugues Husson06683c22020-03-31 23:16:24 +0200263downloadFromFdroid com.aurora.store
Pierre-Hugues Hussonb7a5f4a2017-12-04 17:07:27 +0100264#Mail client
Jon West6656cb52021-04-25 11:08:08 -0400265#~ downloadFromFdroid com.fsck.k9 "Email"
Pierre-Hugues Hussone46e3702018-06-04 21:19:57 +0200266#Calendar/Contacts sync
Pierre-Hugues Husson06683c22020-03-31 23:16:24 +0200267downloadFromFdroid com.etesync.syncadapter
Pierre-Hugues Husson06683c22020-03-31 23:16:24 +0200268# Todo lists
Jon West6969cea2021-05-02 12:18:10 -0400269#~ downloadFromFdroid org.tasks
Unknown2974a752020-11-07 20:18:09 -0500270#Fake assistant that research on duckduckgo
271downloadFromFdroid co.pxhouse.sas
272# Gallery App
273downloadFromFdroid com.simplemobiletools.gallery.pro "Photos Gallery Gallery2"
274# Aurora Fdroid
275downloadFromFdroid com.aurora.adroid
Jon Wested6857b2021-04-01 16:37:30 -0400276# F-Droid App Store
277#~ downloadFromFdroid org.fdroid.fdroid
Jon West1c44e902021-04-01 19:29:47 -0400278#fdroid extension
Jon West3ac1d3e2021-04-24 18:38:42 -0400279downloadFromFdroid org.fdroid.fdroid.privileged
q0kHaN77f09432019-11-11 12:36:35 +0000280#Phonograph
Jon West6969cea2021-05-02 12:18:10 -0400281#~ downloadFromFdroid com.kabouzeid.gramophone "Eleven"
kisekinopureya6a3d0362020-01-19 21:35:08 +0300282#Alarmio
Jackeaglecae8cc12021-06-02 05:21:55 -0400283 downloadFromFdroid me.jfenn.alarmio "GoogleClock DeskClock"
kisekinopureya13634d72019-12-12 01:23:53 +0300284#Mozilla Nlp
kisekinopureyae47d0882020-01-19 21:44:48 +0300285downloadFromFdroid org.microg.nlp.backend.ichnaea
kisekinopureyabb4217d2019-12-10 20:47:31 +0300286#Nominatim Nlp
287downloadFromFdroid org.microg.nlp.backend.nominatim
Jon Westddb6a382021-04-01 15:43:49 -0400288# EtchDroid USB Writer
Jon West6969cea2021-05-02 12:18:10 -0400289#~ downloadFromFdroid eu.depau.etchdroid
290# NewPipe (outdated)
Jon Westdd1770f2021-04-04 19:54:58 -0400291downloadFromFdroid org.schabi.newpipe
Pierre-Hugues Hussonb7a5f4a2017-12-04 17:07:27 +0100292
Jon West3ac1d3e2021-04-24 18:38:42 -0400293# Astian Apps
294# Midori Browser
295downloadFromFdroid org.midorinext.android "Browser2 QuickSearchBox"
296# Astian Spika
297# downloadFromFdroid org.astianspika.android
298# Astian Cloud
299# downloadFromFdroid org.astiancloud.android
300# Astian VPN
301# downloadFromFdroid org.astianvpn.android
302
kisekinopureyabb4217d2019-12-10 20:47:31 +0300303#Web browser
Unknown2974a752020-11-07 20:18:09 -0500304#~ downloadFromFdroid org.mozilla.fennec_fdroid "Browser2 QuickSearchBox"
Jon West6969cea2021-05-02 12:18:10 -0400305#icecat
306#~ downloadFromFdroid org.gnu.icecat "Browser2 QuickSearchBox"
Unknown2974a752020-11-07 20:18:09 -0500307#Public transportation
308#~ downloadFromFdroid de.grobox.liberario
309#Ciphered Instant Messaging
310#downloadFromFdroid im.vector.alpha
311#Nextcloud client
312#~ downloadFromFdroid com.nextcloud.client
313# Social Media Apps
Unknowna0b877c2020-11-07 19:48:33 -0500314#~ downloadFromFdroid org.mariotaku.twidere
315#~ downloadFromFdroid com.pitchedapps.frost
316#~ downloadFromFdroid com.keylesspalace.tusky
paledega6303e2a2020-03-02 09:39:50 +0300317
Jon West9fd0d662021-04-01 16:07:30 -0400318echo -e "${YELLOW}# grabbing MicroG Apps${NC}"
Jon West0d65aa82021-04-04 19:55:11 -0400319downloadFromRepo "$microg" "$microg_dir" com.google.android.gms
320downloadFromRepo "$microg" "$microg_dir" com.google.android.gsf
321downloadFromRepo "$microg" "$microg_dir" com.android.vending "Google Play Store"
322downloadFromRepo "$microg" "$microg_dir" org.microg.gms.droidguard
Pierre-Hugues Hussone1b56f52020-11-03 18:15:49 +0100323
Jon West9fd0d662021-04-01 16:07:30 -0400324echo -e "${YELLOW}# grabbing NanoLX Apps${NC}"
Jon West0d65aa82021-04-04 19:55:11 -0400325downloadFromRepo "$nanolx" "$nanolx_dir" is.xyz.mpv
Unknown2974a752020-11-07 20:18:09 -0500326
Jon West6969cea2021-05-02 12:18:10 -0400327#~ echo -e "${YELLOW}# grabbing NewPipe ${NC}"
328#~ downloadFromRepo "$newpipe" "$newpipe_dir" org.schabi.newpip
329
Jon West9fd0d662021-04-01 16:07:30 -0400330echo -e "${LT_BLUE}# finishing up apps.mk${NC}"
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +0100331echo >> apps.mk
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100332
Jon West9fd0d662021-04-01 16:07:30 -0400333echo -e "${YELLOW}# Cleaning up${NC}"
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100334rm -Rf tmp
Jon West9fd0d662021-04-01 16:07:30 -0400335
336echo -e "${GREEN}# DONE${NC}"