-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
166 lines (129 loc) · 4.89 KB
/
install.sh
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
#!/bin/bash
echo "Updating system and installing required packages..."
sudo yum update -y
sudo yum -y install curl unzip
# URL and basic information
URL="https://tools.hana.ondemand.com/#cloud"
DOWNLOAD_BASE_URL="https://tools.hana.ondemand.com/additional"
# Function to update SAP Cloud Connector
update_scc() {
local INSTALLED_PACKAGE=$(rpm -qa | grep "com.sap.scc-ui")
local CURRENT_VERSION=$(echo "$INSTALLED_PACKAGE" | grep -oP "[0-9]+\.[0-9]+\.[0-9]+")
local NEW_VERSION=$(curl -s "$URL" | grep -oP "sapcc-\K[0-9.]+(?=-linux-x64.zip)" | sort -V | tail -n1)
update_common "SAP Cloud Connector" "sapcc" "$CURRENT_VERSION" "$NEW_VERSION"
}
# Function to update SAP JVM
update_jvm() {
local INSTALLED_PACKAGE=$(rpm -qa | grep "sapjvm")
local CURRENT_VERSION=$(echo "$INSTALLED_PACKAGE" | sed 's/sapjvm-\([^-]*\)-\([^-]*\).*/\1.\2/')
local NEW_VERSION=$(curl -s "$URL" | grep -oP "sapjvm-\K[0-9.]+(?=-linux-x64.zip)" | sort -V | tail -n1)
update_common "SAP JVM" "sapjvm" "$CURRENT_VERSION" "$NEW_VERSION" "rpm"
}
# Common update function
update_common() {
local PRODUCT_NAME=$1
local PRODUCT_PREFIX=$2
local CURRENT_VERSION=$3
local NEW_VERSION=$4
local FILE_TYPE=${5:-zip} # Default to zip if not specified
echo "Checking for $PRODUCT_NAME update..."
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
echo "The latest version of $PRODUCT_NAME is already installed: $CURRENT_VERSION"
return 0
fi
echo "The following version of the $PRODUCT_NAME would be installed: $NEW_VERSION"
read -p "Do you want to proceed with the installation? (y/N) " PROCEED_UPDATE
if [ "${PROCEED_UPDATE,,}" != "y" ]; then
echo "Installation aborted by the user."
return 1
fi
# Download and update process
download_and_update "$PRODUCT_NAME" "$PRODUCT_PREFIX" "$NEW_VERSION" "$FILE_TYPE"
}
# Download and update process
download_and_update() {
local PRODUCT_NAME=$1
local PRODUCT_PREFIX=$2
local NEW_VERSION=$3
local FILE_TYPE=$4
local DOWNLOAD_URL="$DOWNLOAD_BASE_URL/$PRODUCT_PREFIX-$NEW_VERSION-linux-x64.$FILE_TYPE"
local SHA1_URL="$DOWNLOAD_URL.sha1"
# Use a common cleanup function defined outside this scope
mkdir -p update_temp && cd update_temp || { echo "Failed to create/update directory."; exit 1; }
echo "Downloading the new $PRODUCT_NAME version..."
if ! curl -# -b "$EULA_COOKIE_NAME=$EULA_COOKIE_VALUE" -O "$DOWNLOAD_URL"; then
echo "Failed to download the $PRODUCT_NAME version."
cleanup
return 1
fi
echo "Downloading SHA1 hash..."
if ! curl -# -b "$EULA_COOKIE_NAME=$EULA_COOKIE_VALUE" -O "$SHA1_URL"; then
echo "Failed to download the SHA1 hash."
cleanup
return 1
fi
local FILENAME="$PRODUCT_PREFIX-$NEW_VERSION-linux-x64.$FILE_TYPE"
local SHA1_FILENAME="$FILENAME.sha1"
verify_hash "$FILENAME" "$SHA1_FILENAME"
if [ "$FILE_TYPE" = "zip" ]; then
unzip "$FILENAME"
fi
local RPM_PACKAGE=$(ls *.rpm)
echo "Install $PRODUCT_NAME..."
if ! sudo rpm -U "$RPM_PACKAGE"; then
echo "Installation failed."
cleanup
return 1
fi
cleanup
echo "$PRODUCT_NAME installation completed."
}
# Cleanup function
cleanup() {
echo "Cleaning up temporary files..."
cd ..
rm -rf update_temp
}
# Verify the SHA1 hash
verify_hash() {
local FILENAME=$1
local SHA1_FILENAME=$2
echo "Verifying the SHA1 hash..."
local SHA1SUM_EXPECTED=$(cat "$SHA1_FILENAME")
local SHA1SUM_ACTUAL=$(sha1sum "$FILENAME" | awk '{print $1}')
if [ "$SHA1SUM_EXPECTED" != "$SHA1SUM_ACTUAL" ]; then
echo "Hash verification failed. Install aborted."
cleanup
exit 1
fi
echo "Hash verification successful."
}
# Extract EULA information once for both updates
EULA_COOKIE_NAME=$(curl -s "$URL" | grep -oP "eulaConst.devLicense.cookieName = '\K[^']+" )
EULA_COOKIE_VALUE=$(curl -s "$URL" | grep -oP "eulaConst.devLicense.cookieValue = '\K[^']+" )
if [ -z "$EULA_COOKIE_VALUE" ]; then
echo "Failed to extract EULA cookie value."
exit 1
fi
EULA_URL="https://$EULA_COOKIE_VALUE"
echo "Please read the EULA at: $EULA_URL"
read -p "Do you accept the EULA? (y/N) " ACCEPT_EULA
if [ "${ACCEPT_EULA,,}" != "y" ]; then
echo "You did not accept the EULA. Install aborted."
exit 1
fi
# Ask user for each product update
read -p "Do you want to install SAP JVM? (y/N) " UPDATE_JVM
if [ "${UPDATE_JVM,,}" = "y" ]; then
update_jvm
fi
read -p "Do you want to install SAP Cloud Connector? (y/N) " UPDATE_SCC
if [ "${UPDATE_SCC,,}" = "y" ]; then
update_scc
fi
echo "All installations are completed."
echo ""
IP_ADDRESS=$(hostname -I | awk '{print $1}') # Gets the first IP address
echo "Login via https://${IP_ADDRESS}:8443"
echo "Username: Administrator"
echo "Password: manage"