-
Notifications
You must be signed in to change notification settings - Fork 0
/
daybreak_install.bash
executable file
·115 lines (100 loc) · 3.52 KB
/
daybreak_install.bash
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
#! /bin/bash
set -e
COMPILER_BACKENDS="gcc clang zig"
function _choose_compiler_backend() {
if [ $# -eq 0 ]; then
echo "Could not find a supported compiler backend!"
echo "Please install and make available on PATH one of the following:"
echo ${COMPILER_BACKENDS}
exit 1
fi
CC_COMPILER=$1
shift
echo "Checking for compiler backend ${CC_COMPILER}"
if ! command -v ${CC_COMPILER} &> /dev/null; then
echo "Missing compiler backend ${CC_COMPILER}"
_choose_compiler_backend $@
fi
}
function bootstrap_install() {
echo "Bootstrapping Daybreak for the local installation..."
DAYBREAK_BOOTSTRAP=${DAYBREAK_REPO_FOLDER}/bootstrap/${OS}/daybreak
DAYBREAK_OUTPUT=${DAYBREAK_HOME}/bin/daybreak
if [[ ${OS} = "windows" ]]; then
DAYBREAK_BOOTSTRAP=${DAYBREAK_BOOTSTRAP}.exe
DAYBREAK_OUTPUT=${DAYBREAK_OUTPUT}.exe
fi
export C_INCLUDE_PATH=${DAYBREAK_SOURCE_FOLDER}/include
${DAYBREAK_BOOTSTRAP} ${DAYBREAK_SOURCE_FOLDER}/main.day -o ${DAYBREAK_OUTPUT} >> /dev/null
echo "Successfully bootstrapped Daybreak!"
}
function print_export_env() {
echo ""
echo "Identifying default shell and the associated rcfile..."
RC_FILE=${HOME}/.$(basename $(echo ${SHELL}))rc
echo "Identified:"
echo " shell -> ${SHELL}"
echo " rcfile -> ${RC_FILE}"
echo ""
echo "##############"
echo "# Next Steps #"
echo "##############"
echo "Run all of the following commands in your terminal to finish the Daybreak installation"
echo "The first two commands persist the configuration chosen by this install script"
echo "The third command adds daybreak tools to your PATH for every login session and not just the current login session"
echo ""
echo "echo '############' >> ${RC_FILE}"
echo "echo '# Daybreak #' >> ${RC_FILE}"
echo "echo '############' >> ${RC_FILE}"
echo "echo '' >> ${RC_FILE}"
echo "echo 'export CC_COMPILER=${CC_COMPILER}' >> ${RC_FILE}"
echo "echo 'export DAYBREAK_HOME=${DAYBREAK_HOME}' >> ${RC_FILE}"
echo 'echo '"'"'export PATH=${DAYBREAK_HOME}/bin:${PATH}'"'"''" >> ${RC_FILE}"
echo "# If you want to develop for Daybreak, run the following line as well"
echo "echo 'export C_INCLUDE_PATH=${DAYBREAK_SOURCE_FOLDER}/include' >> ${RC_FILE}"
echo "# Run the next command to activate daybreak tools for the current terminal session"
echo "source ${RC_FILE}"
echo ""
echo "Daybreak should now be fully configured and tools available on your path!"
}
function set_default_env() {
echo "Checking environment variables and temporarily setting default values for unset env vars"
echo ""
echo "Identifying OS..."
case "$(uname -s)" in
Linux*) OS=linux;;
Darwin*) OS=osx;;
CYGWIN*) OS=windows;;
MINGW*) OS=windows;;
*) echo "Failed to identify OS"; exit 1;;
esac
echo "Identified OS as ${OS}"
echo ""
if [ -z ${CC_COMPILER} ]; then
_choose_compiler_backend ${COMPILER_BACKENDS}
echo "CC_COMPILER set to default: ${CC_COMPILER} -> $(which ${CC_COMPILER})"
else
echo "CC_COMPILER already set to: ${CC_COMPILER} -> $(which ${CC_COMPILER})"
fi
if [ -z ${DAYBREAK_HOME} ]; then
DAYBREAK_HOME=${HOME}/.daybreak
echo "DAYBREAK_HOME set to default: ${DAYBREAK_HOME}"
else
echo "DAYBREAK_HOME already set to: ${DAYBREAK_HOME}"
fi
if [[ ${OS} = "linux" ]]; then
update-alternatives --set cc $(which ${CC_COMPILER})
fi
echo ""
}
if [ $# -eq 0 ]; then
DAYBREAK_REPO_FOLDER=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)
DAYBREAK_SOURCE_FOLDER=${DAYBREAK_REPO_FOLDER}/src
else
DAYBREAK_REPO_FOLDER=$1
shift
DAYBREAK_SOURCE_FOLDER=${DAYBREAK_REPO_FOLDER}/src
fi
set_default_env
bootstrap_install
print_export_env