-
Notifications
You must be signed in to change notification settings - Fork 0
/
txt
executable file
·239 lines (214 loc) · 5.67 KB
/
txt
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/bash
# This is the current stable release to default to, with Omnibus patch level (e.g. 10.12.0-1)
# Note that the chef template downloads 'x.y.z' not 'x.y.z-r' which should be a duplicate of the latest -r
use_shell=0
# Check whether a command exists - returns 0 if it does, 1 if it does not
exists() {
if command -v $1 &>/dev/null
then
return 0
else
return 1
fi
}
# Set the filename for a deb, based on version and machine
deb_filename() {
filetype="deb"
if [ $machine = "x86_64" ];
then
filename="chef_${version}_amd64.deb"
else
filename="chef_${version}_i386.deb"
fi
}
# Set the filename for an rpm, based on version and machine
rpm_filename() {
filetype="rpm"
filename="chef-${version}.${machine}.rpm"
}
# Set the filename for a Solaris SVR4 package, based on version and machine
svr4_filename() {
PATH=/usr/sfw/bin:$PATH
filetype="solaris"
filename="chef-${version}.${machine}.solaris"
}
# Set the filename for the sh archive
shell_filename() {
filetype="sh"
filename="chef-${version}-${platform}-${platform_version}-${machine}.sh"
}
report_bug() {
echo "Please file a bug report at http://tickets.opscode.com"
echo "Project: Chef"
echo "Component: Packages"
echo "Label: Omnibus"
echo "Version: $version"
echo " "
echo "Please detail your operating system type, version and any other relevant details"
}
# Get command line arguments
while getopts sv: opt
do
case "$opt" in
v) version="$OPTARG";;
s) use_shell=1;;
\?) # unknown flag
echo >&2 \
"usage: $0 [-s] [-v version]"
exit 1;;
esac
done
shift `expr $OPTIND - 1`
machine=$(echo -e `uname -m`)
# Retrieve Platform and Platform Version
if [ -f "/etc/lsb-release" ];
then
platform=$(grep DISTRIB_ID /etc/lsb-release | cut -d "=" -f 2 | tr '[A-Z]' '[a-z]')
platform_version=$(grep DISTRIB_RELEASE /etc/lsb-release | cut -d "=" -f 2)
elif [ -f "/etc/debian_version" ];
then
platform="debian"
platform_version=$(echo -e `cat /etc/debian_version`)
elif [ -f "/etc/redhat-release" ];
then
platform=$(sed 's/^\(.\+\) release.*/\1/' /etc/redhat-release | tr '[A-Z]' '[a-z]')
platform_version=$(sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/redhat-release)
# If /etc/redhat-release exists, we act like RHEL by default
if [ "$platform" = "fedora" ];
then
# Change platform version for use below.
platform_version="6.0"
fi
platform="el"
elif [ -f "/etc/system-release" ];
then
platform=$(sed 's/^\(.\+\) release.\+/\1/' /etc/system-release | tr '[A-Z]' '[a-z]')
platform_version=$(sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/system-release | tr '[A-Z]' '[a-z]')
# amazon is built off of fedora, so act like RHEL
if [ "$platform" = "amazon linux ami" ];
then
platform="el"
platform_version="6.0"
fi
# Apple OS X
elif [ -f "/usr/bin/sw_vers" ];
then
platform="mac_os_x"
# Matching the tab-space with sed is error-prone
platform_version=$(sw_vers | awk '/^ProductVersion:/ { print $2 }')
major_version=$(echo $platform_version | cut -d. -f1,2)
case $major_version in
"10.6") platform_version="10.6" ;;
"10.7") platform_version="10.7" ;;
*) echo "No builds for platform: $major_version"
report_bug
exit 1
;;
esac
# x86_64 Apple hardware often runs 32-bit kernels (see OHAI-63)
x86_64=$(sysctl -n hw.optional.x86_64)
if [ $x86_64 -eq 1 ]; then
machine="x86_64"
fi
elif [ -f "/etc/release" ];
then
platform="solaris2"
machine=$(/usr/bin/uname -p)
platform_version=$(/usr/bin/uname -r)
fi
if [ "x$platform" = "x" ];
then
echo "Unable to determine platform version!"
report_bug
exit 1
fi
# Mangle $platform_version to pull the correct build
# for various platforms
major_version=$(echo $platform_version | cut -d. -f1)
case $platform in
"el")
case $major_version in
"5") platform_version="5" ;;
"6") platform_version="6" ;;
esac
;;
"debian")
case $major_version in
"5") platform_version="6";;
"6") platform_version="6";;
esac
;;
esac
if [ "x$platform_version" = "x" ];
then
echo "Unable to determine platform version!"
report_bug
exit 1
fi
if [ $use_shell = 1 ];
then
shell_filename
else
case $platform in
"ubuntu") deb_filename ;;
"debian") deb_filename ;;
"el") rpm_filename ;;
"fedora") rpm_filename ;;
"solaris2") svr4_filename ;;
*) shell_filename ;;
esac
fi
echo "Downloading Chef $version for ${platform}..."
url="http://www.opscode.com/chef/download?v=${version}&p=${platform}&pv=${platform_version}&m=${machine}"
if exists wget;
then
downloader="wget"
wget -O /tmp/$filename $url 2>/tmp/stderr
elif exists curl;
then
downloader="curl"
curl -L $url > /tmp/$filename
else
echo "Cannot find wget or curl - cannot install Chef!"
exit 5
fi
# Check to see if we got a 404 or an empty file
unable_to_retrieve_package() {
echo "Unable to retrieve a valid package!"
report_bug
echo "URL: $url"
exit 1
}
if [ $downloader == "curl" ]
then
#do curl stuff
grep "The specified key does not exist." /tmp/$filename 2>&1 >/dev/null
if [ $? -eq 0 ] || [ ! -s /tmp/$filename ]
then
unable_to_retrieve_package
fi
elif [ $downloader == "wget" ]
then
#do wget stuff
grep "ERROR 404" /tmp/stderr 2>&1 >/dev/null
if [ $? -eq 0 ] || [ ! -s /tmp/$filename ]
then
unable_to_retrieve_package
fi
fi
echo "Installing Chef $version"
case "$filetype" in
"rpm") rpm -Uvh /tmp/$filename ;;
"deb") dpkg -i /tmp/$filename ;;
"solaris") echo "conflict=nocheck" > /tmp/nocheck
echo "action=nocheck" >> /tmp/nocheck
pkgadd -n -d /tmp/$filename -a /tmp/nocheck chef
;;
"sh" ) bash /tmp/$filename --nox11 ;;
esac
if [ $? -ne 0 ];
then
echo "Installation failed"
report_bug
exit 1
fi