-
Notifications
You must be signed in to change notification settings - Fork 0
/
installTaskIt.sh
82 lines (59 loc) · 2 KB
/
installTaskIt.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
#!/bin/bash
APP_NAME="taskit"
# Add the path to the Go binary
export PATH=$PATH:/usr/local/go/bin
# Print the PATH variable for debugging
echo "PATH: $PATH"
# Check if the script is run as root
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root (use sudo)." 1>&2
exit 1
fi
# Check if an executable with the same name exists in the user's path
if command -v $APP_NAME > /dev/null; then
echo "An executable named '$APP_NAME' is already in your PATH. Please choose a different name or make sure you're not overwriting something important."
exit 1
fi
# Warning message
echo "WARNING: This script will install '$APP_NAME' system-wide."
read -p "Do you want to continue? (y/n): " confirm
if [ "$confirm" != "y" ]; then
echo "Installation cancelled."
exit 0
fi
# Compile the program
echo "Compiling '$APP_NAME'..."
go build -o $APP_NAME
# Hash the binary
HASH=$(sha256sum "$APP_NAME" | awk '{ print $1 }')
# Move to /usr/local/bin
echo "Installing '$APP_NAME' to /usr/local/bin..."
mv $APP_NAME /usr/local/bin/
# Make it executable
echo "Making '$APP_NAME' executable..."
chmod +x /usr/local/bin/$APP_NAME
# Write uninstall script with the hash for verification
cat <<EOL > uninstallTaskIt.sh
#!/bin/bash
# Hash of the installed file
INSTALLED_HASH="$HASH"
# Destination for the binary
DESTINATION="/usr/local/bin/$APP_NAME"
# Hash the currently installed binary
CURRENT_HASH=\$(sha256sum "\$DESTINATION" | awk '{ print \$1 }')
# Verify the hash
if [ "\$INSTALLED_HASH" != "\$CURRENT_HASH" ]; then
echo "Hash mismatch. The file at \$DESTINATION may not be the correct taskit binary."
exit 1
fi
# If hash matches, uninstall
rm "\$DESTINATION"
echo "$APP_NAME uninstalled successfully."
# Delete this uninstall script
echo "Removing uninstall script..."
rm -- "uninstallTaskIt.sh"
echo "Uninstall complete."
EOL
# Make the uninstall script executable
chmod +x uninstallTaskIt.sh
echo "'$APP_NAME' installed successfully. You can now use it from anywhere! Run 'uninstallTaskIt.sh' to uninstall."