Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·208 lines (166 loc) · 5.41 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·208 lines (166 loc) · 5.41 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/bash
# The file is part of the "webifycms/installer", WebifyCMS installer package.
#
# @see https://webifycms.com
# @copyright Copyright (c) 2023 - Present WebifyCMS
# @license https://webifycms.com/license
# @author Mohammed Shifreen <mshifreen@gmail.com>
# =================================================
# WebifyCMS Installer Script
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
GRAY='\033[38;5;244m'
info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
check_prerequisites() {
local missing_deps=0
info "Checking prerequisites..."
if ! command_exists php; then
error "php is not installed."
missing_deps=1
else
local php_version=$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;")
if [[ "$php_version" < "8.4" ]]; then
error "PHP 8.4 or higher is required. Current version: $php_version"
missing_deps=1
fi
fi
if ! command_exists composer; then
error "composer is not installed."
missing_deps=1
fi
if [ $missing_deps -ne 0 ]; then
error "Please install the missing dependencies and try again."
exit 1
fi
info "All prerequisites met."
}
install_development() {
check_prerequisites
local base_dir
base_dir=$(cd .. && pwd)
local app_dir="$base_dir/app"
local ext_base_dir="$base_dir/extensions/ext-base"
local themes_dir="$base_dir/themes"
info "Installing in $base_dir..."
info "Preparing directories..."
mkdir -p "$base_dir/extensions"
mkdir -p "$themes_dir"
info "Cloning repositories..."
clone_repo() {
local repo=$1
local dir=$2
if [ -d "$dir" ]; then
warn "Directory $dir already exists, skipping clone."
else
git clone "$repo" "$dir"
fi
}
clone_repo "https://github.com/webifycms/app.git" "$app_dir"
clone_repo "https://github.com/webifycms/ext-base.git" "$ext_base_dir"
if [ ! -d "$app_dir" ]; then
error "App directory not found. Clone failed?"
exit 1
fi
if [ ! -f "$app_dir/.env" ]; then
info "Setting up environment..."
cp "$app_dir/.env.example" "$app_dir/.env"
sed -i 's/APP_ENV=.*/APP_ENV=development/' "$app_dir/.env"
sed -i 's/APP_DEBUG=.*/APP_DEBUG=true/' "$app_dir/.env"
sed -i '/^DATABASE_/d' "$app_dir/.env"
info "Environment configured."
else
warn ".env already exists, skipping configuration."
fi
if [ ! -f "$app_dir/composer.local.json" ]; then
info "Creating composer.local.json..."
cp "$app_dir/composer.json" "$app_dir/composer.local.json"
# shellcheck disable=SC2016
php -r '
$path = $argv[1];
$json = json_decode(file_get_contents($path), true);
$json["repositories"] = [
[
"type" => "path",
"url" => "../extensions/*",
"options" => ["symlink" => true]
],
[
"type" => "composer",
"url" => "https://asset-packagist.org"
]
];
file_put_contents($path, json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
' "$app_dir/composer.local.json"
info "composer.local.json created."
info "Creating composer.local.lock from composer.lock..."
cp "$app_dir/composer.lock" "$app_dir/composer.local.lock"
else
warn "composer.local.json already exists, skipping."
fi
if ! grep -q "composer.local.json" "$app_dir/.gitignore" 2>/dev/null; then
echo "" >> "$app_dir/.gitignore"
echo "# composer local" >> "$app_dir/.gitignore"
echo "composer.local.json" >> "$app_dir/.gitignore"
echo "composer.local.lock" >> "$app_dir/.gitignore"
info "Added composer.local.json and composer.local.lock to .gitignore."
fi
if [ -d "$ext_base_dir" ]; then
info "Installing ext-base dependencies..."
cd "$ext_base_dir"
composer install
else
error "ext-base directory not found. Clone failed?"
exit 1
fi
info "Installing app dependencies..."
cd "$app_dir"
COMPOSER=composer.local.json composer install
info "Installation complete!"
echo ""
echo -e " ${GREEN}php -S localhost:8000 -t app/public/${NC}"
echo ""
read -p "Do you want to start the development server now? (Y/n): " start_server
start_server=${start_server:-Y}
if [[ "$start_server" =~ ^[Yy]$ ]]; then
info "Starting development server..."
php -S localhost:8000 -t "$app_dir/public/"
else
info "You can start the server later with: php -S localhost:8000 -t app/public/"
fi
}
show_menu() {
echo "Welcome to WebifyCMS Installer"
echo "Please select the installation purpose:"
echo "1) Development"
echo -e "${GRAY}2) Production (Not ready yet)${NC}"
read -p "Enter your choice [1-2]: " choice
case $choice in
1)
install_development
;;
2)
warn "Production installation is not yet supported."
exit 0
;;
*)
error "Invalid choice."
exit 1
;;
esac
}
show_menu