blob: 87a93a02740b31ed0a77af6c151d1d3c9b904660 [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 West81cd34f2021-04-01 19:30:33 -040031# Device type selection
Jon West3ac1d3e2021-04-24 18:38:42 -040032if [ "$1" == "" ]; then
Jon West81cd34f2021-04-01 19:30:33 -040033PS3='Which device type do you plan on building?: '
Jon West0d65aa82021-04-04 19:55:11 -040034echo -e ${YELLOW}"(default is 'ABI:x86_64 & ABI2:x86')"
Jon West81cd34f2021-04-01 19:30:33 -040035TMOUT=10
36options=("ABI:x86_64 & ABI2:x86"
37 "ABI:arm64-v8a & ABI2:armeabi-v7a")
Jon West0d65aa82021-04-04 19:55:11 -040038echo -e "Timeout in $TMOUT sec."${NC}
Jon West81cd34f2021-04-01 19:30:33 -040039select opt in "${options[@]}"
40do
41 case $opt in
42 "ABI:x86_64 & ABI2:x86")
43 echo "you chose choice $REPLY which is $opt"
44 MAIN_ARCH="x86_64"
45 SUB_ARCH="x86"
46 break
47 ;;
48 "ABI:arm64-v8a & ABI2:armeabi-v7a")
49 echo "you chose choice $REPLY which is $opt"
50 MAIN_ARCH="arm64-v8a"
51 SUB_ARCH="armeabi-v7a"
52 break
53 ;;
54 *) echo "invalid option $REPLY";;
55 esac
56done
57if [ "$opt" == "" ]; then
58 MAIN_ARCH="x86_64"
59 SUB_ARCH="x86"
60fi
Jon West3ac1d3e2021-04-24 18:38:42 -040061fi
62
63if [ "$1" == "1" ]; then
64 echo "ABI:x86_64 & ABI2:x86 was preselected"
65 MAIN_ARCH="x86_64"
66 SUB_ARCH="x86"
67fi
68if [ "$1" == "2" ]; then
69 echo "ABI:arm64-v8a & ABI2:armeabi-v7a was preselected"
70 MAIN_ARCH="arm64-v8a"
71 SUB_ARCH="armeabi-v7a"
72fi
Jon West1c44e902021-04-01 19:29:47 -040073
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +010074addCopy() {
Pierre-Hugues Husson16644af2020-04-05 16:08:40 +020075 addition=""
Jon West1c44e902021-04-01 19:29:47 -040076 if [ "$native" != "" ]
77 then
78 unzip bin/$1 "lib/*"
79 if [ "$native" == "$MAIN_ARCH" ];then
80 addition="
81LOCAL_PREBUILT_JNI_LIBS := \\
Jon West3ac1d3e2021-04-24 18:38:42 -040082$(unzip -olv bin/$1 |grep -v Stored |sed -nE 's;.*(lib/'"$MAIN_ARCH"'/.*);\t\1 \\;p')
Jon West1c44e902021-04-01 19:29:47 -040083 "
84 fi
85 if [ "$native" == "$SUB_ARCH" ];then
86 addition="
87LOCAL_MULTILIB := 32
88LOCAL_PREBUILT_JNI_LIBS := \\
Jon West3ac1d3e2021-04-24 18:38:42 -040089$(unzip -olv bin/$1 |grep -v Stored |sed -nE 's;.*(lib/'"$SUB_ARCH"'/.*);\t\1 \\;p')
Jon West1c44e902021-04-01 19:29:47 -040090 "
91 fi
92 fi
Pierre-Hugues Hussone1b56f52020-11-03 18:15:49 +010093 if [ "$2" == com.google.android.gms ] || [ "$2" == com.android.vending ] ;then
94 addition="LOCAL_PRIVILEGED_MODULE := true"
95 fi
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +010096cat >> Android.mk <<EOF
97include \$(CLEAR_VARS)
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +010098LOCAL_MODULE := $2
99LOCAL_MODULE_TAGS := optional
100LOCAL_SRC_FILES := bin/$1
101LOCAL_MODULE_CLASS := APPS
Pierre-Hugues Hussonea4517b2017-12-04 16:45:04 +0100102LOCAL_CERTIFICATE := PRESIGNED
Pierre-Hugues Husson3811d162017-12-04 23:07:00 +0100103LOCAL_OVERRIDES_PACKAGES := $3
Pierre-Hugues Husson16644af2020-04-05 16:08:40 +0200104$addition
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +0100105include \$(BUILD_PREBUILT)
Pierre-Hugues Husson5250fdd2017-12-04 22:18:22 +0100106
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +0100107EOF
108echo -e "\t$2 \\" >> apps.mk
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100109}
110
Jon West9fd0d662021-04-01 16:07:30 -0400111echo -e "${LT_BLUE}# Setting Up${NC}"
Pierre-Hugues Husson16644af2020-04-05 16:08:40 +0200112rm -Rf apps.mk lib
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +0100113cat > Android.mk <<EOF
114LOCAL_PATH := \$(my-dir)
115
116EOF
117echo -e 'PRODUCT_PACKAGES += \\' > apps.mk
118
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100119mkdir -p bin
Pierre-Hugues Hussone1b56f52020-11-03 18:15:49 +0100120
Pierre-Hugues Husson5250fdd2017-12-04 22:18:22 +0100121#downloadFromFdroid packageName overrides
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100122downloadFromFdroid() {
123 mkdir -p tmp
Pierre-Hugues Hussone1b56f52020-11-03 18:15:49 +0100124 [ "$oldRepo" != "$repo" ] && rm -f tmp/index.xml
125 oldRepo="$repo"
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100126 if [ ! -f tmp/index.xml ];then
127 #TODO: Check security keys
Jon West0d65aa82021-04-04 19:55:11 -0400128 failed_count=0
129 array=( $repo $repo2 $repo3 $repo4 $repo5 $repo6 $repo7 $repo8 $repo9 $repo10 $repo11 $repo12 $repo13 )
130 for url in $repo $repo2 $repo3 $repo4 $repo5 $repo6 $repo7 $repo8 $repo9 $repo10 $repo11 $repo12 $repo13 ; do
131 echo -e "${GREEN}# Trying: $url ${NC}"
132 if wget --connect-timeout=10 --tries=2 ${url}index.jar -O tmp/index.jar; then
133 unzip -p tmp/index.jar index.xml > tmp/index.xml
134 echo -e "${GREEN}# Downloaded from $url ${NC}"
135 failed=
136 repo=${url}
137 passed=true
138 break
139 elif [ "$failed" ]; then
140 echo -e "${YELLOW}# $url broken ${NC}"
141 failed=true
142 failed_count=$((failed_count+1))
143 else
144 echo -e "${YELLOW}# $url failed ${NC}"
145 failed=true
146 failed_count=$((failed_count+1))
147 fi
148
149 done
150 echo -e "${Yellow}# Total mirrors: ${#array[@]} ${NC}"
151 echo -e "${RED}# Failed $failed_count mirrors ${NC}"
152 if [ "$failed_count" == "${#array[@]}" ]; then
153 echo -e "${RED}# Failed too many mirrors: $failed_count ${NC}"
154 exit
155
156 fi
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100157 fi
Jon West1c44e902021-04-01 19:29:47 -0400158
159 index=1
160 apk="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./apkname tmp/index.xml)"
161 native="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./nativecode tmp/index.xml)"
162 if [ "$native" != "" ]
163 then
164 index=1
165 while true
166 do
167 apk="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./apkname tmp/index.xml)"
168 native="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./nativecode tmp/index.xml)"
169 if [ "$native" != "" ] && [ "$(echo $native | grep $MAIN_ARCH)" != "" ]
170 then
171 native=$MAIN_ARCH
172 echo -e "${YELLOW}# native is $native ${NC}"
173 break
174 fi
175 if [ "$native" == "" ]
176 then
177 echo -e "${YELLOW}# native is blank or $native ${NC}"
178 break
179 fi
180 index=$((index + 1))
181 done
182 if [ "$native" != "$MAIN_ARCH" ]
183 then
184 index=1
185 while true
186 do
187 apk="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./apkname tmp/index.xml)"
188 native="$(xmlstarlet sel -t -m '//application[id="'"$1"'"]/package['$index']' -v ./nativecode tmp/index.xml)"
189 if [ "$native" != "" ] && [ "$(echo $native | grep $SUB_ARCH)" != "" ]
190 then
191 native=$SUB_ARCH
192 echo -e "${YELLOW}# native is $native ${NC}"
193 break
194 fi
195 index=$((index + 1))
196 done
197 if [ "$native" != "$SUB_ARCH" ]
198 then
199 echo -e "${RED} $1 is not available in $MAIN_ARCH nor $SUB_ARCH ${NC}"
200 exit 1
201 fi
202 fi
203 fi
paledega6303e2a2020-03-02 09:39:50 +0300204 if [ ! -f bin/$apk ];then
205 while ! wget --connect-timeout=10 $repo/$apk -O bin/$apk;do sleep 1;done
Jon Wested6857b2021-04-01 16:37:30 -0400206 else
207 echo -e "${GREEN}# Already grabbed $apk ${NC}"
paledega6303e2a2020-03-02 09:39:50 +0300208 fi
Pierre-Hugues Husson5250fdd2017-12-04 22:18:22 +0100209 addCopy $apk $1 "$2"
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100210}
Jon West1c44e902021-04-01 19:29:47 -0400211
Jon West0d65aa82021-04-04 19:55:11 -0400212downloadStuff() {
213 what="$1"
214 where="$2"
215
216 while ! wget --connect-timeout=10 --tries=2 "$what" -O "$where";do sleep 1;done
217}
218
219#downloadFromRepo repo repo_dir packageName overrides
220downloadFromRepo() {
221 repo="$1"
222 repo_dir="$2"
223 package="$3"
224 overrides="$4"
225
226 mkdir -p "$repo_dir"
227 if [ ! -f "$repo_dir"/index.xml ];then
228 downloadStuff "$repo"/index.jar "$repo_dir"/index.jar
229 unzip -p "$repo_dir"/index.jar index.xml > "$repo_dir"/index.xml
230 fi
231
232 marketvercode="$(xmlstarlet sel -t -m '//application[id="'"$package"'"]' -v ./marketvercode "$repo_dir"/index.xml || true)"
233 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)"
234 downloadStuff "$repo"/"$apk" bin/"$apk"
235
236 addCopy "$apk" "$package" "$overrides"
237}
238
239
Jon West9fd0d662021-04-01 16:07:30 -0400240echo -e "${YELLOW}# grabbing F-Droid Apps${NC}"
Jon West311f0ca2021-04-01 15:42:33 -0400241# Terminal Emulator
242downloadFromFdroid com.termoneplus
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100243#Navigation
244downloadFromFdroid net.osmand.plus
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100245#Calendar
Jon Wested6857b2021-04-01 16:37:30 -0400246downloadFromFdroid ws.xsoh.etar "Calendar"
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100247#Pdf viewer
Pierre-Hugues Husson02f4dcb2018-06-04 21:19:03 +0200248downloadFromFdroid com.artifex.mupdf.viewer.app
Unknown2974a752020-11-07 20:18:09 -0500249# Aurora App Store
Pierre-Hugues Husson06683c22020-03-31 23:16:24 +0200250downloadFromFdroid com.aurora.store
Pierre-Hugues Hussonb7a5f4a2017-12-04 17:07:27 +0100251#Mail client
Pierre-Hugues Husson5250fdd2017-12-04 22:18:22 +0100252downloadFromFdroid com.fsck.k9 "Email"
Pierre-Hugues Hussone46e3702018-06-04 21:19:57 +0200253#Calendar/Contacts sync
Pierre-Hugues Husson06683c22020-03-31 23:16:24 +0200254downloadFromFdroid com.etesync.syncadapter
Pierre-Hugues Husson06683c22020-03-31 23:16:24 +0200255# Todo lists
256downloadFromFdroid org.tasks
Unknown2974a752020-11-07 20:18:09 -0500257#Fake assistant that research on duckduckgo
258downloadFromFdroid co.pxhouse.sas
259# Gallery App
260downloadFromFdroid com.simplemobiletools.gallery.pro "Photos Gallery Gallery2"
261# Aurora Fdroid
262downloadFromFdroid com.aurora.adroid
Jon Wested6857b2021-04-01 16:37:30 -0400263# F-Droid App Store
264#~ downloadFromFdroid org.fdroid.fdroid
Jon West1c44e902021-04-01 19:29:47 -0400265#fdroid extension
Jon West3ac1d3e2021-04-24 18:38:42 -0400266downloadFromFdroid org.fdroid.fdroid.privileged
q0kHaN77f09432019-11-11 12:36:35 +0000267#Phonograph
268downloadFromFdroid com.kabouzeid.gramophone "Eleven"
kisekinopureya6a3d0362020-01-19 21:35:08 +0300269#Alarmio
270downloadFromFdroid me.jfenn.alarmio "GoogleClock DeskClock"
kisekinopureya13634d72019-12-12 01:23:53 +0300271#Mozilla Nlp
kisekinopureyae47d0882020-01-19 21:44:48 +0300272downloadFromFdroid org.microg.nlp.backend.ichnaea
kisekinopureyabb4217d2019-12-10 20:47:31 +0300273#Nominatim Nlp
274downloadFromFdroid org.microg.nlp.backend.nominatim
Jon Westddb6a382021-04-01 15:43:49 -0400275# EtchDroid USB Writer
276downloadFromFdroid eu.depau.etchdroid
Jon Westdd1770f2021-04-04 19:54:58 -0400277# NewPipe
278downloadFromFdroid org.schabi.newpipe
Pierre-Hugues Hussonb7a5f4a2017-12-04 17:07:27 +0100279
Jon West3ac1d3e2021-04-24 18:38:42 -0400280# Astian Apps
281# Midori Browser
282downloadFromFdroid org.midorinext.android "Browser2 QuickSearchBox"
283# Astian Spika
284# downloadFromFdroid org.astianspika.android
285# Astian Cloud
286# downloadFromFdroid org.astiancloud.android
287# Astian VPN
288# downloadFromFdroid org.astianvpn.android
289
kisekinopureyabb4217d2019-12-10 20:47:31 +0300290#Web browser
Unknown2974a752020-11-07 20:18:09 -0500291#~ downloadFromFdroid org.mozilla.fennec_fdroid "Browser2 QuickSearchBox"
292#Public transportation
293#~ downloadFromFdroid de.grobox.liberario
294#Ciphered Instant Messaging
295#downloadFromFdroid im.vector.alpha
296#Nextcloud client
297#~ downloadFromFdroid com.nextcloud.client
298# Social Media Apps
Unknowna0b877c2020-11-07 19:48:33 -0500299#~ downloadFromFdroid org.mariotaku.twidere
300#~ downloadFromFdroid com.pitchedapps.frost
301#~ downloadFromFdroid com.keylesspalace.tusky
paledega6303e2a2020-03-02 09:39:50 +0300302
Jon West9fd0d662021-04-01 16:07:30 -0400303echo -e "${YELLOW}# grabbing MicroG Apps${NC}"
Jon West0d65aa82021-04-04 19:55:11 -0400304downloadFromRepo "$microg" "$microg_dir" com.google.android.gms
305downloadFromRepo "$microg" "$microg_dir" com.google.android.gsf
306downloadFromRepo "$microg" "$microg_dir" com.android.vending "Google Play Store"
307downloadFromRepo "$microg" "$microg_dir" org.microg.gms.droidguard
Pierre-Hugues Hussone1b56f52020-11-03 18:15:49 +0100308
Jon West9fd0d662021-04-01 16:07:30 -0400309echo -e "${YELLOW}# grabbing NanoLX Apps${NC}"
Jon West0d65aa82021-04-04 19:55:11 -0400310downloadFromRepo "$nanolx" "$nanolx_dir" is.xyz.mpv
Unknown2974a752020-11-07 20:18:09 -0500311
Jon West9fd0d662021-04-01 16:07:30 -0400312echo -e "${LT_BLUE}# finishing up apps.mk${NC}"
Pierre-Hugues Hussonc1f73e82017-12-04 16:43:14 +0100313echo >> apps.mk
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100314
Jon West9fd0d662021-04-01 16:07:30 -0400315echo -e "${YELLOW}# Cleaning up${NC}"
Pierre-Hugues Hussonbcc5b642017-12-04 16:27:25 +0100316rm -Rf tmp
Jon West9fd0d662021-04-01 16:07:30 -0400317
318echo -e "${GREEN}# DONE${NC}"