/
compilepackagefunctions
151 lines (133 loc) · 3.87 KB
/
compilepackagefunctions
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
#!/bin/zsh
# Declare colours for easy access
GREEN='\e[1;32m'
RED='\e[1;31m'
YELLOW='\e[1;33m'
WHITE='\e[1;37m'
COLRESET='\e[0m'
function errmsg () {
echo "${RED}==>${WHITE} ${1}${COLRESET}"
}
function infomsg () {
echo "${YELLOW}==>${WHITE} ${1}${COLRESET}"
}
function successmsg () {
echo "${GREEN}==>${WHITE} ${1}${COLRESET}"
}
# Set EDITOR to user default, falling back on vi
EDITOR=${EDITOR:-/usr/bin/vi}
# Unset problematic variables, and reset _built
unset _built
unset epoch
# cd to build directory, download PKGBUILD, show for editing, then automatically build package
function normalbuild () {
if [ -e PKGBUILD ]; then
"${EDITOR}" PKGBUILD && sudo extra-x86_64-build && _built=true
else
errmsg "No PKGBUILD found"
return 1
fi
}
function multibuild {
if [ -e PKGBUILD ]; then
"${EDITOR}" PKGBUILD && sudo multilib-build && _built=true
else
errmsg "No PKGBUILD found"
return 1
fi
}
function getsources {
cd ~/builds
if [[ ! $2 == "skip" ]]; then
infomsg "Downloading sources"
if [[ -d $1 ]]; then
read -q "response?Directory '$1' already exists, overwrite? y/N "
echo
if [[ $response == "y" ]]; then
# Check if $1 is in the repos, otherwise fallback to AUR
if ! asp -f export $1 2>/dev/null; then
cower --ignorerepo -df $1 2>/dev/null
fi
fi
else
if pacman -Si $1 &>/dev/null; then
asp export $1
else
cower --ignorerepo -d $1
fi
fi
fi
if [ -d $1 ]; then
cd $1
else
errmsg "No such package"
return 1
fi
}
# If build was successful
function postbuild {
# If DISPLAY is set and notify-send is installed, send an "urgent" notification
# that compilation has finished, either successfully or otherwise.
if [ $DISPLAY ]; then
if [ -x "$(where notify-send)" ]; then
STATUS="FAILED"
[ $_built ] && STATUS="SUCCESS"
notify-send -u critical -a xfce4-notifyd -i xfce4-notifyd "Compilation of package $1 is now complete. Compilation ${STATUS}!"
fi
fi
if [ $_built ]; then
unset all
# Load PKGBUILD variables
source PKGBUILD &> /dev/null
# Check for package archetecture
if [[ $arch != "any" ]]; then
arch=$(uname -m)
fi
# Create _ver
_ver=${pkgver}-${pkgrel}-${arch}.pkg.tar.xz
# Check for epoch var, and add to _ver if present
[ $epoch ] && _ver=${epoch}:${_ver}
# Check for multi-package
if [[ $(echo $pkgname | wc -w) -gt 1 ]]; then
# Add package names to array
# #TODO: Fix $all when packages have different archs (e.g. i686 and any)
x=1
foreach i in $pkgname; do
all[${x}]=${i}-${_ver}
x=$((x+1))
done
# Check first package exists, confirm completion, and prompt user to install
[ -f ${pkgname[1]}-${_ver} ] && successmsg "Compilation complete. Multiple packages detected. Names stored in \$all"
return 0
fi
# Declare _pkg for easy installation/copying
_pkg=${pkgname}-${_ver}
# Check package exists, confirm completion, and prompt user to install
if [ -f ${_pkg} ]; then
successmsg "Compilation complete, installing..."
sudo pacman -U ${_pkg}
else
errmsg "Could not find '${_pkg}', install manually"
return 1
fi
return 0
fi
}
function getfiles {
cd ~/builds
infomsg "Downloading sources"
_rawhtml=$(curl -s -f "https://projects.archlinux.org/svntogit/packages.git/plain/$1/trunk/" || curl -s -f "https://projects.archlinux.org/svntogit/community.git/plain/$1/trunk/")
if [ ! $_rawhtml ] && return 1
_filelist=$(echo $_rawhtml | grep "\<li\>" | sed 1d | cut -d "'" -f 2)
if [ -d $1 ]; then
cd $1
else
mkdir $1
cd $1
fi
for _file in $(echo $_filelist); do
_filename=$(echo $_file | cut -d "/" -f 6 | sed 's:\?.*::')
rm -f $_filename
curl -s -O "https://projects.archlinux.org/$_file" > $_filename
done
}