Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from Magisk-Modules-Repo/bleeding
Browse files Browse the repository at this point in the history
Bleeding
  • Loading branch information
TechnoSparks authored May 31, 2018
2 parents 4febf3c + b810369 commit e23b503
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 108 deletions.
3 changes: 3 additions & 0 deletions META-INF/com/google/android/update-binary
Original file line number Diff line number Diff line change
Expand Up @@ -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
##########################################################################################
Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand All @@ -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
5 changes: 4 additions & 1 deletion common/system.prop
Original file line number Diff line number Diff line change
@@ -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

27 changes: 17 additions & 10 deletions config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ print_modname() {
ui_print " "
}

print_onFinish() {
ui_print " "
ui_print "[i] Flashing is done!"
ui_print "------------------------------------------------"
}

##########################################################################################
# Replace list
##########################################################################################
Expand Down Expand Up @@ -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
}

##########################################################################################
Expand All @@ -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 "------------------------------------------------"
}
Empty file added data/config.txt
Empty file.
File renamed without changes.
4 changes: 2 additions & 2 deletions module.prop
Original file line number Diff line number Diff line change
@@ -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
128 changes: 52 additions & 76 deletions system/bin/tsbinds
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -13,23 +17,36 @@ 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
echo "Available options:"
echo
echo "help ............... Show this reference text"
echo "h .................. Ditto"
echo "pairs .............. Prints out the folder"
echo " pairs in folderlist"
echo "bind <bind name> ... Binds a specific entry"
echo " by its name"
echo "bind o <src> <des> . Binds <src> to <des>"
echo "bind all ........... Binds all entries "
echo "bind o <src> <des> . Binds <src> to <des>"
echo "unbind <bind name> . Unbinds a specific"
echo " entry by its name"
echo "unbind all ......... Unbinds all entries"
echo "unbind o <des> ..... Unbinds <des>"
echo "check <bind name> .. Check if an entry is binded"
echo "check all .......... Check if all entries are"
echo " individually binded"
Expand All @@ -39,34 +56,17 @@ function printhelp {
echo "update f ........... Update cached entries"
echo " regardless if the user's"
echo " entries are modified"
echo "move <bind name> ... 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 "
echo " mounting on boot"
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 <bind name> . Unbinds a specific"
echo " entry by its name"
echo "unbind all ......... Unbinds all entries"
echo "unbind o <des> ..... Unbinds <des>"
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."
}
Expand All @@ -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!"
Expand All @@ -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
Expand All @@ -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!"
Expand All @@ -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
Expand All @@ -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!"
Expand All @@ -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!"
Expand All @@ -156,65 +161,23 @@ 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
tslog "Force-updated cached list"
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
Expand 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

0 comments on commit e23b503

Please sign in to comment.