forked from eli-schwartz/aurpublish
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchosaur.in
executable file
·155 lines (136 loc) · 4.4 KB
/
archosaur.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
#!/bin/bash
#### 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.
-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 aur.archlinux.org
User aur
Hostname aur.archlinux.org
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. archosaur 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
;;
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
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 -m "splpkg: ${package} ($(git rev-parse --short HEAD))"
GIT_MERGE_AUTOEDIT=no git subtree pull -P "${package}" aur:${pkgbase}.git master -m "mrgpkg: ${package}"
else
git subtree add -P "${package}" aur:${package}.git master -m "addpkg: ${package} ($(git rev-parse --short HEAD))"
fi
exit 0
fi
if (( SPEEDUP )); then
git subtree split -P "${package}" --rejoin -m "splpkg: ${package} ($(git rev-parse --short HEAD))"
fi
git subtree push -P "${package}" aur:${pkgbase}.git master