2021-10-26 11:16:38 +02:00
name : Magisk
on :
2021-10-26 13:43:23 +02:00
push :
pull_request :
2021-10-26 11:16:38 +02:00
workflow_dispatch :
inputs :
magisk_apk :
description : 'Download link to magisk apk.'
required : true
2021-10-26 13:43:23 +02:00
default : 'https://raw.githubusercontent.com/LSPosed/MagiskOnWSA/main/magisk.apk'
2021-10-26 14:27:40 +02:00
gapps_variant :
description: 'Variants of gapps. Should be : [ none, aroma, super, stock, full, mini, micro, nano, pico, tvstock, tvmini]'
required : true
default : 'none'
2021-10-26 11:16:38 +02:00
jobs :
build :
runs-on : ubuntu-20.04
2021-10-26 13:21:40 +02:00
strategy :
matrix :
arch : [ x64, arm64]
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
- name : Download AWS
shell : python
run : |
import requests
from bs4 import BeautifulSoup
import re
import zipfile
import os
import urllib.request
res = requests.post("https://store.rg-adguard.net/api/GetFiles", "type=CategoryId&url=858014f3-3934-4abe-8078-4aa193e74ca8&ring=WIS&lang=en-US", headers={
"content-type": "application/x-www-form-urlencoded"
})
html = BeautifulSoup(res.content, "lxml")
a = html.find("a", string=re.compile("MicrosoftCorporationII\.WindowsSubsystemForAndroid_.*\.msixbundle"))
link = a["href"]
print(f"downloading link: {link}", flush=True)
out_file = "wsa.zip"
2021-10-26 13:21:40 +02:00
arch = "${{ matrix.arch }}"
2021-10-26 11:16:38 +02:00
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)
2021-10-26 13:33:26 +02:00
break
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)
print("done", flush=True)
- name : Download Magisk
shell : python
run : |
import urllib.request
import zipfile
import os
magisk_apk = """${{ github.event.inputs.magisk_apk }}"""
2021-10-26 13:43:23 +02:00
if not magisk_apk :
magisk_apk = """https://raw.githubusercontent.com/LSPosed/MagiskOnWSA/main/magisk.apk"""
2021-10-26 11:16:38 +02:00
out_file = "magisk.zip"
2021-10-26 13:21:40 +02:00
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")
extract_as(zip, f"lib/{ abi_map[arch][0] }/libmagiskinit.so", "magiskinit", "magisk")
2021-10-26 12:20:30 +02:00
extract_as(zip, f"lib/{ abi_map['x64'][0] }/libmagiskinit.so", "magiskpolicy", "magisk")
2021-10-26 14:27:40 +02:00
- name : Download OpenGApps
if : ${{ github.event.inputs.gapps_variant != 'none' && github.event.inputs.gapps_variant != '' }}
shell : python
run : |
import requests
import zipfile
import os
import urllib.request
import json
arch = "${{ matrix.arch }}"
variant = "${{ github.event.inputs.gapps_variant }}"
abi_map = {"x64" : "x86_64", "arm64": "arm64"}
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"]["11.0"]["variants"]}[variant]["zip"]
print(f"downloading link: {link}", flush=True)
out_file = "gapps.zip"
if not os.path.isfile(out_file) :
urllib.request.urlretrieve(link, out_file)
out_dir = "gapps"
with zipfile.ZipFile(out_file) as zip :
if not os.path.isdir(out_dir) :
print(f"unzipping from {out_file}", flush=True)
zip.extractall(out_dir)
print("done", flush=True)
2021-10-26 11:16:38 +02:00
- name : Expand images
run : |
2021-10-26 13:21:40 +02:00
e2fsck -yf ${{ matrix.arch }}/vendor.img
resize2fs ${{ matrix.arch }}/vendor.img 320M
2021-10-26 11:16:38 +02:00
- name : Mount images
run : |
sudo mkdir system
2021-10-26 13:21:40 +02:00
sudo mount -o loop ${{ matrix.arch }}/system.img system
sudo mount -o loop ${{ matrix.arch }}/vendor.img system/vendor
2021-10-26 11:16:38 +02:00
- name : Modify images
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 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 {} \;
chmod +x magisk/magiskpolicy
echo '/dev/wsa-magisk(/.*)? u:object_r:magisk_file:s0' | sudo tee -a system/vendor/etc/selinux/vendor_file_contexts
sudo ./magisk/magiskpolicy --load system/vendor/etc/selinux/precompiled_sepolicy --save system/vendor/etc/selinux/precompiled_sepolicy --magisk "allow * magisk_file lnk_file *"
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
symlink ./magiskinit /dev/wsa-magisk/magiskpolicy
mkdir /dev/wsa-magisk/.magisk 700
mkdir /dev/wsa-magisk/.magisk/mirror 700
mkdir /dev/wsa-magisk/.magisk/block 700
rm /dev/.magisk_unblock
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
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
start YqCTLTppv3ML
service YqCTLTppv3ML /dev/wsa-magisk/magisk --boot-complete
user root
seclabel u:r:magisk:s0
oneshot
EOF
- name : Umount images
run : |
sudo umount system/vendor
sudo umount system
2021-10-26 12:19:23 +02:00
- name : Shrink images
run : |
2021-10-26 13:21:40 +02:00
e2fsck -yf ${{ matrix.arch }}/system.img
resize2fs ${{ matrix.arch }}/system.img
e2fsck -yf ${{ matrix.arch }}/vendor.img
resize2fs ${{ matrix.arch }}/vendor.img
2021-10-26 11:16:38 +02:00
- name : Remove signature
run : |
2021-10-26 13:21:40 +02:00
rm -rf ${{ matrix.arch }}/\[Content_Types\].xml ${{ matrix.arch }}/AppxBlockMap.xml ${{ matrix.arch }}/AppxSignature.p7x ${{ matrix.arch }}/AppxMetadata
2021-10-26 11:16:38 +02:00
- name : Upload WSA
uses : actions/upload-artifact@v2
with :
2021-10-26 13:21:40 +02:00
name : WSA-with-Magisk_${{ matrix.arch }}
path : './${{ matrix.arch }}/*'