-
Notifications
You must be signed in to change notification settings - Fork 7
/
doppler-installer.sh
executable file
·186 lines (148 loc) · 4.46 KB
/
doppler-installer.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check if curl is installed
if ! command_exists curl; then
echo "Error: curl is not installed. Please install curl and try again."
exit 1
fi
# Check if tar is installed
if ! command_exists tar; then
echo "Error: tar is not installed. Please install tar and try again."
exit 1
fi
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# Check if nvm is installed
if ! command -v nvm &> /dev/null; then
echo "Error: nvm is not installed. Please install nvm via 'https://github.com/nvm-sh/nvm' and try again."
exit 1
fi
nvm install --lts
# Function to get OS and architecture
get_os_arch() {
local os=$(uname -s | tr '[:upper:]' '[:lower:]')
local arch=$(uname -m)
case "$os" in
linux*)
os="linux"
;;
darwin*)
os="darwin"
;;
*)
echo "Unsupported OS: $os"
exit 1
;;
esac
case "$arch" in
x86_64)
arch="x86_64"
;;
aarch64|arm64)
arch="aarch64"
;;
*)
echo "Unsupported architecture: $arch"
exit 1
;;
esac
echo "${os}-${arch}"
}
# Check if version is provided
if [ $# -eq 0 ]; then
echo "Error: Please provide a version number."
echo "Usage: $0 <version>"
exit 1
fi
VERSION="$1"
OS_ARCH=$(get_os_arch)
# Base URL
BASE_URL="https://github.com/tee8z/doppler/releases/download"
get_cpu_architecture() {
if [[ "$(uname)" == "Darwin" ]]; then
echo $(uname -m)
else
echo $(uname -m)
fi
}
system=$(uname | tr '[:upper:]' '[:lower:]')
arch=$(get_cpu_architecture)
if [[ "$system" == "linux" ]]; then
filename="doppler-${arch}-unknown-linux-gnu.tar.xz"
elif [[ "$system" == "darwin" ]]; then
if [[ "$arch" == "x86_64" ]]; then
filename="doppler-x86_64-apple-darwin.tar.xz"
elif [[ "$arch" == "arm64" ]] || [[ "$arch" == "aarch64" ]]; then
filename="doppler-aarch64-apple-darwin.tar.xz"
fi
else
filename="doppler-${system}-${arch}.tar.xz"
fi
# Construct the full URL
URL="${BASE_URL}/${VERSION}/${filename}"
echo "Filename: $filename"
# Destination folder
DEST_FOLDER="$HOME/.doppler"
# Create the destination folder if it doesn't exist
mkdir -p "$DEST_FOLDER"
echo "Downloading Doppler @ ${URL}"
# Extract the base name from the filename (remove .tar.xz)
BASE_NAME=$(basename "$filename" .tar.xz)
# Set the destination folder
DEST_FOLDER="$HOME/.doppler/${VERSION}"
# Create the destination folder
mkdir -p "$DEST_FOLDER"
# Download and extract the file
curl --proto '=https' --tlsv1.2 -LsSf "$URL" | tar -xJ --strip-components=1 -C "$DEST_FOLDER"
# Check if the extraction was successful
if [ $? -eq 0 ]; then
echo "Successfully downloaded and extracted Doppler ${VERSION} to $DEST_FOLDER"
else
echo "Error: Failed to download or extract Doppler ${VERSION}"
exit 1
fi
# Path to the original configuration file
CONFIG_FILE="$HOME/.doppler/${VERSION}/build/ui_config/server.conf.ini"
# Read the content of the original file
if [ ! -f "$CONFIG_FILE" ]; then
echo "Error: Configuration file not found at $CONFIG_FILE"
exit 1
fi
CONFIG_CONTENT=$(cat "$CONFIG_FILE")
# Update the paths by replacing $DEST_FOLDER with its actual value
UPDATED_CONFIG=$(echo "$CONFIG_CONTENT" | sed "s|\\\$DEST_FOLDER|$DEST_FOLDER|g")
# Save the updated configuration back to the original file
echo "$UPDATED_CONFIG" > "$CONFIG_FILE"
echo "Configuration updated in $CONFIG_FILE"
# Display the changes (optional)
echo "Changes made:"
diff <(echo "$CONFIG_CONTENT") <(echo "$UPDATED_CONFIG")
if [ -f "$DEST_FOLDER/package.json" ]; then
mv "$DEST_FOLDER/package.json" "$DEST_FOLDER/build/"
else
echo "Warning: package.json not found in $DEST_FOLDER"
fi
if [ -f "$DEST_FOLDER/package-lock.json" ]; then
mv "$DEST_FOLDER/package-lock.json" "$DEST_FOLDER/build/"
else
echo "Warning: package-lock.json not found in $DEST_FOLDER"
fi
if [ -d "$DEST_FOLDER/build/" ]; then
echo "Changing to $DEST_FOLDER/build/ and running npm install"
(
cd "$DEST_FOLDER/build/" && \
npm install || echo "npm install failed"
)
else
echo "Error: $DEST_FOLDER/build/ does not exist"
fi
# Create .env file
cat << EOF > "$DEST_FOLDER/.env"
USERID=1000
GROUPID=1000
EOF
echo ".env file created in $DEST_FOLDER"
echo "Install completed."