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