Skip to content

Commit 0d2f104

Browse files
Add custom install.sh (#19876)
Signed-off-by: Peter Zhu <[email protected]>
1 parent 69e230f commit 0d2f104

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

scripts/install.sh

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/bash
2+
3+
# Copyright OpenSearch Contributors
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# The OpenSearch Contributors require contributions made to
7+
# this file be licensed under the Apache-2.0 license or a
8+
# compatible open source license.
9+
10+
set -ex
11+
12+
function usage() {
13+
echo "Usage: $0 [args]"
14+
echo ""
15+
echo "Arguments:"
16+
echo -e "-v VERSION\t[Required] OpenSearch version."
17+
echo -e "-s SNAPSHOT\t[Optional] Build a snapshot, default is 'false'."
18+
echo -e "-p PLATFORM\t[Optional] Platform, default is 'uname -s'."
19+
echo -e "-a ARCHITECTURE\t[Optional] Build architecture, default is 'uname -m'."
20+
echo -e "-d DISTRIBUTION\t[Optional] Distribution, default is 'tar'."
21+
echo -e "-f ARTIFACTS\t[Optional] Location of build artifacts."
22+
echo -e "-o OUTPUT\t[Optional] Output path."
23+
echo -e "-h help"
24+
}
25+
26+
while getopts ":h:v:s:o:p:a:d:f:" arg; do
27+
case $arg in
28+
h)
29+
usage
30+
exit 1
31+
;;
32+
v)
33+
VERSION=$OPTARG
34+
;;
35+
s)
36+
SNAPSHOT=$OPTARG
37+
;;
38+
o)
39+
OUTPUT=$OPTARG
40+
;;
41+
p)
42+
PLATFORM=$OPTARG
43+
;;
44+
a)
45+
ARCHITECTURE=$OPTARG
46+
;;
47+
d)
48+
DISTRIBUTION=$OPTARG
49+
;;
50+
f)
51+
ARTIFACTS=$OPTARG
52+
;;
53+
:)
54+
echo "Error: -${OPTARG} requires an argument"
55+
usage
56+
exit 1
57+
;;
58+
?)
59+
echo "Invalid option: -${arg}"
60+
exit 1
61+
;;
62+
esac
63+
done
64+
65+
if [ -z "$VERSION" ]; then
66+
echo "Error: missing version."
67+
usage
68+
exit 1
69+
fi
70+
71+
if ! command -v yq > /dev/null; then
72+
echo "Error: yq not found, please install v4 version of yq"
73+
exit 1
74+
fi
75+
76+
[ -z "$SNAPSHOT" ] && SNAPSHOT="false"
77+
[ -z "$PLATFORM" ] && PLATFORM=$(uname -s | awk '{print tolower($0)}')
78+
[ -z "$ARCHITECTURE" ] && ARCHITECTURE=`uname -m`
79+
[ -z "$DISTRIBUTION" ] && DISTRIBUTION="tar"
80+
81+
# Make sure the cwd is where the script is located
82+
DIR="$(dirname "$0")"
83+
echo $DIR
84+
cd $DIR
85+
86+
## Copy the tar installation script into the bundle
87+
MAJOR_VERSION=`echo $VERSION | cut -d. -f1`
88+
if [ "$DISTRIBUTION" = "tar" ]; then
89+
cp -v ../../../scripts/startup/tar/linux/opensearch-tar-install.sh "$OUTPUT/"
90+
elif [ "$DISTRIBUTION" = "deb" ] || [ "$DISTRIBUTION" = "rpm" ]; then
91+
cp -va ../../../scripts/pkg/service_templates/opensearch/* "$OUTPUT/../"
92+
if [ "$MAJOR_VERSION" = "1" ]; then
93+
cp -va ../../../scripts/pkg/build_templates/1.x/opensearch/$DISTRIBUTION/* "$OUTPUT/../"
94+
elif [ "$MAJOR_VERSION" = "2" ]; then
95+
cp -va ../../../scripts/pkg/build_templates/2.x/opensearch/$DISTRIBUTION/* "$OUTPUT/../"
96+
else
97+
cp -va ../../../scripts/pkg/build_templates/current/opensearch/$DISTRIBUTION/* "$OUTPUT/../"
98+
OS_REF=`yq -e '.components[] | select(.name == "OpenSearch-DataFusion") | .ref' ../../../manifests/$VERSION/opensearch-$VERSION.yml`
99+
100+
# DEB and RPM has different default env file location
101+
ENV_FILE_PATH="$OUTPUT/../etc/sysconfig/opensearch"
102+
if [ "$DISTRIBUTION" = "deb" ]; then
103+
ENV_FILE_PATH="$OUTPUT/../etc/default/opensearch"
104+
fi
105+
106+
curl -SfL "https://raw.githubusercontent.com/opensearch-project/OpenSearch/$OS_REF/distribution/packages/src/common/env/opensearch" -o $ENV_FILE_PATH || { echo "Failed to download env file"; exit 1; }
107+
curl -SfL "https://raw.githubusercontent.com/opensearch-project/OpenSearch/$OS_REF/distribution/packages/src/common/systemd/opensearch.service" -o "$OUTPUT/../usr/lib/systemd/system/opensearch.service" || { echo "Failed to download env file"; exit 1; }
108+
109+
# k-NN lib setups
110+
echo -e "\n\n################################" >> $ENV_FILE_PATH
111+
echo -e "# Plugin properties" >> $ENV_FILE_PATH
112+
echo -e "################################" >> $ENV_FILE_PATH
113+
echo -e "\n# k-NN Lib Path" >> $ENV_FILE_PATH
114+
echo "LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/share/opensearch/plugins/opensearch-knn/lib" >> $ENV_FILE_PATH
115+
fi
116+
elif [ "$DISTRIBUTION" = "zip" ] && [ "$PLATFORM" = "windows" ]; then
117+
cp -v ../../../scripts/startup/zip/windows/opensearch-windows-install.bat "$OUTPUT/"
118+
fi

0 commit comments

Comments
 (0)