/
koapp
executable file
·218 lines (188 loc) · 4.01 KB
/
koapp
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
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
#
# Kohana Application Installer
# ============================
#
# This is a small bash script for installing the core files for a Kohana
# application. Will install at the path specified a basic application
# structure, then initialises a git repository for your convenience. The
# core Kohana system files are added as a submodule and you are given
# the option to install Kostache because you just should!
#
#
# Author
# ------
# Luke Morton <lukemorton.designs@gmail.com>
#
#
# Requirements
# ------------
# * git
#
#
# Usage
# -----
# ./koapp install /var/www/my-new-app
#
# Default
DEFAULT_APP_PATH="$HOME/koapp"
set_app_path()
{
if [ -n "$1" ];
then
# Use first arg as application path
app_path="$1"
else
# Request application name
echo "Please provide a path in which to install your new Kohana application: "
read custom_app_path
# Set app path
if [ -n "$custom_app_path" ];
then
app_path="$custom_app_path"
else
app_path="$DEFAULT_APP_PATH"
fi
fi
# Use app name
echo "Using $app_path as application path..."
}
create_app_path()
{
if [ ! -d "$app_path" ];
then
# Create folder in application path
echo "Creating application path..."
mkdir -p $app_path
fi
}
create_folder_structure()
{
# Create application folders with correct perms
echo "Creating application folders..."
mkdir -p {application,modules,public}
mkdir -p application/{config,classes,cache,logs}
echo "Ensuring 777 permissions on application/log and application/cache..."
chmod 0777 application/{cache,logs}
}
init_git()
{
if [ -d ".git" ];
then
# Already a git repo
echo "Application path is already a git repo..."
else
# Init repo
echo "Initialising application folder as git repo..."
git init > /dev/null
fi
}
install_bootstrap()
{
if [ ! -f "application/bootstrap.php" ];
then
# Grab bootstrap and index
echo "Getting bootstrap.php..."
wget https://github.com/kohana/kohana/raw/3.1/master/application/bootstrap.php --output-document=application/bootstrap.php --no-check-certificate > /dev/null 2>&1
fi
}
install_index()
{
if [ ! -f "public/index.php" ];
then
echo "Getting index.php..."
wget https://github.com/DrPheltRight/koapp/raw/develop/resources/index.php --output-document=public/index.php --no-check-certificate > /dev/null 2>&1
fi
}
install_system()
{
if [ ! -d "system" ];
then
# Get system files
echo "Cloning Kohana Core into system..."
git submodule add https://github.com/kohana/core.git system > /dev/null 2>&1
fi
}
install_module()
{
if [ ! -d "modules/$1" ];
then
echo "Would you like to install $1 (y/n)?"
read install
if [ "$install" == "y" ];
then
echo "Installing $1..."
echo "Cloning $1 from $2 into modules/$1..."
git submodule add "$2" "modules/$1" > /dev/null 2>&1
fi
fi
}
install_kostache()
{
install_module kostache https://github.com/zombor/KOstache.git
if [ "$install" == "y" ];
then
mkdir application/templates
fi
}
install_orm()
{
install_module orm https://github.com/kohana/orm.git
if [ "$install" == "y" ];
then
echo ""
echo "[!!] You will need the database module in order to use ORM"
echo ""
install_db
fi
}
install_db()
{
install_module database https://github.com/kohana/database.git
if [ "$install" == "y" ];
then
cp modules/database/config/database.php application/config/database.php
fi
}
update_submodules()
{
# Ensure submodules initialised
echo "Initialising submodules..."
git submodule update --init > /dev/null
}
commit_git()
{
# Add changes
git add . > /dev/null
echo "Please provide a commit message or leave blank to use default: "
read commit
if [ ! -n "$commit" ];
then
commit="Kohana Application Installer run for $app_path"
fi
echo "Commiting original sin...."
git commit -m "$commit" > /dev/null
}
install()
{
echo $1
set_app_path $1
create_app_path
cd $1
create_folder_structure
install_bootstrap
install_index
init_git
install_system
install_kostache
install_orm
install_db
update_submodules
commit_git
echo ""
echo "Installed."
}
if [ "$1" ];
then
$1 $2
fi