summaryrefslogtreecommitdiff
path: root/load_profile.sh
blob: 76557ff8faa261b9bf3e1825a4edc54d1952b782 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh

#useful functions
pm_executable_exists()
{
    if which $1 >/dev/null 2>&1; then
        return 0
    else
        return 1
    fi
}

# detect shell
pm_active_shell="${pm_active_shell-unknown}"
if [ "$pm_active_shell" = "unknown" ]; then
    if [ "$ZSH_NAME" != "" ]; then
        pm_active_shell="zsh"
    elif [ "$BASH" != "" ]; then
        pm_active_shell="bash"
    fi
fi

#detect OS
pm_operating_system="${pm_operating_system-unknown}"
if [ "$pm_operating_system" = "unknown" ]; then
    if pm_executable_exists uname; then
        if [ `uname -o` = "GNU/Linux" ]; then
            pm_operating_system="gnu"
        elif [ `uname -o` = "FreeBSD" ]; then
            pm_operating_system="bsd"
        elif [ `uname -o` = "Darwin" ]; then
            pm_operating_system="darwin"
        elif [ `uname -o` = "Windows NT" ]; then
            pm_operating_system="windows"
        fi
    fi
fi

#detect OS variant/distribution
pm_distribution="${pm_distribution-unknown}"
if [ "$pm_distribution" = "unknown" ]; then
    if [ "$pm_operating_system" = "gnu" ] || [ "$pm_operating_system" = "bsd" ]; then
        if [ -e /etc/debian_version ]; then
            pm_distribution="debian"
        elif [ -e /etc/gentoo-release ]; then
            pm_distribution="gentoo"
        fi
    fi
fi

pm_directory="${pm_directory-`dirname $0`}"

for i in `find "$pm_directory/profile.d" -name profile -type f | sort`; do
    source $i
done

#unset internal variables, unless we are running the unit test
if [ "$pm_test_backdoor" = "" ]; then
    unset pm_directory
    unset pm_distribution
    unset pm_operating_system
    unset pm_active_shell
fi