Skip to content

Commit 7e3dfd2

Browse files
committed
allow latest download
1 parent 4008d60 commit 7e3dfd2

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

latest.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
print_help() {
6+
echo "Installs latest version of pcp. Installation directory defaults to /usr/local/bin."
7+
echo -e
8+
echo "Usage:"
9+
echo "installer.sh [<dir>]"
10+
exit 1
11+
}
12+
13+
default_install_dir="/usr/local/bin"
14+
install_dir=$default_install_dir
15+
install_dir_opt=${1:-}
16+
if [ "$install_dir_opt" ]; then
17+
install_dir="$install_dir_opt"
18+
fi
19+
20+
download_dir=/tmp
21+
22+
latest_release="$(curl -sL https://raw.githubusercontent.com/alekcz/pcp/master/resources/PCP_VERSION)"
23+
24+
case "$(uname -s)" in
25+
Linux*) platform=linux;;
26+
Darwin*) platform=macos;;
27+
esac
28+
29+
download_url="https://github.com/alekcz/pcp/releases/download/$latest_release/pcp-$latest_release-$platform-amd64.zip"
30+
31+
cd "$download_dir"
32+
echo -e "Downloading $download_url."
33+
curl -o "pcp-$latest_release-$platform-amd64.zip" -sL "https://github.com/alekcz/pcp/releases/download/$latest_release/pcp-$latest_release-$platform-amd64.zip"
34+
unzip -qqo "pcp-$latest_release-$platform-amd64.zip"
35+
rm "pcp-$latest_release-$platform-amd64.zip"
36+
mkdir -p "/usr/local/etc/pcp-db"
37+
mkdir -p "$install_dir/pcp-templates"
38+
39+
cd "$install_dir"
40+
if [ -f pcp ]; then
41+
pcp service stop
42+
mv -f "$install_dir/pcp" "$install_dir/pcp.old"
43+
mv -f "$install_dir/pcp-server.jar" "$install_dir/pcp-server.old.jar"
44+
echo "Moving $install_dir/pcp to $install_dir/pcp.old"
45+
echo "Moving $install_dir/pcp-server.jar to $install_dir/pcp-server.old.jar"
46+
fi
47+
48+
mv -f "$download_dir/pcp" "$PWD/pcp"
49+
50+
mv -f "$download_dir/pcp-server.jar" "$PWD/pcp-server.jar"
51+
52+
rm -rf "$PWD/pcp-templates"
53+
mv -f "$download_dir/pcp-templates" "$PWD"
54+
55+
case "$(uname -s)" in
56+
Linux*)
57+
mv -f "$download_dir/pcp.service" "/etc/systemd/system/pcp.service"
58+
systemctl enable pcp.service
59+
systemctl start pcp.service
60+
#systemctl stop pcp.service
61+
;;
62+
Darwin*)
63+
mv -f "$download_dir/com.alekcz.pcp.plist" ~/Library/LaunchAgents/com.alekcz.pcp.plist
64+
chown "$(id -un):$(id -g)" ~/Library/LaunchAgents/com.alekcz.pcp.plist
65+
launchctl load -w ~/Library/LaunchAgents/com.alekcz.pcp.plist
66+
#launchctl unload ~/Library/LaunchAgents/com.alekcz.pcp.plist
67+
;;
68+
esac
69+
70+
chmod a+x "$PWD/pcp"
71+
pcp service start
72+
echo "Successfully installed pcp in $install_dir."

0 commit comments

Comments
 (0)