-
Notifications
You must be signed in to change notification settings - Fork 4
/
aur4
executable file
·214 lines (170 loc) · 3.75 KB
/
aur4
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
#!/bin/bash
shopt -s extglob;
# Usage:
# aur4 <commit-message>
# Example:
# aur4 "Initial import"
# Note: MUST run this script under the cloned (or soon to be cloned) directory of the package's aur4 repository.
# If user requested help, print it.
_chkHelp() {
case "${1}" in
+(-)[hH]*([eE][lL][pP]) )
_help 0;
;;
* )
return
;;
esac;
}
# Print help and exit.
_help() {
local path="$0";
local script=${path##*/};
cat << EOH >&2
Usage:
${script} <commit-message>
Note:
This ${script} script needs to run under the cloned (or soon
to be cloned) directory of the package's aur4 repository.
EOH
#'
[ "${1}" ] && exit "${1}";
exit 1;
}
# Set font color in Terminal.
_c() {
tput sgr0;
(($# == 0)) && return;
local -Ar Codes=(
["black"]="0" ["red"]="1" ["green"]="2" ["yellow"]="3"
["blue"]="4" ["magenta"]="5" ["cyan"]="6" ["white"]="7"
["bk"]="0" ["r"]="1" ["g"]="2" ["y"]="3"
["bu"]="4" ["m"]="5" ["c"]="6" ["w"]="7"
);
local k c;
for k in "${!Codes[@]}"; do
[[ "${k}" == "${1}" ]] &&
c="${Codes["$k"]}";
done;
[ "${c}" ] && tput setaf "${c}";
}
# Set bold font color in Terminal.
# Optionally set a new font color as well.
_C() {
(($#<1)) && _c "${1}";
tput bold;
}
# Reset font color in Terminal to normal.
_u() {
tput sgr0;
}
# Print messages in bold green.
_gecho() {
_C green
for line; do
echo "${line}";
done;
_u;
}
# Print a message in bold green, WITHOUT appending a newline.
_gprint() {
_C green
printf "%s" "$*";
_u;
}
# Echo a command in bold green and then run it.
_gechval() {
_C green;
echo "$@";
eval "$@";
_u;
}
# Run a command silently.
_q() {
eval "$@" >/dev/null;
}
# Exit with error 1 if the previous command returned an error.
_err() {
[[ $? == 0 ]] || exit 1;
}
# Obtain user input (command variant of `read -p`).
_inp() {
_u;
local ans;
read -p "" ans;
printf "\r";
echo "${ans}";
}
# Rerun script if no arguments were passed.
_VrfyArgs() {
((${#ARGS} > 0)) && return;
local msg;
for msg; do
_gprint "${msg}";
ARGS+=( "$(_inp)" );
done;
((${#ARGS} == 0)) && ARGS+=( "$(_inp)" );
$0 "${ARGS[@]}";
exit;
}
# Install any missing package dependencies.
_VrfyDeps() {
if ! _q command -v "yaourt"; then
echo "Install yaourt first.";
exit 1;
fi;
local -Ar Deps=(
['git']='git'
['mksrcinfo']='pkgbuild-introspection'
['wget']='wget'
);
local cmd;
for cmd in "${!Deps[@]}"; do
_q command -v "${cmd}" ||
yaourt -Sa "${Deps[$cmd]}";
done;
}
# Clone an aur4 repo if it has not been cloned already.
_VrfyCloned() {
_isCloned && return 0;
local pkg="${1}";
if ! [ "${pkg}" ]; then
_gprint "Enter package name: ";
read -p "" pkg;
fi;
_clone "${pkg}";
_err;
}
# Test whether the current directory is a cloned git/aur4 repository.
_isCloned() {
[ -d ".git" ] && return 0;
return 1;
}
# Git clone aur4 repository.
_clone() {
local -r repo="${1}";
_gechval git init .;
_gechval git remote add -t \* -f origin "ssh://[email protected]/${repo}.git";
_gechval git checkout master;
}
# Upload local repository to its aur4 repository.
_Upload() {
mksrcinfo;
_err;
git add .;
git add .SRCINFO -f;
_err;
git commit -m "$@";
_err;
git push origin master;
}
_chkHelp "${1}";
declare -a ARGS=( $@ );
declare ROOT;
ROOT="$(basename "${PWD}")";
_VrfyDeps;
_VrfyArgs "Enter commit: ";
declare COMMIT="${ARGS[*]}";
[ "${COMMIT[*]}" ] || _help;
_VrfyCloned;
_Upload "${COMMIT}";