summarylogtreecommitdiffstats
path: root/fake-sudo.sh
blob: d17074c12ab6eaa5a73c027c75061fb35a225828 (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
41
42
43
44
#!/bin/sh
# fake-sudo

shell=""

while [ $# -gt 0 ]; do
    case "$1" in
        --*=*)
		# convert --a=b → --a b
		a="${1%%=*}"; b="${1#*=}"
		shift
		set -- "$a" "$b" "$@"
		;;
	-h|--help)
		echo "usage: $0 [-u <user>] [<cmd> <arg>...]"
		exit 0
		;;
        -i|--login) 
		shell="/bin/sh -"
		shift
		;;
        -u|--user)
		echo "$0: ignoring user=$1" >&2 
		shift 2
		;;
        --)     
		shift
		break
		;;
        -*)     
		echo "$0: invalid option: $1" >&2
		exit 1
		;;
        *)      
		break
		;;
    esac
done

if [ -n "$shell" ]
then
  set -- $shell "$@"
fi 
exec unshare -r -- "$@"