33 lines
915 B
Bash
33 lines
915 B
Bash
#!/bin/bash
|
|
|
|
#bmount () {}
|
|
# sudo bindfs -o allow_other -o map=root/1001:@root/@1001 /var/lib/docker/volumes /data/dvols
|
|
|
|
|
|
dir_rebind_user () {
|
|
local usesudo; local dir;local user;local group
|
|
# $1 new owner
|
|
# $2 dir
|
|
|
|
[ $# -lt 2 ] && echo minimum args needed to rebind are user and directory && return 1
|
|
[[ $EUID -ne 0 ]] && usesudo=sudo
|
|
|
|
[[ $(id -u $1 2> /dev/null) ]] || { echo user $1 does not exist can not continue; return 2; }
|
|
|
|
dir=$(realpath $2)
|
|
user=$(stat -c '%U' $dir)
|
|
group=$(stat -c '%G' $dir)
|
|
$usesudo bindfs --force-user=$1 --force-group=$1 --create-for-user=$user --create-for-group=$group --chown-ignore --chgrp-ignore $dir $dir
|
|
# echo use \'dir_rebind_user_remove $dir\' to remove
|
|
}
|
|
|
|
dir_rebind_user_remove () {
|
|
local usersudo
|
|
[[ $EUID -ne 0 ]] && usesudo=sudo
|
|
$usesudo fusermount -u $1
|
|
}
|
|
|
|
if [ -v PS1 ]; then
|
|
alias dru="dir_rebind_user"
|
|
alias drur="dir_rebind_user_remove"
|
|
fi |