summaryrefslogtreecommitdiffstats
path: root/build_tools/clarch/larch/run/mklarch
blob: 2a1c5740b40a25d66e62929cbdf67083074b74f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#! /bin/bash
#
# mklarch
#
# Author: Michael Towers <gradgrind[at]online[dot]de>
#
# This file is part of the larch project.
#
#    larch is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    larch is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with larch; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
#----------------------------------------------------------------------------
# 2008.06.22

# directory to use for building the CD - the installation root
# It must have LOTS of space, ~ 4GB for a 700MB CD
INSTLDIR=/home/larchroot

# Default path to larch5 repositories (architecture is sub-directory)
larch5path="ftp://ftp.berlios.de/pub/larch/larch5.3"

APP=$( basename $0 )
# Get path to larch base directory, via the location of this script
FULLPATH=$( readlink -f $0 )
SCRIPTDIR=$( dirname ${FULLPATH} )
LARCHDATA=$( dirname ${SCRIPTDIR} )

startdir=$( pwd )
# cd to ensure that the following test works even if '.' is in PATH
cd /
apppath="$( which ${APP} 2>/dev/null )"
if [ $? -ne 0 ] || [ "${apppath}" != "${FULLPATH}" ]; then
    PATH=${SCRIPTDIR}:${PATH}
fi
cd ${startdir}

usage () {
    echo
    echo "Usage:"
    echo "  ${APP} -h     # Show this message"
    echo
    echo "  ${APP} -a  [-f] [-p <profile directory>]"
    echo "                  [-c <package cache directory>]"
    echo "                  [-y <path to pacman database directories>]"
    echo "                  [<build directory>]"
    echo
    echo "  ${APP} [-ugf]   [-p <profile directory>]"
    echo "                  [-c <package cache directory>]"
    echo "                  [-y <path to pacman database directories>]"
    echo "                  [<build directory>]"
    echo
    echo "          -a    Stop after installing Arch system (don't build live system)."
    echo
    echo "          -p    Use the 'profile' in the given directory."
    echo
    echo "          -c    Use an alternative package cache directory"
    echo "                (default is /var/cache/pacman/pkg, on host)"
    echo "          -y    Use existing pacman package database instead"
    echo "                of performing 'pacman -Sy'."
    echo
    echo "          -u    Don't build iso, but install to USB-stick instead"
    echo "          -g    Use GRUB bootloader (default is isolinux/syslinux)"
    echo
    echo "          -f    No interaction. (not recommended)"
    echo "                The script will just plough straight on and destroy"
    echo "                your file-system without first asking."
    echo
    echo "${APP} is the master script for the larch live CD / live USB-stick"
    echo "builder."
    echo
    echo "<build directory> is the directory in which all the building will"
    echo "be done, by default '${INSTLDIR}'"
    echo
    echo "A profile is a directory containing all the necessary"
    echo "configuration details for a larch build. See documentation"
    echo "and examples."
    echo
    echo "If you want to rebuild a live system without reinstalling it"
    echo "(for example if you make minor changes to the profile which"
    echo "don't affect the packages, or if you want a USB-stick instead"
    echo "of a CD, or if writing to the USB-stick failed for some reason)"
    echo "you should look at the 'larchify' script - run it with the '-h'"
    echo "option for usage notes."
    echo
    exit
}

pROFILE=""
DONTASK=""
NOLIVE=""
USB=""
GRUB=""
PKGCACHE=/var/cache/pacman/pkg
# Options to 'inpacs':
INPACSO=""
while getopts ":p:ac:y:ugf" Option
do
  case ${Option} in
    p ) PROFILE="$( readlink -f ${OPTARG} )" ;;
    a ) NOLIVE="-a" ;;
    c ) PKGCACHE="$( readlink -f ${OPTARG} )" ;;
    y ) INPACSO="${INPACSO} -y $( readlink -f ${OPTARG} )" ;;
    u ) USB="-u" ;;
    g ) GRUB="-g" ;;
    f ) DONTASK="-f" ;;
    * ) usage ;;
  esac
done
shift $((${OPTIND} - 1))
if ! [ -d "${PKGCACHE}" ]; then
    echo "Creating package cache: ${PKGCACHE}"
    if ! mkdir -p "${PKGCACHE}"; then
        echo "ERROR: Couldn't create ${PKGCACHE}"
        exit 1
    fi
fi
INPACSO="${INPACSO} -c ${PKGCACHE}"

if [ -n "$1" ]; then
    INSTLDIR=$1
fi
LARCHBUILD="${INSTLDIR}/.larch"

if [ -z "${PROFILE}" ]; then
    PROFILE=${startdir}/profile
fi
if ! [ -f ${PROFILE}/addedpacks ]; then
    echo "ERROR: no 'addedpacks' in profile '${PROFILE}'"
    exit 1
fi

# test if the script is started by root user. If not, exit
if [ $UID -ne 0 ]; then
    echo "Only root can run ${APP}"; exit 1
fi

echo "//"
echo "// **********************************************************"
echo "// This will delete EVERYTHING under"
echo "//"
echo "//        ${INSTLDIR}"
echo "//"

if [ -z "${DONTASK}" ]; then
    echo "// I really mean it ... Are you sure you want to do this?"
    echo "// **********************************************************"
    # Await yes or no
    read -p "// [y/N]: " ans
    if [ -z "$( echo ${ans} | grep '^ *[yY]' )" ]; then exit 0; fi
fi

for fd in $( ls -A ${INSTLDIR} ); do
    rm -rf ${INSTLDIR}/${fd}
#lookforme 
done
mkdir -p ${LARCHBUILD}

############### Call 'inpacs' to do the installation

if [ -f ${PROFILE}/basepacks ]; then
    INPACSO="${INPACSO} -b ${PROFILE}/basepacks"
fi

if [ -f ${PROFILE}/baseveto ]; then
    INPACSO="${INPACSO} -x ${PROFILE}/baseveto"
fi

if [ -f ${PROFILE}/pacman.conf ]; then
    cp ${PROFILE}/pacman.conf .
elif ! [ -f pacman.conf ]; then
    if [ -f /etc/pacman.conf ]; then
        cp /etc/pacman.conf .
    else
        echo "ERROR: Couldn't find pacman.conf"
        exit 1
    fi
fi
INPACSO="${INPACSO} -k pacman.conf"
if [ x = y ]
then
# If necessary add the larch repository to pacman.conf
if ! grep '^[larch5]' pacman.conf &>/dev/null; then
    if [ -d larchrepo ]; then
        larch5path="file://$( readlink -f larchrepo )"
    else
        sysarch="$( uname -m )"
        if [ "${sysarch}" != "x86_64" ]; then
            sysarch="i686"
        fi
        larch5path="${larch5path}/${sysarch}"
    fi
    #sed "/\[testing\]/ i \
	echo "[larch5] " >> pacman.conf
	echo "Server = ${larch5path}" >> pacman.conf
fi

fi

if ! which pacman &>/dev/null; then
    if ! [ -x ${startdir}/pacman ]; then
        echo "ERROR: Couldn't find pacman executable"
        exit 1
    fi
    INPACSO="${INPACSO} -P ${startdir}/pacman"
fi
echo "checking for pre_process.sh"
if [ -f ${PROFILE}/pre-process.sh ]
then
	echo "Running pre-process script"
	cd ${PROFILE}
	./pre-process.sh
	cd -

else
	echo "No pre_process"
fi

inpacs -a ${PROFILE}/addedpacks ${INPACSO} ${INSTLDIR}
if [ $? -ne 0 ]; then exit 1; fi

# Use build version of pacman.conf in live system, without [larch5] repository.
# This can be overwritten by a pacman.conf in the profile's overlay.

rm -f ${INSTLDIR}/etc/pacman.conf
if [ -f ${PROFILE}/pacman.conf ]; then
    # This file should be used in preference to pacman.conf - it is created by
    # larch-setup on non-Arch systems before commenting out the 'Include' lines.
    cp ${PROFILE}/pacman.conf  ${INSTLDIR}/etc/pacman.conf
else
    sed '/^\[larch5\]/,/^ *$/ d' <pacman.conf >${INSTLDIR}/etc/pacman.conf
fi

cachepacs -a ${PROFILE}/cache_packs  $INPACSO -d ${INSTLDIR}


# Generate glibc locales
if [ -f ${PROFILE}/locale.gen ]; then
    echo
    echo "********** Generating locales **********"
    echo
    cat ${PROFILE}/locale.gen ${INSTLDIR}/etc/locale.gen >${INSTLDIR}/etc/locale.gen_new
    mv -f ${INSTLDIR}/etc/locale.gen_new ${INSTLDIR}/etc/locale.gen
    chroot ${INSTLDIR} usr/sbin/locale-gen
fi

# Generate ssh keys
ssh_init ${INSTLDIR}

# Set up a symlink to the installation for 'larchify'
rm -f larchroot && ln -sf ${INSTLDIR} ${startdir}/larchroot
if [ $? -ne 0 ]; then
    echo "WARNING: Couldn't create 'larchroot' symlink"
fi

echo "// ${APP} finished installation of Arch system"
echo "//"

#run script to post-process the new installation
if [ -f ${PROFILE}/post-process.sh ]
then
	${PROFILE}/post-process.sh ${INSTLDIR} ${PROFILE}
	echo ${PROFILE}/post-process.sh ${INSTLDIR} ${PROFILE}
fi


if [ -z "${NOLIVE}" ]; then
    # Get live CD build functions
    . ${LARCHDATA}/buildlive
    mklive
fi