├── .version ├── README.md ├── bin ├── 32-bit │ ├── img2simg │ └── simg2img ├── 64-bit │ ├── ext2simg │ ├── img2simg │ ├── make_ext4fs │ └── simg2img ├── arm │ ├── bash │ ├── img2simg │ ├── simg2img │ ├── toybox │ └── toybox-old └── tools │ ├── bash.zip │ └── unzip-arm ├── default.conf ├── documentation.md ├── documentation.pdf ├── files └── etc │ └── init │ ├── apex-setup.rc │ ├── init.treble-environ.rc │ ├── mediaswcodec-treble.rc │ └── zygote │ ├── init.zygote32.rc │ ├── init.zygote32_64.rc │ ├── init.zygote64.rc │ └── init.zygote64_32.rc ├── install.sh └── sat.sh /.version: -------------------------------------------------------------------------------- 1 | 2.0 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # About the project 2 | 3 | SAT is a script created for unpack/repack image files (especially Generic System Images). It is available on Linux and Android devices. The main aim of SAT is to make some steps simple and automatically. It also contains some features related to GSIs: 4 | 5 | - reduce size of system image file 6 | - convert system from AB architecture to A-only 7 | 8 | **Features for unpack/repack** 9 | * automatically creating names for output files/directories 10 | * prompt warning before overwriting files 11 | * finding alternative names if file/directory exists 12 | * automatically creating and mounting mount points 13 | * option for umount and delete all mount points created by SAT 14 | * colored UI 15 | * printing information of mounted files 16 | * many options for set names of output files, mount points, etc. 17 | * resizing file to minimum size 18 | * enlarge file in order to set a free space after mounting it 19 | * and many more ... 20 | 21 | # Requirements 22 | 23 | **--- Linux ---**\ 24 | From version 2.0 all neccessery binaries are pre-builded, so you don't have to install it manually. 25 | 26 | **--- Android ---**\ 27 | In order to use SAT on Android device you must have: 28 | * rooted phone 29 | * installed busybox (if you haven't it, just download any busybox installer apk eg. from Google Playstore) 30 | * terminal emulator (recommended [Termux]) 31 | 32 | # Installation 33 | 34 | **--- Linux ---**\ 35 |
36 | **I. Download**\ 37 | In terminal: 38 | ``` 39 | $ git clone https://github.com/SoulHunter24/android-tool.git 40 | ``` 41 | **or**\ 42 |
43 | download and unpack archive from **[releases]** 44 | 45 | **II. Run installation script**\ 46 | In terminal: 47 | ``` 48 | $ cd /path/to/sat/directory 49 | $ chmod +x install.sh 50 | $ ./install.sh 51 | ``` 52 | The script will detect your system OS and architecture automatically. 53 | 54 | **Note:** If SAT can't run after installation then close and open terminal again. 55 | 56 | **--- Android ---**\ 57 |
58 | There are two options for installing SAT on Android:\ 59 | **(1)** using terminal emulator\ 60 | **(2)** using TWRP 61 | 62 | **(1) Terminal**\ 63 | I. Download and unpack archive from **[releases]**\ 64 | II. Open terminal and run: 65 | ``` 66 | $ cd /path/to/sat/directory 67 | $ su 68 | # chmod +x install.sh 69 | # sh install.sh 70 | ``` 71 | **Note:** If SAT can't run after installation then close and open terminal again or type "exit" and then "su". 72 | 73 | **(2) TWRP**\ 74 | Just download the special archive from **[releases]** and flash it in TWRP. 75 | 76 | # Usage 77 | SAT has basiclly 4 modes (auto, unpack, repack, no-mode). In each mode you can use some addiotional options (possible to use few options in one command). To use SAT you must run it in terminal with root access (needed to mount files): 78 | ``` 79 | $ su 80 | # sat 81 | ``` 82 | **See a full documentation [here]** 83 | 84 | # Update 85 | 86 | **--- Linux ---** 87 | 88 | To update SAT run below command: 89 | ``` 90 | $ sat -update 91 | ``` 92 | It will do everything automatically and keeps your settings in "default.conf" file. 93 | 94 | **--- Android ---** 95 | 96 | To update SAT on Android you can do this via Termux. Open terminal and run: 97 | ``` 98 | $ pkg install git 99 | $ /data/local/sat/sat -update 100 | ``` 101 | 102 | 103 | [releases]: 104 | [here]: 105 | [Termux]: 106 | 107 | -------------------------------------------------------------------------------- /bin/32-bit/img2simg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heliwrenaid/android-tool/96eb854050f9babe7cae1a098238b33b3c5ce5ce/bin/32-bit/img2simg -------------------------------------------------------------------------------- /bin/32-bit/simg2img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heliwrenaid/android-tool/96eb854050f9babe7cae1a098238b33b3c5ce5ce/bin/32-bit/simg2img -------------------------------------------------------------------------------- /bin/64-bit/ext2simg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heliwrenaid/android-tool/96eb854050f9babe7cae1a098238b33b3c5ce5ce/bin/64-bit/ext2simg -------------------------------------------------------------------------------- /bin/64-bit/img2simg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heliwrenaid/android-tool/96eb854050f9babe7cae1a098238b33b3c5ce5ce/bin/64-bit/img2simg -------------------------------------------------------------------------------- /bin/64-bit/make_ext4fs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heliwrenaid/android-tool/96eb854050f9babe7cae1a098238b33b3c5ce5ce/bin/64-bit/make_ext4fs -------------------------------------------------------------------------------- /bin/64-bit/simg2img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heliwrenaid/android-tool/96eb854050f9babe7cae1a098238b33b3c5ce5ce/bin/64-bit/simg2img -------------------------------------------------------------------------------- /bin/arm/bash: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heliwrenaid/android-tool/96eb854050f9babe7cae1a098238b33b3c5ce5ce/bin/arm/bash -------------------------------------------------------------------------------- /bin/arm/img2simg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heliwrenaid/android-tool/96eb854050f9babe7cae1a098238b33b3c5ce5ce/bin/arm/img2simg -------------------------------------------------------------------------------- /bin/arm/simg2img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heliwrenaid/android-tool/96eb854050f9babe7cae1a098238b33b3c5ce5ce/bin/arm/simg2img -------------------------------------------------------------------------------- /bin/arm/toybox: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heliwrenaid/android-tool/96eb854050f9babe7cae1a098238b33b3c5ce5ce/bin/arm/toybox -------------------------------------------------------------------------------- /bin/arm/toybox-old: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heliwrenaid/android-tool/96eb854050f9babe7cae1a098238b33b3c5ce5ce/bin/arm/toybox-old -------------------------------------------------------------------------------- /bin/tools/bash.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heliwrenaid/android-tool/96eb854050f9babe7cae1a098238b33b3c5ce5ce/bin/tools/bash.zip -------------------------------------------------------------------------------- /bin/tools/unzip-arm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heliwrenaid/android-tool/96eb854050f9babe7cae1a098238b33b3c5ce5ce/bin/tools/unzip-arm -------------------------------------------------------------------------------- /default.conf: -------------------------------------------------------------------------------- 1 | enable_color=true 2 | do_resize=true 3 | M_DIR=/mnt/sat/loop 4 | m_mount_dir=/mnt/sat 5 | -------------------------------------------------------------------------------- /documentation.md: -------------------------------------------------------------------------------- 1 | **Note: To use SAT you must run it with root access (needed to mount files).**\ 2 | **Note: On ANDROID you can operate on mounted image using ONLY TERMINAL !!!**\ 3 | **Note: After flashing a modified system image, it is recommended to resize /system partition** 4 | 5 | ### Naming: 6 | SPARSE_IMG - source .img file that you want to unpack\ 7 | RAW_IMG – it is a unpacked .img file, it can be mount and modify on M_DIR\ 8 | M_DIR – mount point directory, when RAW_IMG is mounted (default: /mnt/sat/loop)\ 9 | OUT_SPARSE_IMG - output image file (after repack) 10 | 11 | ### Auto mode: 12 | Unpack SPARSE_IMG, then repack (it makes sense when using some additional options)\ 13 | **Usage:** 14 | ```sh 15 | sat -a SPARSE_IMG OUT_SPARSE_IMG 16 | ``` 17 | **or:** 18 | ```sh 19 | sat -a SPARSE_IMG 20 | ``` 21 | (OUT_SPARSE_IMG name will be generated automatically) 22 | 23 | ### Unpack mode: 24 | unpack SPARSE_IMG to RAW_IMG, then mount to not busy M_DIR\ 25 | **Usage:** 26 | ```sh 27 | sat -u SPARSE_IMG RAW_IMG 28 | ``` 29 | **or:** 30 | ```sh 31 | sat -u SPARSE_IMG 32 | ``` 33 | (RAW_IMG name will be generated automatically) 34 | 35 | ### Repack mode: 36 | **Usage:** 37 | ```sh 38 | sat -r RAW_IMG OUT_SPARSE_IMG 39 | ``` 40 | Repack RAW_IMG to OUT_SPARSE_IMG\ 41 | **or:** 42 | ```sh 43 | sat -r RAW_IMG 44 | ``` 45 | Repack RAW_IMG to OUT_SPARSE_IMG (automatically generated name)\ 46 | **or:** 47 | ```sh 48 | sat -r 49 | ``` 50 | will repack **last** created RAW_IMG to OUT_SPARSE_IMG (automatically generated name) 51 | 52 | ### No-mode: 53 | This mode is trigerred: 54 | - after each unpack 55 | - before each repack 56 | - when none of -a, -u, -r mode is used\ 57 | It can be uses with some additional options. It operates on last created RAW_IMG (can be changed by -m option) 58 | 59 | 60 | ### Additional options: 61 | **-m M_DIR**\ 62 | change mountpoint directory to M_DIR\ 63 | **-o**\ 64 | overwrite all files (if you don’t want overwrite files, script will create new names/dirs)\ 65 | **-dm**\ 66 | (for unpack) disable automatic RAW_IMG mounting\ 67 | **-c**\ 68 | (for no-mode) umount and delete all M_DIR’s\ 69 | **-vndk X**\ 70 | where X is one of numbers: 26, 27, 28, 29 (you can pass how many numbers do you want). It will automatically delete corresponding vndk folders: 71 | * /lib/vndk-X, 72 | * /lib/vndk-sp-X, 73 | * /lib64/vndk-X, 74 | * /lib64/vndk-sp-X 75 | 76 | **-ab2a**\ 77 | converts system from AB architecture to A-only.\ 78 | **-debug**\ 79 | allow to display errors (by defualt some errors and messages are not displayed)\ 80 | **-ml**\ 81 | prints list of mounted M_DIR’s\ 82 | **-dc**\ 83 | disable colorful UI\ 84 | **-resizeoff**\ 85 | disable resize2fs -M RAW_IMG command before repacking\ 86 | **-free SIZE**\ 87 | (unpack option) set up free space for unpacked RAW_DIR, where SIZE is values in MB\ 88 | Note: when RAW_DIR will be mounted the available free space will be a little lower than SIZE\ 89 | **-ds**\ 90 | (unpack option) delete source SPARSE_IMG after unpack it\ 91 | **-update**\ 92 | just update the script (your changes in default.conf will be kept) 93 | 94 | ### How it works? 95 | SAT basically follows with below proccess: 96 | 97 | **Unpack mode:** 98 | 99 | ```sh 100 | simg2img SPARSE_IMG RAW_IMG 101 | mkdir -p M_DIR 102 | mount RAW_DIR M_DIR 103 | ``` 104 | **No-mode**\ 105 | Here SAT makes some changes in M_DIR (for example when -vndk, -ab2a etc. options is used). 106 | 107 | **Repack-mode** 108 | 109 | ```sh 110 | umount M_DIR 111 | e2fsck -fy RAW_IMG 112 | resize2fs -M RAW_IMG 113 | img2simg RAW_IMG OUT_SPARSE_IMG 114 | ``` 115 | **Auto-mode**\ 116 | Just perform all whole process. 117 | 118 | ### Change default settings: 119 | Some of default settings can be changed using „default.conf” text file. List of available values below:\ 120 | **enable_color=true/false**\ 121 | when set to true, the tool will turn on colorful UI\ 122 | **use_tool_binaries=true/false**\ 123 | when set to true, the tool uses tool’s binaries. Otherwise it will use system packages.\ 124 | **do_resize=true/false**\ 125 | when set to true, resize2fs -M RAW_IMG command is always called before repacking\ 126 | **M_DIR=PATH**\ 127 | change default M_DIR directory to PATH\ 128 | **m_mount_dir=PATH**\ 129 | change directory, where tool creates new M_DIR’s to PATH 130 | 131 | 132 | ### Some example uses: 133 | 134 | **I. reduce size of Generic System Image (GSI)**\ 135 | You must know, which vndk folders you can delete. It depends of your device’s vendor. If you don’t know, then check vndk version using Treble Info app (available in Google Play). To reduce size of .img file delete unnecessary vndk folders by running: 136 | 137 | ```sh 138 | sat -a SPARSE_IMG -vndk 26 27 29 139 | ``` 140 | (in that case you will remove all folders related to 26, 27, 29 vndk version) 141 | 142 | It will unpack SPARSE_IMG to RAW_DIR, then mount it in M_DIR, deleting vndk folders, resize RAW_DIR and repack to OUT_SPARSE_IMG. 143 | 144 | **II. converting system from AB architecture to A-only.** 145 | ```sh 146 | sat -a SPARSE_IMG -ab2a 147 | ``` 148 | Note : If you want you can do 1. and 2. operation by running: 149 | ```sh 150 | sat -a SPARSE_IMG -vndk 26 27 29 -ab2a 151 | ``` 152 | Tip : When you using -a option, it is good practice to use it with -o (if you are sure that tool won’t overwrite important files) 153 | 154 | **III. Unpack SPARSE_IMG and mount, do something with files, repack it** 155 | ```sh 156 | sat -u SPARSE_IMG 157 | (do something with files in M_DIR) 158 | sat -r 159 | ``` 160 | 161 | **IV. Unpack SPARSE_IMG, delete it, set up 300 MB of free space for RAW_DIR and mount it on default M_DIR** 162 | ```sh 163 | sat -u SPARSE_IMG -ds -free 300 164 | (now you can add some files in M_DIR) 165 | ``` 166 | -------------------------------------------------------------------------------- /documentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heliwrenaid/android-tool/96eb854050f9babe7cae1a098238b33b3c5ce5ce/documentation.pdf -------------------------------------------------------------------------------- /files/etc/init/apex-setup.rc: -------------------------------------------------------------------------------- 1 | import /system/etc/init/zygote/init.${ro.zygote}.rc 2 | 3 | on early-fs 4 | mkdir /mnt/runtime/full 0755 root root 5 | mkdir /mnt/runtime/full/self 0755 root root 6 | mkdir /apex 0777 root root 7 | mount tmpfs tmpfs /apex mode=0755,uid=0,gid=0 8 | restorecon /apex 9 | exec -- /system/bin/apexd --bootstrap 10 | export ANDROID_RUNTIME_ROOT /apex/com.android.runtime 11 | export ANDROID_TZDATA_ROOT /apex/com.android.tzdata 12 | symlink /system/product /product 13 | 14 | on fs 15 | exec u:r:su:s0 -- /system/bin/umount -l /product 16 | exec u:r:su:s0 -- /system/bin/rmdir /product 17 | symlink /system/product /product 18 | -------------------------------------------------------------------------------- /files/etc/init/init.treble-environ.rc: -------------------------------------------------------------------------------- 1 | # set up the global environment 2 | on init 3 | export BOOTCLASSPATH /apex/com.android.runtime/javalib/core-oj.jar:/apex/com.android.runtime/javalib/core-libart.jar:/apex/com.android.runtime/javalib/okhttp.jar:/apex/com.android.runtime/javalib/bouncycastle.jar:/apex/com.android.runtime/javalib/apache-xml.jar:/system/framework/framework.jar:/system/framework/ext.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/android.test.base.jar:/apex/com.android.conscrypt/javalib/conscrypt.jar:/apex/com.android.media/javalib/updatable-media.jar 4 | export SYSTEMSERVERCLASSPATH /system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar:/system/framework/com.android.location.provider.jar 5 | -------------------------------------------------------------------------------- /files/etc/init/mediaswcodec-treble.rc: -------------------------------------------------------------------------------- 1 | service media.swcodec /apex/com.android.media.swcodec/bin/mediaswcodec 2 | class main 3 | user mediacodec 4 | group camera drmrpc mediadrm 5 | override 6 | ioprio rt 4 7 | writepid /dev/cpuset/foreground/tasks 8 | -------------------------------------------------------------------------------- /files/etc/init/zygote/init.zygote32.rc: -------------------------------------------------------------------------------- 1 | service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server 2 | class main 3 | priority -20 4 | user root 5 | group root readproc 6 | socket zygote stream 660 root system 7 | socket usap_pool_primary stream 660 root system 8 | onrestart write /sys/android_power/request_state wake 9 | onrestart write /sys/power/state on 10 | onrestart restart audioserver 11 | onrestart restart cameraserver 12 | onrestart restart media 13 | onrestart restart netd 14 | onrestart restart wificond 15 | writepid /dev/cpuset/foreground/tasks 16 | -------------------------------------------------------------------------------- /files/etc/init/zygote/init.zygote32_64.rc: -------------------------------------------------------------------------------- 1 | service zygote /system/bin/app_process32 -Xzygote /system/bin --zygote --start-system-server --socket-name=zygote 2 | class main 3 | priority -20 4 | user root 5 | group root readproc 6 | socket zygote stream 660 root system 7 | socket usap_pool_primary stream 660 root system 8 | onrestart write /sys/android_power/request_state wake 9 | onrestart write /sys/power/state on 10 | onrestart restart audioserver 11 | onrestart restart cameraserver 12 | onrestart restart media 13 | onrestart restart netd 14 | onrestart restart wificond 15 | writepid /dev/cpuset/foreground/tasks 16 | 17 | service zygote_secondary /system/bin/app_process64 -Xzygote /system/bin --zygote --socket-name=zygote_secondary 18 | class main 19 | priority -20 20 | user root 21 | group root readproc 22 | socket zygote_secondary stream 660 root system 23 | socket usap_pool_secondary stream 660 root system 24 | onrestart restart zygote 25 | writepid /dev/cpuset/foreground/tasks 26 | -------------------------------------------------------------------------------- /files/etc/init/zygote/init.zygote64.rc: -------------------------------------------------------------------------------- 1 | service zygote /system/bin/app_process64 -Xzygote /system/bin --zygote --start-system-server 2 | class main 3 | priority -20 4 | user root 5 | group root readproc 6 | socket zygote stream 660 root system 7 | socket usap_pool_primary stream 660 root system 8 | onrestart write /sys/android_power/request_state wake 9 | onrestart write /sys/power/state on 10 | onrestart restart audioserver 11 | onrestart restart cameraserver 12 | onrestart restart media 13 | onrestart restart netd 14 | onrestart restart wificond 15 | writepid /dev/cpuset/foreground/tasks 16 | -------------------------------------------------------------------------------- /files/etc/init/zygote/init.zygote64_32.rc: -------------------------------------------------------------------------------- 1 | service zygote /system/bin/app_process64 -Xzygote /system/bin --zygote --start-system-server --socket-name=zygote 2 | class main 3 | priority -20 4 | user root 5 | group root readproc 6 | socket zygote stream 660 root system 7 | socket usap_pool_primary stream 660 root system 8 | onrestart write /sys/android_power/request_state wake 9 | onrestart write /sys/power/state on 10 | onrestart restart audioserver 11 | onrestart restart cameraserver 12 | onrestart restart media 13 | onrestart restart netd 14 | onrestart restart wificond 15 | writepid /dev/cpuset/foreground/tasks 16 | 17 | service zygote_secondary /system/bin/app_process32 -Xzygote /system/bin --zygote --socket-name=zygote_secondary --enable-lazy-preload 18 | class main 19 | priority -20 20 | user root 21 | group root readproc 22 | socket zygote_secondary stream 660 root system 23 | socket usap_pool_secondary stream 660 root system 24 | onrestart restart zygote 25 | writepid /dev/cpuset/foreground/tasks 26 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #created by: Soul_Hunter24 4 | 5 | BIN_DIR="/data/local/sat" 6 | SAT_DIR=`dirname "$(readlink -f "$0")"` 7 | OS_TYPE=`uname -o` 8 | CONFIG_FILE="$SAT_DIR/default.conf" 9 | TB="unknown" 10 | UPDATE="false" #for Android 11 | BASH_DIR="/system/bin" 12 | 13 | #set environment 14 | set_env () { 15 | FILE="$1" 16 | OS_TYPE="$2" 17 | FIRST_LINE=`head -1 "$FILE"` 18 | if [[ "$FIRST_LINE" != "#!/bin/bash" && "$OS_TYPE" == "Linux" ]] 19 | then 20 | awk -v awkvar="$FIRST_LINE" '{sub(awkvar,"#!/bin/bash")}1' "$FILE" > temp.txt && mv temp.txt "$FILE" 21 | fi 22 | 23 | if [[ "$FIRST_LINE" != "#!/system/bin/bash" && "$OS_TYPE" == "Android" ]] 24 | then 25 | awk -v awkvar="$FIRST_LINE" '{sub(awkvar,"#!/system/bin/bash")}1' "$FILE" > temp.txt && mv temp.txt "$FILE" 26 | fi 27 | } 28 | 29 | add_to_path () { 30 | PATH_TO_SAT='export PATH="'"$1"':$PATH"' 31 | if [ -z "$(cat "$2" | grep "$PATH_TO_SAT")" ] 32 | then 33 | echo " " >> "$2" 34 | echo "$PATH_TO_SAT" >> "$2" 35 | source "$2" 36 | fi 37 | } 38 | 39 | install_on_android () { 40 | cp -f $SAT_DIR/sat $BIN_DIR/sat 41 | chmod 755 $BIN_DIR/sat 42 | 43 | cp -f $SAT_DIR/bin/$ARCH/simg2img $BIN_DIR/simg2img 44 | chmod +x $BIN_DIR/simg2img 45 | 46 | cp -f $SAT_DIR/bin/$ARCH/img2simg $BIN_DIR/img2simg 47 | chmod +x $BIN_DIR/img2simg 48 | 49 | cp -f $SAT_DIR/bin/$ARCH/$TB $BIN_DIR/$TB 50 | chmod 755 $BIN_DIR/$TB 51 | 52 | cp -f $SAT_DIR/bin/tools/unzip-arm $BIN_DIR/unzip-arm 53 | chmod 755 $BIN_DIR/unzip-arm 54 | 55 | mkdir -p "$SAT_DIR/tmpsat" 56 | $BIN_DIR/unzip-arm -o "$SAT_DIR/bin/tools/bash.zip" -d "$SAT_DIR/tmpsat" &> /dev/null 57 | cp -f "$SAT_DIR/tmpsat/system/bin/bash" "$BASH_DIR/bash" 58 | cp -f "$SAT_DIR/tmpsat/system/bin/bashbug" "$BASH_DIR/bashbug" 59 | cp -f "$SAT_DIR/tmpsat/system/etc/bashrc" "/system/etc/bashrc" 60 | cp -f "$SAT_DIR/tmpsat/system/etc/bash_logout" "/system/etc/bash_logout" 61 | chmod 755 $BASH_DIR/bash 62 | chmod 755 $BASH_DIR/bashbug 63 | chmod 755 /system/etc/bashrc 64 | chmod 755 /system/etc/bash_logout 65 | rm -rf "$SAT_DIR/tmpsat" 66 | } 67 | 68 | mod_sat () { 69 | FILE="$SAT_DIR/sat" 70 | 71 | CONTENT="SAT_DIR=$SAT_DIR" 72 | awk -v awkvar="$CONTENT" '{sub("SAT_DIR=unknown",awkvar)}1' $FILE > temp.txt && mv temp.txt $FILE 73 | 74 | CONTENT="OS_TYPE=$OS_TYPE" 75 | awk -v awkvar="$CONTENT" '{sub("OS_TYPE=unknown",awkvar)}1' $FILE > temp.txt && mv temp.txt $FILE 76 | 77 | CONTENT="ARCH=$ARCH" 78 | awk -v awkvar="$CONTENT" '{sub("ARCH=unknown",awkvar)}1' $FILE > temp.txt && mv temp.txt $FILE 79 | 80 | CONTENT="TB=$BIN_DIR/$TB" 81 | awk -v awkvar="$CONTENT" '{sub("TB=unknown",awkvar)}1' $FILE > temp.txt && mv temp.txt $FILE 82 | 83 | CONTENT="ANDROID_BIN=$BIN_DIR" 84 | awk -v awkvar="$CONTENT" '{sub("ANDROID_BIN=unknown",awkvar)}1' $FILE > temp.txt && mv temp.txt $FILE 85 | 86 | } 87 | 88 | #parse options ---------------------------------------------------- 89 | while [ "$#" -gt 0 ]; do 90 | case "$1" in 91 | -u|--update) UPDATE="true" ;; 92 | *) echo "unknown option passed"; exit 1 ;; 93 | esac 94 | shift 95 | done 96 | 97 | #detect OS_TYPE --------------------------------------------------- 98 | case $OS_TYPE in 99 | *Android*|*android*|*ANDROID*) OS_TYPE="Android" ;; 100 | *Linux*|*linux*|*LINUX*|*nix*|*NIX*) 101 | check=`uname -m` 102 | case $check in 103 | *ar*) OS_TYPE="Android" ;; 104 | *) OS_TYPE="Linux" ;; 105 | esac 106 | ;; 107 | *) echo "unkown OS type"; echo " "; exit 1 ;; 108 | esac 109 | 110 | #detect architecture + choose TB---------------------------------------------- 111 | if [ "$OS_TYPE" = "Android" ] 112 | then 113 | ARCH=`getprop "ro.product.cpu.abilist"` 114 | if [ -z "$ARCH" ] 115 | then 116 | ARCH=`getprop "ro.product.cpu.abi"` 117 | fi 118 | 119 | case $ARCH in 120 | *arm64*) ARCH="arm64" ;; #arm64 will use arm bins (changed before install section) 121 | *armeabi*) ARCH="arm" ;; 122 | *) ARCH="arm" ;; 123 | esac 124 | 125 | if [ -e "/dev/loop0" ] 126 | then 127 | TB="toybox" 128 | else 129 | TB="toybox-old" 130 | fi 131 | 132 | else 133 | case "$(uname -m)" in 134 | *x86_64*) ARCH="64-bit" ;; 135 | *) ARCH="32-bit" ;; 136 | esac 137 | fi 138 | 139 | #print config ----------------------------------------------------- 140 | echo " " 141 | echo "OS: $OS_TYPE" 142 | echo "Architecture: $ARCH" 143 | echo " " 144 | 145 | if [ "$ARCH" = "arm64" ] 146 | then 147 | ARCH="arm" 148 | fi 149 | 150 | #install ---------------------------------------------------------- 151 | if [ -f "$SAT_DIR/sat.sh" ] 152 | then 153 | cp -f $SAT_DIR/sat.sh $SAT_DIR/sat 154 | 155 | #setup shell directory 156 | set_env "$SAT_DIR/sat" "$OS_TYPE" 157 | 158 | #setup variables for sat 159 | mod_sat 160 | else 161 | echo "Installation: failed (sat.sh was not found)" 162 | exit 1 163 | fi 164 | 165 | if [ $OS_TYPE = "Linux" ] 166 | then 167 | chmod +x $SAT_DIR/sat 168 | chmod +x $SAT_DIR/bin/$ARCH/simg2img $SAT_DIR/bin/$ARCH/img2simg 169 | 170 | if [ -f ~/.bashrc ] 171 | then 172 | add_to_path "$SAT_DIR" ~/.bashrc 173 | elif [ -f ~/.bash_profile ] 174 | then 175 | add_to_path "$SAT_DIR" ~/.bash_profile 176 | elif [ -f ~/.zshrc ] 177 | then 178 | add_to_path "$SAT_DIR" ~/.zshrc 179 | elif [ -f ~/.zprofile ] 180 | then 181 | add_to_path "$SAT_DIR" ~/.zprofile 182 | elif [ -f ~/.cshrc ] 183 | then 184 | add_to_path "$SAT_DIR" ~/.cshrc 185 | elif [ -f ~/.tcshrc ] 186 | then 187 | add_to_path "$SAT_DIR" ~/.tcshrc 188 | elif [ -f ~/.login ] 189 | then 190 | add_to_path "$SAT_DIR" ~/.login 191 | elif [ -f ~/.kshrc ] 192 | then 193 | add_to_path "$SAT_DIR" ~/.kshrc 194 | elif [ -f ~/.profile ] 195 | then 196 | add_to_path "$SAT_DIR" ~/.profile 197 | else 198 | echo '#path to SAT' > ~/.profile 199 | add_to_path "$SAT_DIR" ~/.profile 200 | fi 201 | 202 | if [ -x "$SAT_DIR/sat" ] && [ -x "$SAT_DIR/bin/$ARCH/simg2img" ] && [ -x "$SAT_DIR/bin/$ARCH/img2simg" ] 203 | then 204 | echo "Installation: success" 205 | echo " " 206 | fi 207 | else 208 | mount -o rw,remount /system 209 | mkdir -p $BIN_DIR 210 | if [ -x "$BASH_DIR/bash" ] && [ -x "$BIN_DIR/sat" ] && [ -x "$BIN_DIR/simg2img" ] && [ -x "$BIN_DIR/img2simg" ] && [ -x "$BIN_DIR/$TB" ] 211 | then 212 | if [[ "$UPDATE" == "false" ]] 213 | then 214 | echo "No need to install" 215 | exit 1 216 | else 217 | install_on_android 218 | fi 219 | else 220 | install_on_android 221 | fi 222 | 223 | if [ -x "$BASH_DIR/bash" ] && [ -x "$BIN_DIR/sat" ] && [ -x "$BIN_DIR/simg2img" ] && [ -x "$BIN_DIR/img2simg" ] && [ -x "$BIN_DIR/$TB" ] 224 | then 225 | add_to_path "$BIN_DIR" /system/etc/mkshrc 226 | add_to_path "$BIN_DIR" /system/etc/bashrc 227 | echo "Installation: success" 228 | else 229 | echo "Installation: failed" 230 | fi 231 | echo " " 232 | mount -o ro,remount /system 233 | fi 234 | 235 | -------------------------------------------------------------------------------- /sat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #created by: Soul_Hunter24 4 | 5 | #SETTINGS 6 | unpack=0 7 | repack=0 8 | dest_opt=0 9 | debug=0 10 | rl=0 11 | ow=0 #overwriting 12 | dm=0 #disable mounting 13 | error_a=0 #-a and -u 14 | error_u=0 #-u and -r in command 15 | error_r=0 #-a and -r in command 16 | mp=0 #change mount point dir 17 | dis_um=0 #disable umounting for repack 18 | print_conf_passed=0 19 | use_tool_binaries="true" 20 | enable_color="true" 21 | do_resize="true" 22 | update="false" 23 | resize_plus="false" 24 | resize_raw="false" 25 | del_source="false" 26 | no_mode=0 27 | aonly=0 28 | ab=0 29 | clean=0 30 | ml=0 31 | 32 | #variables from installer.sh 33 | SAT_DIR=unknown 34 | OS_TYPE=unknown 35 | ARCH=unknown 36 | ANDROID_BIN=unknown 37 | TB=unknown 38 | 39 | start=`pwd` 40 | 41 | config_file="$SAT_DIR/default.conf" 42 | 43 | mount_dir="/mnt/sat/loop" 44 | default_m_dir="/mnt/sat" 45 | raw_dir="$start/system.raw_img" 46 | sparse_dir="NOT_SPECIFIED" 47 | 48 | #---FUNCTIONS--- 49 | my_print () { 50 | txt="$1" 51 | if [[ $enable_color == "true" ]] 52 | then 53 | while [[ "$#" -gt 0 ]]; do 54 | case "$1" in 55 | black) printf "\e[30m";; 56 | red) printf "\e[31m";; 57 | green) printf "\e[32m";; 58 | yellow) printf "\e[33m";; 59 | blue) printf "\e[34m";; 60 | magenta) printf "\e[35m";; 61 | cyan) printf "\e[36m";; 62 | white) printf "\e[37m";; 63 | bold) printf "\e[1m";; 64 | faint) printf "\e[2m";; 65 | italic) printf "\e[3m";; 66 | underlined) printf "\e[4m";; 67 | -source) printf "\e[33;1m";; 68 | -raw) printf "\e[35;1m";; 69 | -mount) printf "\e[36;1m";; 70 | -sparse) printf "\e[34;1m";; 71 | esac 72 | shift 73 | done 74 | printf "$txt" 75 | printf "\e[0m" 76 | else 77 | printf "$txt" 78 | fi 79 | } 80 | 81 | #finding alternative name/dir 82 | free_name () { 83 | tmp="$1" 84 | if [[ $tmp == /* ]] 85 | then 86 | dir=${tmp%/*} 87 | tmp1=${tmp##*/} 88 | name=${tmp1%.*} 89 | ext=${tmp1##*.} 90 | else 91 | dir="$start" 92 | name=${tmp%.*} 93 | ext=${tmp##*.} 94 | fi 95 | iter=1 96 | new_x="$dir/$name-$iter.$ext" 97 | while [[ -f "$new_x" ]] 98 | do 99 | iter=$(( $iter + 1 )) 100 | new_x="$dir/$name-$iter.$ext" 101 | done 102 | echo "$new_x" 103 | } 104 | 105 | print_config () { 106 | if [[ $print_conf_passed == 0 ]] 107 | then 108 | if [[ $1 == "unpack" ]] 109 | then 110 | my_print "\n*** UNPACK SETTINGS ***\n" green bold underlined 111 | my_print "SPARSE_IMG = $source_dir\n" yellow bold 112 | my_print "RAW_IMG = $raw_dir\n" magenta bold 113 | my_print "M_DIR = $mount_dir\n\n" cyan bold 114 | fi 115 | 116 | if [[ $1 == "repack" ]] 117 | then 118 | my_print "\n*** REPACK && NO-MODE SETTINGS ***\n" green bold underlined 119 | my_print "RAW_IMG = $raw_dir\n" magenta bold 120 | my_print "M_DIR = $mount_dir\n" cyan bold 121 | my_print "F_SPARSE_IMG = $sparse_dir\n\n" blue bold 122 | print_conf_passed=1 123 | fi 124 | fi 125 | 126 | source_dir_cp="${source_dir##*/}" 127 | raw_dir_cp="${raw_dir##*/}" 128 | sparse_dir_cp="${sparse_dir##*/}" 129 | } 130 | 131 | raw_to_loop () { 132 | RAW="$1" 133 | if [[ -f "$SAT_DIR/.loop.info" ]] 134 | then 135 | tmp=`cat $SAT_DIR/.loop.info | grep ";$RAW!"` 136 | if [[ -n "$tmp" ]] 137 | then 138 | LOOP="${tmp%%:*}" 139 | else 140 | LOOP="unknown" 141 | fi 142 | else 143 | LOOP="unknown" 144 | fi 145 | echo "$LOOP" 146 | } 147 | 148 | resize_p () { 149 | RAW="$1" 150 | SIZE="$2" 151 | 152 | e2fsck -fy $RAW &> /dev/null 153 | resize2fs -M $RAW &> /dev/null 154 | 155 | RAW_SIZE=`du -m $RAW | awk '{ print $1 }'` 156 | RAW_SIZE=$(( $RAW_SIZE + $SIZE )) 157 | e2fsck -fy $RAW &> /dev/null 158 | my_print "\nResizing "; my_print "${RAW##*/}" -raw; my_print " to "; my_print "$RAW_SIZE MB\n" green bold; my_print "..." 159 | resize2fs -f $RAW $RAW_SIZE'M' &> /dev/null 160 | my_print " Done\n\n" 161 | } 162 | 163 | #load config 164 | if [[ -f $config_file ]] 165 | then 166 | color=`cat $config_file | grep "enable_color="` 167 | binaries=`cat $config_file | grep "use_tool_binaries="` 168 | resize=`cat $config_file | grep "do_resize="` 169 | m_dir=`cat $config_file | grep "M_DIR="` 170 | def_m_dir=`cat $config_file | grep "m_mount_dir="` 171 | os_type=`cat $config_file | grep "OS_TYPE="` 172 | arch=`cat $config_file | grep "ARCH="` 173 | sat_dir=`cat $config_file | grep "SAT_DIR="` 174 | toy=`cat $config_file | grep "TB="` 175 | andr_bin=`cat $config_file | grep "ANDROID_BIN="` 176 | 177 | 178 | if [[ "$color" != "" ]] 179 | then 180 | enable_color="${color##*=}" 181 | fi 182 | if [[ "$binaries" != "" && "$OS_TYPE" == "Linux" ]] 183 | then 184 | use_tool_binaries="${binaries##*=}" 185 | fi 186 | if [[ "$resize" != "" ]] 187 | then 188 | do_resize="${resize##*=}" 189 | fi 190 | if [[ "$m_dir" != "" ]] 191 | then 192 | mount_dir="${m_dir##*=}" 193 | fi 194 | if [[ "$def_m_dir" != "" ]] 195 | then 196 | default_m_dir="${def_m_dir##*=}" 197 | fi 198 | if [[ "$os_type" != "" ]] 199 | then 200 | OS_TYPE="${os_type##*=}" 201 | fi 202 | if [[ "$arch" != "" ]] 203 | then 204 | ARCH="${arch##*=}" 205 | fi 206 | if [[ "$sat_dir" != "" ]] 207 | then 208 | SAT_DIR="${sat_dir##*=}" 209 | fi 210 | if [[ "$toy" != "" ]] 211 | then 212 | TB="${toy##*=}" 213 | fi 214 | if [[ "$andr_bin" != "" ]] 215 | then 216 | ANDROID_BIN="${andr_bin##*=}" 217 | fi 218 | else 219 | my_print "!!! Configuration file ($config_file) was not found ..." yellow bold 220 | fi 221 | 222 | #actions if neccesery values is unknown 223 | if [[ "$SAT_DIR" == "unknown" ]] 224 | then 225 | my_print "\n\nUnable to find SAT main directory\n" red bold 226 | my_print "Please run install.sh again ...\n" red bold 227 | my_print "or\n" red bold 228 | my_print "add SAT_DIR=/path/to/sat to ${config_file##*/}\n\n" red bold 229 | exit 1 230 | fi 231 | 232 | if [[ "$OS_TYPE" == "unknown" ]] 233 | then 234 | my_print "\n\nOS type is not specifed\n" red bold 235 | my_print "Please run install.sh again ...\n" red bold 236 | my_print "or\n" red bold 237 | my_print "add OS_TYPE=Linux (or Android) to $config_file\n\n" red bold 238 | exit 1 239 | fi 240 | 241 | if [[ "$ARCH" == "unknown" ]] 242 | then 243 | my_print "\n\nDevice architecture is not detected\n" red bold 244 | my_print "Please run install.sh again ...\n" red bold 245 | my_print "or\n" red bold 246 | my_print "add ARCH=VAL to $config_file ... \n" red bold 247 | my_print "...where VAL can be one of values: 32-bit,64-bit (for Linux) and arm,arm64 (for Android) \n\n" red bold 248 | exit 1 249 | fi 250 | 251 | if [[ "$TB" == "unknown" ]] 252 | then 253 | use_tool_binaries="false" 254 | my_print "\n\n!!! Can't detect toybox ... Mounting files can not work\n\n" red bold 255 | fi 256 | 257 | if [[ "$ANDROID_BIN" == "unknown" ]] 258 | then 259 | use_tool_binaries="false" 260 | my_print "\n\n!!! Can't detect binaries ... trying some workarounds\n" red bold 261 | my_print "Also try to run install.sh again ...\n\n" red bold 262 | fi 263 | 264 | 265 | #choose options according to OS 266 | if [[ "$OS_TYPE" == "Linux" ]] 267 | then 268 | BIN_DIR="$SAT_DIR/bin/$ARCH" 269 | else 270 | BIN_DIR="$ANDROID_BIN" 271 | fi 272 | 273 | #parse options 274 | declare -a dargs=() 275 | read_d_args() 276 | { 277 | while (($#)) && [[ $1 != -* ]]; do dargs+=("$1"); shift; done 278 | } 279 | declare -a vndks=() 280 | read_vndks() 281 | { 282 | while (($#)) && [[ $1 != -* ]]; do vndks+=("$1"); shift; done 283 | } 284 | while [[ "$#" -gt 0 ]]; do 285 | case "$1" in 286 | -vndk) read_vndks "${@:2}" ; vndks_len=${#vndks[@]} ;; 287 | -a|--auto) read_d_args "${@:2}" ; error_a=1 ; unpack=1; repack=1 ; rl=1 ;; 288 | -u|--unpack) read_d_args "${@:2}" ; error_u=1 ; unpack=1 ;; 289 | -r|--repack) read_d_args "${@:2}" ; error_r=1 ; repack=1 ;; 290 | -o|--overwrite) ow=1 ;; 291 | -ab2a) aonly=1 ;; 292 | -debug) debug=1 ;; 293 | -dm) dm=1 ;; 294 | -m|--mount) m="$2"; shift ; mp=1 ;; 295 | -ml) ml=1 ; no_mode=1 ;; 296 | -c|--clean) clean=1 ; no_mode=1 ;; 297 | -dc) enable_color="false" ;; 298 | -resizeoff) do_resize="false" ;; 299 | -update) update="true" ;; 300 | -free) size="$2"; shift; resize_plus="true" ;; 301 | -ds) del_source="true" ;; 302 | #-freeraw) size="$3"; dest_raw="$2"; shift ; resize_raw="true" ;; 303 | #-h) printf "-h\n" ;; 304 | esac 305 | shift 306 | done 307 | 308 | if [[ $repack == 1 ]] 309 | then 310 | if [[ "${dargs[0]}" == '' ]] 311 | then 312 | rl=1 ; repack=1 ; #repack last unpacked raw image 313 | fi 314 | fi 315 | 316 | if [[ "${dargs[0]}" != '' ]] 317 | then 318 | if [[ $repack == 1 ]] 319 | then 320 | if [[ $unpack == 1 ]] 321 | then 322 | source_dir="${dargs[0]}" 323 | else 324 | raw_dir="${dargs[0]}" 325 | fi 326 | fi 327 | 328 | if [[ $unpack == 1 ]] 329 | then 330 | source_dir="${dargs[0]}" 331 | fi 332 | fi 333 | 334 | if [[ "${dargs[1]}" != '' ]] 335 | then 336 | #change destination for unpack/repack/auto 337 | dest="${dargs[1]}" 338 | dest_opt=1 339 | fi 340 | 341 | #check sense of flags 342 | if [[ $error_u == 1 && $repack == 1 ]] 343 | then 344 | my_print "If u want to unpack and repack use -a option\n" 345 | exit 1; 346 | fi 347 | if [[ $error_u == 1 && $error_a == 1 ]] 348 | then 349 | my_print "Choosed options have no sense (-a with -u)\n" 350 | exit 1; 351 | fi 352 | if [[ $error_u == 1 && $error_r == 1 ]] 353 | then 354 | my_print "Choosed options have no sense (-a with -r)\n" 355 | exit 1; 356 | fi 357 | if [[ $error_u == 1 && $clean == 1 ]] || [[ $error_r == 1 && $clean == 1 ]] || [[ $error_a == 1 && $clean == 1 ]] 358 | then 359 | my_print "You can't use -c with -a, -u, -r\n" 360 | exit 1; 361 | fi 362 | if [[ $error_u == 1 && $ml == 1 ]] || [[ $error_r == 1 && $ml == 1 ]] || [[ $error_a == 1 && $ml == 1 ]] 363 | then 364 | my_print "You can't use -ml with -a, -u, -r\n" 365 | exit 1; 366 | fi 367 | if [[ $error_u == 1 && $update == "true" ]] || [[ $error_r == 1 && $update == "true" ]] || [[ $error_a == 1 && $update == "true" ]] 368 | then 369 | my_print "You can't use --update with -a, -u, -r\n" 370 | exit 1; 371 | fi 372 | if [[ $resize_plus == "true" ]] && [[ -z $size ]] 373 | then 374 | my_print "No size was specified\n" red bold 375 | exit 1 376 | fi 377 | 378 | #update section 379 | if [[ $update == "true" ]] 380 | then 381 | update_dir="$SAT_DIR/sat-update" 382 | mkdir -p "$update_dir" 383 | cd "$update_dir" 384 | 385 | version_now=`cat "$SAT_DIR/.version"` 386 | version_up=`curl https://raw.githubusercontent.com/SoulHunter24/android-tool/master/.version` 387 | 388 | if [[ "$version_up" > "$version_now" ]] 389 | then 390 | my_print "Newer version available\n" green bold 391 | my_print "Downloading resources\n ..." green bold 392 | git clone -b master https://github.com/SoulHunter24/android-tool.git &> /dev/null 393 | my_print "Done\n" green bold 394 | rm -rf android-tool/.git 395 | if [[ -f "$config_file" ]] 396 | then 397 | rm -f "android-tool/default.conf" 398 | mv -f "$config_file" "android-tool/default.conf" 399 | fi 400 | cp -r android-tool/* "$SAT_DIR/" 401 | cp -r android-tool/.version "$SAT_DIR/" 402 | else 403 | my_print "Nothing to upgrade. It's the newest version [v$version_now]\n" yellow bold 404 | exit 1 405 | fi 406 | cd "$SAT_DIR" 407 | rm -rf "$update_dir" 408 | 409 | #write configs to file 410 | echo "SAT_DIR=$SAT_DIR" > update_conf 411 | echo "ARCH=$ARCH" >> update_conf 412 | echo "ANDROID_BIN=$ANDROID_BIN" >> update_conf 413 | echo "TB=$TB" >> update_conf 414 | 415 | chmod +x install.sh 416 | if [[ "$OS_TYPE" == "Linux" ]] 417 | then 418 | ./install.sh -rev1 -linux &> /dev/null 419 | else 420 | su -c sh install.sh -rev1 -android &> /dev/null 421 | fi 422 | 423 | my_print "Tool was upgraded to v$version_up\n" bold green 424 | exit 1 425 | fi 426 | 427 | #check root access 428 | root=`id -u` 429 | if [[ $root -ne 0 ]] 430 | then 431 | my_print "*** Some functionality will not work without root access\n" red bold 432 | fi 433 | 434 | #--- UNPACK CONFIG --- 435 | 436 | if [[ $unpack == 1 ]] 437 | then 438 | 439 | #source_dir exists? + default raw_dir, sparse_dir 440 | if [[ -f "$source_dir" ]] 441 | then 442 | raw_dir="${source_dir%.img}.raw_img" 443 | tmp="${source_dir##*/}" 444 | sparse_dir="${tmp%.img}-modSH24.img" 445 | my_print "\n$source_dir was found ... \n" 446 | else 447 | my_print "\n*** ERROR 404: $source_dir was not found !!!\n" red 448 | exit 1 449 | fi 450 | 451 | # -d : configure 452 | if [[ $dest_opt == 1 ]] 453 | then 454 | if [[ $repack == 1 ]] #for auto 455 | then 456 | sparse_dir="$dest" 457 | else 458 | raw_dir="$dest" 459 | fi 460 | fi 461 | 462 | #raw_dir and source_dir full path 463 | if [[ $raw_dir != /* ]] 464 | then 465 | raw_dir="$start/$raw_dir" 466 | fi 467 | if [[ $source_dir != /* ]] 468 | then 469 | source_dir="$start/$source_dir" 470 | fi 471 | 472 | #change raw_dir because too long name for losetup 473 | if [[ "$OS_TYPE" == "Android" ]] 474 | then 475 | if [[ `echo "$raw_dir" | wc -c` -gt 45 ]] 476 | then 477 | my_print "*** Absolute path of file is too long for mounting...\n" yellow bold 478 | my_print "*** RAW_IMG name will be changed\n" yellow bold 479 | raw_dir="$start/s.raw_img" 480 | fi 481 | fi 482 | 483 | #raw_dir : overwriting 484 | if [[ -f "$raw_dir" ]] 485 | then 486 | if [[ $ow == 1 ]] 487 | then 488 | my_print "*** $raw_dir will be overwrited\n" 489 | else 490 | my_print "\n*** WARNING : $raw_dir exists ... \n" red bold 491 | my_print "Do you want to overwrite this file ? (y/n) : " red bold 492 | read opt 493 | if [[ "$opt" != "y" ]] 494 | then 495 | raw_dir="$(free_name $raw_dir)" 496 | fi 497 | printf "\n" 498 | fi 499 | fi 500 | 501 | # -m : configure 502 | if [[ $mp == 1 ]] 503 | then 504 | if [[ $m == /* ]] 505 | then 506 | mount_dir="$m" 507 | else 508 | mount_dir="$default_m_dir/$m" 509 | fi 510 | fi 511 | 512 | #mount_dir : configure 513 | raw_dir_copy="$raw_dir" 514 | if [[ "$OS_TYPE" == "Android" ]] 515 | then 516 | raw_dir="$(raw_to_loop $raw_dir)" 517 | fi 518 | 519 | tmp1=`mount | grep -F "$raw_dir on" | wc -l` 520 | if [[ $tmp1 != 0 ]] 521 | then 522 | tmp1=`mount | grep -F "$raw_dir on"` 523 | temp=${tmp1##*on } 524 | temp2=${temp% type*} 525 | umount "$temp2" 526 | fi 527 | 528 | tmp=`mount | grep -F " $mount_dir " | wc -l` 529 | if [[ $tmp != 0 ]] 530 | then 531 | my_print "*** $mount_dir is busy\n" 532 | j=0 533 | while [[ $tmp != 0 ]] 534 | do 535 | j=$(( $j + 1 )) 536 | new_mount_dir="$mount_dir-$j" 537 | tmp=`mount | grep -F " $new_mount_dir " | wc -l` 538 | done 539 | mount_dir="$new_mount_dir" 540 | fi 541 | raw_dir="$raw_dir_copy" 542 | 543 | #print unpack config 544 | print_config "unpack" 545 | 546 | #unpacking & mounting 547 | my_print "unpacking "; my_print "$source_dir_cp" -source; printf " to "; my_print "$raw_dir_cp \n" -raw; my_print "..." 548 | if [[ $use_tool_binaries == "true" ]] 549 | then 550 | $BIN_DIR/simg2img $source_dir $raw_dir 551 | else 552 | simg2img $source_dir $raw_dir 553 | fi 554 | my_print " Done\n" 555 | 556 | #increase raw_dir 557 | if [[ "$resize_plus" == "true" ]] 558 | then 559 | resize_p $raw_dir $size 560 | resize_plus="false" 561 | fi 562 | 563 | if [[ $dm == 0 ]] 564 | then 565 | my_print "mounting "; my_print "$raw_dir_cp" -raw; printf " to "; my_print "$mount_dir \n" -mount; my_print "..." 566 | mkdir -p $mount_dir 567 | if [[ "$OS_TYPE" == "Android" ]] 568 | then 569 | LOOP=`"$TB" losetup -sf $raw_dir` 570 | mount -t ext4 "$LOOP" $mount_dir 571 | else 572 | mount $raw_dir $mount_dir 573 | fi 574 | my_print " Done\n" 575 | fi 576 | 577 | #save info 578 | echo "$raw_dir" > "$SAT_DIR/.last.info" 579 | if [[ ! -f "$SAT_DIR/.mount.info" ]] 580 | then 581 | touch "$SAT_DIR/.mount.info" 582 | fi 583 | mou_inf=`cat $SAT_DIR/.mount.info | grep ":$mount_dir;" | wc -l` 584 | if [[ $mou_inf == 0 ]] 585 | then 586 | echo "$raw_dir:$mount_dir;" >> "$SAT_DIR/.mount.info" 587 | fi 588 | 589 | #save info for Android 590 | if [[ ! -f "$SAT_DIR/.loop.info" ]] 591 | then 592 | touch "$SAT_DIR/.loop.info" 593 | fi 594 | loop_inf=`cat $SAT_DIR/.loop.info | grep ":$mount_dir;$raw_dir!" | wc -l` 595 | if [[ $loop_inf == 0 ]] 596 | then 597 | echo "$LOOP:$mount_dir;$raw_dir!" >> "$SAT_DIR/.loop.info" 598 | fi 599 | 600 | #delete source_dir 601 | if [[ "$del_source" == "true" ]] && [[ -e $raw_dir ]] && [[ -s $raw_dir ]] 602 | then 603 | my_print "\nDeleting "; my_print "$source_dir_cp" -source 604 | rm -f $source_dir 605 | my_print "\n...Done\n" 606 | fi 607 | fi 608 | 609 | 610 | #---------NO MODE AND REPACK------ 611 | 612 | # some repack and no-mode config 613 | 614 | #raw_dir : full path 615 | if [[ $raw_dir != /* ]] 616 | then 617 | raw_dir="$start/$raw_dir" 618 | fi 619 | 620 | if [[ $repack == 1 ]] 621 | then 622 | 623 | #-rl : configure 624 | if [[ $rl == 1 ]] 625 | then 626 | last=`cat $SAT_DIR/.last.info` 627 | raw_dir="$last" 628 | fi 629 | 630 | #raw_dir : check 631 | if ! [[ -s "$raw_dir" ]] 632 | then 633 | my_print "*** File is empty\n" red bold 634 | exit 1 635 | fi 636 | 637 | if [[ -f "$raw_dir" ]] 638 | then 639 | my_print "\n$raw_dir was found ... \n" 640 | else 641 | my_print "\n*** ERROR 404: $raw_dir was not found !!!\n" red bold 642 | exit 1 643 | fi 644 | 645 | #detecting mounpoint 646 | raw_dir_copy="$raw_dir" 647 | if [[ "$OS_TYPE" == "Android" ]] 648 | then 649 | raw_dir="$(raw_to_loop $raw_dir)" 650 | fi 651 | tmp=`mount | grep "$raw_dir " | wc -l` 652 | if [[ $tmp != 0 ]] 653 | then 654 | tmp1=`mount | grep "$raw_dir "` 655 | temp=${tmp1##*on } 656 | temp2=${temp% type*} 657 | mount_dir="$temp2" 658 | else 659 | my_print "*** $raw_dir_copy is not mounted\n" 660 | dis_um=1 661 | fi 662 | raw_dir="$raw_dir_copy" 663 | 664 | #sparse_dir : setting name + -d : config 665 | if [[ $dest_opt == 1 ]] 666 | then 667 | sparse_dir="$dest" 668 | else 669 | tmp="${raw_dir##*/}" 670 | sparse_dir="${tmp%.raw_img}-mod.img" 671 | #raw_dir : full path 672 | fi 673 | if [[ $sparse_dir != /* ]] 674 | then 675 | sparse_dir="$start/$sparse_dir" 676 | fi 677 | 678 | #sparse_dir : overwrite 679 | if [[ -f "$sparse_dir" ]] 680 | then 681 | if [[ $ow == 1 ]] 682 | then 683 | my_print "*** $sparse_dir will be overwrited\n" 684 | else 685 | my_print "\n*** WARNING : $sparse_dir exists ... \n" red bold 686 | my_print "Do you want to overwrite this file ? (y/n) : " red bold 687 | read opt 688 | if [[ "$opt" != "y" ]] 689 | then 690 | sparse_dir="$(free_name $sparse_dir)" 691 | fi 692 | fi 693 | fi 694 | fi 695 | 696 | 697 | #detecting mountpoint --- for no mode 698 | if [[ $repack == 0 ]] 699 | then 700 | if [[ "$vndks_len" -ne 0 || $aonly == 1 ]] 701 | then 702 | if [[ $mp == 0 ]] 703 | then 704 | last=`cat $SAT_DIR/.last.info` 705 | raw_dir="$last" 706 | 707 | #detecting mounpoint 708 | raw_dir_copy="$raw_dir" 709 | if [[ "$OS_TYPE" == "Android" ]] 710 | then 711 | raw_dir="$(raw_to_loop $raw_dir)" 712 | fi 713 | 714 | tmp=`mount | grep "$raw_dir " | wc -l` 715 | if [[ $tmp != 0 ]] 716 | then 717 | tmp1=`mount | grep "$raw_dir "` 718 | temp=${tmp1##*on } 719 | temp2=${temp% type*} 720 | mount_dir="$temp2" 721 | fi 722 | raw_dir="$raw_dir_copy" 723 | fi 724 | fi 725 | fi 726 | 727 | # -m : configure !!! use if auto-detect works bad --- for repack and no-mode 728 | if [[ $mp == 1 ]] 729 | then 730 | if [[ $m == /* ]] 731 | then 732 | mount_dir="$m" 733 | else 734 | mount_dir="$default_m_dir/$m" 735 | fi 736 | fi 737 | 738 | #mount_dir : check 739 | mocmd=`mount | grep "$mount_dir" | wc -l` 740 | if [[ $mocmd == 0 && $dis_um == 0 ]] 741 | then 742 | if [[ $dis_um == 0 && $no_mode == 0 ]] 743 | then 744 | my_print "Nothing mounted on $mount_dir\n" 745 | exit 1 746 | fi 747 | fi 748 | 749 | #detecting system arch 750 | if [[ -d "$mount_dir/system" ]] && [[ ! -z "$(ls -A $mount_dir/system)" ]] 751 | then 752 | ab=1 753 | fi 754 | 755 | #print config 756 | if [[ $no_mode == 0 ]] 757 | then 758 | if [[ $unpack == 0 ]] || [[ $unpack == 1 && $repack == 1 ]] 759 | then 760 | print_config "repack" 761 | fi 762 | fi 763 | 764 | #converting to a-only 765 | if [[ $aonly == 1 ]] 766 | then 767 | if [[ $ab == 1 ]] 768 | then 769 | my_print "Converting ab to a-only architecture\n..." 770 | cd "$mount_dir" 771 | ls | grep -v system | xargs rm -rf 772 | mv -f system/* "$mount_dir/" 773 | rm -rf "$mount_dir/system" 774 | 775 | cp -rf "$SAT_DIR/files/etc" "$mount_dir" 776 | cd "$mount_dir/etc/init" 777 | chmod 644 apex-setup.rc 778 | chmod 644 init.treble-environ.rc 779 | chmod 644 mediaswcodec-treble.rc 780 | chmod 755 zygote 781 | cd zygote 782 | chmod 644 *.rc 783 | my_print " Done\n" 784 | ab=0 785 | cd "$start" 786 | else 787 | my_print "*** Hmm...it isn't AB system, no need to convert\n\n" yellow bold 788 | fi 789 | fi 790 | 791 | #deleting vndk 792 | if [[ $vndks_len -ne 0 ]] 793 | then 794 | my_print "deleting vndk folders on "; my_print "$mount_dir\n" -mount; printf "..." 795 | if [[ $ab == 1 ]] 796 | then 797 | cd "$mount_dir/system" 798 | else 799 | cd "$mount_dir" 800 | fi 801 | i="$vndks_len" 802 | while [[ "$i" -ge 0 ]]; do 803 | rm -rf "lib/vndk-${vndks[$i]}" 804 | rm -rf "lib/vndk-sp-${vndks[$i]}" 805 | rm -rf "lib64/vndk-${vndks[$i]}" 806 | rm -rf "lib64/vndk-sp-${vndks[$i]}" 807 | i=$[i-1] 808 | done 809 | my_print " Done\n" 810 | fi 811 | 812 | #repacking 813 | if [[ $repack == 1 ]] 814 | then 815 | cd "$start" 816 | 817 | #for Android: losetup --detach LOOP 818 | if [[ "$OS_TYPE" == "Android" ]] 819 | then 820 | loop_inf=`cat $SAT_DIR/.loop.info | grep ":$mount_dir;" | wc -l` 821 | if [[ "$loop_inf" != 0 ]] 822 | then 823 | loop_inf=`cat $SAT_DIR/.loop.info | grep ":$mount_dir;"` 824 | tmp="${loop_inf%%:*}" 825 | "$TB" losetup -d $tmp 826 | 827 | grep -v ":$tmp;" "$SAT_DIR/.loop.info" > temp.inf 828 | mv -f temp.inf "$SAT_DIR/.loop.info" 829 | fi 830 | fi 831 | if [[ $debug == 1 ]] 832 | then 833 | if [[ $dis_um == 0 ]] 834 | then 835 | my_print "unmounting "; my_print "$mount_dir \n" -mount 836 | umount $mount_dir 837 | rm -rf $mount_dir 838 | fi 839 | if [[ $do_resize == "true" ]] 840 | then 841 | e2fsck -fy $raw_dir 842 | resize2fs -M $raw_dir 843 | fi 844 | else 845 | if [[ $dis_um == 0 ]] 846 | then 847 | my_print "unmounting "; my_print "$mount_dir \n" -mount 848 | umount $mount_dir &> /dev/null 849 | rm -rf $mount_dir &> /dev/null 850 | fi 851 | if [[ $do_resize == "true" ]] 852 | then 853 | e2fsck -fy $raw_dir &> /dev/null 854 | resize2fs -M $raw_dir &> /dev/null 855 | fi 856 | fi 857 | 858 | 859 | my_print "repacking "; my_print "$raw_dir_cp" -raw; printf " to "; my_print "$sparse_dir_cp \n" -sparse; my_print "..." 860 | if [[ $use_tool_binaries == "true" ]] 861 | then 862 | $BIN_DIR/img2simg $raw_dir $sparse_dir 863 | else 864 | img2simg $raw_dir $sparse_dir 865 | fi 866 | my_print " Done\n" 867 | 868 | fi 869 | 870 | #mountlist 871 | if [[ $ml == 1 ]] 872 | then 873 | if [[ -f "$SAT_DIR/.mount.info" ]] 874 | then 875 | cp "$SAT_DIR/.mount.info" .tmpfile.txt 876 | 877 | input=".tmpfile.txt" 878 | echo "tmpfile2" > .tmpfile2.txt 879 | while IFS= read -r line 880 | do 881 | raw="${line%%:*}" 882 | 883 | raw_dir_copy="$raw" 884 | if [[ "$OS_TYPE" == "Android" ]] 885 | then 886 | raw="$(raw_to_loop $raw)" 887 | fi 888 | 889 | tmp1=`mount | grep "$raw "` 890 | check=`cat .tmpfile2.txt | grep "$tmp1" | wc -l` 891 | if [[ $check == 0 ]] 892 | then 893 | if [[ "$OS_TYPE" == "Android" ]] 894 | then 895 | my_print "${raw_dir_copy##*/}: $tmp1\n" green bold 896 | else 897 | my_print "$tmp1\n" green bold 898 | fi 899 | fi 900 | echo "$tmp1" >> .tmpfile2.txt 901 | done < "$input" 902 | 903 | rm -rf .tmpfile.txt 904 | rm -rf .tmpfile2.txt 905 | else 906 | my_print "Nothing is mounted\n" red bold 907 | fi 908 | fi 909 | 910 | 911 | if [[ $clean == 1 ]] 912 | then 913 | if [[ ! -f "$SAT_DIR/.mount.info" ]] 914 | then 915 | my_print "*** There is nothing to remove\n" red 916 | exit 1 917 | fi 918 | my_print "*** Unmount and delete M_DIR's + clear SAT history\n..." 919 | j=`cat "$SAT_DIR/.mount.info" | wc -l` 920 | while [ $j -ne 0 ] 921 | do 922 | str=`sed -n 1p "$SAT_DIR/.mount.info"` 923 | m="${str#*:}" 924 | mpd="${m%?}" 925 | umount "$mpd" &> /dev/null 926 | rm -rf "$mpd" 927 | grep -v ":$mpd;" "$SAT_DIR/.mount.info" > temp 928 | mv temp "$SAT_DIR/.mount.info" 929 | j=$(( $j - 1 )) 930 | done 931 | 932 | j=`cat "$SAT_DIR/.mount.info" | wc -l` 933 | while [ $j -ne 0 ] 934 | do 935 | str=`sed -n 1p "$SAT_DIR/.mount.info"` 936 | r=${str%:} 937 | i=`mount | grep "$r " | wc -l` 938 | 939 | while [ $i -ne 0 ] 940 | do 941 | str=`sed -n 1p "$SAT_DIR/.mount.info"` 942 | NAME=${str##*on } 943 | mpd=${NAME% type*} 944 | umount "$mpd" &> /dev/null 945 | rm -rf "$mpd" 946 | grep -v ":$mpd;" "$SAT_DIR/.mount.info" > temp 947 | mv temp "$SAT_DIR/.mount.info" 948 | i=$(( $i - 1 )) 949 | done 950 | 951 | grep -v "$m" "$SAT_DIR/.mount.info" > temp 952 | mv temp "$SAT_DIR/.mount.info" 953 | j=$(( $j - 1 )) 954 | done 955 | 956 | rm -rf "$default_m_dir" 957 | rm -f "$SAT_DIR/.mount.info" 958 | rm -f "$SAT_DIR/.last.info" 959 | if [[ -e "$SAT_DIR/.loop.info" ]] 960 | then 961 | rm -f "$SAT_DIR/.loop.info" 962 | fi 963 | my_print " Done\n" 964 | fi 965 | 966 | --------------------------------------------------------------------------------