forked from transcode-open/apt-cyg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apt-msys2
executable file
·145 lines (130 loc) · 3.16 KB
/
apt-msys2
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
#!/bin/bash
# The MIT License (MIT)
#
# Copyright (c) 2014 Steven Penny
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
usage () {
local rw=(
'apt-msys2 [command] [packages]'
''
'Commands:'
' install <packages> install packages'
' listfiles <packages> list files owned by packages'
' search <patterns> search for a filename from all available packages'
)
printf '%s\n' "${rw[@]}"
}
urlencode () {
sed '
s / %2f g
s : %3a g
' <<< "$1"
}
findworkspace () {
mirror=http://downloads.sourceforge.net/project/msys2
repo=REPOS/MINGW/$ARCH
local mirrordir=/var/cache/$(urlencode $mirror)/$repo
mkdir -p $mirrordir
cd $mirrordir
}
getdb () {
[ -e mingw64.files.tar.gz ] && return
wget $mirror/$repo/mingw64.files.tar.gz
tar --no-an -Oxf mingw64.files.tar.gz desc files > mingw64.lst
}
apt-listfiles () {
findworkspace
getdb
local pkg
for pkg in ${packages[*]}
do
awk '
$2 == "%NAME%\n" pkg {
print $NF
}
' pkg=$pkg RS=%FILENAME% FS='\n\n' mingw64.lst
done |
head -c-1
}
apt-install () {
findworkspace
getdb
local pkg file eu oe rw
for pkg in ${packages[*]}
do
file=$(awk '$5 == pkg, $0 = $2' pkg=$pkg RS=%FILENAME% FS='\n' mingw64.lst)
wget -nc $mirror/$repo/$file
tar --str 1 -x -C / -f $file
apt-msys2 listfiles $pkg | grep '\.exe$' | while read eu
do
oe=$(sed 's-^.*/--; s-\.exe$--' <<< $eu)
rw=(
'tg=$(cygpath -m $1)'
'shift'
'cygstart ${0#/usr/local} $tg $*'
)
printf '%s\n' "${rw[@]}" > $oe
install $oe /usr/local/bin
done
echo Package $pkg installed
done
}
apt-search () {
findworkspace
getdb
for pkg in ${packages[*]}
do
awk '
$0 ~ pkg {
print $5
}
' pkg="$pkg" RS=%FILENAME% FS='\n' mingw64.lst
done
}
while (( $# ))
do
case "$1" in
install | listfiles | search)
if [[ $command ]]
then
packages+=($1)
else
command=$1
fi
shift
;;
*)
packages+=($1)
shift
;;
esac
done
if [ $HOSTTYPE = x86_64 ]
then
ARCH=x86_64
else
ARCH=x86
fi
if type -t apt-$command | grep -q function
then
apt-$command
else
usage
fi