-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·87 lines (67 loc) · 2.37 KB
/
install.sh
File metadata and controls
executable file
·87 lines (67 loc) · 2.37 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
#!/bin/bash
# Logging helper
function write_log {
level=$1
message=$2
case $level in
"info") foreground_color="\e[34m" ;;
"success") foreground_color="\e[32m" ;;
"warn") foreground_color="\e[33m" ;;
"error") foreground_color="\e[31m" ;;
*) foreground_color="\e[97m" ;; # Default to white
esac
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
formatted_level="[$(echo "$level" | tr '[:lower:]' '[:upper:]')]"
formatted_message="$timestamp $formatted_level $message"
echo -e "$foreground_color$formatted_message\e[0m"
}
# GitHub repository details
version="0.1.9"
bin_name="licensa"
release_tag="v$version"
architecture=$(uname -m)
# Adjust asset_name_unpacked based on architecture
case "$architecture" in
"x86_64")
asset_name_unpacked="${bin_name}-${release_tag}-x86_64-linux"
;;
"aarch64")
asset_name_unpacked="${bin_name}-${release_tag}-aarch64-linux"
;;
*)
write_log "error" "Unsupported architecture: $architecture"
exit 1
;;
esac
asset_name_tar="${asset_name_unpacked}.tar.xz"
release_download_url="https://github.com/ekkolon/licensa/releases/download/$release_tag/$asset_name_tar"
# Target download directory
downloads_folder="/usr/local/src"
download_path="$downloads_folder/$asset_name_tar"
# Prompt the user for confirmation
read -p "This script is set to download and install Licensa CLI $release_tag.
Are you sure you want to proceed? (Type 'Y' for Yes, 'N' for No): " confirmation
if [[ "$confirmation" != 'Y' && "$confirmation" != 'y' ]]; then
write_log "info" "The installation process has been canceled"
exit
fi
write_log "info" "Detected architecture: $architecture"
# Download binary from GitHub release
write_log "info" "Downloading assets from GitHub ..."
wget -q "$release_download_url" -O "$download_path"
write_log "success" "Download succeeded!"
# Unpack the binary
write_log "info" "Unpacking..."
tar -xf "$download_path" -C "$downloads_folder"
write_log "success" "Successfully unpacked $asset_name_tar"
write_log "info" "Installing..."
destination_path="/usr/local/bin"
# Move unpacked source to destination
# TODO: Ask if should override, if path exists
source_folder="$downloads_folder/$asset_name_unpacked"
sudo cp -r "$source_folder"/* "$destination_path"
# Remove downloaded tar.gz
rm -rf "$download_path"
rm -rf "$source_folder"
write_log "success" "Licensa CLI has been installed successfully"
exit