-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpwdjail-rm-Ir
More file actions
executable file
·32 lines (28 loc) · 823 Bytes
/
pwdjail-rm-Ir
File metadata and controls
executable file
·32 lines (28 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh
## Copyright 2017 Clemens Fruhwirth <clemens@endorphin.org>
##
## Usage: pwdjail-rmIr DIR
##
absolute() {
cd $1 && pwd
}
# FIXME any modification to this function with master-zshrc
function pwdjail_get_user_for_directory() {
getent passwd | awk -F: '"'"$1"/'" ~ $6"/" && $5 ~ "Sandbox (X11 )?user" { print $1 }' | head -1
}
SANDBOX_HOME=$(absolute $1)
if [ -z $SANDBOX_HOME ]; then
(>&2 echo "Could not access $1.")
exit 1
fi
SANDBOX_USER=$(pwdjail_get_user_directory "$SANDBOX_HOME")
if [ -z "$SANDBOX_USER" ]; then
(>&2 echo "No user has $SANDBOX_HOME as home directory.")
exit 1
fi
echo "$SANDBOX_USER owns $1. Removing..."
# FIXME killall processes belonging to this user, so that userdel succeeds.
sudo userdel $SANDBOX_USER
echo "Removed user."
echo "Calling \"rm -Ir $1\""
sudo rm -Ir $1