diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary index 0b49ca5..85a6b23 100755 --- a/META-INF/com/google/android/update-binary +++ b/META-INF/com/google/android/update-binary @@ -134,6 +134,9 @@ $LATESTARTSERVICE && cp -af $INSTALLER/common/service.sh $MODPATH/service.sh ui_print "- Setting permissions" set_permissions +ui_print "- Checking on data folder" +set_data + ########################################################################################## # Finalizing ########################################################################################## diff --git a/README.md b/README.md index 733a3e1..05ade53 100644 --- a/README.md +++ b/README.md @@ -7,21 +7,35 @@ Derived from a very long-living trick for users who are struggling with the inte For example, if you mirror the `Download` folder on Internal with the `Stuff from Internet` folder on your SD Card, the same list of cat pictures will be shown on both directories when navigated via a file manager, and any changes will take effect on both paths. ## Notice -- Using this module will disable sdcardfs -- Not compatible with Huawei stock ROMs (Please report if now works on 1.0.8) +- Using this module will disable sdcardfs and esdfs using buildprop - Not compatible when device has no SD Card slot - - Read below + - This is because the module expect to have an SD Card mounted. As for the moment you may use the module without an SD Card by editing /magisk/ts-binds/service.sh. Go to line 17 and read the comment. I will consider a suitable way to workaround this logic in the script. - Not compatible when adoptable storage is used - - Hey there! This is because the module expect to have an SD Card mounted. As for the moment you may use the module without an SD Card by editing /magisk/ts-binds/service.sh. Go to line 17 and read the comment. I will consider a suitable way to workaround this logic in the script. ## Links -- [**More Info and Further Reading**](https://www.technosparks.net/pages/product-documentation/ts-binds) +- [**More Info and Further Reading**](https://www.technosparks.net/pages/product-documentation/ts-binds?from=readme) - [XDA Developers thread](https://forum.xda-developers.com/apps/magisk/module-ts-binds-t3628856) - [→ DOWNLOAD ZIP](https://github.com/Magisk-Modules-Repo/ts-binds/releases) (Also available in Magisk Repo) - [GitHub](https://github.com/Magisk-Modules-Repo/ts-binds/) - [Changelogs](https://github.com/Magisk-Modules-Repo/ts-binds/releases) ## Changelog (2 recent versions) +### 1.0.9 +**Additions** +- New `mount` parameter to output the system's mount entries. Command `tsbinds mount` is to execute in shell +- New `pairs` parameter to output the pair names in the `folderlist`. Great to do quick revision. Command `tsbinds pairs` is to execute in shell + +**Fixes** +- Fix the mount namespace issue - now binds and unbinds take effect the way it should be! + - All the commands are now passed through `su -M -c` to take effect on the global namespace. + +**Modifications** +- Change to use busybox + - Uses hardcoded PATH towards the busybox folder `/sbin/.core/busybox` +- Uses hardcoded path towards module directory `/sbin/.core/img/ts-binds` + - Was `/magisk/ts-binds` but /magisk is a symbolic link towards above path + - I know, hardcoding paths is not recommended by the Magisk documentation, but the module goes forward by Magisk's new version. The reason I had to do this is because there is no other easy alternative to find module's dir other than extreme measures of loopdevice mounting or looping through countless number of directories from root. So instead of taxing the shell during boot, I prefer not to do that instead. + ### 1.0.8 **Regressions** @@ -33,17 +47,3 @@ For example, if you mirror the `Download` folder on Internal with the `Stuff fro **Modifications** - Updated help snippet - -### 1.0.6 & 1.0.7 -**Additions** -- Disable sdcardfs by using prop entries - -**Fixes** -- Invalid path to log file in service.sh - -**Modifications** -- Magisk v14 compliant -- SD card name will not be cached anymore -- Simpler `grep`ing of SD card name -- File overwrite warning is added to `tsbinds help` for the `tsbinds move` feature -- Readme.md now points to GitHub releases to show changelogs instead of commits as changelogs diff --git a/common/system.prop b/common/system.prop index 68694ec..a0313d3 100644 --- a/common/system.prop +++ b/common/system.prop @@ -1,3 +1,6 @@ # Disable sdcardfs by prop -persist.sys.sdcardfs=force_off ro.sys.sdcardfs=false +persist.sys.sdcardfs=force_off +persist.esdfs_sdcard=false +persist.fuse_sdcard=true + diff --git a/config.sh b/config.sh index aadc277..35f1d92 100644 --- a/config.sh +++ b/config.sh @@ -48,12 +48,6 @@ print_modname() { ui_print " " } -print_onFinish() { - ui_print " " - ui_print "[i] Flashing is done!" - ui_print "------------------------------------------------" -} - ########################################################################################## # Replace list ########################################################################################## @@ -93,10 +87,12 @@ set_permissions() { # set_perm $MODPATH/system/lib/libart.so 0 0 0644 # The following is default permissions, DO NOT remove - set_perm_recursive $MODPATH 0 0 0755 0644 - set_perm $MODPATH/service.sh 0 0 0755 - set_perm $MODPATH/system/bin/tsbinds 0 0 0755 - set_perm $MODPATH/ts-binds-folderlist.txt 0 0 0666 + set_perm_recursive $MODPATH 0 0 0755 0644 + + set_perm $MODPATH/service.sh 0 0 0755 + set_perm $MODPATH/system/bin/tsbinds 0 0 0755 + set_perm $MODPATH/data/fresh-folderlist.txt 1023 1023 0664 + set_perm $MODPATH/data/config.txt 0 0 0666 } ########################################################################################## @@ -109,3 +105,14 @@ set_permissions() { # difficult for you to migrate your modules to newer template versions. # Make update-binary as clean as possible, try to only do function calls in it. +set_data() { + if [ ! -d /data/ts-binds ]; then + mv $MODPATH/data /data/ts-binds + fi +} + +print_onFinish() { + ui_print " " + ui_print "[i] Flashing is done!" + ui_print "------------------------------------------------" +} diff --git a/data/config.txt b/data/config.txt new file mode 100644 index 0000000..e69de29 diff --git a/ts-binds-folderlist.txt b/data/fresh-folderlist.txt similarity index 100% rename from ts-binds-folderlist.txt rename to data/fresh-folderlist.txt diff --git a/module.prop b/module.prop index de9f4fc..84d741f 100644 --- a/module.prop +++ b/module.prop @@ -1,7 +1,7 @@ id=ts-binds name=ts-binds -version=1.0.8 -versionCode=12 +version=1.0.9 +versionCode=13 author=TechnoSparks description=ts-binds binds two different folders on your device so that both folders share the same contents minMagisk=1500 diff --git a/system/bin/tsbinds b/system/bin/tsbinds index 59537b7..27807d5 100644 --- a/system/bin/tsbinds +++ b/system/bin/tsbinds @@ -1,6 +1,10 @@ #!/system/bin/sh # sy +# All hail busybox for standardising this script! +busybox=/sbin/.core/busybox +PATH=$busybox:$PATH + # Check if run under root -------------------------------- if ! ls /data > /dev/null 2> /dev/null; then echo "[!] ERROR" @@ -13,12 +17,18 @@ if ! ls /data > /dev/null 2> /dev/null; then fi # Functions ---------------------------------------------- -MODDIR=/magisk/ts-binds +MODDIR=/sbin/.core/img/ts-binds +datadir=/data/ts-binds int=/data/media/0 sd=$(grep -m 1 -Eo "/mnt/media_rw/[0-9A-Z]{4}-[0-9A-Z]{4}" /proc/mounts) -folderlist=$MODDIR/cached-folderlist.sh +folderlist=$datadir/cached-folderlist.sh folderlistuser=$int/ts-binds-folderlist.txt logfile=$int/ts-binds.log + +function supass { + /sbin/su -M -c "$@" +} + function printhelp { echo "tsbinds [options] [arg]" echo @@ -26,10 +36,17 @@ function printhelp { echo echo "help ............... Show this reference text" echo "h .................. Ditto" + echo "pairs .............. Prints out the folder" + echo " pairs in folderlist" echo "bind ... Binds a specific entry" echo " by its name" echo "bind o . Binds to " echo "bind all ........... Binds all entries " + echo "bind o . Binds to " + echo "unbind . Unbinds a specific" + echo " entry by its name" + echo "unbind all ......... Unbinds all entries" + echo "unbind o ..... Unbinds " echo "check .. Check if an entry is binded" echo "check all .......... Check if all entries are" echo " individually binded" @@ -39,16 +56,6 @@ function printhelp { echo "update f ........... Update cached entries" echo " regardless if the user's" echo " entries are modified" - echo "move ... Unbind and then move" - echo " specific recursing files" - echo " and folders to the" - echo " SD card path. Files" - echo " will be overwritten!" - echo "move all ........... Unbind and then move" - echo " all recursing files" - echo " and folders to the" - echo " SD card path. Files" - echo " will be overwritten!" echo "reinit ............. Re-run the script that" echo " runs on boot" echo "disable ............ Disables automatic " @@ -56,17 +63,10 @@ function printhelp { echo "enable ............. Enables automatic " echo " mounting on boot" echo "log ................ Prints out the log" - echo - echo "Available but useless, kept because for" - echo "developmental tests:" + echo "mount .............. Prints out the mount" + echo " entries" echo - echo "unbind . Unbinds a specific" - echo " entry by its name" - echo "unbind all ......... Unbinds all entries" - echo "unbind o ..... Unbinds " - echo - echo "I am experimenting on a disable per" - echo "folder couple feature" + echo echo "Note: running the command reinit, and unbind, move with \"all\" argument may return \"unmount\" errors. Most of the time they can be safely ignored." } @@ -88,7 +88,8 @@ elif [ "$1" == "help" ] || [ "$1" == "h" ]; then # Bind --------------------------------------------------- elif [ "$1" == "bind" ]; then function folderbind { - if grep -q "$3" /proc/mounts; then + cmd="mountpoint -q \"$3\"" + if (supass $cmd); then tslog "$1 is already binded" elif [ ! -d "$2" ] && [ ! -f "$2" ]; then tslog "Bind aborted: Folder '$2' as source doesn't exist!" @@ -97,7 +98,8 @@ elif [ "$1" == "bind" ]; then tslog "Bind aborted: Folder '$3' as target doesn't exist!" return 1 else - mount -o bind "$2" "$3" && tslog "Bind successful: $1" || tslog "Bind failed: $1" + cmd="mount --rbind \"$2\" \"$3\"" + (supass $cmd) && tslog "Bind successful: $1" || tslog "Bind failed: $1" fi } if [ ! "$2" ]; then @@ -108,7 +110,7 @@ elif [ "$1" == "bind" ]; then tslog "All entries were processed" elif [ "$2" == "o" ]; then folderbind "o" $3 $4 - elif line="$(grep "$2" $folderlist)"; then + elif line="$(grep -m 1 "$2" $folderlist)"; then eval $line else tslog "Unable to bind $2, entry not found in list!" @@ -117,10 +119,12 @@ elif [ "$1" == "bind" ]; then # Unbind ------------------------------------------------- elif [ "$1" == "unbind" ]; then function folderbind { - if ! grep -q "$3" /proc/mounts; then + cmd="mountpoint -q \"$3\"" + if ! (supass $cmd); then tslog "$1 is already unbinded" else - umount "$3" && tslog "Unbind successful: $1" || tslog "Unbind failed: $1" + cmd="umount \"$3\"" + (supass $cmd) && tslog "Unbind successful: $1" || tslog "Unbind failed: $1" fi } if [ ! "$2" ]; then @@ -131,7 +135,7 @@ elif [ "$1" == "unbind" ]; then tslog "All entries were processed" elif [ "$2" == "o" ]; then folderbind "o" $3 $4 - elif line="$(grep "$2" $folderlist)"; then + elif line="$(grep -m 1 "$2" $folderlist)"; then eval $line else tslog "Unable to unbind $2, entry not found in list!" @@ -140,14 +144,15 @@ elif [ "$1" == "unbind" ]; then # Check -------------------------------------------------- elif [ "$1" == "check" ]; then function folderbind { - grep -q "$3" /proc/mounts && tslog "$1 is BINDED" || tslog "$1 is NOT binded" + cmd="mountpoint -q \"$3\"" + (supass $cmd) && tslog "$1 is BINDED" || tslog "$1 is NOT binded" } if [ ! "$2" ]; then echo 'E: Bind name is not provided!'; elif [ "$2" == "all" ]; then source $folderlist tslog "All entries were checked" - elif line="$(grep "$2" $folderlist)"; then + elif line="$(grep -m 1 "$2" $folderlist)"; then eval $line else tslog "Unable to check $2, entry not found in list!" @@ -156,15 +161,11 @@ elif [ "$1" == "check" ]; then # Update ------------------------------------------------- elif [ "$1" == "update" ]; then if [ ! -f $folderlistuser ]; then - cp $MODDIR/ts-binds-folderlist.txt $folderlistuser - chmod 0664 $folderlistuser - chown 1023:1023 $folderlistuser + cp $datadir/fresh-folderlist.txt $folderlistuser tslog "Copied user list to internal storage" tsbinds update elif [ ! -f $folderlist ]; then cp $folderlistuser $folderlist - chmod 0755 $folderlist - chown 0:0 $folderlist tslog "Cached the user list" elif [ "$2" ] && [ "$2" == "f" ]; then cp -f $folderlistuser $folderlist @@ -172,49 +173,11 @@ elif [ "$1" == "update" ]; then elif [ ! $folderlist -nt $folderlistuser ]; then tslog "Difference found between cached and original user list" cp -f $folderlistuser $folderlist - chmod 0755 $folderlist - chown 0:0 $folderlist tslog "Updated cached list" else tslog "No update made to cached list" fi -# Move --------------------------------------------------- -elif [ "$1" == "move" ]; then - if [ ! "$2" ]; then - echo 'E: Bind name is not provided!' - elif [ "$2" == "all" ]; then - tsbinds unbind all - function folderbind { - if [ "$(ls -A "$3")" ]; then - mv -f "$3/"* "$2/" && tslog "Files moved successfully for $1" || tslog "Moving operation failed for $1" - else - tslog "No files to move for $1" - fi - } - source $folderlist - tsbinds bind all - elif line="$(grep "$2" $folderlist)"; then - function folderbind { - wasBinded=no - if grep -q "$3" /proc/mounts; then - wasBinded=yes - tsbinds unbind $1 - fi - if [ "$(ls -A "$3")" ]; then - mv -f "$3/"* "$2/" && tslog "Files moved successfully for $1" || tslog "Moving operation failed for $1" - else - tslog "No files to move for $1" - fi - if [ $wasBinded == "yes" ]; then - tsbinds bind $1 - fi - } - eval $line; - else - tslog "Unable to move contents of $2, entry not found in list!" - fi - # Reinit ------------------------------------------------- elif [ "$1" == "reinit" ]; then tsbinds unbind all @@ -232,12 +195,25 @@ elif [ "$1" == "enable" ]; then elif [ "$1" == "log" ]; then cat $logfile echo + +# Print mount -------------------------------------------- +elif [ "$1" == "mount" ]; then + supass mount + echo + +# Print folder pairs ------------------------------------- +elif [ "$1" == "pairs" ]; then + while IFS='' read -r line || [[ -n "$line" ]]; do + if ! (echo $line | grep -Eo "#\| +" > /dev/null 2> /dev/null); then + echo $line | awk '{print $2}' + fi + done < $folderlist # Action unrecognised ------------------------------------ else echo "E: Unknown action \"$1\" supplied" fi -# Force log proper permission -chown 1023:1023 $logfile $folderlistuser -chmod 0664 $logfile $folderlistuser +# Force log proper permission ---------------------------- +chown 1023:1023 $logfile $folderlistuser $folderlist +chmod 0664 $logfile $folderlistuser $folderlist