WSABuilds/.github/workflows/magisk.yml

657 lines
30 KiB
YAML
Raw Normal View History

name: Build WSA
2021-10-26 11:16:38 +02:00
on:
workflow_dispatch:
inputs:
2022-02-16 20:44:27 +01:00
arch:
description: "Build architecture"
2022-02-16 20:44:27 +01:00
required: true
2022-03-10 09:52:30 +01:00
default: "x64"
2022-02-16 20:44:27 +01:00
type: choice
options:
- x64
- arm64
- x64 & arm64
release_type:
description: "WSA release type"
required: true
2022-05-20 23:58:09 +02:00
default: "insider fast"
type: choice
options:
- retail
- release preview
- insider slow
- insider fast
2021-10-26 11:16:38 +02:00
magisk_apk:
2022-02-13 19:15:31 +01:00
description: "Magisk version"
2021-10-26 11:16:38 +02:00
required: true
default: "stable"
2022-02-13 19:15:31 +01:00
type: choice
options:
- stable
- beta
- canary
2021-10-26 17:16:21 +02:00
gapps_variant:
description: "Variants of GApps"
2021-10-26 17:16:21 +02:00
required: true
2022-03-10 09:52:30 +01:00
default: "full"
2022-02-13 19:01:53 +01:00
type: choice
options:
- none
- super
- stock
- full
- mini
- micro
- nano
- pico
- tvstock
- tvmini
gapps_version:
description: "Android version of GApps"
required: true
2022-05-20 23:56:46 +02:00
default: "12.1"
type: choice
options:
- 11.0
- 12.1
root_sol:
2022-02-13 19:15:31 +01:00
description: "Root solution"
required: true
default: "magisk"
2022-02-13 19:01:53 +01:00
type: choice
options:
- magisk
- none
2021-10-26 11:16:38 +02:00
jobs:
2022-02-16 20:44:27 +01:00
matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Generate build matrix
id: set-matrix
uses: actions/github-script@v6
with:
script: |
let matrix = {};
let arch = "${{ github.event.inputs.arch }}"
switch ( arch ) {
case "x64":
matrix.arch = ["x64"];
break;
case "arm64":
matrix.arch = ["arm64"];
break;
default:
matrix.arch = ["x64", "arm64"];
break;
}
core.setOutput("matrix",JSON.stringify(matrix));
2021-10-26 11:16:38 +02:00
build:
runs-on: ubuntu-20.04
2022-02-16 20:44:27 +01:00
needs: matrix
strategy:
2022-02-16 20:44:27 +01:00
matrix: ${{fromJson(needs.matrix.outputs.matrix)}}
2021-10-26 11:16:38 +02:00
steps:
- name: Dependencies
run: |
pip3 install beautifulsoup4 lxml
sudo apt-get update && sudo apt-get install setools lzip wine winetricks patchelf
wget -qO- "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/archive/$GITHUB_REF.tar.gz" | sudo tar --wildcards -zxvf- -C ~ --strip-component=2 '*/wine/*' '*/linker/*'
2021-12-11 21:27:26 +01:00
winetricks msxml6
2022-03-25 13:13:53 +01:00
echo "163.172.251.201 store.rg-adguard.net" | sudo tee -a /etc/hosts
2021-10-30 14:00:49 +02:00
- name: Download WSA
2021-10-26 11:16:38 +02:00
shell: python
run: |
import requests
from bs4 import BeautifulSoup
import re
import zipfile
import os
import urllib.request
2021-12-12 00:39:19 +01:00
arch = "${{ matrix.arch }}"
release_type_map = {"retail": "Retail", "release preview": "RP", "insider slow": "WIS", "insider fast": "WIF"}
release_type = release_type_map["${{ github.event.inputs.release_type }}"] if "${{ github.event.inputs.release_type }}" != "" else "Retail"
2021-12-12 00:39:19 +01:00
res = requests.post("https://store.rg-adguard.net/api/GetFiles", f"type=CategoryId&url=858014f3-3934-4abe-8078-4aa193e74ca8&ring={release_type}&lang=en-US", headers={
2021-10-26 11:16:38 +02:00
"content-type": "application/x-www-form-urlencoded"
2022-05-02 05:19:04 +02:00
}, verify=False) # source site has expired cert
2021-10-26 11:16:38 +02:00
html = BeautifulSoup(res.content, "lxml")
2021-12-12 00:39:19 +01:00
a = html.find("a", string=re.compile(f"Microsoft\.UI\.Xaml\..*_{arch}_.*\.appx"))
2021-10-26 11:16:38 +02:00
link = a["href"]
2021-12-12 00:39:19 +01:00
print(f"downloading link: {link}", flush=True)
out_file = "xaml.appx"
if not os.path.isfile(out_file):
urllib.request.urlretrieve(link, out_file)
2021-10-26 11:16:38 +02:00
2021-12-12 00:39:19 +01:00
a = html.find("a", string=re.compile(f"Microsoft\.VCLibs\..*_{arch}_.*\.appx"))
link = a["href"]
2021-10-26 11:16:38 +02:00
print(f"downloading link: {link}", flush=True)
2021-12-12 00:39:19 +01:00
out_file = "vclibs.appx"
if not os.path.isfile(out_file):
urllib.request.urlretrieve(link, out_file)
2021-10-26 11:16:38 +02:00
2021-12-12 00:39:19 +01:00
a = html.find("a", string=re.compile("MicrosoftCorporationII\.WindowsSubsystemForAndroid_.*\.msixbundle"))
link = a["href"]
print(f"downloading link: {link}", flush=True)
2021-10-26 11:16:38 +02:00
out_file = "wsa.zip"
if not os.path.isfile(out_file):
urllib.request.urlretrieve(link, out_file)
zip_name = ""
with zipfile.ZipFile(out_file) as zip:
for f in zip.filelist:
2021-10-26 12:41:08 +02:00
if arch in f.filename.lower():
2021-10-26 11:16:38 +02:00
zip_name = f.filename
if not os.path.isfile(zip_name):
print(f"unzipping to {zip_name}", flush=True)
zip.extract(f)
ver_no = zip_name.split("_")
ver = ver_no[1]
2021-12-11 21:27:26 +01:00
with open(os.environ['GITHUB_ENV'], 'a') as g:
g.write(f'WSA_VER={ver}\n')
rel = ver_no[3].split(".")
rell = str(rel[0])
2021-12-11 21:27:26 +01:00
with open(os.environ['GITHUB_ENV'], 'a') as g:
g.write(f'WSA_REL={rell}\n')
2021-12-11 22:50:28 +01:00
if 'language' in f.filename.lower() or 'scale' in f.filename.lower():
2021-12-11 21:27:26 +01:00
name = f.filename.split("-", 1)[1].split(".")[0]
zip.extract(f)
with zipfile.ZipFile(f.filename) as l:
for g in l.filelist:
if g.filename == 'resources.pri':
g.filename = f'{name}.pri'
l.extract(g, 'pri')
2021-12-11 22:50:28 +01:00
print(f"extract resource pack {g.filename}")
2021-12-11 21:27:26 +01:00
elif g.filename == 'AppxManifest.xml':
g.filename = f'{name}.xml'
l.extract(g, 'xml')
2021-10-26 11:16:38 +02:00
with zipfile.ZipFile(zip_name) as zip:
if not os.path.isdir(arch):
print(f"unzipping from {zip_name}", flush=True)
zip.extractall(arch)
2021-12-11 21:27:26 +01:00
2021-10-26 11:16:38 +02:00
print("done", flush=True)
- name: Download Magisk
shell: python
run: |
import urllib.request
import zipfile
import os
import json
import requests
2021-10-26 11:16:38 +02:00
magisk_apk = """${{ github.event.inputs.magisk_apk }}"""
2021-10-26 13:43:23 +02:00
if not magisk_apk:
magisk_apk = "stable"
if magisk_apk == "stable" or magisk_apk == "beta" or magisk_apk == "canary":
magisk_apk = json.loads(requests.get(f"https://github.com/topjohnwu/magisk-files/raw/master/{magisk_apk}.json").content)['magisk']['link']
2022-02-13 19:15:31 +01:00
2021-10-26 11:16:38 +02:00
out_file = "magisk.zip"
arch = "${{ matrix.arch }}"
2021-10-26 11:16:38 +02:00
abi_map={"x64" : ["x86_64", "x86"], "arm64" : ["arm64-v8a", "armeabi-v7a"]}
if not os.path.isfile(out_file):
urllib.request.urlretrieve(magisk_apk, out_file)
def extract_as(zip, name, as_name, dir):
info = zip.getinfo(name)
info.filename = as_name
zip.extract(info, dir)
with zipfile.ZipFile(out_file) as zip:
extract_as(zip, f"lib/{ abi_map[arch][0] }/libmagisk64.so", "magisk64", "magisk")
extract_as(zip, f"lib/{ abi_map[arch][1] }/libmagisk32.so", "magisk32", "magisk")
standalone_policy = False
try:
2022-03-17 12:04:39 +01:00
zip.getinfo(f"lib/{ abi_map[arch][0] }/libmagiskpolicy.so")
standalone_policy = True
except:
pass
2021-10-26 11:16:38 +02:00
extract_as(zip, f"lib/{ abi_map[arch][0] }/libmagiskinit.so", "magiskinit", "magisk")
if standalone_policy:
extract_as(zip, f"lib/{ abi_map[arch][0] }/libmagiskpolicy.so", "magiskpolicy", "magisk")
else:
extract_as(zip, f"lib/{ abi_map[arch][0] }/libmagiskinit.so", "magiskpolicy", "magisk")
2021-12-11 13:49:58 +01:00
extract_as(zip, f"lib/{ abi_map[arch][0] }/libmagiskboot.so", "magiskboot", "magisk")
extract_as(zip, f"lib/{ abi_map[arch][0] }/libbusybox.so", "busybox", "magisk")
if standalone_policy:
extract_as(zip, f"lib/{ abi_map['x64'][0] }/libmagiskpolicy.so", "magiskpolicy", ".")
else:
extract_as(zip, f"lib/{ abi_map['x64'][0] }/libmagiskinit.so", "magiskpolicy", ".")
2021-12-11 13:49:58 +01:00
extract_as(zip, f"assets/boot_patch.sh", "boot_patch.sh", "magisk")
extract_as(zip, f"assets/util_functions.sh", "util_functions.sh", "magisk")
2021-10-26 14:27:40 +02:00
- name: Download OpenGApps
2022-05-20 23:56:46 +02:00
if: ${{ github.event.inputs.gapps_variant != 'none' && github.event.inputs.gapps_variant != '' && github.event.inputs.gapps_version != '12.1' }}
2021-10-26 14:27:40 +02:00
shell: python
run: |
import requests
import zipfile
import os
import urllib.request
import json
import re
2021-10-26 14:27:40 +02:00
arch = "${{ matrix.arch }}"
variant = "${{ github.event.inputs.gapps_variant }}"
abi_map = {"x64" : "x86_64", "arm64": "arm64"}
release = "${{ github.event.inputs.gapps_version }}"
try:
res = requests.get(f"https://api.opengapps.org/list")
j = json.loads(res.content)
link = {i["name"]: i for i in j["archs"][abi_map[arch]]["apis"][release]["variants"]}[variant]["zip"]
except Exception:
print("Failed to fetch from opengapps api, fallbacking to sourceforge rss...")
res = requests.get(f'https://sourceforge.net/projects/opengapps/rss?path=/{abi_map[arch]}&limit=100')
link = re.search(f'https://.*{abi_map[arch]}/.*{release}.*{variant}.*\.zip/download', res.text).group().replace('.zip/download', '.zip').replace('sourceforge.net/projects/opengapps/files', 'downloads.sourceforge.net/project/opengapps')
2021-10-26 14:27:40 +02:00
print(f"downloading link: {link}", flush=True)
out_file = "gapps.zip"
if not os.path.isfile(out_file):
urllib.request.urlretrieve(link, out_file)
print("done", flush=True)
2021-10-27 15:59:25 +02:00
2022-05-20 23:56:46 +02:00
- name: Download OpenGApps
if: ${{ matrix.arch == 'x64' && github.event.inputs.gapps_variant == 'full' && github.event.inputs.gapps_version == '12.1' }}
shell: python
run: |
2022-05-21 00:03:00 +02:00
import requests
2022-05-20 23:56:46 +02:00
import os
import urllib.request
2022-05-21 00:03:00 +02:00
link = "https://ipfs.infura.io/ipfs/Qmbh8NKAtiaYSgXHj7GTXMcU2AqxCp3jof31Gneffr8XNi?filename=gapps.zip"
2022-05-20 23:56:46 +02:00
print(f"downloading link: {link}", flush=True)
2022-05-21 00:06:05 +02:00
out_file = "gapps.zip"
2022-05-20 23:56:46 +02:00
if not os.path.isfile(out_file):
2022-05-21 00:03:00 +02:00
request.get(link)
2022-05-20 23:56:46 +02:00
print("done", flush=True)
2021-10-27 15:59:25 +02:00
- name: Extract GApps and expand images
if: ${{ github.event.inputs.gapps_variant != 'none' && github.event.inputs.gapps_variant != '' }}
2021-10-26 11:16:38 +02:00
run: |
2021-10-27 15:59:25 +02:00
mkdir gapps
2021-11-30 13:03:41 +01:00
unzip -p gapps.zip {Core,GApps}/'*.lz' | tar --lzip -C gapps -xvf - -i --strip-components=2 --exclude='setupwizardtablet-x86_64' --exclude='packageinstallergoogle-all' --exclude='speech-common' --exclude='markup-lib-arm' --exclude='markup-lib-arm64' --exclude='markup-all' --exclude='setupwizarddefault-x86_64' --exclude='pixellauncher-all' --exclude='pixellauncher-common'
2021-10-27 15:59:25 +02:00
2021-10-26 17:16:21 +02:00
e2fsck -yf ${{ matrix.arch }}/system.img
2021-10-27 15:59:25 +02:00
resize2fs ${{ matrix.arch }}/system.img $(( $(du -sB512 gapps | cut -f1) + $(du -sB512 ${{ matrix.arch }}/system.img | cut -f1) ))s
# TODO: calculate the size dynamically for better compatibility
2021-10-26 17:16:21 +02:00
e2fsck -yf ${{ matrix.arch }}/product.img
resize2fs ${{ matrix.arch }}/product.img 1024M
e2fsck -yf ${{ matrix.arch }}/system_ext.img
resize2fs ${{ matrix.arch }}/system_ext.img 200M
2021-10-27 15:59:25 +02:00
- name: Expand vendor
run: |
e2fsck -yf ${{ matrix.arch }}/vendor.img
resize2fs ${{ matrix.arch }}/vendor.img 400M
2021-10-26 11:16:38 +02:00
- name: Mount images
run: |
sudo mkdir system
sudo mount -o loop ${{ matrix.arch }}/system.img system
sudo mount -o loop ${{ matrix.arch }}/vendor.img system/vendor
sudo mount -o loop ${{ matrix.arch }}/product.img system/product
sudo mount -o loop ${{ matrix.arch }}/system_ext.img system/system_ext
- name: Integrate Magisk
2021-11-11 01:48:49 +01:00
if: ${{ github.event.inputs.root_sol == 'magisk' || github.event.inputs.root_sol == '' }}
2021-10-26 11:16:38 +02:00
run: |
sudo mkdir system/sbin
sudo chcon --reference system/init.environ.rc system/sbin
sudo chown root:root system/sbin
sudo chmod 0700 system/sbin
sudo cp magisk/* system/sbin/
sudo cp magisk.zip system/sbin/magisk.apk
2021-11-15 12:16:29 +01:00
sudo tee -a system/sbin/loadpolicy.sh <<EOF
#!/system/bin/sh
2022-04-12 11:46:42 +02:00
mkdir -p /data/adb/magisk
cp /sbin/* /data/adb/magisk/
chmod -R 755 /data/adb/magisk
2021-12-11 13:49:58 +01:00
restorecon -R /data/adb/magisk
2021-12-19 07:22:46 +01:00
for module in \$(ls /data/adb/modules); do
if ! [ -f "/data/adb/modules/\$module/disable" ] && [ -f "/data/adb/modules/\$module/sepolicy.rule" ]; then
/sbin/magiskpolicy --live --apply "/data/adb/modules/\$module/sepolicy.rule"
2021-11-15 12:16:29 +01:00
fi
done
EOF
2021-10-26 11:16:38 +02:00
sudo find system/sbin -type f -exec chmod 0755 {} \;
sudo find system/sbin -type f -exec chown root:root {} \;
sudo find system/sbin -type f -exec chcon --reference system/product {} \;
sudo patchelf --replace-needed libc.so "${HOME}/libc.so" ./magiskpolicy || true
sudo patchelf --replace-needed libm.so "${HOME}/libm.so" ./magiskpolicy || true
sudo patchelf --replace-needed libdl.so "${HOME}/libdl.so" ./magiskpolicy || true
sudo patchelf --set-interpreter "${HOME}/linker64" ./magiskpolicy || true
2021-12-11 13:49:58 +01:00
chmod +x ./magiskpolicy
2021-10-26 11:16:38 +02:00
echo '/dev/wsa-magisk(/.*)? u:object_r:magisk_file:s0' | sudo tee -a system/vendor/etc/selinux/vendor_file_contexts
2021-12-11 13:49:58 +01:00
echo '/data/adb/magisk(/.*)? u:object_r:magisk_file:s0' | sudo tee -a system/vendor/etc/selinux/vendor_file_contexts
sudo ./magiskpolicy --load system/vendor/etc/selinux/precompiled_sepolicy --save system/vendor/etc/selinux/precompiled_sepolicy --magisk "allow * magisk_file lnk_file *"
2021-10-26 11:16:38 +02:00
sudo tee -a system/system/etc/init/hw/init.rc <<EOF
on post-fs-data
start logd
start adbd
mkdir /dev/wsa-magisk
mount tmpfs tmpfs /dev/wsa-magisk mode=0755
copy /sbin/magisk64 /dev/wsa-magisk/magisk64
chmod 0755 /dev/wsa-magisk/magisk64
symlink ./magisk64 /dev/wsa-magisk/magisk
symlink ./magisk64 /dev/wsa-magisk/su
symlink ./magisk64 /dev/wsa-magisk/resetprop
copy /sbin/magisk32 /dev/wsa-magisk/magisk32
chmod 0755 /dev/wsa-magisk/magisk32
copy /sbin/magiskinit /dev/wsa-magisk/magiskinit
chmod 0755 /dev/wsa-magisk/magiskinit
copy /sbin/magiskpolicy /dev/wsa-magisk/magiskpolicy
chmod 0755 /dev/wsa-magisk/magiskpolicy
2021-10-26 11:16:38 +02:00
mkdir /dev/wsa-magisk/.magisk 700
mkdir /dev/wsa-magisk/.magisk/mirror 700
mkdir /dev/wsa-magisk/.magisk/block 700
copy /sbin/magisk.apk /dev/wsa-magisk/stub.apk
2021-10-26 11:16:38 +02:00
rm /dev/.magisk_unblock
2021-11-15 12:16:29 +01:00
start IhhslLhHYfse
2021-10-26 11:16:38 +02:00
start FAhW7H9G5sf
2021-10-26 13:37:11 +02:00
wait /dev/.magisk_unblock 40
2021-10-26 11:16:38 +02:00
rm /dev/.magisk_unblock
2021-11-15 12:16:29 +01:00
service IhhslLhHYfse /system/bin/sh /sbin/loadpolicy.sh
user root
seclabel u:r:magisk:s0
oneshot
2021-10-26 11:16:38 +02:00
service FAhW7H9G5sf /dev/wsa-magisk/magisk --post-fs-data
user root
seclabel u:r:magisk:s0
oneshot
service HLiFsR1HtIXVN6 /dev/wsa-magisk/magisk --service
class late_start
user root
seclabel u:r:magisk:s0
oneshot
on property:sys.boot_completed=1
mkdir /data/adb/magisk 755
copy /sbin/magisk.apk /data/adb/magisk/magisk.apk
2021-10-26 11:16:38 +02:00
start YqCTLTppv3ML
service YqCTLTppv3ML /dev/wsa-magisk/magisk --boot-complete
user root
seclabel u:r:magisk:s0
oneshot
EOF
2021-12-11 21:27:26 +01:00
- name: Merge Language Resources
run: |
cp ${{ matrix.arch }}/resources.pri pri/en-us.pri
2021-12-12 10:00:45 +01:00
cp ${{ matrix.arch }}/AppxManifest.xml xml/en-us.xml
2021-12-11 21:27:26 +01:00
tee priconfig.xml <<EOF
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resources targetOsVersion="10.0.0" majorVersion="1">
<index root="\" startIndexAt="\">
<indexer-config type="folder" foldernameAsQualifier="true" filenameAsQualifier="true" qualifierDelimiter="."/>
<indexer-config type="PRI"/>
</index>
</resources>
EOF
wine64 ~/makepri.exe new /pr pri /in MicrosoftCorporationII.WindowsSubsystemForAndroid /cf priconfig.xml /of ${{ matrix.arch }}/resources.pri /o
sed -i -zE "s/<Resources.*Resources>/<Resources>\n$(cat xml/* | grep -Po '<Resource [^>]*/>' | sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/\$/\\$/g' | sed 's/\//\\\//g')\n<\/Resources>/g" ${{ matrix.arch }}/AppxManifest.xml
2021-12-18 14:19:30 +01:00
- name: Add extra packages
2021-10-28 13:36:36 +02:00
run: |
2021-12-11 22:50:28 +01:00
wget -qO- "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/archive/$GITHUB_REF.tar.gz" | sudo tar --wildcards -zxvf- --strip-component=2 '*/${{ matrix.arch }}/system/*'
2021-10-28 13:36:36 +02:00
sudo find system/system/priv-app -type d -exec chmod 0755 {} \;
sudo find system/system/priv-app -type f -exec chmod 0644 {} \;
2021-12-13 13:02:54 +01:00
sudo find system/system/priv-app -exec chcon --reference=system/system/priv-app {} \;
2021-10-26 15:41:38 +02:00
- name: Integrate GApps
if: ${{ github.event.inputs.gapps_variant != 'none' && github.event.inputs.gapps_variant != '' }}
run: |
2021-12-11 22:50:28 +01:00
wget -qO- "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/archive/$GITHUB_REF.tar.gz" | sudo tar --wildcards -zxvf- --strip-component=2 '*/${{ matrix.arch }}/gapps/*'
2021-10-31 14:57:56 +01:00
shopt -s extglob
sudo cp -vr gapps/!(product) system/system
sudo cp -vr gapps/product/* system/product/
2021-10-26 17:16:21 +02:00
sudo find system/system/{app,etc,framework,priv-app} -exec chown root:root {} \;
sudo find system/product/{app,etc,overlay,priv-app} -exec chown root:root {} \;
sudo find system/system/{app,etc,framework,priv-app} -type d -exec chmod 0755 {} \;
sudo find system/product/{app,etc,overlay,priv-app} -type d -exec chmod 0755 {} \;
sudo find system/system/{app,framework,priv-app} -type f -exec chmod 0644 {} \;
2021-10-31 14:57:56 +01:00
ls gapps/etc/ | xargs -n 1 -I dir sudo find system/system/etc/dir -type f -exec chmod 0644 {} \;
2021-10-26 17:16:21 +02:00
sudo find system/product/{app,etc,overlay,priv-app} -type f -exec chmod 0644 {} \;
sudo find system/system/{app,framework,priv-app} -type d -exec chcon --reference=system/system/app {} \;
sudo find system/product/{app,etc,overlay,priv-app} -type d -exec chcon --reference=system/product/app {} \;
2021-10-31 14:57:56 +01:00
ls gapps/etc/ | xargs -n 1 -I dir sudo find system/system/etc/dir -type d -exec chcon --reference=system/system/etc/permissions {} \;
2021-10-26 17:16:21 +02:00
sudo find system/system/{app,framework,priv-app} -type f -exec chcon --reference=system/system/framework/ext.jar {} \;
2021-10-31 14:57:56 +01:00
ls gapps/etc/ | xargs -n 1 -I dir sudo find system/system/etc/dir -type f -exec chcon --reference=system/system/etc/permissions {} \;
2021-10-26 17:16:21 +02:00
sudo find system/product/{app,etc,overlay,priv-app} -type f -exec chcon --reference=system/product/etc/permissions/privapp-permissions-venezia.xml {} \;
sudo patchelf --replace-needed libc.so "${HOME}/libc.so" ./magiskpolicy || true
sudo patchelf --replace-needed libm.so "${HOME}/libm.so" ./magiskpolicy || true
sudo patchelf --replace-needed libdl.so "${HOME}/libdl.so" ./magiskpolicy || true
sudo patchelf --set-interpreter "${HOME}/linker64" ./magiskpolicy || true
2021-12-11 13:49:58 +01:00
chmod +x ./magiskpolicy
sudo ./magiskpolicy --load system/vendor/etc/selinux/precompiled_sepolicy --save system/vendor/etc/selinux/precompiled_sepolicy "allow gmscore_app gmscore_app vsock_socket { create connect write read }" "allow gmscore_app device_config_runtime_native_boot_prop file read" "allow gmscore_app system_server_tmpfs dir search" "allow gmscore_app system_server_tmpfs file open"
2021-10-27 13:28:04 +02:00
- name: Fix GApps prop
2021-10-27 15:59:25 +02:00
if: ${{ github.event.inputs.gapps_variant != 'none' && github.event.inputs.gapps_variant != '' }}
2021-10-27 13:28:04 +02:00
shell: sudo python {0}
run: |
from __future__ import annotations
from io import TextIOWrapper
from os import system, path
2021-10-27 13:28:04 +02:00
from typing import OrderedDict
2021-10-26 19:57:05 +02:00
2021-10-27 13:28:04 +02:00
class Prop(OrderedDict):
def __init__(self, file: TextIOWrapper) -> None:
super().__init__()
for i, line in enumerate(file.read().splitlines(False)):
if '=' in line:
k, v = line.split('=', 2)
self[k] = v
else:
self[f".{i}"] = line
2021-10-26 19:57:05 +02:00
2021-10-27 13:28:04 +02:00
def __str__(self) -> str:
return '\n'.join([v if k.startswith('.') else f"{k}={v}" for k, v in self.items()])
2021-10-26 19:57:05 +02:00
2021-10-27 13:28:04 +02:00
def __iadd__(self, other: str) -> Prop:
self[f".{len(self)}"] = other
return self
2021-10-26 19:57:05 +02:00
2021-10-27 13:28:04 +02:00
new_props = {
("product", "brand"): "google",
("product", "manufacturer"): "Google",
("build", "product"): "redfin",
("product", "name"): "redfin",
("product", "device"): "redfin",
("product", "model"): "Pixel 5",
("build", "flavor"): "redfin-user"
}
def description(sec: str, p: Prop) -> str:
return f"{p[f'ro.{sec}.build.flavor']} {p[f'ro.{sec}.build.version.release_or_codename']} {p[f'ro.{sec}.build.id']} {p[f'ro.{sec}.build.version.incremental']} {p[f'ro.{sec}.build.tags']}"
def fingerprint(sec: str, p: Prop) -> str:
return f"""{p[f"ro.product.{sec}.brand"]}/{p[f"ro.product.{sec}.name"]}/{p[f"ro.product.{sec}.device"]}:{p[f"ro.{sec}.build.version.release"]}/{p[f"ro.{sec}.build.id"]}/{p[f"ro.{sec}.build.version.incremental"]}:{p[f"ro.{sec}.build.type"]}/{p[f"ro.{sec}.build.tags"]}"""
def fix_prop(sec, prop):
if not path.exists(prop):
return
2021-10-27 13:28:04 +02:00
print(f"fixing {prop}", flush=True)
with open(prop, 'r') as f:
p = Prop(f)
p += "# extra prop added by MagiskOnWSA"
for k, v in new_props.items():
p[f"ro.{k[0]}.{k[1]}"] = v
if k[0] == "build":
p[f"ro.{sec}.{k[0]}.{k[1]}"] = v
elif k[0] == "product":
p[f"ro.{k[0]}.{sec}.{k[1]}"] = v
p["ro.build.description"] = description(sec, p)
p[f"ro.build.fingerprint"] = fingerprint(sec, p)
p[f"ro.{sec}.build.description"] = description(sec, p)
p[f"ro.{sec}.build.fingerprint"] = fingerprint(sec, p)
p[f"ro.bootimage.build.fingerprint"] = fingerprint(sec, p)
with open(prop, 'w') as f:
f.write(str(p))
for sec, prop in {"system": "system/system/build.prop", "product": "system/product/build.prop", "system_ext": "system/system_ext/build.prop", "vendor": "system/vendor/build.prop", "odm": "system/vendor/odm/etc/build.prop"}.items():
fix_prop(sec, prop)
2021-10-26 11:16:38 +02:00
- name: Umount images
run: |
sudo umount system/vendor
sudo umount system/product
sudo umount system/system_ext
2021-10-26 11:16:38 +02:00
sudo umount system
2021-10-26 12:19:23 +02:00
- name: Shrink images
run: |
e2fsck -yf ${{ matrix.arch }}/system.img
2021-10-26 18:45:03 +02:00
resize2fs -M ${{ matrix.arch }}/system.img
e2fsck -yf ${{ matrix.arch }}/vendor.img
2021-10-26 18:45:03 +02:00
resize2fs -M ${{ matrix.arch }}/vendor.img
e2fsck -yf ${{ matrix.arch }}/product.img
2021-10-26 18:45:03 +02:00
resize2fs -M ${{ matrix.arch }}/product.img
e2fsck -yf ${{ matrix.arch }}/system_ext.img
2021-10-26 18:45:03 +02:00
resize2fs -M ${{ matrix.arch }}/system_ext.img
2021-10-31 09:37:54 +01:00
- name: Remove signature and add scripts
2021-10-26 11:16:38 +02:00
run: |
rm -rf ${{ matrix.arch }}/\[Content_Types\].xml ${{ matrix.arch }}/AppxBlockMap.xml ${{ matrix.arch }}/AppxSignature.p7x ${{ matrix.arch }}/AppxMetadata
2021-12-12 00:39:19 +01:00
cp vclibs.appx xaml.appx ${{ matrix.arch }}
2021-10-31 10:20:59 +01:00
tee ${{ matrix.arch }}/Install.ps1 <<EOF
# Automated Install script by Mioki
# http://github.com/okibcn
2021-12-11 18:56:48 +01:00
function Test-Administrator {
2021-10-31 09:37:54 +01:00
[OutputType([bool])]
param()
process {
[Security.Principal.WindowsPrincipal]\$user = [Security.Principal.WindowsIdentity]::GetCurrent();
return \$user.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator);
}
}
2021-12-13 04:03:27 +01:00
function Finish {
Clear-Host
Start-Process "wsa://com.topjohnwu.magisk"
Start-Process "wsa://com.android.vending"
}
2021-12-11 18:56:48 +01:00
if (-not (Test-Administrator)) {
2022-04-14 07:42:15 +02:00
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force
2022-02-01 03:18:53 +01:00
\$proc = Start-Process -PassThru -WindowStyle Hidden -Verb RunAs powershell.exe -Args "-executionpolicy bypass -command Set-Location '\$PSScriptRoot'; &'\$PSCommandPath' EVAL"
2021-12-11 18:56:48 +01:00
\$proc.WaitForExit()
if (\$proc.ExitCode -ne 0) {
2021-12-12 01:47:30 +01:00
Clear-Host
2021-12-11 18:56:48 +01:00
Write-Warning "Failed to launch start as Administrator\`r\`nPress any key to exit"
\$null = \$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}
exit
}
elseif ((\$args.Count -eq 1) -and (\$args[0] -eq "EVAL")) {
2022-02-01 03:18:53 +01:00
Start-Process powershell.exe -Args "-executionpolicy bypass -command Set-Location '\$PSScriptRoot'; &'\$PSCommandPath'"
2021-10-31 09:37:54 +01:00
exit
}
2022-03-25 13:01:35 +01:00
if (((Test-Path -Path $(ls -Q ./${{ matrix.arch }} | paste -sd "," -)) -eq \$false).Count) {
Write-Error "Some files are missing in the zip. Please try to download it again from the browser downloader, or try to run the workflow again. Press any key to exist"
\$null = \$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
exit 1
}
2021-12-11 18:56:48 +01:00
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"
2021-12-11 18:56:48 +01:00
2021-12-12 01:47:30 +01:00
\$VMP = Get-WindowsOptionalFeature -Online -FeatureName 'VirtualMachinePlatform'
if (\$VMP.State -ne "Enabled") {
Enable-WindowsOptionalFeature -Online -NoRestart -FeatureName 'VirtualMachinePlatform'
Clear-Host
Write-Warning "Need restart to enable virtual machine platform\`r\`nPress y to restart or press any key to exit"
\$key = \$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
If ("y" -eq \$key.Character) {
Restart-Computer -Confirm
}
Else {
exit 1
}
2021-12-12 00:39:19 +01:00
}
2021-12-12 01:47:30 +01:00
Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Path vclibs.appx
Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Path xaml.appx
2021-12-12 00:39:19 +01:00
2021-12-11 18:56:48 +01:00
\$Installed = \$null
2021-12-12 00:21:46 +01:00
\$Installed = Get-AppxPackage -Name 'MicrosoftCorporationII.WindowsSubsystemForAndroid'
2021-12-11 18:56:48 +01:00
2021-12-13 04:03:27 +01:00
If ((\$null -ne \$Installed) -and (-not (\$Installed.IsDevelopmentMode))) {
Clear-Host
Write-Warning "There is already one installed WSA. Please uninstall it first.\`r\`nPress y to uninstall existing WSA or press any key to exit"
\$key = \$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
If ("y" -eq \$key.Character) {
Remove-AppxPackage -Package \$Installed.PackageFullName
2021-12-11 18:56:48 +01:00
}
Else {
2021-12-13 04:03:27 +01:00
exit 1
2021-12-11 18:56:48 +01:00
}
}
2021-12-12 01:47:30 +01:00
Clear-Host
2021-12-11 18:56:48 +01:00
Write-Host "Installing MagiskOnWSA..."
Stop-Process -Name "wsaclient" -ErrorAction "silentlycontinue"
2021-12-13 04:03:27 +01:00
Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Register .\AppxManifest.xml
if (\$?) {
Finish
}
Elseif (\$null -ne \$Installed) {
Clear-Host
Write-Host "Failed to update, try to uninstall existing installation while preserving userdata..."
Remove-AppxPackage -PreserveApplicationData -Package \$Installed.PackageFullName
Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Register .\AppxManifest.xml
if (\$?) {
Finish
}
}
Write-Host "All Done\`r\`nPress any key to exit"
\$null = \$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
2021-10-31 09:37:54 +01:00
EOF
- name: Generate artifact name
run: |
variant="${{ github.event.inputs.gapps_variant }}"
2021-11-10 11:25:23 +01:00
root="${{ github.event.inputs.root_sol }}"
if [[ "$root" = "none" ]]; then
2021-11-10 11:31:48 +01:00
name1=""
2021-11-10 11:25:23 +01:00
elif [[ "$root" = "" ]]; then
name1="-with-magisk"
else
name1="-with-${root}"
fi
if [[ "$variant" = "none" || "$variant" = "" ]]; then
2021-11-10 11:25:23 +01:00
name2="-NoGApps"
else
2021-11-10 11:25:23 +01:00
name2="-GApps-${variant}"
fi
echo "artifact_name=WSA${name1}${name2}_${{ env.WSA_VER }}_${{ matrix.arch }}_${{ env.WSA_REL }}" >> $GITHUB_ENV
2022-05-16 01:19:36 +02:00
- name: Compress
run: |
2022-05-16 01:43:49 +02:00
zip -9qrv ${{ env.artifact_name }}.zip ./${{ matrix.arch }}/*
2021-10-26 11:16:38 +02:00
- name: Upload WSA
2022-05-16 01:19:36 +02:00
uses: softprops/action-gh-release@v1
2021-10-26 11:16:38 +02:00
with:
2022-05-20 19:40:15 +02:00
files: ./${{ env.artifact_name }}.zip
2022-05-16 01:43:49 +02:00
tag_name: ./${{ env.artifact_name }}