1 #!/bin/ksh -p
2 #
3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms of version
6 # 1.0 of the CDDL.
7 #
8 # A full copy of the text of the CDDL should have accompanied this
9 # source. A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
11 #
12 # Copyright 2016 Joyent, Inc. All rights reserved.
13 #
14
15 #
16 # This is only an example install script. It is not currently used for anything.
17 #
18
19 PATH=/bin:/usr/bin:/usr/sbin
20 export PATH
21
22 fullpath()
23 {
24 typeset path="$1"
25
26 echo $path | egrep -s "^/" || path="${PWD:=$(pwd)}/$path"
27 echo $path
28 }
29
30 makedir()
31 {
32 typeset dirname=$(fullpath "$1")
33 typeset mode=""
34
35 [[ $# -eq 2 ]] && mode="-m $2"
36
37 [[ -d "$dirname" ]] && return
38
39 if ! mkdir $mode -p "$dirname"; then
40 echo $(gettext "Aborting installation...")
41 exit 255
42 fi
43 }
44
45 symlink()
46 {
47 typeset src="$1"
48 typeset dst=$(fullpath "$2")
49
50 [[ -e "$dst" || -h "$dst" ]] && rm -f "$dst"
51
52 if ! ln -s "$src" "$dst"; then
53 echo $(gettext "Aborting installation...")
54 exit 255
55 fi
56 }
57
58 install_ln()
59 {
60 typeset source="$1"
61 typeset target=$(fullpath "$2")
62
63 log " Installing \"$target\""
64
65 mv -f "$target" "$target.$tag" 2>/dev/null
66
67 if ! ln -s "$source" "$target"; then
68 return 1
69 fi
70
71 return 0
72 }
73
74 # If we weren't passed 3 arguments, exit now.
75 [[ $# -lt 3 ]] && exit 254
76
77 # Extract the brand directory name from the path.
78 branddir=$(dirname "$0")
79 zonename="$1"
80 zoneroot="$2"
81 install_src="3"
82 install_root="$zoneroot/root"
83 ZPOOL=`df $ZONEROOT | awk -F '[()]' '{split($2, field, "/"); print field[1]; }'`
84 if [ -z "$ZPOOL" ]; then
85 ROOTDEV="none"
86 else
87 ROOTDEV="/dev/$ZPOOL"
88 fi
89
90 if [[ ! -f "$install_src" ]]; then
91 echo "$install_src: file not found\n"
92 exit 254
93 fi
94
95 if [[ ! -d "$install_root" ]]; then
96 if ! mkdir -p "$install_root" 2>/dev/null; then
97 echo "Could not create install directory $install_root"
98 exit 254
99 fi
100 fi
101
102 if ! ( cd "$install_root" && gtar -xzf "$install_src" ) ; then
103 echo "Error: extraction from tar archive failed"
104 exit 255
105 fi
106
107 tag="lxsave_$(date +%m.%d.%Y@%T)"
108
109 if [[ ! -d "$install_root" ]]; then
110 exit 255
111 fi
112
113 cd "$install_root"
114
115 makedir native/dev
116 makedir native/etc/default
117 makedir native/etc/svc/volatile
118 makedir native/lib
119 makedir native/proc
120 makedir native/tmp 1777
121 makedir native/usr
122 makedir native/var
123
124 makedir mnt
125 makedir opt
126 makedir usr/local/bin
127 makedir usr/local/include
128 makedir usr/local/lib
129 makedir usr/local/sbin
130 makedir usr/local/share
131 makedir usr/local/src
132
133 makedir dev 0755
134 makedir tmp 1777
135 makedir proc 0555
136 makedir boot 0755
137
138 symlink /bin/sh sbin/sh
139 symlink /bin/su usr/bin/su
140 symlink /native/usr/lib/ld.so.1 usr/lib/ld.so.1
141
142 libpam_so="$(echo lib/libpam.so.0.*)"
143 libpam_misc="$(echo lib/libpam_misc.so.0.*)"
144 libpamc_so="$(echo lib/libpamc.so.0.*)"
145
146 symlink "/$libpam_so" lib/libpam.so.0
147 symlink "/$libpam_misc" lib/libpam_misc.so.0
148 symlink "/$libpamc_so" lib/libpamc.so.0
149
150 makedir var/ld
151
152 if ! crle -c var/ld/ld.config -l /native/lib:/native/usr/lib \
153 -s /native/lib/secure:/native/usr/lib/secure; then
154 exit 255
155 fi
156
157 mv -f etc/fstab etc/fstab.$tag 2>/dev/null
158
159 cat > etc/fstab <<- EOF
160 $ROOTDEV / zfs defaults 1 1
161 proc /proc proc defaults 0 0
162 EOF
163
164 if [[ $? -ne 0 ]]; then
165 exit 255
166 fi
167
168 if [[ ! -e "$install_root/etc/hosts" ]]; then
169 cat > "$install_root/etc/hosts" <<-_EOF_
170 127.0.0.1 localhost
171 _EOF_
172 fi
173
174 #
175 # Perform distribution-specific changes.
176 #
177 distro=""
178 if [[ -f etc/redhat-release ]]; then
179 distro="redhat"
180 elif [[ -f etc/lsb-release ]]; then
181 if egrep -s Ubuntu etc/lsb-release; then
182 distro="ubuntu"
183 elif [[ -f etc/debian_version ]]; then
184 distro="debian"
185 fi
186 elif [[ -f etc/debian_version ]]; then
187 distro="debian"
188 fi
189
190 if [[ -z $distro ]]; then
191 exit 255
192 fi
193
194 exit 0