-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathaurpublish.in
executable file
·180 lines (158 loc) · 5.27 KB
/
aurpublish.in
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
#!/bin/bash
REMOTE_URL='aur@aur.archlinux.org:'
#### Declare common functions
# usage and other awkward blocks of preformatted text
usage() {
cat <<- _EOF_
Usage: ${0##*/} [OPTIONS] PACKAGE
Usage: ${0##*/} log [<options>] PACKAGE [[--] <path>...]
Usage: ${0##*/} setup
Push a subtree to the AUR
OPTIONS
-p, --pull Instead of publishing, pull changes from the AUR.
Can import packages into a new subtree.
-s, --speedup Speedup future publishing by recording the subtree
history during a push. This creates a merge commit
and a second copy of all commits in the subtree.
For more details, see the "--rejoin" option in git
subtree.
-u, --url Specify the URL of the server that should be used
for git operations.
-h, --help Show this usage message
COMMANDS
setup Install githooks to the repository
log Wrapper for \`git log\`, substituting a package
subtree for the revision/branch. This is only
useful if changes were pulled from the AUR
(because \`git log\` isn't very good at reading
subtrees).
_EOF_
}
ssh_config() {
cat <<- _EOF_
\`\`\`
Host aur.archlinux.org
User aur
IdentityFile ~/.ssh/keys/aur
\`\`\`
_EOF_
}
# check if pkgname is already committed in git, relative to repository root
is_package_in_git() {
git ls-tree -d --name-only HEAD | grep -qxF "${1}"
}
#### Do the great option check
if [[ $# -eq 0 ]]; then
echo "error: No arguments passed. aurpublish needs a package to upload."
exit 1
fi
while [[ "${1}" != "" ]]; do
case ${1} in
-h|--help)
usage
exit
;;
-p|--pull)
PULL_SUBTREE=1
shift
package=$(readlink -m "${1}")
package=${package##*/}
;;
-s|--speedup)
SPEEDUP=1
;;
-u|--url)
REMOTE_URL=${2%/}
URL_SET=1
shift
;;
log)
LOG=1
while [[ ${2} && ! -d ${2} ]]; do
log_pre_opts+=("${2}")
shift
done
;;
setup)
SETUP=1
;;
*)
if [[ -n ${package} ]]; then
echo "error: multiple packages specified"
exit 1
fi
package=$(readlink -m "${1}")
package=${package##*/}
(( LOG )) && break
;;
esac
shift
done
#### INIT
# Run from the repository root, no matter where the script is installed.
toplevel=$(git rev-parse --show-toplevel) || exit 1
if [[ $(git rev-parse --is-inside-git-dir) = true ]]; then
echo "error: cannot be run from within GIT_DIR"
exit 1
elif [[ ! ${toplevel} -ef ${PWD} ]]; then
cd "${toplevel}"
fi
# sanity check
if ! git rev-parse -q --verify HEAD > /dev/null ; then
echo "error: cannot be run from a branch without any commits"
echo "At least commit a README.md or something..."
exit 1
fi
if (( ! ( PULL_SUBTREE || SETUP ) )) && ! is_package_in_git "${package}"; then
echo "${0##*/}: unrecognized package '${package}'"
echo "Try '${0##*/} --help' for more information."
exit 1
fi
#### MAIN
if (( SETUP )); then
echo "Adding commit hooks..."
shopt -s nullglob
for hook in "@HOOKSDIR@"/*.hook; do
hookname=${hook##*/}
echo "-> ${hookname}"
ln -sf "${hook}" "$(git rev-parse --git-dir)/hooks/${hookname%.hook}"
done
echo "Add the following snippet to your ~/.ssh/config (assuming ssh key is in ~/.ssh/keys/aur):"
ssh_config
exit 0
fi
if (( LOG )); then
shift
git log "${log_pre_opts[@]}" $(git subtree split -P "${package}") "$@"
exit 0
fi
if (( ! URL_SET )); then
# use git configured remoteUrl, if set
REMOTE_URL=$(git config --default "${REMOTE_URL}" --get aurpublish.remoteUrl | sed 's:/*$::')
# warn the user if they have a non-default ssh alias for 'aur'
auralias=$(ssh -G aur | awk '$1 == "hostname" { print $2 }')
if [[ ${auralias} != 'aur' && ${auralias} != 'aur.archlinux.org' ]]; then
echo "Warning: You have a non-default alias for 'aur' in your ssh configuration. (${auralias})"
echo "Previous versions of aurpublish used the 'aur' ssh hostname, but you should now use the --url option."
echo ""
echo "This operation will use the git server at: ${REMOTE_URL}"
echo ""
read -p "Do you wish to continue? [y/n] " userwarned
[[ ${userwarned} = [yY] ]] || exit 1
fi
fi
pkgbase="$(sed -rn 's/pkgbase = (.*)/\1/p' "${package}"/.SRCINFO 2>/dev/null)"
if (( PULL_SUBTREE )); then
# test if prefix already exists
if is_package_in_git ${package}; then
git subtree split -P "${package}" --rejoin
git subtree pull -P "${package}" ${REMOTE_URL}/${pkgbase}.git master -m "Merge subtree '${package}'"
else
git subtree add -P "${package}" ${REMOTE_URL}/${package}.git master
fi
exit 0
fi
if (( SPEEDUP )); then
git subtree split -P "${package}" --rejoin
fi
git subtree push -P "${package}" ${REMOTE_URL}/${pkgbase}.git master