Can now change passwd without requiring chroot
[dtc-xen.git] / src / dtc_install_centos
1 #!/bin/sh
2
3 CACHEDIR="/var/cache/yum"      # where yum caches stuff -- is created as a subdir
4                                # of the destination chroot
5
6 # FIXME perhaps after installation the script can modify the target machine's yum config to point to our Squid proxy
7 #       or define http_proxy inside the machine.  that would make upgrades for customers much much faster.
8 # better idea: instead of using a web cache, use a stash on the machine, we rsync the new RPMs into it once it's finished
9 # we would need a mutex (flock or fcntl based?) that mutially excludes the critical section
10 # the critical section is both the yum and the rsync process
11 # we also need to rsync packages from the stash into the var cache on the vps, and a mutex to lock out if another yum is running, just as in the first scenario
12 # cannot use a symlink because its chrooted for the duration of the process
13 # at any case, the repo names for different distros need to be different, otherwise the caches will clash horribly
14 # FIXME once that is done, we can stop using apt-proxy or apt-cacher
15 # FIXME try to make it for suse, mandriva or any other rpm-based distro
16
17 YUMENVIRON="$1"                # where the yum config is generated and deployed
18 INSTALLROOT="$2"               # destination directory / chroot for installation
19
20 if [ "${INSTALLROOT}" = "" -o ! -d "${INSTALLROOT}" -o "${YUMENVIRON}" = "" ] ; then
21         echo "usage: centos-installer /yum/environment (will be created) /destination/directory (must exist)"
22         echo "dest dir MUST BE an absolute path"
23         exit 126
24 fi
25
26 set -e
27 set -x
28
29 which rpm >/dev/null 2>&1 || { echo "rpm is not installed.  please install rpm." ; exit 124 ; }
30
31 # sometimes when the RPM database is inconsistent, yum fails but exits with success status
32 # we make sure the db is in good health
33 mkdir -p /var/lib/rpm
34 rpm --rebuilddb
35
36 # set distro ver
37 releasever=6
38
39 # detect architecture
40 ARCH=`uname -m`
41 if [ "${ARCH}" = x86_64 ] ; then
42         exclude="*.i386 *.i586 *.i686"
43         basearch=x86_64
44 elif [ "${ARCH}" = i686 ] ; then
45         exclude="*.x86_64"
46         basearch=i386
47 else
48         echo "Unknown architecture: ${ARCH} -- stopping centos-installer"
49         exit 3
50 fi
51
52 # make yum environment
53
54 mkdir -p ${YUMENVIRON}/pluginconf.d ${YUMENVIRON}/repos.d ${CACHEDIR} ${INSTALLROOT}/var/log
55
56 # In case the folder is not there:
57 mkdir -p /var/lib/rpm
58
59 # configure yum:
60
61 cat > "${YUMENVIRON}/yum.conf" << EOF
62 [main]
63 reposdir=$YUMENVIRON/repos.d
64 pluginconfpath=$YUMENVIRON/pluginconf.d
65 cachedir=$CACHEDIR
66 installroot=$INSTALLROOT
67 exclude=$exclude
68 keepcache=1
69 #debuglevel=4
70 #errorlevel=4
71 pkgpolicy=newest
72 distroverpkg=centos-release
73 tolerant=1
74 exactarch=1
75 obsoletes=1
76 gpgcheck=1
77 plugins=1
78 metadata_expire=1800
79 EOF
80
81 cat > "${YUMENVIRON}/pluginconf.d/installonlyn.conf" << EOF
82 [main]
83 enabled=1
84 tokeep=5
85 EOF
86
87 cat > "${YUMENVIRON}/repos.d/CentOS-Base.repo" << EOF
88 [base]
89 name=CentOS-6 - Base
90 #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
91 mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
92 gpgcheck=1
93 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
94
95 [updates]
96 name=CentOS-6 - Updates
97 #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
98 mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
99 gpgcheck=1
100 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
101
102 [extras]
103 name=CentOS-6 - Extras
104 #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
105 mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
106 gpgcheck=1
107 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
108
109 [centosplus]
110 name=CentOS-6 - Plus
111 #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
112 mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
113 gpgcheck=1
114 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
115 EOF
116
117 # unleash yum
118
119 export LANG=C
120 exec yum -c "${YUMENVIRON}/yum.conf" -y install coreutils basesystem centos-release yum-basearchonly initscripts upstart nano nano yum wget which passwd joe screen