-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
43 lines (30 loc) · 1.11 KB
/
install.sh
File metadata and controls
43 lines (30 loc) · 1.11 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
#!/bin/bash
set -e
APP_NAME="study"
INSTALL_DIR="/usr/local/bin"
SOURCE_FILE="main.go"
PROJECT_ROOT="$(dirname "$0")"
if [ "$EUID" -ne 0 ]; then
echo "Error: This script must be run as root."
echo "Usage: sudo ./install.sh"
exit 1
fi
if ! command -v go &> /dev/null; then
echo "Error: Go is not installed or not in PATH."
exit 1
fi
go build -ldflags "-s -w" -o $APP_NAME $SOURCE_FILE # -s -w for a smaller binary
install -m 755 "$APP_NAME" "$INSTALL_DIR/$APP_NAME"
rm "$APP_NAME"
if [ -d "$BASH_COMP_DIR" ] && [ -f "$PROJECT_ROOT/completions/study.bash" ]; then
install -m 644 -D "$PROJECT_ROOT/completions/study.bash" "/etc/bash_completion.d/$APP_NAME"
fi
ZSH_COMP_DIR="/usr/share/zsh/site-functions"
if [ -d "$ZSH_COMP_DIR" ] && [ -f "$PROJECT_ROOT/completions/_study" ]; then
install -m 644 "$PROJECT_ROOT/completions/_study" "$ZSH_COMP_DIR/_$APP_NAME"
fi
echo "Restart your terminal for auto completion to take effect."
echo " Usage:"
echo " sudo $APP_NAME on # To block sites"
echo " sudo $APP_NAME off # To unblock sites"
echo " sudo $APP_NAME status # To check the current status"