7 while getopts ":a" opt; do
13 echo "Invalid option: -$OPTARG" >&2
18 if [ -z "$AUTOMODE" ]; then
27 if [ -n "$PLYMOUTH" -a "$PLYMOUTH" -eq 1 ]; then
28 plymouth display-message --text "$1"
34 function check_echo_reboot {
36 if [[ $key != 'r' && $key != 'R' ]]; then
41 function read_config {
43 CONF_FILE="/etc/installer.conf"
45 if [ ! -e $CONF_FILE ]; then
46 message "Installation failure, missing /etc/installer.conf"
47 test $REBOOT_ON_FAILURE -eq 1 && (
58 SRCMNT=$(mktemp -d /media/srctmp.XXXXXX)
59 TGTMNT=$(mktemp -d /media/tgttmp.XXXXXX)
60 SRCOSMNT=$(mktemp -d /media/srcostmp.XXXXXX)
63 function find_devices {
64 for i in $(ls /sys/block/*/device/model); do
65 dev=$(echo $i | cut -d'/' -f-4) ;
66 device=$(echo $i | cut -d'/' -f4)
67 grep -q 1 $dev/removable
68 if [ "$?" = "1" ]; then
69 TARGET_DEV="/dev/$device";
74 if [ -z "$TARGET_DEV" ]; then
75 message "Installation failure, unable to find suitable install target media"
76 test $REBOOT_ON_FAILURE -eq 1 && (
84 # Global variable for storing the partition option parameters;
87 function msdos_partition_options {
88 # the partition number
90 # used for storing the per-part variables,
91 # accessed via indirect referencing
94 tmp="INSTALLERFW_PART${i}_SIZE"
96 [ -z "$size" ] && size="1024"
97 if [[ "$INSTALLERFW_PART_COUNT" = "$((i+1))" ]]; then
98 # an 'empty' value means that sfdisk will use
99 # the defaults, in this case expanding to the
103 params=$(printf "${params}\n%s" ",${size}")
105 tmp="INSTALLERFW_PART${i}_FSTYPE"
108 [ "$fstype" = "swap" ] && typeid='82'
109 params=$(printf "${params}%s" ",${typeid}")
111 # handle bootflag last
112 tmp="INSTALLERFW_PART${i}_BOOTFLAG"
113 local bootflag=${!tmp}
114 if [ "$bootflag" = "True" ]; then
115 params=$(printf "${params}%s" ',*')
117 params=$(printf "${params}\n")
121 function gpt_partition_options {
122 # the partition number
124 # used for storing the per-part variables,
125 # accessed via indirect referencing
128 tmp="INSTALLERFW_PART${i}_ALIGN"
130 [ -n "$align" ] && params=$(printf "${params}%s" " --set-alignment=${align}")
132 # sgdisk uses '0' to mean 'default value'
133 params=$(printf "$params%s" " --new=0:0")
135 tmp="INSTALLERFW_PART${i}_SIZE"
137 if [[ "$INSTALLERFW_PART_COUNT" = "$((i+1))" ]]; then
140 [ -z "$size" ] && size="1024"
141 [ -n "$size" ] && params=$(printf "${params}%s" ":${size}M")
143 # TODO: need to handle swap partition types if encountered
145 # the following GUID option does not accept default partition values,
146 # so partition numbering must start at index 1, not 0
147 local partnum="$((i+1))"
149 tmp="INSTALLERFW_PART${i}_TYPE_ID"
151 [ -n "$typeid" ] && params=$(printf "${params}%s" " --typecode=${partnum}:${typeid}")
154 function partition_msdos {
155 # make sure there is a newline in the heredoc,
156 # or else sfdisk fails to parse the input
157 /usr/sbin/sfdisk --in-order -uM ${TARGET_DEV} << EOF
164 function partition_gpt {
165 /usr/sbin/sgdisk -Z ${TARGET_DEV}
166 /usr/sbin/sgdisk ${1} ${TARGET_DEV}
170 function format_device {
173 # the actual partition numbers begin at index 1, not 0
174 local partnum="$((instfw_pnum+1))"
176 # TODO: need to handle swap partitions
178 /usr/sbin/mkfs.${fstype} ${TARGET_DEV}${partnum}
180 if [[ ${fstype} = "btrfs" ]]; then
181 mount ${TARGET_DEV}${partnum} $TGTMNT
182 /usr/sbin/btrfs subvolume create ${TGTMNT}/tizen
183 /usr/sbin/btrfs subvolume create ${TGTMNT}/tizen/.snapshots
184 SUBVOLID=$(/usr/sbin/btrfs subvolume list $TGTMNT | grep 'tizen$' | awk '{ print $2 }')
185 echo "Setting subvolume ${SUBVOLID} as default"
186 /usr/sbin/btrfs subvolume set-default $SUBVOLID $TGTMNT
192 function mount_device {
195 # the actual partition numbers begin at index 1, not 0
196 local partnum="$((instfw_pnum+1))"
200 # we make this substitution in extlinux.conf on the target device
201 [ "$mountpoint" = "/" ] && ROOTFS="${TARGET_DEV}${partnum}"
203 mkdir -p ${TGTMNT}/${mountpoint}
205 # for this to work, the rootfs partition entry in installer.conf
206 # must be first entry, or else some mount points will be hidden
208 mount ${TARGET_DEV}${partnum} ${TGTMNT}/${mountpoint}
211 function install_extlinux {
212 mkdir -p ${TGTMNT}/boot/extlinux
213 cat > ${TGTMNT}/boot/extlinux/extlinux.conf << EOF
217 menu background splash.png
218 menu title Welcome to Tizen PC!
219 menu color border 0 #ffffffff #00000000
220 menu color sel 7 #ff000000 #ffffffff
221 menu color title 0 #ffffffff #00000000
222 menu color tabmsg 0 #ffffffff #00000000
223 menu color unsel 0 #ffffffff #00000000
224 menu color hotsel 0 #ff000000 #ffffffff
225 menu color hotkey 7 #ffffffff #ff000000
226 menu color timeout_msg 0 #ffffffff #00000000
227 menu color timeout 0 #ffffffff #00000000
228 menu color cmdline 0 #ffffffff #00000000
232 menu label Boot Tizen
234 append root=${ROOTFS} ${INSTALLERFW_KERNEL_OPTS} ${ROOTFLAGS}
238 cp /usr/share/branding/default/syslinux/syslinux-vesa-splash.jpg ${TGTMNT}/boot/extlinux/splash.png
240 cat /usr/share/syslinux/mbr.bin > ${TARGET_DEV}
241 /sbin/extlinux -i ${TGTMNT}/boot/extlinux
244 function install_os {
245 rsync -WaHXSh --exclude='/dev/' --exclude='/lost+found/' --exclude='/media/*' --exclude='/sys/' --exclude='/proc/' --exclude="/tmp/" --exclude="/run/" $SRCOSMNT/ $TGTMNT
248 chmod 0755 ${TGTMNT}/dev
250 # TODO: switch to using systemd mount units instead of the fstab
251 #rm ${TGTMNT}/etc/fstab
253 if [[ $FILESYSTEM = "btrfs" ]]; then
254 ROOTFLAGS="rootflags=subvol=tizen"
259 if [ "$INSTALLERFW_PTABLE_FORMAT" = "msdos" ]; then
263 if [[ $FILESYSTEM = "btrfs" ]]; then
264 sed -i 's|SUBVOLUME="/"|SUBVOLUME="'${TGTMNT}'"|' /etc/snapper/configs/root
265 snapper create -d "Factory Default"
269 function unmount_devices {
272 [ -d "$TGTMNT" ] && umount -R $TGTMNT
275 message "This installation will wipe all data from the hard drive, hit Y key to continue or ctrl-alt-del to abort."
276 if [ -n "$PLYMOUTH" -a "$PLYMOUTH" -eq 1 ]; then
277 plymouth watch-keystroke --command="/usr/bin/test" --keys "yY"
280 if [[ $key != 'y' && $key != 'Y' ]]; then
281 test $REBOOT_ON_FAILURE -eq 1 && /usr/sbin/reboot
284 if [ -n "$PLYMOUTH" -a "$PLYMOUTH" -eq 1 ]; then
285 plymouth hide-message --text "This installation will wipe all data from the hard drive, hit Y key to continue or ctrl-alt-del to abort."
291 message "Installing on to the hard disk now, this will take a few minutes..."
294 # first, generate the option list to pass to either 'sfdisk' or 'sgdisk'
295 while [ "$pnum" -lt "$INSTALLERFW_PART_COUNT" ]; do
296 if [ "$INSTALLERFW_PTABLE_FORMAT" = "msdos" ]; then
297 msdos_partition_options $pnum
298 elif [ "$INSTALLERFW_PTABLE_FORMAT" = "gpt" ]; then
299 gpt_partition_options $pnum
304 # now, do the partitioning
305 if [ "$INSTALLERFW_PTABLE_FORMAT" = "msdos" ]; then
306 partition_msdos "$params"
307 elif [ "$INSTALLERFW_PTABLE_FORMAT" = "gpt" ]; then
308 partition_gpt "$params"
311 pnum="$((INSTALLERFW_PART_COUNT-1))"
312 # NOTE: for now, partitions are processed in reverse order, and we
313 # expect the rootfs to be the last entry in installer.conf
314 while [ "$pnum" -ge "0" ]; do
315 tmp="INSTALLERFW_PART${pnum}_FSTYPE"
318 format_device $fstype $pnum
320 tmp="INSTALLERFW_PART${pnum}_MOUNTPOINT"
323 mount_device $mountpoint $pnum
334 if [ -n "$PLYMOUTH" -a "$PLYMOUTH" -eq 1 ]; then
335 plymouth hide-message --text "Installing on to the hard disk now, this will take a few minutes..."
337 message "Hit R key to reboot and then remove the usb stick. Enjoy!"
339 if [ -n "$PLYMOUTH" -a "$PLYMOUTH" -eq 1 ]; then
340 plymouth watch-keystroke --command="/usr/bin/test" --keys "rR"