2014-05-25 04:02:57 -07:00
|
|
|
#!/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:'
|
2014-05-25 11:09:59 -07:00
|
|
|
' install <packages> install packages'
|
|
|
|
' listfiles <packages> list files owned by packages'
|
|
|
|
' search <patterns> search for a filename from all available packages'
|
2014-05-25 04:02:57 -07:00
|
|
|
)
|
|
|
|
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 () {
|
|
|
|
[ -a mingw64.files.tar.gz ] && return
|
|
|
|
wget $mirror/$repo/mingw64.files.tar.gz
|
|
|
|
tar --no-an -Oxf mingw64.files.tar.gz desc files > mingw64.lst
|
|
|
|
}
|
|
|
|
|
2014-05-25 11:09:59 -07:00
|
|
|
apt-listfiles () {
|
|
|
|
findworkspace
|
|
|
|
getdb
|
|
|
|
local pkg
|
|
|
|
for pkg in ${packages[*]}
|
|
|
|
do
|
|
|
|
awk '
|
|
|
|
$2 == "%NAME%\n" pkg {
|
2014-05-25 11:17:39 -07:00
|
|
|
print $NF
|
2014-05-25 11:09:59 -07:00
|
|
|
}
|
|
|
|
' pkg=$pkg RS=%FILENAME% FS='\n\n' mingw64.lst
|
|
|
|
done |
|
|
|
|
head -c-1
|
|
|
|
}
|
|
|
|
|
2014-05-25 04:02:57 -07:00
|
|
|
apt-install () {
|
|
|
|
findworkspace
|
|
|
|
getdb
|
2014-05-25 12:36:38 -07:00
|
|
|
local pkg file eu oe rw
|
2014-05-25 04:02:57 -07:00
|
|
|
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
|
2014-05-25 12:36:38 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-05-25 04:02:57 -07:00
|
|
|
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
|
|
|
|
|
2014-05-25 11:09:59 -07:00
|
|
|
install | listfiles | search)
|
2014-05-25 04:02:57 -07:00
|
|
|
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
|