Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create script wrapper to simplify things and etc #53

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
30 changes: 30 additions & 0 deletions SETUP.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@echo off

rem get registry key for windows developer mode
set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
set VALUE_NAME=AllowDevelopmentWithoutDevLicense
FOR /F "tokens=2* skip=2" %%a in ('reg query "%KEY_NAME%" /v "%VALUE_NAME%"') do set ValueValue=%%b
if %ValueValue% neq 1 (
echo Please Enable Windows Developer Mode in Settings
timeout 2 >nul
echo After that, press enter to continue
timeout 1 >nul
echo Opening Settings
timeout 4 >nul
start ms-settings:developers
pause
)
rem start install.sh
set current_dir=%~dp0
pushd %current_dir%
if exist %current_dir%install.sh (
wsl sudo ./install.sh
) else (
rem for some reason this else is showing even the install.sh is exist
echo install.sh.sh not found
timeout 3 >nul
)
rem get uac confirm from sudo.vbs and then install appx-package
for /d %%a in ("%current_dir%msix_unpack\*") do set manifest=%%~fa%\AppxManifest.xml
"%current_dir%sudo.vbs" powershell Add-AppxPackage -Register '%manifest%'
pause
16 changes: 14 additions & 2 deletions VARIABLES.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
#!/bin/bash

# Modify your variables here to corretly reference your directory and subdir
Root="/mnt/c/GAppsWSA"
# get current dir of this script
Root="$(pwd)"

# Your Windows architecture, x64 or arm64
Architecture="x64"
# get architecture based on wsl architecture
# its always same as windows afaik
Architecture=$(uname -m)
if [ $Architecture == 'x86_64' ]; then
Architecture="x64"
elif [ $Architecture == 'arm64' ||
$Architecture == 'aarch64' ]; then
Architecture="ARM64"
else
echo "is your cpu 64 bit or arm64 ?"
exit
fi

MiscRoot="$Root/misc"
PropRoot="$MiscRoot/prop/$Architecture"
Expand Down
121 changes: 61 additions & 60 deletions apply.sh
Original file line number Diff line number Diff line change
@@ -1,84 +1,85 @@
#!/bin/bash

# added quote mark ('"') for every variable so it wont be a problem if the path has space/whitespace
. ./VARIABLES.sh

echo "Copying build.prop for each image"
cp "$PropRoot/build_system_ext.prop" /mnt/system_ext/build.prop
cp "$PropRoot/build_system.prop" /mnt/system/build.prop
cp "$PropRoot/build_system.prop" /mnt/system/system/build.prop
cp "$PropRoot/build_product.prop" /mnt/product/build.prop
cp "$PropRoot/build_vendor.prop" /mnt/vendor/build.prop
cp "$PropRoot/build_vendor_odm.prop" /mnt/vendor/odm/etc/vendor.prop
cp "$PropRoot"/build_system_ext.prop /mnt/system_ext/build.prop
cp "$PropRoot"/build_system.prop /mnt/system/build.prop
cp "$PropRoot"/build_system.prop /mnt/system/system/build.prop
cp "$PropRoot"/build_product.prop /mnt/product/build.prop
cp "$PropRoot"/build_vendor.prop /mnt/vendor/build.prop
cp "$PropRoot"/build_vendor_odm.prop /mnt/vendor/odm/etc/vendor.prop

echo "Copying GApps files to system..."
cp -f -a $GAppsOutputFolder/app/* $InstallDir/app
cp -f -a $GAppsOutputFolder/etc/* $InstallDir/etc
cp -f -a $GAppsOutputFolder/overlay/* $InstallDir/overlay
cp -f -a $GAppsOutputFolder/priv-app/* $InstallDir/priv-app
cp -f -a $GAppsOutputFolder/framework/* $InstallDir/framework
cp -f -a "$GAppsOutputFolder"/app/* "$InstallDir"/app
cp -f -a "$GAppsOutputFolder"/etc/* "$InstallDir"/etc
cp -f -a "$GAppsOutputFolder"/overlay/* "$InstallDir"/overlay
cp -f -a "$GAppsOutputFolder"/priv-app/* "$InstallDir"/priv-app
cp -f -a "$GAppsOutputFolder"/framework/* "$InstallDir"/framework

echo "Applying root file ownership"
find $InstallDir/app -exec chown root:root {} &>/dev/null \;
find $InstallDir/etc -exec chown root:root {} &>/dev/null \;
find $InstallDir/overlay -exec chown root:root {} &>/dev/null \;
find $InstallDir/priv-app -exec chown root:root {} &>/dev/null \;
find $InstallDir/framework -exec chown root:root {} &>/dev/null \;
find $InstallDir/lib -exec chown root:root {} &>/dev/null \;
find $InstallDir/lib64 -exec chown root:root {} &>/dev/null \;
find "$InstallDir"/app -exec chown root:root {} &>/dev/null \;
find "$InstallDir"/etc -exec chown root:root {} &>/dev/null \;
find "$InstallDir"/overlay -exec chown root:root {} &>/dev/null \;
find "$InstallDir"/priv-app -exec chown root:root {} &>/dev/null \;
find "$InstallDir"/framework -exec chown root:root {} &>/dev/null \;
find "$InstallDir"/lib -exec chown root:root {} &>/dev/null \;
find "$InstallDir"/lib64 -exec chown root:root {} &>/dev/null \;

echo "Setting directory permissions"
find $InstallDir/app -type d -exec chmod 755 {} \;
find $InstallDir/etc -type d -exec chmod 755 {} \;
find $InstallDir/overlay -type d -exec chmod 755 {} \;
find $InstallDir/priv-app -type d -exec chmod 755 {} \;
find $InstallDir/framework -type d -exec chmod 755 {} \;
find $InstallDir/lib -type d -exec chmod 755 {} \;
find $InstallDir/lib64 -type d -exec chmod 755 {} \;
find "$InstallDir"/app -type d -exec chmod 755 {} \;
find "$InstallDir"/etc -type d -exec chmod 755 {} \;
find "$InstallDir"/overlay -type d -exec chmod 755 {} \;
find "$InstallDir"/priv-app -type d -exec chmod 755 {} \;
find "$InstallDir"/framework -type d -exec chmod 755 {} \;
find "$InstallDir"/lib -type d -exec chmod 755 {} \;
find "$InstallDir"/lib64 -type d -exec chmod 755 {} \;

echo "Setting file permissions"
find $InstallDir/app -type f -exec chmod 644 {} \;
find $InstallDir/overlay -type f -exec chmod 644 {} \;
find $InstallDir/priv-app -type f -exec chmod 644 {} \;
find $InstallDir/framework -type f -exec chmod 644 {} \;
find $InstallDir/lib -type f -exec chmod 644 {} \;
find $InstallDir/lib64 -type f -exec chmod 644 {} \;
find $InstallDir/etc/permissions -type f -exec chmod 644 {} \;
find $InstallDir/etc/default-permissions -type f -exec chmod 644 {} \;
find $InstallDir/etc/preferred-apps -type f -exec chmod 644 {} \;
find $InstallDir/etc/sysconfig -type f -exec chmod 644 {} \;
find "$InstallDir"/app -type f -exec chmod 644 {} \;
find "$InstallDir"/overlay -type f -exec chmod 644 {} \;
find "$InstallDir"/priv-app -type f -exec chmod 644 {} \;
find "$InstallDir"/framework -type f -exec chmod 644 {} \;
find "$InstallDir"/lib -type f -exec chmod 644 {} \;
find "$InstallDir"/lib64 -type f -exec chmod 644 {} \;
find "$InstallDir"/etc/permissions -type f -exec chmod 644 {} \;
find "$InstallDir"/etc/default-permissions -type f -exec chmod 644 {} \;
find "$InstallDir"/etc/preferred-apps -type f -exec chmod 644 {} \;
find "$InstallDir"/etc/sysconfig -type f -exec chmod 644 {} \;

echo "Applying SELinux security contexts to directories"
find $InstallDir/app -type d -exec chcon --reference=$InstallDir/app {} \;
find $InstallDir/overlay -type d -exec chcon --reference=$InstallDir/overlay {} \;
find $InstallDir/priv-app -type d -exec chcon --reference=$InstallDir/priv-app {} \;
find $InstallDir/framework -type d -exec chcon --reference=$InstallDir/framework {} \;
find $InstallDir/lib -type d -exec chcon --reference=$InstallDir/lib {} \;
find $InstallDir/lib64 -type d -exec chcon --reference=$InstallDir/lib64 {} \;
find $InstallDir/etc/permissions -type d -exec chcon --reference=$InstallDir/etc/permissions {} \;
find $InstallDir/etc/default-permissions -type d -exec chcon --reference=$InstallDir/etc/permissions {} \;
find $InstallDir/etc/preferred-apps -type d -exec chcon --reference=$InstallDir/etc/permissions {} \;
find $InstallDir/etc/sysconfig -type d -exec chcon --reference=$InstallDir/etc/sysconfig {} \;
find "$InstallDir"/app -type d -exec chcon --reference="$InstallDir"/app {} \;
find "$InstallDir"/overlay -type d -exec chcon --reference="$InstallDir"/overlay {} \;
find "$InstallDir"/priv-app -type d -exec chcon --reference="$InstallDir"/priv-app {} \;
find "$InstallDir"/framework -type d -exec chcon --reference="$InstallDir"/framework {} \;
find "$InstallDir"/lib -type d -exec chcon --reference="$InstallDir"/lib {} \;
find "$InstallDir"/lib64 -type d -exec chcon --reference="$InstallDir"/lib64 {} \;
find "$InstallDir"/etc/permissions -type d -exec chcon --reference="$InstallDir"/etc/permissions {} \;
find "$InstallDir"/etc/default-permissions -type d -exec chcon --reference="$InstallDir"/etc/permissions {} \;
find "$InstallDir"/etc/preferred-apps -type d -exec chcon --reference="$InstallDir"/etc/permissions {} \;
find "$InstallDir"/etc/sysconfig -type d -exec chcon --reference="$InstallDir"/etc/sysconfig {} \;

echo "Applying SELinux security contexts to files"
find $InstallDir/framework -type f -exec chcon --reference=$InstallDir/framework/ext.jar {} \;
find $InstallDir/overlay -type f -exec chcon --reference=$InstallDir/app/CertInstaller/CertInstaller.apk {} \;
find $InstallDir/app -type f -exec chcon --reference=$InstallDir/app/CertInstaller/CertInstaller.apk {} \;
find $InstallDir/priv-app -type f -exec chcon --reference=$InstallDir/priv-app/Shell/Shell.apk {} \;
find $InstallDir/lib -type f -exec chcon --reference=$InstallDir/lib/libcap.so {} \;
find $InstallDir/lib64 -type f -exec chcon --reference=$InstallDir/lib64/libcap.so {} \;
find $InstallDir/etc/permissions -type f -exec chcon --reference=$InstallDir/etc/fs_config_dirs {} \;
find $InstallDir/etc/default-permissions -type f -exec chcon --reference=$InstallDir/etc/fs_config_dirs {} \;
find $InstallDir/etc/preferred-apps -type f -exec chcon --reference=$InstallDir/etc/fs_config_dirs {} \;
find $InstallDir/etc/sysconfig -type f -exec chcon --reference=$InstallDir/etc/fs_config_dirs {} \;
find "$InstallDir"/framework -type f -exec chcon --reference="$InstallDir"/framework/ext.jar {} \;
find "$InstallDir"/overlay -type f -exec chcon --reference="$InstallDir"/app/CertInstaller/CertInstaller.apk {} \;
find "$InstallDir"/app -type f -exec chcon --reference="$InstallDir"/app/CertInstaller/CertInstaller.apk {} \;
find "$InstallDir"/priv-app -type f -exec chcon --reference="$InstallDir"/priv-app/Shell/Shell.apk {} \;
find "$InstallDir"/lib -type f -exec chcon --reference="$InstallDir"/lib/libcap.so {} \;
find "$InstallDir"/lib64 -type f -exec chcon --reference="$InstallDir"/lib64/libcap.so {} \;
find "$InstallDir"/etc/permissions -type f -exec chcon --reference="$InstallDir"/etc/fs_config_dirs {} \;
find "$InstallDir"/etc/default-permissions -type f -exec chcon --reference="$InstallDir"/etc/fs_config_dirs {} \;
find "$InstallDir"/etc/preferred-apps -type f -exec chcon --reference="$InstallDir"/etc/fs_config_dirs {} \;
find "$InstallDir"/etc/sysconfig -type f -exec chcon --reference="$InstallDir"/etc/fs_config_dirs {} \;

echo "Applying SELinux policy"
# Sed will remove the SELinux policy for plat_sepolicy.cil, preserve policy using cp
cp $InstallDir/etc/selinux/plat_sepolicy.cil $InstallDir/etc/selinux/plat_sepolicy_new.cil
sed -i 's/(allow gmscore_app self (process (ptrace)))/(allow gmscore_app self (process (ptrace)))\n(allow gmscore_app self (vsock_socket (read write create connect)))\n(allow gmscore_app device_config_runtime_native_boot_prop (file (read)))/g' $InstallDir/etc/selinux/plat_sepolicy_new.cil
cp $InstallDir/etc/selinux/plat_sepolicy_new.cil $InstallDir/etc/selinux/plat_sepolicy.cil
rm $InstallDir/etc/selinux/plat_sepolicy_new.cil
cp "$InstallDir"/etc/selinux/plat_sepolicy.cil "$InstallDir"/etc/selinux/plat_sepolicy_new.cil
sed -i 's/(allow gmscore_app self (process (ptrace)))/(allow gmscore_app self (process (ptrace)))\n(allow gmscore_app self (vsock_socket (read write create connect)))\n(allow gmscore_app device_config_runtime_native_boot_prop (file (read)))/g' "$InstallDir"/etc/selinux/plat_sepolicy_new.cil
cp "$InstallDir"/etc/selinux/plat_sepolicy_new.cil "$InstallDir"/etc/selinux/plat_sepolicy.cil
rm "$InstallDir"/etc/selinux/plat_sepolicy_new.cil

# Prevent android from using cached SELinux policy
echo '0000000000000000000000000000000000000000000000000000000000000000' > $InstallDir/etc/selinux/plat_sepolicy_and_mapping.sha256
echo '0000000000000000000000000000000000000000000000000000000000000000' > "$InstallDir"/etc/selinux/plat_sepolicy_and_mapping.sha256

echo "!! Apply completed !!"
33 changes: 17 additions & 16 deletions extend_and_mount_images.sh
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
#!/bin/bash

# added quote mark ('"') for every variable so it wont be a problem if the path has space/whitespace
. ./VARIABLES.sh

echo "chk product.img"
e2fsck -f $ImagesRoot/product.img
e2fsck -f "$ImagesRoot"/product.img

echo "Resizing product.img"
resize2fs $ImagesRoot/product.img 240M
resize2fs "$ImagesRoot"/product.img 240M

echo "chk system.img"
e2fsck -f $ImagesRoot/system.img
e2fsck -f "$ImagesRoot"/system.img

echo "Resizing system.img"
resize2fs $ImagesRoot/system.img 1280M
resize2fs "$ImagesRoot"/system.img 1280M

echo "chk system_ext.img"
e2fsck -f $ImagesRoot/system_ext.img
e2fsck -f "$ImagesRoot"/system_ext.img

echo "Resizing system_ext.img"
resize2fs $ImagesRoot/system_ext.img 108M
resize2fs "$ImagesRoot"/system_ext.img 108M

echo "chk vendor.img"
e2fsck -f $ImagesRoot/vendor.img
e2fsck -f "$ImagesRoot"/vendor.img

echo "Resizing vendor.img"
resize2fs $ImagesRoot/vendor.img 300M
resize2fs "$ImagesRoot"/vendor.img 300M

echo "Creating mount point for product"
mkdir -p $MountPointProduct
mkdir -p "$MountPointProduct"

echo "Creating mount point for system_ext"
mkdir -p $MountPointSystemExt
mkdir -p "$MountPointSystemExt"

echo "Creating mount point for system"
mkdir -p $MountPointSystem
mkdir -p "$MountPointSystem"

echo "Creating mount point for vendor"
mkdir -p $MountPointVendor
mkdir -p "$MountPointVendor"

echo "Mounting product"
mount -o rw $ImagesRoot/product.img $MountPointProduct
mount -o rw "$ImagesRoot"/product.img $MountPointProduct

echo "Mounting system_ext"
mount -o rw $ImagesRoot/system_ext.img $MountPointSystemExt
mount -o rw "$ImagesRoot"/system_ext.img $MountPointSystemExt

echo "Mounting system"
mount -o rw $ImagesRoot/system.img $MountPointSystem
mount -o rw "$ImagesRoot"/system.img $MountPointSystem

echo "Mounting vendor"
mount -o rw $ImagesRoot/vendor.img $MountPointVendor
mount -o rw "$ImagesRoot"/vendor.img $MountPointVendor

echo "!! Images mounted !!"
33 changes: 17 additions & 16 deletions extract_gapps_pico.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
#!/bin/bash

# added quote mark ('"') for every variable so it wont be a problem if the path has space/whitespace
. ./VARIABLES.sh

rm -rf $GAppsOutputFolder
rm -rf $GAppsTmpFolder
rm -rf $GAppsExtractFolder
rm -rf "$GAppsOutputFolder"
rm -rf "$GAppsTmpFolder"
rm -rf "$GAppsExtractFolder"

mkdir -p $GAppsOutputFolder
mkdir -p $GAppsTmpFolder
mkdir -p $GAppsExtractFolder
mkdir -p "$GAppsOutputFolder"
mkdir -p "$GAppsTmpFolder"
mkdir -p "$GAppsExtractFolder"

echo "Unzipping OpenGApps"
for file in "$GAppsRoot/"*.zip; do unzip -q "$file" -d $GAppsExtractFolder; done
for file in "$GAppsRoot"/*.zip; do unzip -q "$file" -d "$GAppsExtractFolder"; done

echo "Extracting Core Google Apps"
for f in "$GAppsExtractFolder/Core/"*.lz; do tar --lzip -xvf "$f" -C $GAppsTmpFolder &>/dev/null; done
for f in "$GAppsExtractFolder"/Core/*.lz; do tar --lzip -xvf "$f" -C "$GAppsTmpFolder" &>/dev/null; done

echo "Extracting Google Apps"
for f in "$GAppsExtractFolder/GApps/"*.lz; do tar --lzip -xvf "$f" -C $GAppsTmpFolder &>/dev/null; done
for f in "$GAppsExtractFolder"/GApps/*.lz; do tar --lzip -xvf "$f" -C "$GAppsTmpFolder" &>/dev/null; done

echo "Deleting duplicates & conflicting apps"
rm -rf "$GAppsTmpFolder/setupwizardtablet-x86_64" # We already have setupwizard "default"
rm -rf "$GAppsTmpFolder/packageinstallergoogle-all" # The image already has a package installer, and we are not allowed to have two.
rm -rf "$GAppsTmpFolder"/setupwizardtablet-x86_64 # We already have setupwizard "default"
rm -rf "$GAppsTmpFolder"/packageinstallergoogle-all # The image already has a package installer, and we are not allowed to have two.

echo "Merging folders"
for D in $GAppsTmpFolder/*; do [ -d "${D}" ] && cp -r ${D}/* $GAppsOutputFolder; done
for D in "$GAppsTmpFolder"/*; do [ -d "${D}" ] && cp -r "${D}"/* "$GAppsOutputFolder"; done

echo "Merging subfolders"
for D in $GAppsOutputFolder/*; do [ -d "${D}" ] && cp -r ${D}/* $GAppsOutputFolder && rm -rf ${D}; done
for D in "$GAppsOutputFolder"/*; do [ -d "${D}" ] && cp -r "${D}"/* "$GAppsOutputFolder" && rm -rf ${D}; done

echo "Post merge operation"
cp -r $GAppsOutputFolder/product/* $GAppsOutputFolder && rm -rf "$GAppsOutputFolder/product";
cp -r "$GAppsOutputFolder"/product/* "$GAppsOutputFolder" && rm -rf "$GAppsOutputFolder"/product;

echo "Deleting temporary files"
rm -rf $GAppsTmpFolder
rm -rf $GAppsExtractFolder
rm -rf "$GAppsTmpFolder"
rm -rf "$GAppsExtractFolder"

echo "!! GApps folder ready !!"