aboutsummarylogtreecommitdiffstats
path: root/fake-su.sh
blob: dfa57878d29dfe87f608236c93bee1aac6059030 (plain)
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
33
34
35
36
37
38
39
40
#!/bin/sh
# fake-su

cmd=""
shell="/bin/sh"

while [ $# -gt 0 ]; do
    case "$1" in
        -h|--help)
		echo "usage: $0 [-l] [-] [<user> [<arg>...]]"
		exit 0
		;;
        -|-l|--login) 
		shell="$shell -"; shift
		;;
        -c|--command)
		cmd="$2"; shift 2
		;;
        --)     
		shift
		break
		;;
        -*)     
		echo "$0: invalid option: $1" >&2
		exit 1
		;;
        *)      
		echo "$0: ignoring user=$1" >&2
		shift
		break
		;;
    esac
done

if [ -z "$cmd" ]
then
   exec unshare -r -- "$shell" "$@"
else
   exec unshare -r -- "$shell" -c "$cmd" "$@"
fi