-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·69 lines (58 loc) · 2.3 KB
/
install.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
#!/bin/sh
# Check if the system is Linux
if [ $(uname) != 'Linux' ]; then
echo "This script is designed for linux only, sorry!"
exit 1
fi
set -e
# Define text formatting variables
RED='[1;31m'
GREEN='[1;32m'
YELLOW='[1;33m'
CYAN='[1;36m'
BOLD='[1m'
RESET='[0m'
# Print a cool banner
printf '\n%b' $CYAN && cat << 'EOF'
▪ ▄▄
▪ ██ ██▌
▄█▀▄ ▐█·▐█·
▐█▌.▐▌▐█▌.▀
▀█▄▀▪▀▀▀ ▀
EOF
printf '%b' $RESET
# Check if running as root
if [ $(id -u) = 0 ]; then
printf "%bwarning:%b please don't run random scripts you find on the internet as root!\n" $YELLOW $RESET
printf '%bsudo or doas will be used when elevated privileges are required%b\n' $BOLD $RESET
exit 1
fi
# Check for cargo (Rust package manager)
if !command -v cargo >/dev/null 2>&1; then
printf '%berror:%b can not find %bcargo%b in your $PATH, please ensure it is correctly installed\n' $RED $RESET $BOLD $RESET
exit 1
fi
# Determine the available privilege escalation command (sudo or doas)
if command -v sudo >/dev/null 2>&1; then
PRIV_ESC='sudo'
elif command -v doas >/dev/null 2>&1; then
PRIV_ESC='doas'
else
printf '%berror:%b can not find %bsudo%b or %bdoas%b in your $PATH, one of these is required\n' $RED $RESET $BOLD $RESET $BOLD $RESET
exit 1
fi
# Navigate to the script's directory
cd "$(dirname "$0")"
# Build the binary using cargo
printf '%bSTEP 1:%b %bbuilding the binary%b (this may take a few minutes)\n\n' $GREEN $RESET $BOLD $RESET
cargo build --release
# Strip debug symbols from the binary if strip is available
command -v strip >/dev/null 2>&1 && strip -s ./target/release/pooi
# Copy necessary files to system directories
printf '\n%bSTEP 2:%b %bcopying files%b (elevated privileges are required)\n\n' $GREEN $RESET $BOLD $RESET
$PRIV_ESC install -Dvm755 ./target/release/pooi /usr/local/bin/pooi
$PRIV_ESC install -Dvm644 ./etc/completions/_oi /usr/share/zsh/site-functions/_oi
$PRIV_ESC install -Dvm644 ./etc/completions/pooi.bash /usr/share/bash-completion/completions/pooi
$PRIV_ESC install -Dvm644 ./etc/completions/pooi.fish /usr/share/fish/vendor_completions.d/pooi.fish
# Print completion message
printf '\n%bDONE:%b %bthanks for testing! %b<3%b (this repo is no longer needed and can be deleted)\n' $GREEN $RESET $BOLD $RED $RESET