-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh-makepkg.sh
executable file
·190 lines (159 loc) · 4.48 KB
/
ssh-makepkg.sh
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
#! /bin/bash
port=22
declare -a PKG
declare -a DEP
declare -a TEMP
editor=/bin/true
CFLAGS=( $(gcc -march=native -Q --help=target | grep enable | cut -d ' ' -f 3) -O2 -pipe -fstack-protector-strong )
function ipset {
if [ -z $ipnotset ]
then export ip=$1
export ipnotset=false
else echo 'Ip was parsed multiple times'
exit 2
fi
}
function check_installed {
pacman -Qi $1 &> /dev/null ; if [ ! $? = 0 ]
then pacman -Qsq ^$1\$ &> /dev/null ; if [ ! $? = 0 ]
then pacman -Si $1 &> /dev/null ; if [ ! $? = 0 ]
then DEP=( $1 ${DEP[@]/%$1} ) && return 1
fi
fi
fi
}
function deps_calc {
if [ "$(echo ${TEMP[@]} | grep $@)" ]
then break 1
fi
temp=$(cower --format='%D %K %M' -i $@)
for i in $temp
do while true
do temp2=$(echo $i | cut -f1 -d">")
TEMP=( $temp2 ${TEMP[@]} )
check_installed $temp2
if [ "$?" = 1 ]
then deps_calc $temp2
else break 1
fi
done
done
}
help='Usage: (user@)host (-p 22) (-e) pkg1 pkg2 pkg3
Arguments in parenthesis can be ommited.
-p: port (defaults to 22)
-e: edit pkgbuilds (defaults to /bin/true - no editor)
Packages are to be separated by space. There is no need for them to be in order.
Dependencies are to be automatically resolved in both the remote and local machine.
In the remote machine are automatically uninstalled when not needed.
Example: [email protected] -p 123 sway-git wlc-git
'
if [[ -z $(echo $@) ]] ; then echo 'use -h | --help for help' ; exit ; fi
while true; do
case $1 in
'' ) break ;;
*@*.*.* ) ipset $@ ; shift ;;
*.*.* ) ipset $@ ; shift ;;
*.lan ) ping $1 -c1 &> /dev/null && ipset $@ ; shift ;;
-p ) export port=$2 ; shift 2 ;;
-h | --help ) echo "$help" ; exit 0 ;;
-e | --edit ) export editor=$EDITOR ; shift ;;
*/PKGBUILD ) echo wip ; exit 4 ; shift ;;
* ) PKG=( $1 ${PKG[@]/%$1} ) ; shift 1 ;;
esac
done
if [ -z $ipnotset ] ; then echo 'No ip was set for the remote ssh server' ; exit 2 ; fi
if [ ! -e /tmp/scp-receive ] ; then mkdir /tmp/scp-receive ; fi
for i in ${PKG[@]} ; do
deps_calc $i ; done
ssh -t $ip $(echo '-p' $port) export "EDITOR=$editor" "
export pkg=\"$(echo ${PKG[@]})\" " "
export dep=\"$(echo ${DEP[@]})\" " "
export CFLAGS=\"${CFLAGS[@]}\" " "
export CXXFLAGS=\"${CFLAGS[@]}\" " '
PATH="/usr/local/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl"' '
echo CFLAGS=\"$CFLAGS\" > ~/.makepkg.conf
echo CXXFLAGS=\"${CFLAGS[@]}\" >> ~/.makepkg.conf
declare -a old_DEPs
declare -a DEP
declare -a PKG
export PKGDEST="/tmp/scp"
for i in $dep $pkg
do PKG=( ${PKG[@]} $i )
done
function check_installed {
pacman -Qi $1 &> /dev/null ; if [ ! $? = 0 ]
then pacman -Qsq ^$1\$ &> /dev/null ; if [ ! $? = 0 ]
then pacman -Si $1 &> /dev/null ; if [ ! $? = 0 ]
then DEP=( $1 ${DEP[@]/%$1} ) && return 1
fi
fi
fi
}
function deps_calc {
if [ "$(echo ${TEMP[@]} | grep $@)" ]
then break 1
fi
temp=$(cower --format='%D %K %M' -i $@)
for i in $temp
do while true
do temp2=$(echo $i | cut -f1 -d">")
TEMP=( $temp2 ${TEMP[@]} )
check_installed $temp2
if [ "$?" = 1 ]
then deps_calc $temp2
else break 1
fi
done
done
}
function Build_deps {
cower -fd $1 ; cd $1
if [ -e ~/.config/aur-hooks/$1.hook ]
then bash ~/.config/aur-hooks/$1.hook
fi
$EDITOR PKGBUILD ; yes \ | makepkg -fsri
old_DEPs=( $1 ${old_DEPs[@]} )
}
function Build {
cower -fd $1 ; cd $1
if [ -e ~/.config/aur-hooks/$1.hook ]
then bash ~/.config/aur-hooks/$1.hook
fi
$EDITOR PKGBUILD ; yes \ | makepkg -fsr
}
sudo -v
sudo pacman -Syu
[ ! -e /tmp/scp ] && mkdir /tmp/scp
[ ! -e /tmp/build ] && mkdir /tmp/build
cd /tmp/build
for i in ${PKG[@]}
do deps_calc $i
done
for i in ${DEP[@]}
do Build_deps $i
PKG=( ${PKG[@]/%$i} )
done
for i in ${PKG[@]} ; do
Build $i
done
if [ ! -z "${old_DEPs[@]}" ] ; then
yes | sudo pacman -Rc ${old_DEPs[@]} ; fi
rm -rf /tmp/build/
sudo -k
'
echo "SCP into machine to download packages"
scp $(echo '-P' $port) $ip:/tmp/scp/* /tmp/scp-receive/ ; if [ ! $? = 0 ]
then echo 'Dunno what is up.... packages are most likely still there.'
else ssh $ip $(echo '-p' $port) '
rm -rf /tmp/scp/*'
fi
sudo -v
sudo pacman -U /tmp/scp-receive/*
sudo -k
read -p "Delete pkgs? y/n?" choice
case "$choice" in
y|Y|yes ) rm -rf /tmp/scp-receive/* ;;
n|N|no ) exit ;;
* ) exit ;;
esac