15586
|
1 #!/bin/sh
|
20450
|
2 set -e
|
|
3
|
|
4 # This script will download binary codecs for MPlayer unto a Debian system.
|
15586
|
5
|
|
6 # Author: thuglife, mennucc1
|
|
7 #
|
|
8
|
20450
|
9 CODECDIR=/usr/lib/codecs
|
|
10 PREFDIR=/var/lib/mplayer/prefs
|
|
11 MYSITE='http://people.debian.org/~mennucc1/mplayer'
|
15586
|
12
|
20450
|
13 dpkgarch=$(dpkg --print-installation-architecture)
|
15592
|
14
|
20450
|
15 [ -d $PREFDIR ] || mkdir -v $PREFDIR
|
|
16 [ -d $CODECDIR ] || mkdir -v $CODECDIR
|
|
17 cd $CODECDIR
|
|
18 [ -d mplayer_binary_codecs ] || mkdir -v mplayer_binary_codecs
|
15586
|
19
|
20450
|
20
|
|
21 choosemirror ()
|
|
22 {
|
|
23 cd $PREFDIR
|
15586
|
24
|
20450
|
25 #if [ ! -r mirrors ] || find mirrors -mtime +20 ; then
|
|
26 echo Downloading mirrors list..
|
|
27 wget -nv -c -N $MYSITE/mirrors || true
|
|
28 #fi
|
|
29 if [ ! -r bestsites ] || [ mirrors -nt bestsites ] || \
|
|
30 find bestsites -mtime +20 > /dev/null ; then
|
|
31 if which netselect > /dev/null ; then
|
|
32 echo Choosing best mirrors using netselect....
|
|
33 netselect -s 5 $( cat mirrors ) | awk '{print $2}' > bestsites
|
|
34 elif which fping > /dev/null ; then
|
|
35 fping -C 1 $( sed 's#.*//##;s#/.*##' mirrors ) 2>&1 | \
|
|
36 egrep -v 'bytes.*loss' | sort -n -k3 | \
|
|
37 grep -v ': *-' | awk '/:/{print $1}' | head -5 > bestsites
|
15586
|
38 else
|
20450
|
39 echo "(If you install 'netselect', it will select the best mirror for you"
|
|
40 echo " you may wish to stop this script and rerun after installation)"
|
|
41 sleep 5
|
|
42 head -3 mirrors > bestsites
|
15586
|
43 fi
|
20450
|
44 fi
|
|
45 }
|
|
46
|
|
47
|
|
48
|
|
49 INSTALL () {
|
|
50 filename="$3"
|
|
51 dir="$2"
|
|
52 url="$1"
|
|
53
|
|
54 cd $CODECDIR/mplayer_binary_codecs
|
|
55
|
|
56 if [ -r $filename ] ; then
|
|
57 cp $filename $filename.bak
|
|
58 fi
|
|
59
|
|
60 if [ "$url" = @MAINSITE@ ] ; then
|
|
61 cat $PREFDIR/bestsites | while read mainsite ; do
|
|
62 echo Downloading $filename from $mainsite ...
|
|
63 wget -v -c -N $mainsite/$dir/$filename || true
|
|
64 if [ -r "$filename" ] ; then
|
|
65 UNPACK "$filename"
|
|
66 [ -r $filename.bak ] && rm $filename.bak
|
|
67 return 0
|
|
68 fi
|
|
69 done
|
|
70 else
|
|
71 wget -v -c -N $url/$dir/$filename || true
|
|
72 if [ -r "$filename" ] ; then
|
|
73 UNPACK "$filename"
|
|
74 [ -r $filename.bak ] && rm $filename.bak
|
|
75 return 0
|
|
76 fi
|
|
77 fi
|
15586
|
78 }
|
|
79
|
|
80
|
20450
|
81
|
|
82
|
|
83 UNPACK ()
|
|
84 {
|
|
85 filename="$1"
|
|
86 if [ ! -r $filename.bak ] || ! cmp $filename.bak $filename ; then
|
|
87 echo Installing $filename ...
|
|
88 if [ -r $filename.list ] ; then
|
|
89 tr '\n' '\000' < $filename.list | xargs -r0 rm || true
|
|
90 UNLINK $filename.list
|
|
91 rm $filename.list
|
|
92 fi
|
|
93
|
|
94 case "$filename" in
|
|
95 *.tar.gz)
|
|
96 tar xvzf $filename > $filename.list
|
|
97 #rm $filename
|
|
98 ;;
|
|
99 *.tgz)
|
|
100 tar xvzf $filename > $filename.list
|
|
101 #rm $filename
|
|
102 ;;
|
|
103 *.tar.bz2)
|
|
104 tar --bzip2 -xvf $filename > $filename.list
|
|
105 #rm $filename
|
|
106 ;;
|
|
107 esac
|
|
108 LINK $filename.list
|
|
109 echo "Installed $filename Succesfully!"
|
|
110 fi
|
|
111 }
|
|
112
|
|
113 LINK () {
|
|
114 cd $CODECDIR/
|
|
115 cat $CODECDIR/mplayer_binary_codecs/$1 | while read f ; do
|
|
116 ln -sbf mplayer_binary_codecs/"$f" .
|
|
117 done
|
|
118 }
|
|
119
|
|
120 UNLINK () {
|
|
121 ### FIXME
|
|
122 # cd $CODECDIR
|
|
123 # cat $CODECDIR/mplayer_binary_codecs/$1 | while f do
|
|
124 # ln -sbf mplayer_binary_codecs/"$f"
|
|
125 # done
|
|
126 if which symlinks > /dev/null ; then
|
|
127 symlinks -d $CODECDIR
|
|
128 fi
|
|
129 }
|
|
130
|
15586
|
131 if [ `whoami` != root ]; then
|
20450
|
132 echo "You must be 'root' to use this script. Login as root first!"
|
|
133 exit 1
|
|
134 fi
|
15586
|
135
|
|
136 case "$1" in
|
20450
|
137 install)
|
|
138 choosemirror
|
|
139 cd $PREFDIR
|
|
140 #if [ ! -r codecs_list ] || find codecs_list -mtime +20 ; then
|
|
141 echo 'Getting codecs list ...'
|
|
142 wget -nv -c -N $MYSITE/codecs_list || true
|
|
143 #fi
|
15586
|
144
|
20450
|
145 if grep -q "^$dpkgarch" $PREFDIR/codecs_list ] ; then
|
|
146 egrep -v "^[[:space:]]*(#|$)" $PREFDIR/codecs_list | \
|
|
147 while read arch url dir file info ; do
|
|
148 if [ "$dpkgarch" = "$arch" ]; then
|
|
149 echo Installing $file $info...
|
|
150 INSTALL "$url" "$dir" "$file"
|
|
151 n=1
|
|
152 fi
|
|
153 done
|
|
154 else
|
|
155 echo "Sorry, no codecs for your arch '$dpkgarch'. Sorry dude :("
|
|
156 exit 1
|
|
157 fi
|
|
158 ;;
|
15586
|
159
|
20450
|
160 uninstall)
|
20831
|
161 cd $CODECDIR/
|
20450
|
162 rm -rf mplayer_binary_codecs
|
|
163 #FIXME we need a better clean system
|
|
164 if which symlinks > /dev/null ; then
|
|
165 symlinks -d .
|
|
166 else
|
20831
|
167 echo "please install the package 'symlinks' and run 'symlinks -d $CODECDIR' "
|
20450
|
168 fi
|
|
169 echo "Uninstalled Succesfully!"
|
|
170 ;;
|
15586
|
171
|
20450
|
172 *)
|
|
173 echo "Usage: {install|uninstall}"
|
20831
|
174 echo "This program will install binary codecs for MPlayer."
|
20450
|
175 exit 1
|
|
176 ;;
|
15586
|
177
|
|
178 esac
|
|
179
|
|
180
|
|
181 exit 0
|