-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·176 lines (161 loc) · 4.62 KB
/
install
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
#!/bin/bash
function usage {
echo ""
echo "Installs or updates dkr"
echo ""
echo "$0 [OPTIONS]"
echo ""
column -t -s':' <<< "
--bin-file=${DKR_BIN_PATH} : The location the dkr bin file should be installed. This should be on the PATH.
--bin-path=${DKR_BIN_DIR_PATH} : The location the built-in extention files should be installed to.
: These will be deleted and reinstalled every time the install script is run.
: User extensions should be put in the DKR_HOME directory instead.
--home=${DKR_HOME} : The location user extention files should be put.
--profile=${DKR_PROFILE} : The location of the user's bash profile file.
: A simple 'source' line for the dkr profile file will be added to this file the first time the installer is run.
--dkr-profile-file=${DKR_PROFILE_FILE} : The location the dkr profile should be installed to.
: This file ensures that all the environment variables and functions required are available in the bash session.
--docker-command=$(which docker) : The location of the docker bin.
--debug : Prints debug information
--help : Prints this help file.
"
}
help=false
while [ "$1" != "" ]; do
case "$1" in
--bin-file)
DKR_BIN_PATH="$2"
shift
;;
--bin-path)
DKR_BIN_DIR_PATH="$2"
shift
;;
--home)
DKR_HOME="$2"
shift
;;
--profile)
if [ "$DKR_PROFILE" != "$2" ] && [ "$DKR_PROFILE" != "" ]; then
echo "WARNING: Cannot use flag '--profile' if it's been previously set. Ignoring."
else
DKR_PROFILE="$2"
fi
shift
;;
--dkr-profile-file)
if [ "$DKR_PROFILE_FILE" != "$2" ] && [ "$DKR_PROFILE_FILE" != "" ]; then
echo "WARNING: Cannot use flag '--dkr-profile-file' if it's been previously set. Ignoring."
else
DKR_PROFILE_FILE="$2"
fi
shift
;;
--docker-command)
DKR_DOCKER_COMMAND="$2"
shift
;;
--debug)
set -x
shift
;;
--no-pull)
NO_PULL=true
;;
--help)
help=true
;;
*)
echo "Unknown flag: '$1'"
exit 1
;;
esac
shift
done
if [ "${DKR_BIN_DIR_PATH}" == "" ]; then
if [ -d ~/bin ]; then
DKR_BIN_DIR_PATH=~/bin/.dkr_builtins
else
DKR_BIN_DIR_PATH=/usr/local/var/dkr
fi
fi
if [ "${DKR_BIN_PATH}" == "" ]; then
if [ -d /usr/local/bin/dkr ]; then
# for compatibility with existing installs
DKR_BIN_PATH=/usr/local/bin/dkr
else
DKR_BIN_PATH=~/bin/dkr
fi
fi
if [ "${DKR_HOME}" == "" ]; then
DKR_HOME=~/.dkr
fi
if [ "${DKR_PROFILE}" == "" ]; then
if [ -f ~/.bashrc ]; then
DKR_PROFILE=~/.bashrc
else
DKR_PROFILE=~/.profile
fi
fi
if [ "${DKR_PROFILE_FILE}" == "" ]; then
DKR_PROFILE_FILE=~/.dkrprofile
fi
if [ "${DKR_DOCKER_COMMAND}" == "" ]; then
DKR_DOCKER_COMMAND="$(which docker)"
fi
if [ "${help}" == "true" ]; then
export DKR_BIN_DIR_PATH
export DKR_BIN_PATH
export DKR_HOME
export DKR_PROFILE
export DKR_PROFILE_FILE
export DKR_DOCKER_COMMAND
usage
exit 0
fi
if [ -d .git ]; then
if [ "${NO_PULL}" != "true" ]; then
echo "Attempting to update the repo."
git pull 1> /dev/null 2> /dev/null
if [ "$?" != "0" ]; then
echo "Unable to update repo. There are probably local changes that conflict."
fi
fi
fi
2>/dev/null 1>/dev/null grep '# ADDED BY DKR' "${DKR_PROFILE}"
if [ "$?" == "0" ]; then
echo "Detected dkr was previously installed."
installed=true
else
installed=false
fi
# Older version of dkr installed by linking things. Make sure the links are gone.
2>/dev/null 1>/dev/null unlink "${DKR_BIN_DIR_PATH}"
2>/dev/null 1>/dev/null unlink "${DKR_BIN_PATH}"
rm -rf "${DKR_BIN_DIR_PATH}"
rm -f "${DKR_BIN_PATH}"
mkdir -p "${DKR_HOME}"
mkdir -p "${DKR_BIN_DIR_PATH}"
cp dkr "${DKR_BIN_PATH}"
cp home/* "${DKR_BIN_DIR_PATH}"
if [ "${installed}" != "true" ]; then
if [ ! -f "${DKR_PROFILE}" ]; then
echo "WARNING: ${DKR_PROFILE} doesn't exist. It will be created."
fi
echo "# ADDED BY DKR" >> ${DKR_PROFILE}
echo "if [ -f \"${DKR_PROFILE_FILE}\" ]; then" >> ${DKR_PROFILE}
echo " source \"${DKR_PROFILE_FILE}\"" >> ${DKR_PROFILE}
echo "fi" >> ${DKR_PROFILE}
fi
# (Re)generate the DKR_PROFILE_FILE which should be sourced into the bash profile
echo "export DKR_HOME=\"${DKR_HOME}\"" > "${DKR_PROFILE_FILE}"
echo "export DKR_BIN_DIR_PATH=\"${DKR_BIN_DIR_PATH}\"" >> "${DKR_PROFILE_FILE}"
echo "export DKR_BIN_PATH=\"${DKR_BIN_PATH}\"" >> "${DKR_PROFILE_FILE}"
echo "export DKR_PROFILE=\"${DKR_PROFILE}\"" >> "${DKR_PROFILE_FILE}"
echo "export DKR_PROFILE_FILE=\"${DKR_PROFILE_FILE}\"" >> "${DKR_PROFILE_FILE}"
echo "export DKR_DOCKER_COMMAND=\"${DKR_DOCKER_COMMAND}\"" >> "${DKR_PROFILE_FILE}"
cat profileFile >> "${DKR_PROFILE_FILE}"
echo "Successfully installed dkr to \"${DKR_BIN_PATH}\". You may need to restart your bash session or run:"
echo ""
echo "source \"${DKR_PROFILE_FILE}\""
echo ""