-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·147 lines (134 loc) · 3.84 KB
/
install
File metadata and controls
executable file
·147 lines (134 loc) · 3.84 KB
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
#!/bin/bash
function usage {
echo ""
echo "Installs or updates dkr"
echo ""
echo "$0 [OPTIONS]"
echo ""
column -t -s':' <<< "
--bin-file=/usr/local/var/dkr : The location the dkr bin file should be installed.
--bin-path=/usr/local/bin/dkr : The location the built-in extention files should be installed to.
--home=~/.dkr : The location user extention files should be put.
--profile=~/.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=~/.dkrprofile : 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.
"
}
while [ "$1" != "" ]; do
case "$1" in
--bin-file)
DKR_BIN_DIR_PATH="$2"
shift
;;
--bin-path)
DKR_BIN_PATH="$2"
shift
;;
--home)
DKR_HOME="$2"
shift
;;
--profile)
if [ "$DKR_PROFILE" != "$2" ]; 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" != "$2" ]; 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)
usage
exit 0
;;
*)
echo "Unknown flag: '$1'"
exit 1
;;
esac
shift
done
if [ "${DKR_BIN_DIR_PATH}" == "" ]; then
DKR_BIN_DIR_PATH=/usr/local/var/dkr
fi
if [ "${DKR_BIN_PATH}" == "" ]; then
DKR_BIN_PATH=/usr/local/bin/dkr
fi
if [ "${DKR_HOME}" == "" ]; then
DKR_HOME=~/.dkr
fi
if [ "${DKR_PROFILE}" == "" ]; then
DKR_PROFILE=~/.profile
fi
if [ "${DKR_PROFILE_FILE}" == "" ]; then
DKR_PROFILE_FILE=~/.dkrprofile
fi
if [ "${DKR_DOCKER_COMMAND}" == "" ]; then
DKR_DOCKER_COMMAND="$(which docker)"
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 "source \"${DKR_PROFILE_FILE}\"" >> ${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 ""