forked from PierreBeucher/cloudypad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·179 lines (150 loc) · 6.3 KB
/
install.sh
File metadata and controls
executable file
·179 lines (150 loc) · 6.3 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
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
# Installation arguments
# Override by setting related environment variable
DEFAULT_CLOUDYPAD_SCRIPT_REF=v0.38.0
CLOUDYPAD_HOME=${CLOUDYPAD_HOME:-"$HOME/.cloudypad"}
CLOUDYPAD_SCRIPT_REF=${CLOUDYPAD_SCRIPT_REF:-$DEFAULT_CLOUDYPAD_SCRIPT_REF}
# Use a unique ID for installer script as we can't identify user at this point
INSTALL_POSTHOG_ID="cli-install"
INSTALL_POSTHOG_API_KEY="phc_caJIOD8vW5727svQf90FNgdALIyYYouwEDEVh3BI1IH"
# Sends anonymous technical analytics event during installation
# No personal data is sent
send_analytics_event() {
event=$1
eventDetails=$2
if [ "$CLOUDYPAD_ANALYTICS_DISABLE" != "true" ]; then
curl -s -o /dev/null -L --header "Content-Type: application/json" -d "{
\"api_key\": \"$INSTALL_POSTHOG_API_KEY\",
\"event\": \"$event\",
\"distinct_id\": \"$INSTALL_POSTHOG_ID\",
\"properties\": {
\"\$process_person_profile\": false,
\"event_details\": \"$eventDetails\",
\"os_name\": \"$(uname -s)\",
\"os_arch\": \"$(uname -m)\"
}
}" https://eu.i.posthog.com/capture/
fi
}
exit_with_error() {
error_message=$1
send_analytics_event "cli_install_error" "$error_message"
exit 1
}
send_analytics_event "cli_install_start"
echo "Installing Cloudy Pad version $CLOUDYPAD_SCRIPT_REF"
CLOUDYPAD_SCRIPT_URL="https://raw.githubusercontent.com/PierreBeucher/cloudypad/$CLOUDYPAD_SCRIPT_REF/cloudypad.sh"
# ===
# Constants, do not override
INSTALL_DIR="$CLOUDYPAD_HOME/bin"
SCRIPT_NAME="cloudypad"
SCRIPT_PATH="$INSTALL_DIR/cloudypad"
# Check if cloudypad is already in PATH
if command -v cloudypad >/dev/null 2>&1; then
CURRENT_CLOUDYPAD_PATH=$(command -v cloudypad)
# Read from /dev/tty to ensure read will work even if script is piped to shell such as install.sh | sh
echo "cloudypad is already installed at ${CURRENT_CLOUDYPAD_PATH}. Do you want to overwrite it? (y/N): "
read CONFIRM < /dev/tty
if [[ "$CONFIRM" != "y" ]]; then
echo "Installation aborted."
exit 1
fi
fi
if [ "$CLOUDYPAD_INSTALL_SKIP_DOCKER_CHECK" != "true" ]; then
# Check if Docker is installed and usable
if ! docker --version > /dev/null; then
echo "Docker is not installed or running 'docker --version' failed. Please make sure you have a working Docker installation. See https://docs.docker.com/engine/install/"
exit_with_error "docker --version failed"
fi
# Check if Docker daemon is accessible
if ! docker info > /dev/null; then
echo "Docker is installed but not usable. Have you added yourself to docker group? See https://docs.docker.com/engine/install/linux-postinstall/"
echo "You might need to run 'sudo usermod -aG docker \$USER' and restart your logout / log back before being able to use Docker"
exit_with_error "docker info failed"
fi
fi
# Create secure directory for Cloudy Pad home as it may contain sensitive data
mkdir -p "$CLOUDYPAD_HOME"
chmod 0700 $CLOUDYPAD_HOME
mkdir -p "$INSTALL_DIR"
echo "Downloading $CLOUDYPAD_SCRIPT_URL..."
if command -v curl >/dev/null 2>&1; then
curl --fail -sSL -o "$SCRIPT_PATH" "$CLOUDYPAD_SCRIPT_URL"
elif command -v wget >/dev/null 2>&1; then
wget -O "$SCRIPT_PATH" "$CLOUDYPAD_SCRIPT_URL"
else
echo "Error: Neither curl nor wget is available to download Cloudy Pad. Please install wget or curl and try again."
exit_with_error "missing curl/wget"
fi
chmod +x "$SCRIPT_PATH"
echo "Downloading Cloudy Pad container images..."
# Skip download of container images if Docker install check is skipped
# Will be done on first run anyway
if [ "$CLOUDYPAD_INSTALL_SKIP_DOCKER_CHECK" != "true" ]; then
$SCRIPT_PATH download-container-images
fi
# Identify shell to adapt behavior accordingly
SHELL_NAME=$(basename "${SHELL}")
echo "Detected shell: '$SHELL_NAME'"
STARTUP_FILE=""
case "${SHELL_NAME}" in
"bash")
# Terminal.app on macOS prefers .bash_profile to .bashrc, so we prefer that
# file when trying to put our export into a profile. On *NIX, .bashrc is
# preferred as it is sourced for new interactive shells.
if [ "$(uname)" != "Darwin" ]; then
if [ -e "${HOME}/.bashrc" ]; then
STARTUP_FILE="${HOME}/.bashrc"
elif [ -e "${HOME}/.bash_profile" ]; then
STARTUP_FILE="${HOME}/.bash_profile"
else
# Default to .bashrc if both are absent
STARTUP_FILE="${HOME}/.bashrc"
fi
else
if [ -e "${HOME}/.bash_profile" ]; then
STARTUP_FILE="${HOME}/.bash_profile"
elif [ -e "${HOME}/.bashrc" ]; then
STARTUP_FILE="${HOME}/.bashrc"
else
# Default to .bash_profile if both are absent
STARTUP_FILE="${HOME}/.bash_profile"
fi
fi
;;
"zsh")
STARTUP_FILE="${ZDOTDIR:-$HOME}/.zshrc"
;;
*)
echo
echo "WARNING: Couldn't identify startup file to use (such as .bashrc or .zshrc) for your current shell."
echo " Detected shell from \$SHELL=$SHELL environment variable: '$SHELL_NAME'"
echo " To finalize installation please ensure $INSTALL_DIR is on your \$PATH"
echo " Otherwise you may not be able to run Cloudy Pad CLI."
echo " Alternatively, use directly $SCRIPT_PATH to run Cloudy Pad CLI."
echo " If you think this is a bug, please create an issue: https://github.com/PierreBeucher/cloudypad/issues"
;;
esac
if [ -n "${STARTUP_FILE}" ]; then
# Create startup file if it does not exists. Rare situation but may happen
touch "${STARTUP_FILE}"
LINE_TO_ADD="export PATH=\$PATH:${INSTALL_DIR}"
if ! grep -q "# add CloudyPad CLI PATH" "${STARTUP_FILE}"; then
echo "Adding ${INSTALL_DIR} to \$PATH in ${STARTUP_FILE}"
printf "\\n# add CloudyPad CLI PATH\\n%s\\n\\n" "${LINE_TO_ADD}" >> "${STARTUP_FILE}"
fi
echo "Successfully installed Cloudy Pad 🥳"
echo
echo "Restart your shell to add cloudypad on your PATH or run:"
echo
echo " source $STARTUP_FILE"
echo
fi
echo
echo "Get started by creating a Cloudy Pad instance:"
echo
echo " cloudypad create"
echo
echo "If you enjoy Cloudy Pad, please star us ⭐ https://github.com/PierreBeucher/cloudypad"
echo "🐛 Found a bug? Create an issue: https://github.com/PierreBeucher/cloudypad/issues"
echo
send_analytics_event "cli_install_finish"