-
Notifications
You must be signed in to change notification settings - Fork 0
/
aurbranch
executable file
·128 lines (116 loc) · 3.06 KB
/
aurbranch
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
#!/bin/bash
# Compose option string.
opts="$(
offbranch -h | while read
do
if [[ "$REPLY" =~ ^' -'([^b])( <.*>)?.* ]]
then
echo -n ${BASH_REMATCH[1]}${BASH_REMATCH[2]:+:}
fi
done
)"
# Provide temporary directory.
# File list for -z and -i arguments are rewritten there.
readonly tmpdir="$(mktemp -d --tmpdir aurbranch.XXXXXXXXXX)"
trap "rm -r '$tmpdir'" EXIT
# Resolve symbolic links.
resolve() {
local readonly addpath="${1##*${separator:=:}}"
local readonly filename="${1%$separator*}"
if [ -h "$filename" ]
then
printf "%s%s%s$2" "$(readlink "$filename")" "$separator" "$addpath"
else
printf "%s$2" "$1"
fi
}
# Resolve a list option argument, given delimiter.
list() {
local readonly fifo="$(mktemp -up "$tmpdir" pipe.XXXXXXXXXX)"
mkfifo "$fifo"
while read -rd "$1"
do
resolve "$REPLY" "\0"
done < "$OPTARG" > "$fifo" &
pass+=("-z" "$fifo")
}
# Parse arguments.
verbose=:
while [ $OPTIND -le $# ]
do
if getopts "p:i:rv$opts" argument
then
case $argument in
h)
echo "usage: $0 [options] <additional files>"
echo 'Commit changes in the PKGBUILD to an AUR distribution branch.'
echo ' -p <script> file to use in place of PKGBUILD'
echo ' -i <script> file to use in place of .SRCINFO'
echo ' -r omit install and source files'
echo 'Also supports all options offbranch accepts, apart from -b.'
exit ;;
p) pkgbuild="$OPTARG" ;;
i) srcinfo="$OPTARG" ;;
r) source=false ;;
v) verbose=echo ;;
s) separator="$OPTARG" ;;&
l) list $'\n' ;;
z) list $'' ;;
\?) exit 1 ;;
*) pass+=("-$argument" ${OPTARG:+"$OPTARG"}) ;;
esac
else
pass+=("$(resolve "${!OPTIND}")")
let OPTIND++
fi
done
# Generate missing .SRCINFO.
if [ -z "$srcinfo" ]
then
if [ -n "$pkgbuild" ]
then
# "cd ... cd $OLDPWD", acts like "pushd ... popd", but only
# modifies $OLDPWD when the directory was actually changed.
cd "$(dirname "$pkgbuild")"
makepkg --printsrcinfo -p "${pkgbuild##*/}" > .SRCINFO
if [ -n "${OLDPWD}" ]
then
srcinfo="$PWD/.SRCINFO"
cd "$OLDPWD"
fi
else
makepkg --printsrcinfo > .SRCINFO
fi
fi
# Determine branch name.
readonly pkgbase="$(grep -Po "(?<=pkgbase = ).*" "${srcinfo:-.SRCINFO}")"
$verbose "Composing $pkgbase"
branch=aur
if [ -n "$(git rev-parse --show-prefix 2> /dev/null)" ]
then
branch+="/$pkgbase"
fi
# Add source and install files.
if [ -z "${source++}" ]
then
source /usr/share/makepkg/util/source.sh
readonly startdir=.
for source in $(sed -n \
's/^\t*\(source\|install\) = \(.*\)$/\2/p' "${srcinfo:-.SRCINFO}")
do
file="$(get_filename "$source")"
[ -n "$(git ls-files "$file")" ] && pass+=("$(resolve "$file")")
done
fi
# Update the branch.
offbranch -b "$branch" \
"${pkgbuild:+$pkgbuild:}PKGBUILD" \
"${srcinfo:+$srcinfo:}.SRCINFO" \
"${pass[@]}"
# Create branch, if needed, and propagate errors.
case $? in
2) offremote -fn "$branch" \
"ssh://aur@aur.archlinux.org/${pkgbase}.git" ;;
[0-7]) ;;
*) exit $? ;;
esac