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
|
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 # Copyright 2016 OmniTI Computer Consulting, Inc. All rights reserved.
14 #
15
16 PATH=/bin:/usr/bin:/usr/sbin
17 export PATH
18
19 . /usr/lib/brand/shared/common.ksh
20
21 ZFS_SEED=""
22 TAR_SEED=""
23
24 bad_usage() {
25 echo "LX zone install bad option"
26 echo "Available options are:"
27 echo " -s <absolute-pathname> Path to ZFS send stream or gzip thereof"
28 echo " -t <absolute-pathname> Path to tar archive or gzip thereof"
29 exit $ZONE_SUBPROC_USAGE
30 }
31
32 while getopts "R:s:t:z:" opt
33 do
34 case "$opt" in
35 R) ZONEPATH="$OPTARG";;
36 z) ZONENAME="$OPTARG";;
37 s) ZFS_SEED="$OPTARG";;
38 t) TAR_SEED="$OPTARG";;
39 *) bad_usage ;;
40 esac
41 done
42 shift OPTIND-1
43
44 if [[ $ZFS_SEED == "" && $TAR_SEED == "" ]]; then
45 echo "The -s <absolute-pathname> argument or the -t <absolute-pathname>"
46 echo "argument is required for LX installation."
47 bad_usage
48 fi
49
50 if [[ $ZFS_SEED != "" && $TAR_SEED != "" ]]; then
51 echo "You must only specify one of -s or -t for LX installation."
52 bad_usage
53 fi
54
55 # Set the ZONEPATH_DS variable so we know the zone's dataset.
56 get_zonepath_ds $ZONEPATH
57
58 # Do something based on whatever ZFS_SEED is.
59
60 if [[ -f $TAR_SEED ]]; then
61 type=`file -b $TAR_SEED | awk '{print $1}'`
62 if [[ $type == "gzip" ]]; then
63 args="-xzf"
64 else
65 args="-xf"
66 fi
67 cd $ZONEPATH
68 # Be very precise about permissions and ownership.
69 mkdir -m 0755 dev
70 chgrp sys dev
71 mkdir -m 0755 root
72 chgrp root sys
73 cd root
74 gtar $args $TAR_SEED
75 exit 0
76 elif [[ ! -f $ZFS_SEED ]]; then
77 # Try and eat a snapshot or a filesystem.
78 outstr=`zfs list -Ht filesystem $ZFS_SEED 2>/dev/null | awk '{print $1}'`
79 if [[ $outstr == $ZFS_SEED ]]; then
80 # We have a zfs filesystem name.
81 # Snapshot it using today's date/time
82 snapname=`date -u "+%Y-%m-%d:%H:%M:%S"`
83 ZFS_SEED=$ZFS_SEED@$snapname
84 zfs snapshot $ZFS_SEED
85 if [[ $? != 0 ]]; then
86 echo "ZFS snapshot ($ZFS_SEED) command failed ($?)."
87 exit $ZONE_SUBPROC_FATAL
88 fi
89 # else continue on with the new snapshot...
90 fi
91
92 outstr=`zfs list -Ht snapshot $ZFS_SEED 2>/dev/null | awk '{print $1}'`
93 if [[ $outstr == $ZFS_SEED ]]; then
94 # Hmmm, we found a snapshot name!
95 echo "Cloning from snapshot $ZFS_SEED"
96 # zoneadm already created $ZONEPATH_DS, destroy it before we clone.
97 zfs destroy $ZONEPATH_DS
98 zfs clone $ZFS_SEED $ZONEPATH_DS
99 if [[ $? != 0 ]]; then
100 echo "ZFS clone ($ZFS_SEED to $ZONEPATH_DS) failed ($?)."
101 exit $ZONE_SUBPROC_FAIL
102 fi
103 # zfs promote $ZONEPATH_DS
104 # if [[ $? != 0 ]]; then
105 # echo "ZFS promote ($ZONEPATH_DS) failed ($?)."
106 # exit $ZONE_SUBPROC_FAIL
107 # fi
108 else
109 echo "Seed file $ZFS_SEED $TAR_SEED not found."
110 bad_usage
111 fi
112 else
113 type=`file -b $ZFS_SEED | awk '{print $1}'`
114
115 # For now, we are dependent on the output of file(1).
116 # I'm being cheesy in checking the first word of file(1)'s output.
117 if [[ $type == "ZFS" ]]; then
118 zfs recv -F $ZONEPATH_DS < $ZFS_SEED
119 elif [[ $type == "gzip" ]]; then
120 gunzip -c $ZFS_SEED | zfs recv -F $ZONEPATH_DS
121 else
122 echo "Seed file $ZFS_SEED not a ZFS receive (or compressed) one."
123 bad_usage
124 fi
125
126 if [[ $? != 0 ]]; then
127 echo "ZFS receive command failed ($?)."
128 exit $ZONE_SUBPROC_FATAL
129 fi
130 fi
131
132 # One Joyent-ism we need to clean up.
133 rmdir $ZONEPATH/cores
134 # And one we should probably adopt.
135 zfs set devices=off $ZONEPATH_DS
136
137 exit 0
|