-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_sh_fix.patch
More file actions
147 lines (140 loc) · 4.51 KB
/
setup_sh_fix.patch
File metadata and controls
147 lines (140 loc) · 4.51 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
--- setup.sh.orig
+++ setup.sh
@@ -8,7 +8,9 @@
set -e
# Strict mode
-set -euo pipefail
+# Modified to handle unbound variables more gracefully
+# The 'u' flag was causing errors with unbound variables
+set -eo pipefail
IFS=$'\n\t'
# ===== Color Definitions =====
@@ -67,10 +69,22 @@
}
# Error handler
-handle_error() {
+original_handle_error() {
local line=$1
local exit_code=$2
- log "ERROR" "Script failed at line $line with exit code $exit_code"
+ log "ERROR" "Script failed at line $line with exit code ${exit_code:-1}"
+ log "WARNING" "Please check the logs for details and fix the issue"
+ log "INFO" "For assistance, consult the documentation or contact support"
+}
+
+# Enhanced error handler with more detailed information
+handle_error() {
+ local line=$1
+ local exit_code=${2:-1}
+
+ log "ERROR" "Script failed at line $line with exit code $exit_code"
+ log "ERROR" "Command that failed: $(sed -n "${line}p" $0 2>/dev/null || echo "Unknown command")"
+ log "ERROR" "Current working directory: $(pwd)"
log "WARNING" "Please check the logs for details and fix the issue"
log "INFO" "For assistance, consult the documentation or contact support"
}
@@ -87,7 +101,7 @@
APP_HOME=${APP_HOME:-"/opt/jobscraper"}
APP_PORT=${APP_PORT:-5001}
APP_NAME=${APP_NAME:-"jobscraper"}
-PYTHON_VERSION=${PYTHON_VERSION:-"3.10"}
+PYTHON_VERSION=${PYTHON_VERSION:-"3.10"}
POSTGRES_VERSION=${POSTGRES_VERSION:-"15"}
USE_NGINX=${USE_NGINX:-"true"}
USE_SSL=${USE_SSL:-"true"}
@@ -1696,13 +1710,30 @@
log "SUCCESS" "Job Scraper Application has been successfully set up!"
}
+# Process command line arguments safely
+process_args() {
+ # Initialize options with default values
+ UNINSTALL=false
+ HELP=false
+ NO_VERIFY=false
+
+ # Process arguments
+ for arg in "$@"; do
+ case "$arg" in
+ --uninstall) UNINSTALL=true ;;
+ --help) HELP=true ;;
+ --no-verify) NO_VERIFY=true ;;
+ *) log "WARNING" "Unknown option: $arg" ;;
+ esac
+ done
+}
+
# ===== Main Execution =====
# Print banner
cat << 'EOF'
___ _ _____
|_ | | | / ___|
- | | ___ | |__ \ `--. ___ _ __ __ _ _ __ ___ _ __
+ | | ___ | |__ \ `--. ___ _ __ __ _ _ __ ___ _ __
| |/ _ \| '_ \ `--. \/ __| '__/ _` | '_ \ / _ \ '__|
/\__/ / (_) | |_) |/\__/ / (__| | | (_| | |_) | __/ |
\____/ \___/|_.__/ \____/ \___|_| \__,_| .__/ \___|_|
@@ -1713,22 +1744,51 @@
log "INFO" "Starting Job Scraper Production Setup"
log "INFO" "This script will set up the Job Scraper application for production use"
-
-# Check if uninstall was requested
-if [ "$1" = "--uninstall" ]; then
- log "WARNING" "Uninstall mode requested"
- log "INFO" "This will remove the Job Scraper application from your system"
- log "INFO" "Are you sure you want to continue? (y/n)"
- read -r confirm
- if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
- log "INFO" "Uninstall canceled"
- exit 0
- fi
- uninstall_application
- log "SUCCESS" "Uninstallation completed"
- exit 0
+
+# Process command line arguments safely
+process_args "$@"
+
+# Handle --help flag
+if [ "$HELP" = true ]; then
+ cat << EOF
+Usage: $0 [OPTIONS]
+
+This script sets up the Job Scraper application for production use.
+
+Options:
+ --uninstall Uninstall the Job Scraper application
+ --no-verify Skip verification step
+ --help Display this help message
+
+Example:
+ $0 # Install the application
+ $0 --uninstall # Uninstall the application
+EOF
+ exit 0
fi
+# Handle uninstall mode
+if [ "$UNINSTALL" = true ]; then
+ (
+ log "WARNING" "Uninstall mode requested"
+ log "INFO" "This will remove the Job Scraper application from your system"
+ log "INFO" "Are you sure you want to continue? (y/n)"
+ read -r confirm
+ if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
+ log "INFO" "Uninstall canceled"
+ exit 0
+ fi
+
+ # Create a backup before uninstalling
+ log "INFO" "Creating backup before uninstall"
+ backup_dir="/opt/jobscraper_backup_$(date +%Y%m%d%H%M%S)"
+ mkdir -p "$backup_dir"
+ cp -r /opt/jobscraper/* "$backup_dir/" 2>/dev/null || true
+
+ uninstall_application
+ log "SUCCESS" "Uninstallation completed"
+ exit 0
+ )
+fi
# Run installation steps
check_system_requirements
update_system_packages