-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstaller.sh
More file actions
141 lines (124 loc) · 3.88 KB
/
installer.sh
File metadata and controls
141 lines (124 loc) · 3.88 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
set -e
set -eo pipefail
print_error_message() {
echo "An error occurred. Please visit <link_needed> for assistance."
}
trap 'if [ $? -ne 0 ]; then print_error_message; fi' EXIT
awsctlpath="$HOME/awsctl/"
printf "\\e[1mINSTALLATION\\e[0m\\n"
if [ -d "$awsctlpath" ]; then
echo "Previous installation detected."
else
mkdir "${awsctlpath}"
echo "Created $awsctlpath folder."
fi
ARCH=$(uname -m)
if [ "$ARCH" = "arm64" ]; then
ARCH="arm64"
elif [ "$ARCH" = "x86_64" ]; then
ARCH="amd64"
else
echo "Unsupported architecture: $ARCH"
exit 1
fi
OS_NAME=$(uname -s)
VERSION=${1:-latest} # Accept version as an argument, default to 'latest' if not provided
if [ "$VERSION" = "latest" ]; then
# Use latest release API to avoid redirects
LATEST_TAG=$(curl -s https://api.github.com/repos/BerryBytes/awsctl/releases/latest | grep 'tag_name' | cut -d '"' -f 4)
if [ -z "$LATEST_TAG" ]; then
echo "Error: Could not fetch latest version"
exit 1
fi
VERSION=$LATEST_TAG
fi
# Validate version format
if [[ ! "$VERSION" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]]; then
echo "Error: Invalid version format '$VERSION'"
echo "Please use format like: v1.2.3 or latest"
exit 1
fi
case "$OS_NAME" in
Darwin|Linux)
FILENAME="awsctl_${OS_NAME}_${ARCH}"
;;
*)
echo "Error: Unsupported OS '$OS_NAME'"
echo "Check releases: https://github.com/BerryBytes/awsctl/releases"
exit 1
;;
esac
DOWNLOAD_URL="https://github.com/BerryBytes/awsctl/releases/download/${VERSION}/${FILENAME}"
trap 'echo; echo "Download interrupted."; exit 1' INT
echo "Downloading awsctl ${VERSION} for ${OS_NAME}/${ARCH}..."
if ! curl -fL --retry 3 --retry-delay 2 --connect-timeout 30 "$DOWNLOAD_URL" -o "$HOME/awsctl/awsctl"; then
echo "Error: Download failed (URL: $DOWNLOAD_URL)"
echo "Possible reasons:"
echo "1. Version $VERSION doesn't exist"
echo "2. No build for ${OS_NAME}/${ARCH}"
echo "3. Network issues"
echo "Check available releases: https://github.com/BerryBytes/awsctl/releases"
exit 1
fi
# Verify the downloaded file
if [ ! -s "$HOME/awsctl/awsctl" ]; then
echo "Error: Downloaded file is empty or missing"
exit 1
fi
echo "Download completed successfully"
chmod +x "$HOME/awsctl/awsctl"
if [ $? -eq 0 ]; then
echo ""
else
echo "Error: chmod failed."
exit 1
fi
CURRENT_SHELL="$SHELL"
if [[ "$CURRENT_SHELL" = "/bin/bash" || "$CURRENT_SHELL" = "/usr/bin/bash" ]]; then
echo "Detected Bash shell."
CONFIG_FILE="$HOME/.bashrc"
if grep -q '^[^#]*awsctl' "$CONFIG_FILE"; then
echo "The PATH is already set in $CONFIG_FILE."
else
echo "export PATH=\"$HOME/awsctl:\$PATH\"" >>"$CONFIG_FILE"
source "$CONFIG_FILE"
fi
elif [[ "$CURRENT_SHELL" = "/bin/zsh" || "$CURRENT_SHELL" = "/usr/bin/zsh" ]]; then
echo "Detected Zsh shell."
CONFIG_FILE="$HOME/.zshrc"
if grep -q '^[^#]*awsctl' "$CONFIG_FILE"; then
echo "The PATH is already set in $CONFIG_FILE."
else
echo "export PATH=\"$HOME/awsctl:\$PATH\"" >>"$CONFIG_FILE"
echo ""
zsh
fi
elif [[ "$CURRENT_SHELL" = "/bin/fish" || "$CURRENT_SHELL" = "/usr/bin/fish" ]]; then
echo "Detected Fish shell."
fish -c "set -U fish_user_paths \"$HOME/awsctl\" \$fish_user_paths"
else
printf "\\e[1mFAILURE\\e[0m\\n"
echo "Unsupported shell detected: $CURRENT_SHELL"
echo "Please set the PATH manually."
echo "See <link_needed>"
fi
echo ""
printf "\\e[1m------INSTALLATION COMPLETED------\\e[0m\\n"
echo ""
printf "\\e[1mSUMMARY\\e[0m\\n"
echo " awsctl is a CLI tool for managing AWS resources."
echo ""
printf "\\e[1mUSAGE\\e[0m\\n"
echo " awsctl --help"
echo ""
printf "\\e[1mUNINSTALL\\e[0m\\n"
echo " everything is installed into ~/awsctl/,"
echo " so you can remove it like so:"
echo ""
echo " rm -rf ~/awsctl/"
echo ""
printf "\\e[1mTIP\\e[0m\\n"
printf " Inorder to use awsctl in this terminal, please run \\e[34msource ~/.bashrc\\e[0m or your own shell CONFIG_FILE\n"
echo ""
exit