CRUX-ARM : Home

Home :: Documentation :: Download :: Development :: Community :: Ports :: Packages :: Bugs :: Links :: About :: Donors
bc330452c3a113f538bea8972b8701f7e2c06897
[initrd.git] / filesystem / setup
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
25 VERSION="2.7"
26
27 do_dialog() {
28 dialog --backtitle "CRUX $VERSION Setup" --no-shadow "$@"
29 }
30
31 do_abort() {
32 do_dialog --aspect 50 --defaultno --yesno "Abort installation?" 0 0 && exit 1
33 }
34
35 do_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
46 welcome() {
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
50 select_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
64 select_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
79 select_collections() {
80 if [ "$ACTION" != "INSTALL" ]; then
81 return 0
82 fi
83 if [ ! -d core ] || [ ! -d kernel ]; then
84 do_dialog --aspect 50 --msgbox "Package directories (core and 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 }
93
94 ask_detailed() {
95 if [ "$ACTION" != "INSTALL" ]; then
96 return 0
97 fi
98 do_dialog --aspect 50 --defaultno --yesno "Do you want the chance to select packages individually?" 0 0 && DO_DETAILED="yes"
99 }
100
101 select_packages() {
102 if [ ! -d core ] || [ ! -d kernel ]; then
103 do_dialog --aspect 50 --msgbox "Package directories (core and kernel) were not found in $crux_dir. Aborting." 0 0
104 exit 1
105 fi
106 if [ "$ACTION" = "INSTALL" ]; then
107 if [ "$DO_DETAILED" = "yes" ]; then
108 for collection in core opt xorg; do
109 [ ! -d $collection ] && continue
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.*' | cut -d'/' -f2 | sed "s|.pkg.tar.[^ ]*|\t($collection) $checked\n|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 [ ! -d $collection ] && continue
124 presel=`grep $collection $collfile`
125 if [ "$presel" == "$collection" ]; then
126 find $collection -name '*.pkg.tar.*' | cut -d'/' -f2 | sed "s|.pkg.tar.[^ ]*|\t($collection) $checked\n|g" | sort >> $pkgfile
127 fi
128 done
129 fi
130 else
131 # Upgrade
132 do_dialog --aspect 50 --infobox "Searching for packages, please wait..." 0 0
133 TITLE="Select packages to upgrade:"
134 INSTALLED_PACKAGES=`pkginfo -r $ROOT -i | gawk '{ print $1; }'`
135 for package in $INSTALLED_PACKAGES; do
136 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 ' '`"
137 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 ' '`"
138 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 ' '`"
139 done
140 do_select --separate-output --checklist "$TITLE" 19 60 12 $CORE_LIST $OPT_LIST $XORG_LIST 2> $pkgfile
141 fi
142 }
143
144 check_dependencies() {
145 if [ "$ACTION" != "INSTALL" ]; then
146 return 0
147 fi
148 do_dialog --aspect 50 --infobox "Checking dependencies, please wait..." 0 0
149 get_missing_deps
150 if [ -n "$MISSING_DEPS" ]; then
151 for package in $MISSING_DEPS; do
152 _package="`find . -name '${package}#*.pkg.tar.*' | sed 's/.pkg.tar.[^ ]*/ /g'`"
153 _collection="`dirname $_package | cut -d'/' -f2`"
154 # every item should be in the form: "acl#2.2.51-1 (core)"
155 MISSING_LIST="$MISSING_LIST $_package ($_collection)"
156 done
157 TITLE="The following packages are needed by the ones you selected"
158 do_select --separate-output --checklist "$TITLE" 19 60 12 $MISSING_LIST 2>> $pkgfile
159 fi
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 | awk '{print $1}'`; 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 if [ -f $PKG_FILE ]; then
234 pkgadd -r $ROOT $PKGARGS $PKG_FILE > $tmpfile 2>&1
235 if [ $? = 0 ]; then
236 echo "OK" >> $logfile
237 else
238 let $((ERRORS+=1))
239 echo "ERROR" >> $logfile
240 echo "" >> $logfile
241 cat $tmpfile >> $logfile
242 echo "" >> $logfile
243 fi
244 fi
245 done
246
247 # Install kernel
248 if [ ! -d $ROOT/usr/src/linux-$KERNEL_VERSION ]; then
249 progressbar "Installing `basename $KERNEL .tar.bz2`..."
250 echo -n "Installing `basename $KERNEL .tar.bz2`....." >> $logfile
251 (
252 set -e
253 tar -C $ROOT/usr/src -xjf $KERNEL
254 cp -f ./kernel/linux-$KERNEL_VERSION.config $ROOT/usr/src/linux-$KERNEL_VERSION/.config
255 ) > $tmpfile 2>&1
256 if [ $? = 0 ]; then
257 echo "OK" >> $logfile
258 else
259 let $((ERRORS+=1))
260 echo "ERROR" >> $logfile
261 echo "" >> $logfile
262 cat $tmpfile >> $logfile
263 echo "" >> $logfile
264 fi
265 else
266 echo "Directory $ROOT/usr/src/linux-$KERNEL_VERSION already exists." >> $logfile
267 echo "Assuming linux-$KERNEL_VERSION is already installed." >> $logfile
268 fi
269
270 # Log footer
271 echo "----------------------------------------------------------" >> $logfile
272 echo "$ERRORS error(s) found" >> $logfile
273
274 cat $logfile > $tmpfile
275
276 echo "" > $logfile
277 if [ "$ERRORS" = "0" ]; then
278 echo "$ACTION COMPLETED SUCCESSFULLY!" >> $logfile
279 else
280 echo "$ACTION FAILED!" >> $logfile
281 fi
282 echo "" >> $logfile
283 echo "" >> $logfile
284 cat $tmpfile >> $logfile
285
286 ) | do_dialog --title " Please wait " --gauge "" 8 60 0
287
288 # Show log
289 do_dialog --exit-label "OK" --textbox $logfile 19 68
290 }
291
292 main() {
293 welcome
294 select_action
295 select_root
296 select_collections
297 ask_detailed
298 select_packages
299 check_dependencies
300 confirm
301 if [ "$ACTION" = "UPGRADE" ] && [ -f /usr/bin/setup-helper ]
302 then
303 (/usr/bin/setup-helper $ROOT &> $helperlogfile) | do_dialog \
304 --title " Please wait [2.6 -> 2.7 check]" --gauge "" 8 60 0
305 fi
306 install_packages
307 cat $helperlogfile 2> /dev/null
308 }
309
310 tmpfile=/tmp/tmp.$$
311 collfile=/tmp/collections.$$
312 pkgfile=/tmp/packages.$$
313 logfile=/tmp/log.$$
314 helperlogfile=/tmp/log-helper.$$
315 crux_dir=/media/crux
316 neededfile=/tmp/needed.$$
317 markedfile=/tmp/marked.$$
318
319 # Detailed selection of packages
320 DO_DETAILED="no"
321 MISSINGDEPS=""
322
323 trap "rm -f $tmpfile $pkgfile $collfile $neededfile $markedfile" 0 1 2 5 15
324
325 if [ "$1" != "" ]; then
326 crux_dir=$1
327 fi
328
329 depsfile=$crux_dir/setup.dependencies
330
331 if [ -d $crux_dir ]; then
332 cd $crux_dir
333 else
334 do_dialog --aspect 50 --msgbox "Directory $crux_dir not found. Aborting." 0 0
335 exit 1
336 fi
337
338 main
339
340 # End of file