-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild
More file actions
executable file
·172 lines (145 loc) · 4.24 KB
/
build
File metadata and controls
executable file
·172 lines (145 loc) · 4.24 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env bash
##
# Farpy - A programming language
#
# Copyright (c) 2025 Fernando (FernandoTheDev)
#
# This software is licensed under the MIT License.
# See the LICENSE file in the project root for full license information.
##
# Installation script for farpy
# Usage: ./build {install|remove|build}
# Safety configuration for bash
set -euo pipefail
BIN_NAME="farpy"
INSTALL_PATH="/usr/local/bin/$BIN_NAME"
LIBS="./stdlib/*"
FARPY_DIR="${HOME}/.farpy"
HOME_STDLIBS="${FARPY_DIR}/libs"
LOG_FILE="${FARPY_DIR}/install.log"
# Colors for terminal output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log_message() {
local type=$1
local message=$2
local symbol=""
local color=$NC
case $type in
"info") symbol="ℹ️" && color=$BLUE ;;
"success") symbol="✅" && color=$GREEN ;;
"warning") symbol="⚠️" && color=$YELLOW ;;
"error") symbol="❌" && color=$RED ;;
*) symbol="•" ;;
esac
echo -e "${color}${symbol} ${message}${NC}"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$type] $message" >>"$LOG_FILE" 2>/dev/null || true
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
check_prerequisites() {
log_message "info" "Checking prerequisites..."
if ! command_exists deno; then
log_message "error" "Deno is required but not found. Please install Deno first."
log_message "info" "Visit https://deno.land/#installation for installation instructions."
exit 1
fi
}
ensure_directories() {
mkdir -p "$FARPY_DIR" "$HOME_STDLIBS"
touch "$LOG_FILE"
log_message "info" "Created necessary directories at $FARPY_DIR"
}
build() {
log_message "info" "Building $BIN_NAME..."
if deno task compile; then
log_message "success" "Build completed successfully."
else
log_message "error" "Build failed. See logs for details."
exit 1
fi
}
install_bin() {
check_prerequisites
ensure_directories
log_message "info" "Starting installation process for $BIN_NAME..."
build
log_message "info" "Copying standard libraries to $HOME_STDLIBS..."
if [[ -d "./stdlib" ]]; then
cp -rf $LIBS "$HOME_STDLIBS"
else
log_message "warning" "Standard library directory not found. Installation might be incomplete."
fi
log_message "info" "Installing $BIN_NAME to $INSTALL_PATH..."
if [[ -f "bin/$BIN_NAME" ]]; then
if sudo install -m 0755 "bin/$BIN_NAME" "$INSTALL_PATH"; then
log_message "success" "$BIN_NAME installed successfully at $INSTALL_PATH"
log_message "info" "You can now run '$BIN_NAME' from anywhere."
else
log_message "error" "Failed to install binary. Check permissions."
exit 1
fi
else
log_message "error" "Binary not found at bin/$BIN_NAME. Build may have failed."
exit 1
fi
}
remove_bin() {
log_message "info" "Preparing to remove $BIN_NAME..."
if [[ -f "$INSTALL_PATH" ]]; then
if sudo rm -f "$INSTALL_PATH"; then
log_message "success" "Removed binary from $INSTALL_PATH"
else
log_message "error" "Failed to remove binary. Check permissions."
exit 1
fi
else
log_message "warning" "Binary not found at $INSTALL_PATH. Nothing to remove."
fi
if [[ -d "$FARPY_DIR" ]]; then
log_message "info" "Removing configuration directory..."
if rm -rf "$FARPY_DIR"; then
log_message "success" "Removed configuration directory at $FARPY_DIR"
else
log_message "warning" "Failed to remove configuration directory."
fi
fi
log_message "success" "Uninstallation completed."
}
show_help() {
cat <<EOF
Farpy Installation Script
Usage:
$0 install - Build and install farpy
$0 build - Build only without installing
$0 remove - Remove farpy from your system
$0 help - Display this help message
For more information, visit the documentation.
EOF
}
case "${1:-help}" in
"install")
install_bin
;;
"build")
check_prerequisites
ensure_directories
build
;;
"remove")
remove_bin
;;
"help")
show_help
;;
*)
log_message "error" "Unknown command: ${1:-}"
show_help
exit 1
;;
esac
exit 0