-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathinstall_ipm.sh
More file actions
117 lines (101 loc) · 3 KB
/
install_ipm.sh
File metadata and controls
117 lines (101 loc) · 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
#!/usr/bin/env bash
set -e
APPNAME="ipm"
# Global installation dir for Linux/macOS
INSTALL_DIR="/usr/local/bin"
# Detect OS + ARCH
OS="$(uname | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
# Normalize architecture
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
esac
EXT=""
if [[ "$OS" == "mingw"* || "$OS" == "cygwin"* || "$OS" == "msys"* ]]; then
OS="windows"
EXT=".exe"
INSTALL_DIR="$USERPROFILE/.local/bin"
fi
TARGET="$INSTALL_DIR/$APPNAME$EXT"
DOWNLOAD_URL="https://github.com/HexmosTech/Installerpedia/releases/latest/download/ipm-$OS-$ARCH$EXT"
###################################
# On Linux/macOS, prompt for sudo upfront
###################################
if [[ "$OS" != "windows" ]]; then
echo "==> Installation requires sudo. You may be asked for your password."
sudo -v # prompt for password upfront
fi
###################################
# Ensure install dir exists
###################################
if [[ "$OS" != "windows" ]]; then
sudo mkdir -p "$INSTALL_DIR"
fi
###################################
# Check existing binary
###################################
if [[ -f "$TARGET" ]]; then
if [[ "$OS" != "windows" ]]; then
if [[ -x "$TARGET" ]] && file "$TARGET" | grep -q 'ELF\|Mach-O'; then
echo "==> $APPNAME already installed and valid at $TARGET"
echo "Run it using: $APPNAME"
exit 0
else
echo "==> Invalid binary found, reinstalling..."
sudo rm -f "$TARGET"
fi
else
echo "==> $APPNAME already exists at $TARGET"
echo "Run it using: $TARGET"
exit 0
fi
fi
INSTALL_ID="install-$(date +%s)-$RANDOM"
# Track installation start
(
curl -s -X POST "https://us.i.posthog.com/i/v0/e/" \
-H "Content-Type: application/json" \
-d "{
\"api_key\": \"phc_bC7cMka8DieEik61bxec1xAg3hANE8oNNGoelwXoE9I\",
\"event\": \"ipm_install_started\",
\"distinct_id\": \"$INSTALL_ID\",
\"properties\": {
\"os\": \"$OS\",
\"arch\": \"$ARCH\",
\"method\": \"curl\"
}
}" >/dev/null 2>&1
) &
###################################
# Download binary
###################################
echo "==> Installing $APPNAME ($OS-$ARCH) to $INSTALL_DIR ..."
echo "==> Downloading from $DOWNLOAD_URL ..."
if [[ "$OS" != "windows" ]]; then
sudo curl -L "$DOWNLOAD_URL" -o "$TARGET"
sudo chmod +x "$TARGET"
else
curl -L "$DOWNLOAD_URL" -o "$TARGET"
fi
# Track installation success
(
curl -s -X POST "https://us.i.posthog.com/i/v0/e/" \
-H "Content-Type: application/json" \
-d "{
\"api_key\": \"phc_bC7cMka8DieEik61bxec1xAg3hANE8oNNGoelwXoE9I\",
\"event\": \"ipm_install_succeeded\",
\"distinct_id\": \"$INSTALL_ID\",
\"properties\": {
\"os\": \"$OS\",
\"arch\": \"$ARCH\",
\"method\": \"curl\"
}
}" >/dev/null 2>&1
) &
echo "==> Installation complete!"
if [[ "$OS" == "windows" ]]; then
echo "Run it using: $TARGET"
else
echo "Run it using: $APPNAME"
fi