root/quickinst/quickinst

Revision 323, 5.5 KB (checked in by henning, 4 months ago)

quickinst: default url bug

  • Property svn:executable set to *
Line 
1#!/bin/bash
2# Arch Linux bootstrap script. Released under the terms of the GPL.
3# henning mueller <henning@orgizm.net>
4
5usage() {
6cat >&2 <<EOF
7usage: $(basename $0) [options] <ftp|cd> <target> [source]
8
9This script is for installing Arch Linux after manual partitioning and
10network configuration.
11
12For the FTP installation, the original throttled Arch mirror is selected by
13default, so run with another mirror as [source], please. The full URL is
14expected in this case. Example:
15ftp://ftp5.gwdg.de/pub/linux/archlinux/current/os/x86_64
16
17If you want to bootstrap another architecture than the script is currently
18running on, you have to specify a custom source.
19
20Options:
21    -i <file>  Include packages from <file> in the installation. <file> should
22               contain one package name per line.
23    -x         Xen mode. Activate serial console and deactivate virtual
24               terminals.
25
26EOF
27exit 1
28}
29
30wget="wget -q -t0"
31arch=$(uname -m)
32
33while [ $# -gt 1 ]; do
34        case $1 in
35                -i)
36                        [ ! -f $2 ] &&
37                                echo "Package file '$2' does not exist." &&
38                                exit 1
39                        addpkgs=$(cat $2 | tr "\n" " ")
40                        shift; shift
41                        ;;
42                -v) wget="wget -t0"; shift;;
43                -x) xen=true; shift;;
44                -h) usage;;
45                *) break
46        esac
47done
48
49mode=$1
50target=$2
51source=$3
52
53chroot=true
54fstab=true
55
56[ "$mode" == "" ] || [ "$target" == "" ] && usage
57[ "$mode" == "ftp" ] || [ "$mode" == "cd" ] || usage
58
59[ "$UID" != "0" ] &&
60        echo "run as root, please." >&2 &&
61        exit 1
62
63[ $(echo $target | egrep ^/) ] ||
64        target=$(pwd)/$target
65
66[ -d "$target" ] ||
67        mkdir -p $target
68
69[ "$source" == "" ] &&
70        source=ftp://ftp.tu-chemnitz.de/pub/linux/archlinux/core/os/$arch ||
71        arch=$(basename $source)
72
73[ -f /etc/arch-release ] && [ ! $chroot ] &&
74        on_arch=true
75
76cache=$target/var/cache/pacman/pkg
77[ $on_arch ] && {
78        mkdir -p $(dirname $cache)
79        mkdir -p $target/var/lib/pacman
80        [ ! -d $cache ] &&
81                ln -s /var/cache/pacman/pkg $cache
82} || {
83        mkdir -p $cache
84}
85
86[ "$mode" == "ftp" ] && {
87        install() {
88                cd $cache
89                echo "  · $1"
90
91                package=$(ls $1*.pkg.tar.gz 2>/dev/null | tail -1)
92
93                [ ! -f "$package" ] &&
94                        $wget $source/$1*.pkg.tar.gz ||
95                        exit 1
96
97                package=$(ls $1*.pkg.tar.gz | tail -1)
98                tar xzf $package -C $target ||
99                exit 1
100        }
101}
102[ "$mode" == "cd" ] && {
103        install() {
104                exit 1
105        }
106}
107
108[ $on_arch ] || {
109        echo · downloading and installing bash.
110                for package in glibc ncurses readline bash; do
111                        install $package
112                done
113}
114
115echo · downloading and installing pacman.
116        for package in libfetch libarchive acl attr zlib bzip2; do
117                install $package
118        done
119        for package in openssl xz-utils pacman-?. pacman-mirrorlist; do
120                install $package
121        done
122
123echo · installing base.
124        cd $target
125        cp /etc/resolv.conf etc/resolv.conf
126
127        mkdir sys proc dev tmp 2> /dev/null
128
129        [ -z "$addpkgs" ] && { # TODO source for extra and community
130                echo -e "[core]\nServer = $source" >> tmp/pacman.conf
131                config="--config tmp/pacman.conf"
132        }
133
134#       sed -ie "s/#S/S/g" etc/pacman.d/mirrorlist
135
136        cp etc/pacman.d/mirrorlist etc/pacman.d/mirrorlist.original
137        tmp=$(echo $source | sed -e "s/current/\$repo/")
138        echo "Server = $tmp" > etc/pacman.d/mirrorlist
139
140        [ $on_arch ] && {
141                pacman --noconfirm $config -r $target \
142                        -Sfy base $addpkgs || exit 1
143        } || {
144                mount -o bind /dev dev
145                mount -t proc none proc
146                mount -t sysfs none sys
147
148                chroot $target /bin/bash <<EOF
149                        pacman --noconfirm $config \
150                                -Sfy base $addpkgs || exit 1
151EOF
152        }
153
154[ $xen ] && {
155        echo · preparing for use in xen.
156
157                vc=xvc0
158
159                [ -f /etc/debian_version ] && vc=hvc0
160
161                cat <<EOF > etc/inittab
162rc::sysinit:/etc/rc.sysinit
163rs:S1:wait:/etc/rc.single
164rm:2345:wait:/etc/rc.multi
165rh:06:wait:/etc/rc.shutdown
166su:S:wait:/sbin/sulogin -p
167c:2345:respawn:/sbin/agetty -8 38400 $vc linux
168EOF
169
170                echo $vc > etc/securetty
171}
172
173[ $fstab ] && {
174        grep $target /proc/mounts | while read line; do
175                device=$(echo $line | cut -d ' ' -f 1)
176                uuid=$(/lib/udev/vol_id --uuid $device)
177
178                [ "$(echo $line | sed -e "s:$target::" | cut -d ' ' -f 2)" == "" ] &&
179                        repl='/' || repl=''
180
181                [ "$uuid" != "" ] &&
182                        echo $line | sed -e "s:$target:$repl:" -e "s:$device:UUID=$uuid:" \
183                                >> etc/fstab
184        done
185}
186
187echo · cleaning up.
188        [ -h $cache ] && rm $cache && mkdir $cache
189        [ $on_arch ] || umount sys proc dev
190        mv etc/resolv.conf.pacorig etc/resolv.conf
191        rm -f etc/*.pac* tmp/pac* .FILELIST .INSTALL .PKGINFO
192        ln -s . boot/boot
193
194echo -e "\nPackage installation complete.\n"
195
196[ ! $xen ] && cat <<EOF
197Probably you have to install a boot loader.
198Therefor chroot into your system (you have to be root):
199mount -o bind /dev $target/dev
200mount -t proc none $target/proc
201mount -t sysfs none $target/sys
202chroot $target /bin/bash
203
204For grub:
205install-grub <hdd> <boot-partition> (example: /dev/sda /dev/sda1)
206
207For lilo:
208lilo
209
210A default initramfs setup was created during the package installation process.
211If you have special demands, generate a new one after editing
212/etc/mkinitcpio.conf and /etc/mkinitcpio.d/kernel26-fallback.conf:
213mkinitcpio -p kernel26 -k <kernel-version> (example: 2.6.26-ARCH)
214
215Don't forget to set a root password.
216
217For completing the installation, edit /etc/rc.conf and /etc/fstab before
218unmounting the devices and rebooting.
219
220EOF
221
222[ $xen ] && cat <<EOF
223Don't forget to set a root password:
224chroot $target /bin/bash
225passwd
226
227For completing the installation, edit /etc/rc.conf and /etc/fstab before
228creating the xen guest.
229
230Your xen config could look like this:
231kernel = '/boot/vmlinuz26-xen'
232memory = 256
233name = 'guest'
234disk = [ 'phy:/dev/mapper/lvm-guest,sda1,w' ]
235vif = [ 'bridge=br0' ]
236ramdisk = '/boot/kernel26-xen.img'
237root = '/dev/sda1 ro'
238vcpus = 1
239extra = '3 console=xvc0'
240restart = 'onreboot'
241
242EOF
Note: See TracBrowser for help on using the browser.