CRUX-ARM : Home

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