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 [ "$profile_home" = "$BASH_SOURCE" ] && profile_home=$PWD
7 [ "$profile_home" = "$HOME" ] || PROFILE_HOME=$profile_home
11 # Remember if nocaseglob was on.
14 # Turn it off so we source stuff in the right order.
16 # Remember if nullglob was on.
19 # Turn it on so we can look in subdirectories.
24 # Turn it off to set case-sensitive matching
27 # Force these to come before everything else.
32 # Remember PATH so we can mangle it to find tsort and sed.
34 PATH=/usr/bin:/bin:/usr/ccs/bin
36 # Sort all scripts by dependencies.
37 PROFILE_D=${PROFILE_HOME:-~}/.profile.d
40 for i in $PROFILE_D/{*/,}*.bashrc; do
41 dep=$(sed -n 's/^##*[ ]*profile-required:[ ]*//p' "$i")
43 if [ -n "$dep" ]; then
56 # Avoid odd number of tokens for tsort.
57 n=$(echo "$deps" | wc -w)
58 if [ $((n%2)) = 1 ]; then
63 sorted=$(echo "$deps" | tsort)
64 if [ -n "$sorted" ]; then
74 # Source them all in the right order.
77 for j in $PROFILE_D/{,*/}$i; do
78 [ -e "$j" ] || continue
80 [ "${sourced/ $k /}" = "$sourced" ] || continue
82 sourced="$sourced $k "
87 # Maybe turn nocaseglob back on.
88 [ $nocg = 0 ] && shopt -s nocaseglob
89 # Maybe turn nullglob back off.
90 [ $nullglob = 0 ] || shopt -u nullglob
95 unset i j k d n dep deps path required unsorted sourced
96 unset lc_all nullglob nocg
98 # Don't inherit failure from the last script.