summaryrefslogtreecommitdiffstats
path: root/rooty 2.sh
blob: 2b4dad9728f303ac895676523499c5c832da466a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash

# $0 is visible globally, in functions too

# apparently su -c accepts a command and 1 argument, hence we export
CMDL_ARGS=$@
export CMDL_ARGS

chk_root()
{
    if [[ ! $(id -u) -eq 0 ]]; then
        echo "root user required";
        # exec works similar to fork()
        exec su -c "\"$0\" $CMDL_ARGS"
        exit $?
    fi
}

chk_root $@
if [[ $(id -u) -eq 0 ]]; then
    echo "you're root"
fi