forked from kororaproject/kp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkp
executable file
·224 lines (191 loc) · 4.73 KB
/
kp
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
219
220
221
222
223
224
#!/bin/bash
#
# Copyright 2012-2013 "Korora Project" <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the temms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
VERSION="0.1.0"
#
# PRE-INIT
#
SUB_COMMAND=""
CONFIG_FILE=""
_CALLED=$(dirname "${0}")
# assume first parameter to be the subcommand
while [ $# -gt 0 ] && [ -z ${SUB_COMMAND} ]
do
case "$1" in
init|--init)
SUB_COMMAND=init
;;
list|--list)
SUB_COMMAND=list
;;
help|--help)
SUB_COMMAND=help
;;
build|--build)
SUB_COMMAND=build
;;
repository|--repository)
SUB_COMMAND=repository
;;
sync|--sync)
SUB_COMMAND=sync
;;
checkout|--checkout)
SUB_COMMAND=checkout
;;
release|--release)
SUB_COMMAND=release
;;
upstream|--upstream)
SUB_COMMAND=upstream
;;
--config*)
if [ ${#1} -eq 8 ]
then
CONFIG_FILE=$2
shift
else
CONFIG_FILE="${1/--config=/}"
fi
;;
*)
echo "Unknown command specified: $1"
exit 1
;;
esac
shift
done
# set to help if no sub command found
[ -z "${SUB_COMMAND}" ] && SUB_COMMAND=help
#
# DEFAULTS
#
[ -z ${LIB_DIR} ] && LIB_DIR="/usr/share/lib/kp/lib"
[ -z ${WORKING_DIR} ] && WORKING_DIR="/var/lib/kp"
[ -z ${RELEASE_DIR} ] && RELEASE_DIR="/tmp"
[ -z ${LOG_DIR} ] && LOG_DIR="/usr/share/lib/kp/log"
[[ -z ${CONFIG_FILE} ]] && [[ -f "${_CALLED}/kp.conf" ]] && CONFIG_FILE="${_CALLED}/kp.conf"
#
# INCLUDES
#
if [ ! -r "${CONFIG_FILE}" -a "${SUB_COMMAND}" != "init" ]
then
echo "FATAL: No configuration file found."
exit 1
else
source "${CONFIG_FILE}"
fi
if [ ! -d "${LIB_DIR}" -a "${SUB_COMMAND}" != "init" ]
then
echo "FATAL: Invalid LIB_DIR defined."
exit 1
else
source "${LIB_DIR}/kp_core"
fi
if [ ! -d "${LOG_DIR}" -a "${SUB_COMMAND}" != "init" ]
then
echo "FATAL: Invalid LOG_DIR defined. Did you run --init?"
exit 1
fi
# build working subdirectories
WORKING_CONFIG_DIR="${WORKING_DIR}/conf"
WORKING_PACKAGES_DIR="${WORKING_DIR}/packages"
WORKING_REPOSITORY_DIR="${WORKING_DIR}/repository"
WORKING_KICKSTART_DIR="${WORKING_DIR}/kickstart"
WORKING_RELEASE_DIR="${WORKING_DIR}/release"
WORKING_RELEASE_CACHE_DIR="${WORKING_DIR}/release/cache"
WORKING_RELEASE_TMP_DIR="${WORKING_DIR}/release/tmp"
SCRIPT=${0##*/}
if [ ! -d "${WORKING_DIR}" -a "${SUB_COMMAND}" != "init" ]
then
_error "Working directory doesn't not exist. Have you run \"kp --init\"?"
exit 1
fi
# variables based on config
# default to git:// for git protocol unless otherwise specified
GIT_URL="${GIT_URL_GIT}"
# if we're using a developer account we can't use git://
if [ -n "${KP_DEV_ACCOUNT}" -a "${GIT_PROTOCOL}" == "git" ]
then
_error "Developers cannot use git://, set GIT_PROTOCOL to either 'ssh' or 'http' in your config"
exit 1
# if we're anonymous we can't use ssh://
elif [ -z "${KP_DEV_ACCOUNT}" -a "${GIT_PROTOCOL}" == "ssh" ]
then
_error "SSH access is only available to developers, set GIT_PROTOCOL to either 'git' or 'http' in your config"
exit 1
fi
case "${GIT_PROTOCOL}" in
git)
GIT_URL="${GIT_URL_GIT}"
;;
http|https)
GIT_PROTOCOL="https"
GIT_URL="${GIT_URL_HTTP}"
;;
ssh)
GIT_URL="${GIT_URL_SSH}"
;;
*)
GIT_PROTOCOL="git"
GIT_URL="${GIT_URL_GIT}"
if [ "${SUB_COMMAND}" == "checkout" ]
then
_warn "Unknown protocol specified, falling back to default of git://"
fi
;;
esac
#
# INCLUDES
#
CALL_PATH=$(dirname $0)
source "${LIB_DIR}/kp_${SUB_COMMAND}" $@
NOW=$(date +'%s')
NOW_LITERAL=$(date '+%Y-%m-%d %H:%M:%S')
LOG_FILE="${LOG_DIR}/kp-${SUB_COMMAND}-${NOW}.log"
if [ "${SUB_COMMAND}" != "init" ]
then
touch $LOG_FILE
_log "Logging started: ${NOW_LITERAL}"
fi
#
# DEPENDANCY CHECKS
#
_MOCK_VERSION=$(mock --version 2>/dev/null)
if [ ${?} -ne 0 ]
then
_error "Can't find mock. Is it installed?"
exit 1
fi
_MOCK_GROUPS=$(getent group mock | grep $(id -ng))
if [ ${?} -ne 0 ]
then
_error "Current user is not part of the mock group."
exit 1
fi
_SPECTOOL_VERSIOIN=$(spectool --version 2>/dev/null)
if [ ${?} -ne 0 ]
then
_error "Can't find spectool. Is it installed?"
# exit 1
fi
#
# MAIN
#
# start the main function sourced above
parse_args $@
main