1 if [ -t 0 -o "${0:0:1}" = "-" -o "$1" = "force" ]; then
2 # Set up PROFILE_HOME if called outside HOME.
3 if [ -z "$PROFILE_HOME" ]; then
4 # BASH_SOURCE isn't available prior to bash 3.
5 profile_home=${BASH_SOURCE%/*}
6 [ -n "$profile_home" -a -d "$profile_home" -a ! "${profile_home:0:1}" = "/" ] && profile_home=$(readlink -f "$profile_home" 2>/dev/null)
7 [ "$profile_home" = "$BASH_SOURCE" ] && profile_home=$PWD
8 [ "$profile_home" = "$HOME" ] || PROFILE_HOME=$profile_home
9 PROFILE_RC="$profile_home/.bash_profile"
13 # Remember if nocaseglob was on.
16 # Turn it off so we source stuff in the right order.
18 # Remember if nullglob was on.
21 # Turn it on so we can look in subdirectories.
26 # Turn it off to set case-sensitive matching
29 # Force these to come before everything else.
34 # Remember PATH so we can mangle it to find tsort and sed.
36 PATH=/usr/bin:/bin:/usr/ccs/bin
38 # Sort all scripts by dependencies.
39 PROFILE_D=${PROFILE_HOME:-~}/.profile.d
42 for i in $PROFILE_D/{*/,}*.bashrc; do
43 dep=$(sed -n 's/^##*[ ]*profile-required:[ ]*//p' "$i")
45 if [ -n "$dep" ]; then
58 # Avoid odd number of tokens for tsort.
59 n=$(echo "$deps" | wc -w)
60 if [ $((n%2)) = 1 ]; then
65 sorted=$(echo "$deps" | tsort)
66 if [ -n "$sorted" ]; then
76 # Source them all in the right order.
79 for j in $PROFILE_D/{,*/}$i; do
80 [ -e "$j" ] || continue
82 [ "${sourced/ $k /}" = "$sourced" ] || continue
84 sourced="$sourced $k "
89 # Maybe turn nocaseglob back on.
90 [ $nocg = 0 ] && shopt -s nocaseglob
91 # Maybe turn nullglob back off.
92 [ $nullglob = 0 ] || shopt -u nullglob
97 unset i j k d n dep deps path required unsorted sourced
98 unset lc_all nullglob nocg
100 # Don't inherit failure from the last script.