From 9789c3f69cc8427b999ca6e7d746223f1c81cc05 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Tue, 26 Oct 2021 17:16:38 +0800 Subject: [PATCH] Initial commit --- .github/workflows/magisk.yml | 167 +++++++++++++++++++++++++++++++++++ README.md | 14 +++ 2 files changed, 181 insertions(+) create mode 100644 .github/workflows/magisk.yml create mode 100644 README.md diff --git a/.github/workflows/magisk.yml b/.github/workflows/magisk.yml new file mode 100644 index 0000000..fa94826 --- /dev/null +++ b/.github/workflows/magisk.yml @@ -0,0 +1,167 @@ +name: Magisk + +on: + workflow_dispatch: + inputs: + magisk_apk: + description: 'Download link to magisk apk.' + required: true + arch: + description: 'Architecture to build. Should be x64 or arm64.' + required: true + default: 'x64' + +jobs: + build: + runs-on: ubuntu-20.04 + 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" + + arch = "${{ github.event.inputs.arch }}" + + 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: + if f.filename.__contains__(arch): + zip_name = f.filename + if not os.path.isfile(zip_name): + print(f"unzipping to {zip_name}", flush=True) + zip.extract(f) + + 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 }}""" + + out_file = "magisk.zip" + + arch = "${{ github.event.inputs.arch }}" + + 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") + - name: Expand images + run: | + e2fsck -yf ${{ github.event.inputs.arch }}/vendor.img + resize2fs ${{ github.event.inputs.arch }}/vendor.img 320M + - name: Mount images + run: | + sudo mkdir system + sudo mount -o loop ${{ github.event.inputs.arch }}/system.img system + sudo mount -o loop ${{ github.event.inputs.arch }}/vendor.img system/vendor + - 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 {} \; + ln -s magiskinit magisk/magiskpolicy + 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 <