From dc90575112dd4ab5ac4a1a1efba6aeb3f59d2d8d Mon Sep 17 00:00:00 2001 From: cupang-afk Date: Tue, 26 Oct 2021 05:19:29 +0700 Subject: [PATCH 1/8] Added script wrapper --- SETUP.cmd | 29 +++++++++++++++++ install.sh | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ sudo.vbs | 19 +++++++++++ 3 files changed, 140 insertions(+) create mode 100644 SETUP.cmd create mode 100644 install.sh create mode 100644 sudo.vbs diff --git a/SETUP.cmd b/SETUP.cmd new file mode 100644 index 0000000..5df0f71 --- /dev/null +++ b/SETUP.cmd @@ -0,0 +1,29 @@ +@echo off + +rem get req 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 ( + echo user_promt.sh not found + timeout 3 >nul +) +rem install appx +for /d %%a in ("%current_dir%msix_unpack\*") do set manifest=%%~fa%\AppxManifest.xml +"%current_dir%sudo.vbs" powershell Add-AppxPackage -Register '%manifest%' +pause \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..da88140 --- /dev/null +++ b/install.sh @@ -0,0 +1,92 @@ +#!/bin/bash +function loading_spinner() { + local pid=$! + local spin='-\|/' + local i=0 + while kill -0 $pid 2>/dev/null + do + i=$(( (i+1) %4 )) + printf "\r${spin:$i:1}" + sleep .1 + done +} +function convertPath() { + #convert path to WSL(linux) Format and add (/mnt) + #remove ("); lowercase disk letter; remove (:); change (\) to (/); add ("/mnt) to first line; add (") to last line + #input example ("C:/Windows") output ("/mnt/c/Windows") + echo $(sed 's/"//g; s/^\(.\{1\}\)/\L&\E/; s/://; s/\\/\//g; s/^/\/mnt\//; s/$//' <<<"$1") +} +function check_unzip_lzip() { + if [ ! command -v unzip &> /dev/null || + ! command -v lzip &> /dev/null || + ! command -v pv &> /dev/null ]; then + echo "unzip and/or lzip could not be found" + echo "Installing" + sudo apt install unzip lzip -y + fi +} +function createUnpackDir() { + if [ ! -d "$UNPACK_DIR" ]; then + echo "Creating $UNPACK_DIR" + mkdir "$UNPACK_DIR" + fi +} + +check_unzip_lzip +#get all variable from VARIABLES.sh +. ./VARIABLES.sh + +#ask user to input the path to the MsixBundle and OpenGapps.zip +clear +read -rp "Enter MsixBundle PATH (drag here or copy as path): " MsixBundlePath +read -rp "Enter OpenGapps.zip PATH (drag here or copy as path): " OpenGappsPath +clear + +echo "!! You got $Architecture CPU !!" +echo "----------------" + +# start +UNPACK_DIR=$Root/msix_unpack +createUnpackDir + +# set msixbundle var and opengapps var +MsixBundlePath=$(convertPath "$MsixBundlePath") +MsixBundleName=`basename "$MsixBundlePath"` +OpenGappsPath=$(convertPath "$OpenGappsPath") +OpenGappsName=`basename "$OpenGappsPath"` + +echo "Extracting ${Architecture} WsaPackage from $MsixBundleName" +unzip -joq "$MsixBundlePath" "WsaPackage_*_${Architecture}_*" -d "$UNPACK_DIR" & loading_spinner + +# set WsaPackage var +WsaPackagePath=$(find "$UNPACK_DIR"/WsaPackage_*_${Architecture}_*) +WsaPackageName=`basename "$WsaPackagePath"` +WsaPackageUnpackDir=$UNPACK_DIR/${WsaPackageName%.*} +WsaPackageExclude="AppxMetadata [Content_Types].xml AppxBlockMap.xml AppxSignature.p7x" + +echo "Extracting $WsaPackageName" +unzip -oq "$WsaPackagePath" -x $WsaPackageExclude -d "$WsaPackageUnpackDir" & loading_spinner + +echo "Remove $MsixBundleName" +rm -rf "$UNPACK_DIR/$WsaPackageName" + +echo "Copy $OpenGappsName" +cp "$OpenGappsPath" "$GAppsRoot" + +echo "Moving .img file to $ImagesRoot" +mv "$WsaPackageUnpackDir"/*.img "$ImagesRoot" + +# run other script +echo "----------------" +. ./extract_gapps_pico.sh +echo "----------------" +. ./extend_and_mount_images.sh +echo "----------------" +. ./apply.sh +echo "----------------" +. ./unmount_images.sh +echo "----------------" + +echo "Moving .img file Back to $WsaPackageUnpackDir" +mv "$ImagesRoot"/*img "$WsaPackageUnpackDir" +# if done, back to cmd \ No newline at end of file diff --git a/sudo.vbs b/sudo.vbs new file mode 100644 index 0000000..237b36e --- /dev/null +++ b/sudo.vbs @@ -0,0 +1,19 @@ +Option Explicit +If WScript.Arguments.Count = 0 Then + WScript.Echo "Usage: sudo program [arg1 arg2 ...]" & vbCrLf & _ + "Run `program` with paramators as root in new console window" +Else + Dim ShellApp, WshShell + Dim cmd, varg, i + Set WshShell = CreateObject("WScript.Shell") + cmd = WshShell.ExpandEnvironmentStrings("%COMSPEC%") + 'Build paramator + varg = "/C CD " & WshShell.CurrentDirectory & " & " + For i = 0 To WScript.Arguments.Count - 1 + varg = varg & " " & WScript.Arguments(i) + Next + varg = varg & " & PAUSE" + 'run cmd /C ... as root + Set ShellApp = CreateObject("Shell.Application") + ShellApp.ShellExecute cmd, varg, "", "runas" +End If \ No newline at end of file From 6be507d6a362365948f2b152a64026a2b2913aad Mon Sep 17 00:00:00 2001 From: cupang-afk Date: Tue, 26 Oct 2021 05:23:44 +0700 Subject: [PATCH 2/8] Added quotation mark for variables --- apply.sh | 121 +++++++++++++++++++------------------ extend_and_mount_images.sh | 33 +++++----- extract_gapps_pico.sh | 33 +++++----- unmount_images.sh | 9 +-- 4 files changed, 100 insertions(+), 96 deletions(-) diff --git a/apply.sh b/apply.sh index f713d65..eb70d32 100644 --- a/apply.sh +++ b/apply.sh @@ -1,84 +1,85 @@ #!/bin/bash +# added quote mark ('"') for every variable so it wont conflict when 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 !!" diff --git a/extend_and_mount_images.sh b/extend_and_mount_images.sh index f5a8b15..f4f1f54 100644 --- a/extend_and_mount_images.sh +++ b/extend_and_mount_images.sh @@ -1,53 +1,54 @@ #!/bin/bash +# added quote mark ('"') for every variable so it wont conflict when 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 !!" \ No newline at end of file diff --git a/extract_gapps_pico.sh b/extract_gapps_pico.sh index af0c195..c8eae2d 100644 --- a/extract_gapps_pico.sh +++ b/extract_gapps_pico.sh @@ -1,39 +1,40 @@ #!/bin/bash +# added quote mark ('"') for every variable so it wont conflict when 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 !!" diff --git a/unmount_images.sh b/unmount_images.sh index 7b0ef6d..cd13f57 100644 --- a/unmount_images.sh +++ b/unmount_images.sh @@ -1,17 +1,18 @@ #!/bin/bash +# added quote mark ('"') for every variable so it wont conflict when path has space/whitespace . ./VARIABLES.sh echo "Unmounting product.img" -umount $MountPointProduct +umount "$MountPointProduct" echo "Unmounting system_ext.img" -umount $MountPointSystemExt +umount "$MountPointSystemExt" echo "Unmounting system.img" -umount $MountPointSystem +umount "$MountPointSystem" echo "Unmounting vendor.img" -umount $MountPointVendor +umount "$MountPointVendor" echo "!! Unmounting completed !!" \ No newline at end of file From c0cb882870fee93bb493c9906c38c5eaec626970 Mon Sep 17 00:00:00 2001 From: cupang-afk Date: Tue, 26 Oct 2021 05:24:40 +0700 Subject: [PATCH 3/8] Added function get current directory for $Root variable and added get architecture from wsl architecture function --- VARIABLES.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/VARIABLES.sh b/VARIABLES.sh index ef73ae2..d7e4949 100644 --- a/VARIABLES.sh +++ b/VARIABLES.sh @@ -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="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && 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 or arm64 ??" + exit +fi MiscRoot="$Root/misc" PropRoot="$MiscRoot/prop/$Architecture" From 8bc08b174d3519f7fcc4a5e18a51ae6430eb31ff Mon Sep 17 00:00:00 2001 From: cupang-afk Date: Tue, 26 Oct 2021 13:22:12 +0700 Subject: [PATCH 4/8] added quote mark ('"') for every variable so it wont be a problem if the path has space/whitespace --- apply.sh | 2 +- extend_and_mount_images.sh | 2 +- extract_gapps_pico.sh | 2 +- unmount_images.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apply.sh b/apply.sh index eb70d32..b851e96 100644 --- a/apply.sh +++ b/apply.sh @@ -1,6 +1,6 @@ #!/bin/bash -# added quote mark ('"') for every variable so it wont conflict when path has space/whitespace +# 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" diff --git a/extend_and_mount_images.sh b/extend_and_mount_images.sh index f4f1f54..136d8dd 100644 --- a/extend_and_mount_images.sh +++ b/extend_and_mount_images.sh @@ -1,6 +1,6 @@ #!/bin/bash -# added quote mark ('"') for every variable so it wont conflict when path has space/whitespace +# added quote mark ('"') for every variable so it wont be a problem if the path has space/whitespace . ./VARIABLES.sh echo "chk product.img" diff --git a/extract_gapps_pico.sh b/extract_gapps_pico.sh index c8eae2d..a266ad8 100644 --- a/extract_gapps_pico.sh +++ b/extract_gapps_pico.sh @@ -1,6 +1,6 @@ #!/bin/bash -# added quote mark ('"') for every variable so it wont conflict when path has space/whitespace +# added quote mark ('"') for every variable so it wont be a problem if the path has space/whitespace . ./VARIABLES.sh rm -rf "$GAppsOutputFolder" diff --git a/unmount_images.sh b/unmount_images.sh index cd13f57..6d09d82 100644 --- a/unmount_images.sh +++ b/unmount_images.sh @@ -1,6 +1,6 @@ #!/bin/bash -# added quote mark ('"') for every variable so it wont conflict when path has space/whitespace +# added quote mark ('"') for every variable so it wont be a problem if the path has space/whitespace . ./VARIABLES.sh echo "Unmounting product.img" From 3c85709220280e6156d8b7c88b41e7e45d1e6c27 Mon Sep 17 00:00:00 2001 From: cupang-afk Date: Tue, 26 Oct 2021 13:23:49 +0700 Subject: [PATCH 5/8] Added function get current directory and function to get architecture --- VARIABLES.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/VARIABLES.sh b/VARIABLES.sh index d7e4949..cc32941 100644 --- a/VARIABLES.sh +++ b/VARIABLES.sh @@ -2,6 +2,7 @@ # Modify your variables here to corretly reference your directory and subdir # get current dir of this script +# the example output for this is "C:\Windows",if using pwd only "C:\Windows\" Root="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Your Windows architecture, x64 or arm64 @@ -14,7 +15,7 @@ elif [ $Architecture == 'arm64' || $Architecture == 'aarch64' ]; then Architecture="ARM64" else - echo "is your cpu 64 or arm64 ??" + echo "is your cpu 64 bit or arm64 ?" exit fi From fdb7b53d61bed45ac9fb2c57791fdd6aad442178 Mon Sep 17 00:00:00 2001 From: cupang-afk Date: Tue, 26 Oct 2021 13:26:33 +0700 Subject: [PATCH 6/8] Added remove section for removing AppxMetadata etc --- install.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index da88140..0c52d2f 100644 --- a/install.sh +++ b/install.sh @@ -58,25 +58,31 @@ OpenGappsName=`basename "$OpenGappsPath"` echo "Extracting ${Architecture} WsaPackage from $MsixBundleName" unzip -joq "$MsixBundlePath" "WsaPackage_*_${Architecture}_*" -d "$UNPACK_DIR" & loading_spinner -# set WsaPackage var +# set extracted WsaPackage var WsaPackagePath=$(find "$UNPACK_DIR"/WsaPackage_*_${Architecture}_*) WsaPackageName=`basename "$WsaPackagePath"` WsaPackageUnpackDir=$UNPACK_DIR/${WsaPackageName%.*} -WsaPackageExclude="AppxMetadata [Content_Types].xml AppxBlockMap.xml AppxSignature.p7x" +WsaPackageExclude=".AppxMetadata .[Content_Types].xml .AppxBlockMap.xml .AppxSignature.p7x" echo "Extracting $WsaPackageName" -unzip -oq "$WsaPackagePath" -x $WsaPackageExclude -d "$WsaPackageUnpackDir" & loading_spinner +unzip -oq "$WsaPackagePath" -d "$WsaPackageUnpackDir" & loading_spinner echo "Remove $MsixBundleName" rm -rf "$UNPACK_DIR/$WsaPackageName" +echo "Remove Metadata and other in $WsaPackageName" +rm -rf "$WsaPackageUnpackDir/AppxMetadata" +rm -rf "$WsaPackageUnpackDir/[Content_Types].xml" +rm -rf "$WsaPackageUnpackDir/AppxBlockMap.xml" +rm -rf "$WsaPackageUnpackDir/AppxSignature.p7x" + echo "Copy $OpenGappsName" cp "$OpenGappsPath" "$GAppsRoot" echo "Moving .img file to $ImagesRoot" mv "$WsaPackageUnpackDir"/*.img "$ImagesRoot" -# run other script +# run script echo "----------------" . ./extract_gapps_pico.sh echo "----------------" @@ -89,4 +95,4 @@ echo "----------------" echo "Moving .img file Back to $WsaPackageUnpackDir" mv "$ImagesRoot"/*img "$WsaPackageUnpackDir" -# if done, back to cmd \ No newline at end of file +# if all done, the terminal should back to cmd From bacb8fe321da31dfbe9f739d067b7e3c3f9c0a94 Mon Sep 17 00:00:00 2001 From: cupang-afk Date: Tue, 26 Oct 2021 13:27:19 +0700 Subject: [PATCH 7/8] Small change for rem comment --- SETUP.cmd | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/SETUP.cmd b/SETUP.cmd index 5df0f71..78e2350 100644 --- a/SETUP.cmd +++ b/SETUP.cmd @@ -1,6 +1,6 @@ @echo off -rem get req key for windows developer mode +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 @@ -20,10 +20,11 @@ pushd %current_dir% if exist %current_dir%install.sh ( wsl sudo ./install.sh ) else ( - echo user_promt.sh not found + rem for some reason this else is showing even the install.sh is exist + echo install.sh.sh not found timeout 3 >nul ) -rem install appx +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 \ No newline at end of file From b55947ba31bddaf5e6bc9b4945a5badd7054d92b Mon Sep 17 00:00:00 2001 From: cupang-afk Date: Tue, 26 Oct 2021 13:45:10 +0700 Subject: [PATCH 8/8] using pwd for $Root is quite simple i guess --- VARIABLES.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/VARIABLES.sh b/VARIABLES.sh index cc32941..2ac1cb2 100644 --- a/VARIABLES.sh +++ b/VARIABLES.sh @@ -2,8 +2,7 @@ # Modify your variables here to corretly reference your directory and subdir # get current dir of this script -# the example output for this is "C:\Windows",if using pwd only "C:\Windows\" -Root="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +Root="$(pwd)" # Your Windows architecture, x64 or arm64 # get architecture based on wsl architecture