sane verbosity levels for menu initialization
[mplayer/glamo.git] / TOOLS / binary_codecs.sh
blob410bede0f5943f4e6e9a7ca4a82dbb71bfbfcbe4
1 #!/bin/sh
2 set -e
4 # avoid insecure tempfile creation
5 umask 0022
7 # This script will download binary codecs for MPlayer unto a Debian system.
9 # Author: thuglife, mennucc1
12 CODECDIR=/usr/lib/codecs
13 PREFDIR=/var/lib/mplayer/prefs
14 MYSITE='http://people.debian.org/~mennucc1/mplayer'
16 dpkgarch=$(dpkg --print-installation-architecture)
18 [ -d $PREFDIR ] || mkdir -v $PREFDIR
19 [ -d $CODECDIR ] || mkdir -v $CODECDIR
20 cd $CODECDIR
21 [ -d mplayer_binary_codecs ] || mkdir -v mplayer_binary_codecs
24 choosemirror ()
26 cd $PREFDIR
28 #if [ ! -r mirrors ] || find mirrors -mtime +20 ; then
29 echo "Downloading mirrors list"
30 wget -nv -c -N $MYSITE/mirrors || true
31 #fi
32 if [ ! -r bestsites ] || [ mirrors -nt bestsites ] || \
33 find bestsites -mtime +20 | grep -q bestsites ; then
34 if which netselect > /dev/null ; then
35 echo Choosing best mirrors using netselect
36 netselect -s 5 -t 5 $( cat mirrors ) | awk '{print $2}' > bestsites
37 elif which fping > /dev/null ; then
38 fping -C 1 $( sed 's#.*//##;s#/.*##' mirrors ) 2>&1 | \
39 egrep -v 'bytes.*loss' | sort -n -k3 | \
40 grep -v ': *-' | awk '/:/{print $1}' | head -5 | ( while read mainsite ; do
41 grep $mainsite $PREFDIR/mirrors ; done ) > bestsites
42 else
43 echo "(If you install 'netselect' or 'fping', it will select the best mirror for you"
44 echo " you may wish to stop this script and rerun after installation)"
45 sleep 3
46 head -3 mirrors > bestsites
53 INSTALL () {
54 filename="$3"
55 dir="$2"
56 url="$1"
58 cd $CODECDIR/mplayer_binary_codecs
60 if [ -r $filename ] ; then
61 cp $filename $filename.bak
64 if [ "$url" = @MAINSITE@ ] ; then
65 cat $PREFDIR/bestsites | while read mainsite ; do
66 echo Downloading $filename from $mainsite ...
67 wget -c -N $mainsite/$dir/$filename || true
68 if [ -r "$filename" ] ; then
69 UNPACK "$filename"
70 return 0
72 done
73 else
74 wget -c -N $url/$dir/$filename || true
75 if [ -r "$filename" ] ; then
76 UNPACK "$filename"
77 return 0
85 UNPACK ()
87 filename="$1"
88 if [ -r $filename.bak ] && cmp $filename.bak $filename && [ -r $filename.list ] ; then
89 echo It appears that $filename was already succesfully installed
90 [ -r $filename.bak ] && rm $filename.bak
91 else
92 if grep -q " $filename$" $PREFDIR/MD5SUMS ; then
93 echo Checking MD5 for $filename
94 grep " $filename$" $PREFDIR/MD5SUMS | md5sum -c -
95 else
96 echo Warning: no MD5 for $filename were found. Hit enter to continue.
97 read dummy
99 echo Installing $filename ...
100 if [ -r $filename.list ] ; then
101 tr '\n' '\000' < $filename.list | xargs -r0 rm || true
102 UNLINK $filename.list
103 rm $filename.list
106 tarfail () { echo FAILED $filename ; rm $filename.list ; exit 1 ; }
108 case "$filename" in
109 *.tar.gz)
110 tar xvzf $filename > $filename.list || tarfail
111 #rm $filename
113 *.tgz)
114 tar xvzf $filename > $filename.list || tarfail
115 #rm $filename
117 *.tar.bz2)
118 tar --bzip2 -xvf $filename > $filename.list || tarfail
119 #rm $filename
121 esac
122 [ -r $filename.bak ] && rm $filename.bak
123 LINK $filename.list
124 echo "Installed $filename Succesfully!"
128 LINK () {
129 cd $CODECDIR/
130 cat $CODECDIR/mplayer_binary_codecs/$1 | while read f ; do
131 ln -sbf mplayer_binary_codecs/"$f" .
132 done
135 UNLINK () {
136 ### FIXME
137 # cd $CODECDIR
138 # cat $CODECDIR/mplayer_binary_codecs/$1 | while f do
139 # ln -sbf mplayer_binary_codecs/"$f"
140 # done
141 if which symlinks > /dev/null ; then
142 symlinks -d $CODECDIR
146 if [ `whoami` != root ]; then
147 echo "You must be 'root' to use this script. Login as root first!"
148 exit 1
151 case "$1" in
152 install)
153 if test -x /bin/bzip2 || test -x /usr/bin/bzip2 ; then : ; else
154 echo You need to install bzip2
155 exit 1
157 choosemirror
158 cd $PREFDIR
159 #if [ ! -r codecs_list ] || find codecs_list -mtime +20 ; then
160 echo "Getting codecs list"
161 wget -nv -c -N $MYSITE/codecs_list || true
164 cd $PREFDIR
165 echo Downloading MD5 sums from main site
166 [ -r MD5SUMS ] && mv MD5SUMS MD5SUMS.bak
167 if wget -nv -N http://www.mplayerhq.hu/MPlayer/releases/codecs/MD5SUMS ; then
168 [ -r MD5SUMS.bak ] && rm MD5SUMS.bak
169 else
170 echo "failed"
171 if [ -r MD5SUMS.bak ] ; then
172 echo "trying to use backup"
173 mv MD5SUMS.bak MD5SUMS
177 if grep -q "^$dpkgarch" $PREFDIR/codecs_list ; then
178 egrep -v "^[[:space:]]*(#|$)" $PREFDIR/codecs_list | \
179 while read arch url dir file info ; do
180 if [ "$dpkgarch" = "$arch" ]; then
181 echo Downloading and installing $file $info...
182 INSTALL "$url" "$dir" "$file"
184 done
185 needlibstd=no
186 test "$dpkgarch" = "powerpc" && needlibstd=yes
187 test "$dpkgarch" = "i386" && needlibstd=yes
188 if test "$needlibstd" = "yes" && ! test -r /usr/lib/libstdc++.so.5 ; then
189 echo "Warning: you need to install libstdc++ 5 libraries"
190 echo -n "Do it now? "
191 read R
192 case $R in
193 y*) apt-get install libstdc++5 ;;
194 *) echo "If you change your mind, use the command"
195 echo " apt-get install libstdc++5" ;;
196 esac
198 else
199 echo "Sorry, no codecs for your arch '$dpkgarch'. Sorry dude :("
200 exit 1
204 uninstall)
205 cd $CODECDIR/
206 rm -rf mplayer_binary_codecs
207 #FIXME we need a better clean system
208 if which symlinks > /dev/null ; then
209 symlinks -d .
210 else
211 echo "please install the package 'symlinks' and run 'symlinks -d $CODECDIR' "
213 echo "Uninstalled Succesfully!"
217 echo "Usage: {install|uninstall}"
218 echo "This program will install binary codecs for MPlayer."
219 exit 1
222 esac
225 exit 0