-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·203 lines (183 loc) · 5.27 KB
/
init.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
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
#!/bin/bash
#
# Type: Script Shell Installer
# Description: Simple script Management.
#
#
# Supported: Unix
# Release State: 1.0.1
# Script Name: init.sh
# Author: William C. Canin
# E-Mail: [email protected]
# Home page: https://williamcanin.com
# License:
# The MIT License (MIT)
# Copyright (c) 2017 William C. Canin <[email protected]>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# ******************************************************************************
#
# Note: Not use with root.
# Usage: bash init.sh help
#
# Global variables
LIB_DIR="./src/lib"
GETGEMS_PATH="_gems"
CSS_PATH="assets/css"
JS_PATH="assets/js"
# Import LIBs
source "$LIB_DIR/shell/global/functions/utils.lib"
source "./deploy.conf"
# Verify exists .git
function _add_repo_git(){
if [[ ! -d "./.git" ]]; then
git init
fi
}
# Function to capture Jekyll's build folder.
function _get_destination(){
if [[ -f "$1" ]]; then
destination_build="$(cat "$1" | grep destination | cut -d':' -f2 | cut -d' ' -f2)"
fi
}
# Function add/verify remote url
function _add_remoteurl(){
rem_verify="$(sed -n '/url/p' .git/config | cut -d'=' -f2 | cut -d' ' -f2)"
if [[ ! -n $rem_verify ]]; then
git remote add origin $remoteURL
fi
}
# Enter a specific folder
function _enter_folder(){
if [[ -d "$1" ]]; then
cd $1
fi
}
# Function execute pull before push
function _pull_execute(){
if [[ $pull == "yes" ]]; then
git pull origin $1
fi
}
# Function get branch for create checkout or no
function _git_checkout(){
branch_get="$(git branch --list | sed -n "/$1/p" | cut -d'*' -f2 | awk '{ gsub (" ", "", $0); print}')"
if [[ -z $branch_get ]]; then
git checkout -b $1
else
git checkout $branch_get
fi
}
# Function build project and deploy project build
function _deploy_site(){
if [[ $compile == "yes" ]]; then
JEKYLL_ENV=production bundle exec jekyll b
fi
_get_destination "_config.yml"
_enter_folder $destination_build
_add_repo_git
_add_remoteurl
_pull_execute $built
msg_header "Deploy source files. Wait ..."
_git_checkout $built
git add .
git commit -m "$commit - $(date)"
git push origin -u $built
msg_finish "Done!"
}
# Function start deploy source files
function _deploy_source(){
_add_repo_git
_add_remoteurl
_pull_execute $source
_git_checkout $source
msg_header "Deploy source files. Wait ..."
git add .
git commit -m "$commit - $(date)"
git push origin -u $source
msg_finish "Done!"
}
# Menu
case $1 in
install )
gem install bundler --pre
bundle install
msg_finish "Done!"
;;
serve )
JEKYLL_ENV=development bundle exec jekyll s
msg_finish "Done!"
;;
build )
JEKYLL_ENV=production bundle exec jekyll b
msg_finish "Done!"
;;
post)
if [[ ! -f "$(ls $GETGEMS_PATH/bundle/ruby/*/bin/rake)" ]]; then
msg_warning "You need Rake to continue. Install the project dependencies first."
msg_warning "Command: $0 install"
exit 1
else
msg_header "Creating new post \"BLOG\""
msg_header "Add TITLE:"
read -p "> " title_
if [[ -z "${title_}" ]]; then
msg_error "The TITLE variable is required! Try again."
else
bundle exec rake post TITLE="${title_}"
msg_finish "Done!"
fi
fi
;;
page)
if [[ ! -f "$(ls $GETGEMS_PATH/bundle/ruby/*/bin/rake)" ]]; then
msg_warning "You need Rake to continue. Install the project dependencies first."
msg_warning "Command: $0 install"
exit 1
else
msg_header "Creating new post \"BLOG\""
msg_header "Add TITLE:"
read -p "> " title_
if [[ -z "${title_}" ]]; then
msg_error "The TITLE variable is required! Try again."
else
bundle exec rake page TITLE="${title_}"
msg_finish "Done!"
fi
fi
;;
reset)
msg_header "Reset all the pure settings. Wait ..."
rm -rf ".git"
rm -rf "Gemfile.lock"
rm -rf "$GETGEMS_PATH"
_get_destination "_config.yml"
rm -rf "$destination_build"
rm -rf "$CSS_PATH"
rm -rf "$JS_PATH"
msg_finish "Done!"
;;
deploy:source)
_deploy_source
;;
deploy:site)
_deploy_site
;;
*|help)
msg_warning "Usage: $0 { install | build | serve | post:blog | deploy:source | deploy:site | reset }"
;;
esac
# END