Subversion Repository

Parent Directory Parent Directory | Revision Log Revision Log


Revision 60 - (show annotations)
Sun Dec 26 03:14:27 2010 UTC (2 years, 4 months ago) by acrux
File size: 12092 byte(s)
synced with 2.7RC1
1 #!/bin/bash
2 #
3 # CRUX PPC Setup, based on CRUX Setup
4 #
5 # Copyright (c) 2001-2004 by Per Liden <per@fukt.bth.se>
6 # Copyright (c) 2004 Giulivo Navigante <giulivo@linuxmail.org>
7 # Copyright (c) 2005-2011 The CRUX PPC Team - http://cruxppc.org/
8 #
9 # release codename is: ottobre 2010
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
24 # USA.
25
26 VERSION="2.7 "
27
28 do_dialog() {
29 dialog --backtitle "Setup: CRUX PPC $VERSION (32bit) " --no-shadow "$@"
30 }
31
32 do_abort() {
33 do_dialog --aspect 50 --defaultno --yesno "WARNING: Abort installation?" 0 0 && exit 1
34 }
35
36 do_select() {
37 while true; do
38 do_dialog "$@"
39 if [ $? != 0 ]; then
40 do_abort
41 else
42 break
43 fi
44 done
45 }
46
47 welcome() {
48 do_select --aspect 5 --yesno "Welcome!\n\nThis script will guide you through the installation of CRUX PPC packages.\n\nBefore starting the installation make sure you have read and understood the \"CRUX PPC Installation Guide\". If you have done that then please continue, else abort the installation and come back later.\n\nAre you really sure you want to continue?" 0 0
49 }
50
51 select_action() {
52 do_select --menu "Install or upgrade?" 9 45 2 \
53 "1" "Install CRUX PPC $VERSION " \
54 "2" "Upgrade to CRUX PPC $VERSION " 2> $tmpfile
55 ACTION=`cat $tmpfile`
56 if [ "$ACTION" = "1" ]; then
57 ACTION="INSTALL"
58 else
59 ACTION="UPGRADE"
60 do_select --aspect 5 --yesno "NOTE!\n\nBefore upgrading make sure /etc/pkgadd.conf in the old installation is tuned to fit your needs, important files might otherwise be overwritten. Further, when this script has completed the upgrade you need to go though the rejected files in /var/lib/pkg/rejected/ and upgrade them manually if needed. See the pkgadd(8) man page for more information about /etc/pkgadd.conf.\n\nAre you really sure you want to continue?" 0 0
61 fi
62 }
63
64 select_root() {
65 while true; do
66 do_select --aspect 40 --inputbox "Enter directory where your CRUX PPC root partition is mounted:" 0 0 "/mnt" 2> $tmpfile
67 ROOT=`cat $tmpfile`
68 if [ -d "$ROOT" ]; then
69 if [ "$ACTION" = "INSTALL" ] || [ -f "$ROOT/var/lib/pkg/db" ]; then
70 break
71 fi
72 do_dialog --aspect 50 --msgbox "Directory does not look like a CRUX PPC root directory. Try again." 0 0
73 else
74 do_dialog --aspect 50 --msgbox "Directory not found. Try again." 0 0
75 fi
76 done
77 }
78
79 select_collections() {
80 if [ "$ACTION" != "INSTALL" ]; then
81 return 0
82 fi
83 if [ ! -d core ] || [ ! -d opt ] || [ ! -d xorg ] || [ ! -d kernel ]; then
84 do_dialog --aspect 50 --msgbox "Package directories (core, opt, xorg or kernel) were not found in $crux_dir. Aborting." 0 0
85 exit 1
86 fi
87 TITLE="Select collections to install:\n(detailed package selection will follow)"
88 do_select --separate-output --checklist "$TITLE" 13 60 6 \
89 core "The core packages (required)" ON \
90 opt "Optional packages" OFF \
91 xorg "X.org packages" OFF 2> $collfile
92 sed -i 's|\"||g' $collfile
93 }
94
95 ask_detailed() {
96 if [ "$ACTION" != "INSTALL" ]; then
97 return 0
98 fi
99 do_dialog --aspect 50 --defaultno --yesno "Do you want the chance to select packages individually?" 0 0 && DO_DETAILED="yes"
100 }
101
102 select_packages() {
103 if [ ! -d core ] || [ ! -d opt ] || [ ! -d xorg ] || [ ! -d kernel ]; then
104 do_dialog --aspect 50 --msgbox "Package directories (core, opt, xorg or kernel) were not found in $crux_dir. Aborting." 0 0
105 exit 1
106 fi
107 if [ "$ACTION" = "INSTALL" ]; then
108 if [ "$DO_DETAILED" = "yes" ]; then
109 for collection in core opt xorg; do
110 presel=`grep $collection $collfile`
111 if [ "$presel" == "$collection" ]; then
112 checked=ON
113 else
114 checked=OFF
115 fi
116 do_dialog --aspect 50 --infobox "Searching for packages, please wait..." 0 0
117 TITLE="Select $collection packages to install:"
118 PKG_LIST=`find $collection \( -name '*.pkg.tar.gz' -o -name '*.pkg.tar.bz2' -o -name '*.pkg.tar.xz' \) -printf "%f ($collection) $checked\n" | sed 's/.pkg.tar.[^ ]*//g' | sort | xargs echo ' '`
119 do_select --separate-output --checklist "$TITLE" 19 60 12 $PKG_LIST 2>> $pkgfile
120 done
121 else # no detailed selection
122 for collection in core opt xorg; do
123 presel=`grep $collection $collfile`
124 if [ "$presel" == "$collection" ]; then
125 find $collection \( -name '*.pkg.tar.gz' -o -name '*.pkg.tar.bz2' -o -name '*.pkg.tar.xz' \) -printf "%f\n" | sed 's/.pkg.tar.*//g' | sort >> $pkgfile
126 fi
127 done
128 fi
129 else
130 # Upgrade
131 do_dialog --aspect 50 --infobox "Searching for packages, please wait..." 0 0
132 TITLE="Select packages to upgrade:"
133 INSTALLED_PACKAGES=`pkginfo -r $ROOT -i | gawk '{ print $1; }'`
134 for package in $INSTALLED_PACKAGES; do
135 CORE_LIST="$CORE_LIST `find core \( -name \"${package}#*.pkg.tar.gz\" -o -name \"${package}#*.pkg.tar.bz2\" -o -name \"${package}#*.pkg.tar.xz\" \) -printf '%f (core) ON\n' | sed 's/.pkg.tar.[^ ]*/ /g' | sort | xargs echo ' '`"
136 OPT_LIST="$OPT_LIST `find opt \( -name \"${package}#*.pkg.tar.gz\" -o -name \"${package}#*.pkg.tar.bz2\" -o -name \"${package}#*.pkg.tar.xz\" \) -printf '%f (opt) ON\n' | sed 's/.pkg.tar.[^ ]*/ /g' | sort | xargs echo ' '`"
137 XORG_LIST="$XORG_LIST `find xorg \( -name \"${package}#*.pkg.tar.gz\" -o -name \"${package}#*.pkg.tar.bz2\" -o -name \"${package}#*.pkg.tar.xz\" \) -printf '%f (xorg) ON\n' | sed 's/.pkg.tar.[^ ]*/ /g' | sort | xargs echo ' '`"
138 done
139 do_select --separate-output --checklist "$TITLE" 19 60 12 $CORE_LIST $OPT_LIST $XORG_LIST 2> $pkgfile
140 fi
141 sed -i 's|\"||g' $pkgfile
142 sed -i 's|\\\#|\#|g' $pkgfile
143 }
144
145 check_dependencies() {
146 if [ "$ACTION" != "INSTALL" ]; then
147 return 0
148 fi
149 do_dialog --aspect 50 --infobox "Checking dependencies, please wait..." 0 0
150 get_missing_deps
151 if [ -n "$MISSING_DEPS" ]; then
152 for package in $MISSING_DEPS; do
153 MISSING_LIST="$MISSING_LIST `find . \( -name \"${package}#*.pkg.tar.gz\" -o -name \"${package}#*.pkg.tar.bz2\" -o -name \"${package}#*.pkg.tar.xz\" \) -printf '%f %p ON\n' | sed 's/.pkg.tar.[^ ]*/ /g' | sed 's|./|(|;s|/.* O|) O|' | sort | xargs echo ' '`"
154 done
155 TITLE="The following packages are needed by the ones you selected"
156 do_select --separate-output --checklist "$TITLE" 19 60 12 $MISSING_LIST 2>> $pkgfile
157 fi
158 sed -i 's|\"||g' $pkgfile
159 sed -i 's|\\\#|\#|g' $pkgfile
160 }
161
162 get_missing_deps() {
163 needed=""
164 toinstall=`sed 's/\#.*//g' $pkgfile`
165 for f in $toinstall; do
166 pdeps=`grep "^$f\:" $depsfile|sed "s|^$f: ||g"`
167 for d in $pdeps; do
168 needed="$needed $d"
169 done
170 done
171 sed 's/\#.*//g' $pkgfile|sort -u > $markedfile
172 echo $needed|tr ' ' '\n'|sort -u > $neededfile
173 MISSING_DEPS=`comm -1 -3 $markedfile $neededfile`
174 }
175
176 confirm() {
177 if [ "$ACTION" = "INSTALL" ]; then
178 # Install
179 do_select --aspect 25 --yesno "Selected packages will now be installed. Are you sure you want to continue?" 0 0
180 else
181 # Upgrade
182 do_select --aspect 25 --yesno "Selected packages will now be upgraded. Are you sure you want to continue?" 0 0
183 fi
184 }
185
186 progressbar() {
187 echo "XXX"
188 expr $COUNT '*' 100 / $TOTAL
189 echo "\n$*"
190 echo "XXX"
191 let $((COUNT+=1))
192 }
193
194 install_packages() {
195 if [ ! -d $ROOT/var/lib/pkg ]; then
196 mkdir -p $ROOT/var/lib/pkg
197 touch $ROOT/var/lib/pkg/db
198 fi
199
200 if [ -d $ROOT/var/lib/pkg/rejected ]; then
201 rm -rf $ROOT/var/lib/pkg/rejected
202 fi
203
204 if [ "$ACTION" = "INSTALL" ]; then
205 PKGARGS=""
206 else
207 # We use -f here since we want to avoid pkgadd conflicts.
208 # Unwanted/Unexpected conflicts could arise if files are
209 # moved from one package to another, or if the user added
210 # the files himself. Instead of failing the whole upgrade
211 # we force the upgrade. This should be fairly safe and it
212 # will probably help to avoid some "semi-bogus" errors from
213 # pkgadd. The rules in /etc/pkgadd.conf will still be used.
214 PKGARGS="-f -u"
215 fi
216
217 (
218 # Log header
219 echo "Log ($logfile)" > $logfile
220 echo "----------------------------------------------------------" >> $logfile
221
222 # Install packages
223 KERNEL=./kernel/linux-*.tar.bz2
224 KERNEL_VERSION=`basename $KERNEL .tar.bz2 | sed "s/linux-//"`
225 TOTAL=`cat $pkgfile | wc -l`
226 let $((TOTAL+=1))
227 let $((COUNT=0))
228 let $((ERRORS=0))
229 for FILE in `cat $pkgfile`; do
230 progressbar "Installing $FILE..."
231 echo -n "Installing $FILE....." >> $logfile
232 PKG_FILE=`find . \( -name "$FILE.pkg.tar.gz" -o -name "$FILE.pkg.tar.bz2" -o -name "$FILE.pkg.tar.xz" \)`
233 pkgadd -r $ROOT $PKGARGS $PKG_FILE > $tmpfile 2>&1
234 if [ $? = 0 ]; then
235 echo "OK" >> $logfile
236 else
237 let $((ERRORS+=1))
238 echo "ERROR" >> $logfile
239 echo "" >> $logfile
240 cat $tmpfile >> $logfile
241 echo "" >> $logfile
242 fi
243 done
244
245 # Install kernel
246 if [ ! -d $ROOT/usr/src/linux-$KERNEL_VERSION ]; then
247 progressbar "Installing `basename $KERNEL .tar.bz2`..."
248 echo -n "Installing `basename $KERNEL .tar.bz2`....." >> $logfile
249 (
250 set -e
251 tar -C $ROOT/usr/src -xjf $KERNEL
252 # cp -f ./kernel/linux-$KERNEL_VERSION.config $ROOT/usr/src/linux-$KERNEL_VERSION/.config
253 # cp -f ./kernel/linux-$KERNEL_VERSION.patch $ROOT/usr/src/
254 cp -f ./kernel/cruxppc-logo.diff $ROOT/usr/src/
255 for config in ./kernel/*config; do
256 cp $config $ROOT/usr/src/
257 done
258
259 chown -R root.root $ROOT/usr/src/linux-$KERNEL_VERSION
260 chmod -R go-w $ROOT/usr/src/linux-$KERNEL_VERSION
261 shopt -s nullglob
262 for patch in ./kernel/*patch; do
263 # patch -s -d $ROOT/usr/src/linux-$KERNEL_VERSION -p1 < $patch
264 cp $patch $ROOT/usr/src/
265 done
266 if [ ! -d $ROOT/lib/modules/$KERNEL_VERSION ]; then
267 mkdir -p $ROOT/lib/modules/$KERNEL_VERSION
268 depmod -b $ROOT -a $KERNEL_VERSION
269 fi
270 ) > $tmpfile 2>&1
271 if [ $? = 0 ]; then
272 echo "OK" >> $logfile
273 else
274 let $((ERRORS+=1))
275 echo "ERROR" >> $logfile
276 echo "" >> $logfile
277 cat $tmpfile >> $logfile
278 echo "" >> $logfile
279 fi
280 else
281 echo "Directory $ROOT/usr/src/linux-$KERNEL_VERSION already exists." >> $logfile
282 echo "Assuming linux-$KERNEL_VERSION is already installed." >> $logfile
283 fi
284
285 # Log footer
286 echo "----------------------------------------------------------" >> $logfile
287 echo "$ERRORS error(s) found" >> $logfile
288
289 cat $logfile > $tmpfile
290
291 echo "" > $logfile
292 if [ "$ERRORS" = "0" ]; then
293 echo "$ACTION COMPLETED SUCCESSFULLY!" >> $logfile
294 else
295 echo "$ACTION FAILED!" >> $logfile
296 fi
297 echo "" >> $logfile
298 echo "" >> $logfile
299 cat $tmpfile >> $logfile
300
301 ) | do_dialog --title " Please wait " --gauge "" 8 60 0
302
303 # Show log
304 do_dialog --exit-label "OK" --textbox $logfile 19 68
305 }
306
307 main() {
308 welcome
309 select_action
310 select_root
311 select_collections
312 ask_detailed
313 select_packages
314 check_dependencies
315 confirm
316 if [ "$ACTION" = "UPGRADE" ] && [ -f /usr/bin/setup-helper ]; then
317 (
318 /usr/bin/setup-helper $ROOT &> $helperlogfile
319 ) | do_dialog --title " Please wait [2.6 -> 2.7 check]" --gauge "" 8 60 0
320 fi
321 install_packages
322 cat $helperlogfile 2> /dev/null
323 }
324
325 tmpfile=/tmp/tmp.$$
326 collfile=/tmp/collections.$$
327 pkgfile=/tmp/packages.$$
328 logfile=/tmp/log.$$
329 helperlogfile=/tmp/log-helper.$$
330 crux_dir=/crux
331 neededfile=/tmp/needed.$$
332 markedfile=/tmp/marked.$$
333
334 # Detailed selection of packages
335 DO_DETAILED="no"
336 EXECUTE_SCRIPTS="yes"
337 MISSINGDEPS=""
338
339 trap "rm -f $tmpfile $pkgfile $collfile $neededfile $markedfile" 0 1 2 5 15
340
341 if [ "$1" != "" ]; then
342 crux_dir=$1
343 fi
344
345 depsfile=$crux_dir/setup.dependencies
346
347 if [ -d $crux_dir ]; then
348 cd $crux_dir
349 else
350 do_dialog --aspect 50 --msgbox "Directory $crux_dir not found. Aborting." 0 0
351 exit 1
352 fi
353
354 main
355
356 # End of file

Properties

Name Value
svn:executable *