-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot
executable file
·189 lines (162 loc) · 6.25 KB
/
boot
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
#
# NOTE: This file is AUTO-GENERATED once by '../.pgs/' by taking the file
# from https://github.com/pinf/genesis.pinf.org/blob/master/boot
# This file may be comitted to git and maintained manually from now on. If not committed
# to git, the file will be removed again on 'clean'.
# If you don't want './.pgs/' to leave any trace behind in your original code,
# DO NOT COMMIT THIS CODE (remove line if you decide to do so)
#
if [ -z "$HOME" ]; then
echo "ERROR: 'HOME' environment variable is not set!"
exit 1
fi
# Source https://github.com/cadorn/bash.origin
# NOTE: Setting up Bash.Origin is the ONLY SEQUENCE that MODIFIES OUTSIDE of the 'PGS_WORKSPACE_ROOT'!
export BO_ROOT_SCRIPT_PATH="$HOME/.bash.origin"
if [ ! -f "$BO_ROOT_SCRIPT_PATH" ]; then
# Not installed so we need to download & install.
# TODO: Alternatively use `wget`
curl "https://raw.githubusercontent.com/bash-origin/bash.origin/master/bash.origin?t=$(date +%s)" | BO="install" sh
fi
. "$BO_ROOT_SCRIPT_PATH"
function init {
eval BO_SELF_BASH_SOURCE="$BO_READ_SELF_BASH_SOURCE"
BO_deriveSelfDir ___TMP___ "$BO_SELF_BASH_SOURCE"
local __BO_DIR__="$___TMP___"
# Seed the PINF.Genesis System
export PGS_REGISTRY_DIRPATH="$HOME/.pgs.registry"
# TODO: Rename to 'PGS_WORKSPACE_DIRPATH'
export PGS_WORKSPACE_ROOT="$__BO_DIR__"
if [ -z "$PGS_PINF_DIRPATH" ]; then
export PGS_PINF_DIRPATH="$PGS_WORKSPACE_ROOT/.pinf"
fi
export PGS_PACKAGES_DIRPATH="$PGS_WORKSPACE_ROOT/.deps"
export BO_PACKAGES_DIR="$PGS_PACKAGES_DIRPATH"
if [ -z "$BO_GLOBAL_SYSTEM_CACHE_DIR" ]; then
BO_ensure_env_HOME "Use default .bash.origin.cache"
export BO_GLOBAL_SYSTEM_CACHE_DIR="$HOME/.bash.origin.cache"
fi
export BO_SYSTEM_CACHE_DIR="$BO_PACKAGES_DIR"
# Global static cache for SMI
if [ -z "$SMI_CACHE_DIRPATH" ]; then
export SMI_CACHE_DIRPATH="$PGS_PINF_DIRPATH/github.com~sourcemint~smi~0/cache"
fi
if [ -z "$PIO_PROFILE_PATH" ]; then
BO_realpath "PIO_PROFILE_PATH" "$__BO_DIR__/../$(basename $__BO_DIR__).profile.json"
if [ "$PIO_PROFILE_PATH" == "" ]; then
PIO_PROFILE_PATH="$__BO_DIR__/profile.json"
fi
export PIO_PROFILE_PATH
fi
# XDG Base Directory Specification
# @see http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
export XDG_DATA_HOME="$PGS_PINF_DIRPATH/standards.freedesktop.org~basedir-spec~0"
export XDG_CONFIG_HOME="$XDG_DATA_HOME/config"
export XDG_CONFIG_DIRS="$XDG_DATA_HOME/config"
export XDG_DATA_DIRS="$XDG_DATA_HOME/data"
export XDG_CACHE_HOME="$XDG_DATA_HOME/cache"
export XDG_RUNTIME_DIR="$XDG_DATA_HOME/runtime"
if [ -f "$BO_PACKAGES_DIR/github.com~bash-origin~bash.origin~0/source/installed/master/bash.origin" ]; then
# Use OUR Bash.Origin script from now on (even to handle the install if the previously
# installed version supports delegation).
export BO_ROOT_SCRIPT_PATH="$BO_PACKAGES_DIR/github.com~bash-origin~bash.origin~0/source/installed/master/bash.origin"
"$BO_ROOT_SCRIPT_PATH" BO install > /dev/null
fi
. "$BO_ROOT_SCRIPT_PATH"
BO_checkVerbose "VERBOSE" "$@"
# TODO: Move these elsewhere
if [ "$VERBOSE" == "1" ]; then
# @see https://github.com/kriskowal/q#long-stack-traces
export Q_DEBUG=1
fi
# if [ "$VERBOSE" == "1" ]; then
# if BO_has printenv ; then
# printenv
# fi
# fi
function activateProfile {
if [ -e "$__BO_DIR__/../$(basename $__BO_DIR__).activate.sh" ]; then
BO_sourcePrototype "$__BO_DIR__/../$(basename $__BO_DIR__).activate.sh"
fi
if [ -e "$PGS_PINF_DIRPATH/expand.genesis.pinf.org/uid" ]; then
export PGS_WORKSPACE_UID="`cat "$PGS_PINF_DIRPATH/expand.genesis.pinf.org/uid"`"
export PGS_WORKSPACE_UID_DOMAINSAFE=`echo "$PGS_WORKSPACE_UID" | sed 's/~/-/g' | sed 's/\./-/g'`
export PGS_PINF_EPOCH="$PGS_WORKSPACE_UID"
export PIO_PROFILE_KEY="$PGS_WORKSPACE_UID"
# TODO: Set these vars in plugins that get loaded here.
# i.e. load the script files from the plugins here by providing a
# given container environment.
export SM_KEEP_NS_RAW="$PGS_WORKSPACE_UID"
fi
}
activateProfile
BO_sourcePrototype "$__BO_DIR__/.pgs/pgs.sh" "boot"
activateProfile
if [ "$1" == "activate" ]; then
return 0
fi
# We always need to expand the PGS system to ensure all minimal code is in position.
pgsExpand $@
# We call it again to updated any changes after expansion.
activateProfile
function linkDependencies {
if [ ! -e "$__BO_DIR__/.pgs/.provisioned" ]; then
return 0
fi
# If a global dependency is present but not linked for the source installed aspect
# we link ours into the global namespace. We also link ours if it does not exist at all.
function linkDependency {
if [ ! -e "$1" ]; then
BO_log "$DEBUG" "Skip linking (source does not exist) '$1' to '$2'"
return 0;
fi
if [ ! -e "$2" ]; then
rm -Rf "$2" > /dev/null || true
fi
if [ -L "$2" ]; then
# Already a symlink so we leave it alone.
BO_log "$DEBUG" "Skip linking (already a symlink at target) '$1' to '$2'"
return 0
fi
# Replace file with symlink
rm -Rf "$2" > /dev/null || true
BO_log "$VERBOSE" "Linking '$1' to '$2'"
if [ ! -d "$(dirname "$2")" ]; then
mkdir -p "$(dirname "$2")"
fi
ln -s "$1" "$2"
}
linkDependency "$PGS_PACKAGES_DIRPATH/github.com~bash-origin~bash.origin~0/source/installed/master/bash.origin" "$HOME/.bash.origin"
# TODO: Use configurable base directory instead of assuming '$HOME'.
if [ ! -e "$HOME/.bash.origin.cache" ]; then
mkdir "$HOME/.bash.origin.cache"
fi
if [ -e "$PGS_WORKSPACE_ROOT/package.json" ]; then
if grep -q -e '"name": "genesis.pinf.org"' "$PGS_WORKSPACE_ROOT/package.json"; then
linkDependency "$__BO_DIR__" "$HOME/.bash.origin.cache/github.com~pinf~genesis.pinf.org~0/source/installed/master"
fi
fi
for dir in "$__BO_DIR__/.deps/"* ; do
dir="$(basename $dir)"
if [ -e "$__BO_DIR__/.deps/$dir/source/installed/master" ]; then
linkDependency "$__BO_DIR__/.deps/$dir/source/installed/master" "$HOME/.bash.origin.cache/$dir/source/installed/master"
fi
done
}
# TODO: Do this via a 'smi-for-bash.origin' module (the same one sm.expand uses).
linkDependencies
if [ "$1" == "expand" ]; then
return 0
fi
if [ "$1" == "turn" ]; then
pgsTurn ${*:2}
else
if [ "$PGS_BOOT_TO" == "turn" ]; then
pgsTurn $@
else
pgsSpin $@
fi
fi
}
init $@