diff --git a/README.md b/README.md index ae46d32..f4f0f3c 100644 --- a/README.md +++ b/README.md @@ -106,3 +106,8 @@ For more detailed configuration of rclone please refer to [official documentatio * Specify custom params for individual remotes via /sdcard/.rclone/.REMOTENAME.params +### v1.4 +* Add ability to disable a remote +* Add a wrapper script for rclone +* Make remount possible with adb via `su --mount-master -c` + diff --git a/binary/rclone-wrapper.sh b/binary/rclone-wrapper.sh new file mode 100755 index 0000000..ec9fdae --- /dev/null +++ b/binary/rclone-wrapper.sh @@ -0,0 +1,63 @@ +#!/system/xbin/bash + +MODDIR=${0%/*} + +#. $MODDIR/module.prop >> /dev/null 2>&1 + +IMGDIR=/sbin/.core/img +id=com.piyushgarg.rclone + +USER_CONFDIR=/sdcard/.rclone +CLOUDROOTMOUNTPOINT=/mnt/cloud + +if [ -d ${IMGDIR}/${id} ]; then + + HOME=${IMGDIR}/${id} + +else + + HOME=$={MODDIR} + +fi + +disable () { + + touch ${USER_CONFDIR}/.$*.disable +} + +unmount () { + + umount -f ${CLOUDROOTMOUNTPOINT}/* >> /dev/null 2>&1 + kill -9 $(pgrep -x rclone) >> /dev/null 2>&1 + + rm -r ${CLOUDROOTMOUNTPOINT} >> /dev/null 2>&1 +} + + +remount () { + + umount -f ${CLOUDROOTMOUNTPOINT}/* >> /dev/null 2>&1 + sleep 1 + ${HOME}/service.sh + +} + +if [[ ${1} = disable ]]; then + + echo "disabling remote ${2}" + touch $USER_CONFDIR/.${2}.disable + +elif [[ ${1} = remount ]]; then + + remount + +elif [[ ${1} = unmount ]]; then + + unmount + +else + + $HOME/rclone $* + +fi + diff --git a/changelog.md b/changelog.md index 9376f15..24e45d9 100644 --- a/changelog.md +++ b/changelog.md @@ -13,3 +13,8 @@ * Move user rclone.conf & related to /sdcard/.rclone/ * Control global --vfs-cache-mode via simple files placed in /sdcard/.rclone/ * Specify custom params for individual remotes via /sdcard/.rclone/.REMOTENAME.params + +## v1.4 +* Add ability to disable a remote +* Add a wrapper script for rclone +* Make remount possible via `su --mount-master` diff --git a/common/disable.sh b/common/disable.sh old mode 100644 new mode 100755 diff --git a/common/manual.sh b/common/manual.sh old mode 100644 new mode 100755 diff --git a/common/service.sh b/common/service.sh index bc4fedd..12d2167 100755 --- a/common/service.sh +++ b/common/service.sh @@ -1,4 +1,4 @@ -#!/system/bin/sh +#!/system/xbin/bash # Do NOT assume where your module will be located. # ALWAYS use $MODDIR if you need to know where this script # and module is placed. @@ -7,21 +7,22 @@ MODDIR=${0%/*} -#. $MODDIR/module.prop >> /dev/null 2>&1 - IMGDIR=/sbin/.core/img id=com.piyushgarg.rclone -if [ -d $IMGDIR/$id ]; then +if [ -d ${IMGDIR}/${id} ]; then + + ln -sf ${IMGDIR}/${id}/rclone-wrapper.sh /sbin/rclone + ln -sf ${IMGDIR}/${id}/fusermount /sbin/fusermount + ln -sf ${IMGDIR}/${id}/rclone-mount /sbin/rclone-mount + HOME=${IMGDIR}/${id} - ln -sf $IMGDIR/$id/rclone /sbin/rclone - ln -sf $IMGDIR/$id/fusermount /sbin/fusermount - ln -sf $IMGDIR/$id/rclone-mount /sbin/rclone-mount else - ln -sf $MODDIR/rclone /sbin/rclone - ln -sf $MODDIR/fusermount /sbin/fusermount - ln -sf $MODDIR/rclone-mount /sbin/rclone-mount + ln -sf ${MODDIR}/rclone-wrapper.sh /sbin/rclone + ln -sf ${MODDIR}/fusermount /sbin/fusermount + ln -sf ${MODDIR}/rclone-mount /sbin/rclone-mount + HOME=${MODDIR} fi @@ -30,14 +31,15 @@ USER_CONFDIR=/sdcard/.rclone #/sdcard/rclone.conf is really a sensitive file containing all the important tokens and is exposed to all the apps. #Do we really want to keep it there after use? Lets decide and close the loop. -USER_CONF=$USER_CONFDIR/rclone.conf +USER_CONF=${USER_CONFDIR}/rclone.conf -CONFIGFILE=$MODDIR/rclone.conf +CONFIGFILE=${HOME}/.config/rclone/rclone.conf LOGFILE=/sdcard/rclone.log -HOME=/mnt -CLOUDROOTMOUNTPOINT=$HOME/cloud +HOME=${MODDIR} +CLOUDROOTMOUNTPOINT=/mnt/cloud #RCLONE PARAMETERS +DISABLE=0 BUFFERSIZE=8M CACHEMAXSIZE=256M DIRCACHETIME=24h @@ -46,90 +48,97 @@ CACHEMODE=writes CACHE=/data/rclone/cache CACHE_BACKEND=/data/rclone/cache-backend +if [[ -e ${USER_CONFDIR}/.disable ]]; then + + exit 0 + +fi + custom_params () { - PARAMS="BUFFERSIZE CACHEMAXSIZE DIRCACHETIME READAHEAD CACHEMODE" + PARAMS="BUFFERSIZE CACHEMAXSIZE DIRCACHETIME READAHEAD CACHEMODE DISABLE" + BAD_SYNTAX="(^\s*#|^\s*$|^\s*[a-z_][^[:space:]]*=[^;&\(\`]*$)" - if [[ -e $USER_CONFDIR/.$remote.param ]]; then + if [[ -e ${USER_CONFDIR}/.${remote}.param ]] && [[ ! $(egrep -q -iv "${BAD_SYNTAX}" ${USER_CONFDIR}/.${remote}.param) ]]; then - if ! egrep -q -iv "$BAD_SYNTAX" $USER_CONFDIR/.$remote.param; then + echo "loading .${remote}.param" for PARAM in ${PARAMS[@]}; do while read -r VAR; do - if [[ "$(echo "${VAR}" |grep -w "$PARAM")" ]]; then + if [[ "$(echo "${VAR}" |grep -w "${PARAM}")" ]]; then + echo "Importing ${VAR}" eval $(echo "${VAR}" |cut -d ' ' -f 1) - + fi - done < $USER_CONFDIR/.$remote.param + done < ${USER_CONFDIR}/.${remote}.param done - else + else - echo ".$remote.param contains bad syntax" + echo ".${remote}.param contains bad syntax" - fi fi } -if [[ ! -d $CLOUDROOTMOUNTPOINT ]]; then +if [[ ! -d ${CLOUDROOTMOUNTPOINT} ]]; then - mkdir -p $CLOUDROOTMOUNTPOINT + mkdir -p ${CLOUDROOTMOUNTPOINT} fi -if [[ ! -d $CACHE ]]; then +if [[ ! -d ${CACHE} ]]; then - mkdir -p $CACHE + mkdir -p ${CACHE} fi -if [[ ! -d $CACHE_BACKEND ]]; then +if [[ ! -d ${CACHE_BACKEND} ]]; then - mkdir -p $CACHE_BACKEND + mkdir -p ${CACHE_BACKEND} fi if [[ ! -L /mnt/runtime/read/cloud ]]; then - ln -sf $CLOUDROOTMOUNTPOINT /mnt/runtime/read/cloud + ln -sf ${CLOUDROOTMOUNTPOINT} /mnt/runtime/read/cloud fi if [[ ! -L /mnt/runtime/write/cloud ]]; then - ln -sf $CLOUDROOTMOUNTPOINT /mnt/runtime/write/cloud + ln -sf ${CLOUDROOTMOUNTPOINT} /mnt/runtime/write/cloud fi -until [[ $(getprop sys.boot_completed) = 1 ]] && [[ $(getprop dev.bootcomplete) = 1 ]] && [[ $(getprop service.bootanim.exit) = 1 ]] && [[ $(getprop init.svc.bootanim) = stopped ]] && [[ -e $USER_CONF ]] || [[ $COUNT -eq 240 ]]; do +until [[ $(getprop sys.boot_completed) = 1 ]] && [[ $(getprop dev.bootcomplete) = 1 ]] && [[ $(getprop service.bootanim.exit) = 1 ]] && [[ $(getprop init.svc.bootanim) = stopped ]] && [[ -e ${USER_CONF} ]] || [[ ${COUNT} -eq 240 ]]; do sleep 5 ((++COUNT)) done -if [[ -e $USER_CONF ]]; then +if [[ -e ${USER_CONF} ]]; then - cp $USER_CONF $CONFIGFILE - chmod 0600 $CONFIGFILE + cp ${USER_CONF} ${CONFIGFILE} + chmod 0600 ${CONFIGFILE} fi -if [[ -e $USER_CONFDIR/.nocache ]]; then +if [[ -e ${USER_CONFDIR}/.nocache ]]; then CACHEMODE=off fi -if [[ -e $USER_CONFDIR/.mincache ]]; then +if [[ -e ${USER_CONFDIR}/.mincache ]]; then CACHEMODE=minimal @@ -147,28 +156,38 @@ if [[ -e $USER_CONFDIR/.fullcache ]]; then fi -echo CACHEMODE will be ${CACHEMODE}. - sleep 10 -/sbin/rclone listremotes --config ${CONFIGFILE}|cut -f1 -d: | - while read remote; do +echo "Default CACHEMODE ${CACHEMODE}" - #ignore the remote which is not required by the user. - if [[ -e "${USER_CONFDIR}/${remote}.skip" ]]; then - echo "ignored ${remote} as requested." +$HOME/rclone listremotes --config ${CONFIGFILE}|cut -f1 -d: | + while read remote; do + + echo + + DISABLE=0 + + custom_params + +#ignore the remote which is not required by the user + + if [[ ${DISABLE} = 1 ]] || [[ -e ${USER_CONFDIR}/.${remote}.disable ]]; then + + echo "${remote} disabled by user" continue + fi - custom_params - echo "[$remote] will be available at -> [${CLOUDROOTMOUNTPOINT}/${remote}]" + echo "[${remote}] available at: -> [${CLOUDROOTMOUNTPOINT}/${remote}]" mkdir -p ${CLOUDROOTMOUNTPOINT}/${remote} - /sbin/rclone mount ${remote}: ${CLOUDROOTMOUNTPOINT}/${remote} --config ${CONFIGFILE} --max-read-ahead ${READAHEAD} --buffer-size ${BUFFERSIZE} --dir-cache-time ${DIRCACHETIME} --poll-interval 5m --attr-timeout ${DIRCACHETIME} --vfs-cache-mode ${CACHEMODE} --vfs-read-chunk-size 2M --vfs-read-chunk-size-limit 10M --vfs-cache-max-age 10h0m0s --vfs-cache-max-size ${CACHEMAXSIZE} --cache-dir=${CACHE} --cache-chunk-path ${CACHE_BACKEND} --cache-chunk-clean-interval 10m0s --log-file ${LOGFILE} --allow-other --gid 1015 --daemon + su --mount-master -c $HOME/rclone mount ${remote}: ${CLOUDROOTMOUNTPOINT}/${remote} --config ${CONFIGFILE} --max-read-ahead ${READAHEAD} --buffer-size ${BUFFERSIZE} --dir-cache-time ${DIRCACHETIME} --poll-interval 5m --attr-timeout ${DIRCACHETIME} --vfs-cache-mode ${CACHEMODE} --vfs-read-chunk-size 2M --vfs-read-chunk-size-limit 10M --vfs-cache-max-age 10h0m0s --vfs-cache-max-size ${CACHEMAXSIZE} --cache-dir=${CACHE} --cache-chunk-path ${CACHE_BACKEND} --cache-chunk-clean-interval 10m0s --log-file ${LOGFILE} --allow-other --gid 1015 --daemon sleep 5 done #as of now serving over http that can be browsed through. /sbin/rclone serve http ${CLOUDROOTMOUNTPOINT} --addr 127.0.0.1:38762 --no-checksum --no-modtime --read-only & +/sbin/rclone serve ftp ${CLOUDROOTMOUNTPOINT} --addr 0.0.0.0:38763 --no-checksum --no-modtime --read-only & + echo echo "...done" diff --git a/install.sh b/install.sh index 7fed311..26594eb 100755 --- a/install.sh +++ b/install.sh @@ -159,6 +159,8 @@ on_install() { unzip -p "$ZIPFILE" binary/fusermount-${ARCH} > $MODPATH/fusermount ui_print "+ Extracting rclone-mount script to $MODPATH/rclone-mount" unzip -p "$ZIPFILE" binary/rclone-mount > $MODPATH/rclone-mount + ui_print "+ Extracting rclone-wrapper.sh script to $MODPATH/rclone-mount" + unzip -p "$ZIPFILE" binary/rclone-wrapper.sh > $MODPATH/rclone-wrapper.sh } # Only some special files require specific permissions @@ -173,6 +175,7 @@ set_permissions() { set_perm $MODPATH/fusermount 0 0 0755 set_perm $MODPATH/rclone-mount 0 0 0755 set_perm $MODPATH/service.sh 0 0 0500 + set_perm $MODPATH/rclone-wrapper.sh 0 0 0500 # Here are some examples: # set_perm_recursive $MODPATH/system/lib 0 0 0755 0644 # set_perm $MODPATH/system/bin/app_process32 0 2000 0755 u:object_r:zygote_exec:s0 diff --git a/module.prop b/module.prop index 5f9ee99..5fe7423 100644 --- a/module.prop +++ b/module.prop @@ -1,9 +1,9 @@ id=com.piyushgarg.rclone name=rclone-mount -modVer=1.3 +modVer=1.4 BinVer=1.47 -version=rclone: (v1.47.0) mod: (v1.3) -versionCode=103 +version=rclone: (v1.47.0) mod: (v1.4) +versionCode=104 author=piyushgarg @ github.com description=Mount cloud storage locally using rclone & fusermount. Virtually limitless storage expansion with support for dozens of cloud providers. Extremely useful for streaming large media files without need for full caching. Binaries obtained directly from rclone.org. Please refer to README.md for more info.