summaryrefslogtreecommitdiffstats
path: root/build_tools/clarch/larch/run/larchify
blob: abc0c6d8670de89fd8809978a500a5e8dd8b3085 (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
#! /bin/bash
#
# larchify
#
# 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.02.13

# Default target directory:
INSTLDIR=larchroot

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} [-irugf] [-p <profile directory>] [<target directory>]"
    echo
    echo "          -p    Use the 'profile' in the given directory."
    echo "                The default is the directory 'profile' in the"
    echo "                current directory, if it exists. A build without"
    echo "                a profile is also, in principle, possible."
    echo "          -i    Only rebuild iso (or install to USB-stick),"
    echo "                don't regenerate CD data"
    echo
    echo "          -r    Reuse old system and home sqfs"
    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} builds a larch live CD / live USB-stick from the Arch Linux"
    echo "installation in <target directory>. The default target directory"
    echo "(which can also be a symlink) is 'larchroot' in the current"
    echo "working directory."
    echo
    echo "A profile is a directory containing all the necessary"
    echo "configuration details for a larch build. See documentation"
    echo "and examples."
    echo
    exit
}

PROFILE=""
DONTASK=""
USB=""
GRUB=""
REISO=""
REBUILD=""
REUSE=""
while getopts ":p:irugf" Option
do
  case ${Option} in
    p ) PROFILE="$( readlink -f ${OPTARG} )" ;;
    i ) REISO="-i" ;;
    r ) REUSE="-r" ;;
    u ) USB="-u" ;;
    g ) GRUB="-g" ;;
    f ) DONTASK="-f" ;;
    * ) usage ;;
  esac
done
shift $((${OPTIND} - 1))
if [ -n "$1" ]; then
    INSTLDIR="$1"
fi

if [ -d "${INSTLDIR}" ]; then
    if [ "${INSTLDIR}" = "/" ]; then
        INSTLDIR=""
    else
        INSTLDIR=$( readlink -f ${INSTLDIR} )
    fi
else
    echo "ERROR: no target directory supplied"
    usage
fi
LARCHBUILD="${INSTLDIR}/.larch"

if [ -z "${PROFILE}" ]; then
    if [ -d ${startdir}/profile ]; then
        PROFILE=${startdir}/profile
    elif [ -z "${DONTASK}" ]; then
        read -p "// Build without a profile? [y/N]: " ans
        # Await yes or no
        if [ -z "$( echo ${ans} | grep '^ *[yY]' )" ]; then exit 0; fi
        echo
    fi
elif ! [ -d ${PROFILE} ]; then
    echo "ERROR: profile '${PROFILE}' not found "
    usage
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

# Get live CD build functions
. ${LARCHDATA}/buildlive

if [ -n "${REISO}" ]; then
    buildiso
else
    mklive
fi