-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·83 lines (60 loc) · 2.07 KB
/
install.sh
File metadata and controls
executable file
·83 lines (60 loc) · 2.07 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
#!/bin/sh
set -e
BINARY_NAME="devsetup"
DESTINATION_FOLDER="$HOME/.local/bin"
RAW_CONTENT_URL="https://raw.githubusercontent.com/shetty-tejas/devsetup/refs/heads/master"
BINARY_FILE_LOCATION="$DESTINATION_FOLDER/$BINARY_NAME"
# Utility Functions
# Function to echo messages to STDERR.
error() { printf "ERROR: %b\n" "$1" >&2; }
# Function to echo messages to STDOUT.
log() { printf "%b\n" "$1"; }
# Command Functions.
# Function to install devsetup.
install() {
if [ -e "$BINARY_FILE_LOCATION" ]; then
error "'$BINARY_NAME' already exists in '$DESTINATION_FOLDER'.\n\nOptions:\n - To update: Run '$BINARY_NAME update-self'.\n - To add to PATH: Add '$DESTINATION_FOLDER' to your PATH variable."
exit 1
fi
binary_url="$RAW_CONTENT_URL/$BINARY_NAME"
temp_file=$(mktemp)
log "Downloading 'devsetup'...\n"
if command -v curl >/dev/null 2>&1; then
if ! curl -s -S -f "$binary_url" -o "$temp_file"; then
error "Failed to download the latest version."
rm -f "$temp_file"
exit 1
fi
else
error "'curl' not found."
rm -f "$temp_file"
exit 1
fi
# Check if the download was successful and the file is not empty
if [ ! -s "$temp_file" ]; then
error "Downloaded file is empty."
rm -f "$temp_file"
exit 1
fi
# Make sure the downloaded file is a valid shell script
first_line=$(head -n 1 "$temp_file")
if log "$first_line" | grep -Eq '^#!.*[ /](bash|sh)'; then
:
else
error "Downloaded file doesn't appear to be a valid shell script."
rm -f "$temp_file"
exit 1
fi
log "Making directory at '$DESTINATION_FOLDER' if it doesn't exist..."
mkdir -p "$DESTINATION_FOLDER"
log "Writing the script at '$BINARY_FILE_LOCATION'..."
touch "$BINARY_FILE_LOCATION"
cat "$temp_file" >"$BINARY_FILE_LOCATION"
chmod +x "$BINARY_FILE_LOCATION"
log "Cleaning up...\n"
rm -f "$temp_file"
log "Installed '$BINARY_NAME' at '$DESTINATION_FOLDER'. Please add this location to your PATH if not already done."
log "Run '$BINARY_NAME init-config' to initialize a sample configuration file."
exit 0
}
install