-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·89 lines (79 loc) · 2.51 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# Define the target directory where the swtp script will be placed
TARGET_DIR="$HOME/.swtp/bin"
VERSION_FILE="$HOME/.swtp/version"
# Create the target directories if they don't exist
mkdir -p "$TARGET_DIR"
# Download the latest tagged version of swtp script from the repository
LATEST_TAG=$(curl -s https://api.github.com/repos/kisztof/swtp/tags | grep -o '"name": "[^"]*' | head -n 1 | sed 's/"name": "//')
if [ $? -ne 0 ]; then
echo "Failed to fetch the latest tag. Exiting."
exit 1
fi
# Store the version in a file
echo "$LATEST_TAG" > "$VERSION_FILE"
curl -L "https://raw.githubusercontent.com/kisztof/swtp/$LATEST_TAG/bin/swtp.sh" -o "$TARGET_DIR/swtp"
if [ $? -ne 0 ]; then
echo "Failed to download swtp. Exiting."
exit 1
fi
# Make swtp executable
chmod +x "$TARGET_DIR/swtp"
if [ $? -ne 0 ]; then
echo "Failed to make swtp executable. Exiting."
exit 1
fi
echo "swtp has been installed successfully in $TARGET_DIR."
# Determine the shell profile file based on the current shell
SHELL_PROFILE=""
case "$SHELL" in
*/bash)
SHELL_PROFILE="$HOME/.bashrc"
;;
*/zsh)
SHELL_PROFILE="$HOME/.zshrc"
;;
*/fish)
SHELL_PROFILE="$HOME/.config/fish/config.fish"
;;
*/csh)
SHELL_PROFILE="$HOME/.cshrc"
;;
*/ksh)
SHELL_PROFILE="$HOME/.kshrc"
;;
*/dash)
SHELL_PROFILE="$HOME/.dashrc"
;;
*)
echo "Unsupported shell. Please update your PATH manually."
exit 1
;;
esac
# Update PATH in the shell profile if it doesn't already contain the target directory
if [ -n "$SHELL_PROFILE" ] && ! grep -q "export PATH=\"$TARGET_DIR:\$PATH\"" "$SHELL_PROFILE"; then
case "$SHELL" in
*/fish)
echo "set -gx PATH $TARGET_DIR \$PATH" >> "$SHELL_PROFILE"
;;
*)
echo "export PATH=\"$TARGET_DIR:\$PATH\"" >> "$SHELL_PROFILE"
;;
esac
echo "PATH has been updated. You may need to restart your shell or run 'source $SHELL_PROFILE'."
else
echo "PATH already contains $TARGET_DIR. No changes were made."
fi
read -p "Would you like to restart your shell to apply changes? (y/n): " choice
case "$choice" in
y|Y)
# Restart the shell
exec "$SHELL"
;;
n|N)
echo "You may need to restart your shell or run 'source $SHELL_PROFILE' to apply changes."
;;
*)
echo "Invalid option. You may need to restart your shell or run 'source $SHELL_PROFILE' to apply changes."
;;
esac