From 571facb4d38efcf2dff508e79d4a2c9a5680bb7b Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Fri, 19 Jul 2013 14:16:09 -0400 Subject: [PATCH] remove ivi/pc hardcoding - We now rely on one single configuration file that can be set when creating images. - Added option -a to make it work with plymouth when called from systemd - renamed pc-installer -> system-installer - Cleanup spec Change-Id: I043cd63675cc455f5f2b7d1c207841d403effbb7 Signed-off-by: Anas Nashif --- data/ivi.conf | 1 - data/pc.conf | 1 - packaging/pc-installer.spec | 43 +--- scripts/install.sh | 215 ------------------- scripts/system-installer | 237 +++++++++++++++++++++ ...-installer.service => system-installer.service} | 2 +- 6 files changed, 246 insertions(+), 253 deletions(-) delete mode 100644 data/ivi.conf delete mode 100644 data/pc.conf delete mode 100644 scripts/install.sh create mode 100644 scripts/system-installer rename systemd/{pc-installer.service => system-installer.service} (67%) diff --git a/data/ivi.conf b/data/ivi.conf deleted file mode 100644 index 27c9e57..0000000 --- a/data/ivi.conf +++ /dev/null @@ -1 +0,0 @@ -FILESYSTEM=ext4 diff --git a/data/pc.conf b/data/pc.conf deleted file mode 100644 index a0e93fd..0000000 --- a/data/pc.conf +++ /dev/null @@ -1 +0,0 @@ -FILESYSTEM=btrfs diff --git a/packaging/pc-installer.spec b/packaging/pc-installer.spec index c9e438e..81eddb9 100644 --- a/packaging/pc-installer.spec +++ b/packaging/pc-installer.spec @@ -1,38 +1,19 @@ Name: pc-installer Version: 0.2 Release: 2 -License: GPLv2 +License: GPL-2.0 Summary: PC Installer -Group: Base/System +Group: Base/Utilities Source: %{name}-%{version}.tar.xz -Source1001: pc-installer.manifest Requires: rsync Requires: plymouth Requires: syslinux-extlinux Requires: btrfs-progs Requires: snapper +Source1001: pc-installer.manifest %description -Installs a system from a live USB stick to a local hard-disk. - -%package conf-ivi -License: GPLv2 -Summary: Configuration for IVI -Group: Base/Startup -Conflicts: pc-installer-conf-pc - -%description conf-ivi -Installer configuration file for IVI. - -%package conf-pc -License: GPLv2 -Summary: Configuration for PC -Group: Base/Startup -Conflicts: pc-installer-conf-ivi - -%description conf-pc -Installer configuration file for PC. - +Installs a system from a USB stick to a local hard-disk. %prep %setup -q @@ -45,20 +26,12 @@ install -d %{buildroot}/%{_sbindir} install -d %{buildroot}/%{_sysconfdir}/installer install -d %{buildroot}/%{_unitdir} -install -m 0644 systemd/pc-installer.service %{buildroot}/%{_unitdir} -install -m 0775 scripts/install.sh %{buildroot}/%{_sbindir}/pc-installer -install -m 0644 data/* %{buildroot}/%{_sysconfdir}/installer/ +install -m 0644 systemd/system-installer.service %{buildroot}/%{_unitdir} +install -m 0775 scripts/system-installer %{buildroot}/%{_sbindir}/system-installer %files %manifest %{name}.manifest %defattr(-,root,root) -%{_sbindir}/pc-installer -/%{_unitdir}/pc-installer.service - -%files conf-ivi -%defattr(-,root,root) -%{_sysconfdir}/installer/ivi.conf +%{_sbindir}/system-installer +%{_unitdir}/system-installer.service -%files conf-pc -%defattr(-,root,root) -%{_sysconfdir}/installer/pc.conf diff --git a/scripts/install.sh b/scripts/install.sh deleted file mode 100644 index 24e7e86..0000000 --- a/scripts/install.sh +++ /dev/null @@ -1,215 +0,0 @@ -#!/bin/sh - -function message { - if [ -n "$PLYMOUTH" ]; then - plymouth display-message --text $1 - else - echo $1 - fi -} - -function read_config { - local CONF_FILE="" - if [[ -e "/etc/installer/pc.conf" ]]; then - CONF_FILE="/etc/installer/pc.conf" - elif [[ -e "/etc/installer/ivi.conf" ]]; then - CONF_FILE="/etc/installer/ivi.conf" - fi - - if [[ ! $CONF_FILE ]]; then - message "Installation failure, missing /etc/installer.conf" - sleep 5 - /usr/sbin/reboot - fi - - FILESYSTEM=$(grep -i 'FILESYSTEM' $CONF_FILE | cut -d'=' -f2) -} - -function set_mounts { - SRCMNT=$(mktemp -d /media/srctmp.XXXXXX) - TGTMNT=$(mktemp -d /media/tgttmp.XXXXXX) - SRCOSMNT=$(mktemp -d /media/srcostmp.XXXXXX) -} - -function find_devices { - for i in $(ls /sys/block/*/device/model); do - dev=$(echo $i | cut -d'/' -f-4) ; - device=$(echo $i | cut -d'/' -f4) - grep -q 1 $dev/removable - if [ "$?" = "1" ]; then - TARGET_DEV="/dev/$device"; - break - fi - - done - - if [ -z "$TARGET_DEV" ]; then - message "Installation failure, unable to find suitable install target media" - sleep 5 - /usr/sbin/reboot - fi -} - -function partition_device { - -for part in $(parted -s $TARGET_DEV print | awk '/^ / {print $1}') -do -parted -s $TARGET_DEV rm $part -done -SIZE=`parted -ms $TARGET_DEV unit MB print | grep -i "$TARGET_DEV" | cut -d":" -f2 | sed 's/MB//i'` -parted -s $TARGET_DEV mklabel gpt -parted -s $TARGET_DEV mkpart primary 0 2000 -parted -s $TARGET_DEV mkpart primary 2001 $SIZE -parted -s $TARGET_DEV set 2 boot on -sync -} - -function format_device { - /usr/sbin/mkswap ${TARGET_DEV}1 - - /usr/sbin/mkfs.${FILESYSTEM} -L ROOTFS ${TARGET_DEV}2 - - if [[ $FILESYSTEM = "btrfs" ]]; then - mount ${TARGET_DEV}2 $TGTMNT - /usr/sbin/btrfs subvolume create ${TGTMNT}/tizen - /usr/sbin/btrfs subvolume create ${TGTMNT}/tizen/.snapshots - SUBVOLID=$(/usr/sbin/btrfs subvolume list $TGTMNT | grep 'tizen$' | awk '{ print $2 }') - echo "Setting subvolume ${SUBVOLID} as default" - /usr/sbin/btrfs subvolume set-default $SUBVOLID $TGTMNT - sync - umount $TGTMNT - fi -} - -function mount_devices { - local squash_img=/run/initramfs/live/LiveOS/squashfs.img - - if [ -e "$squash_img" ]; then - mount -oloop,ro $squash_img $SRCMNT - mount -oloop,ro $SRCMNT/LiveOS/ext3fs.img $SRCOSMNT - else - SRCOSMNT="/" - fi - - mount ${TARGET_DEV}2 $TGTMNT -} - -function install_os { - rsync --progress -WaAHXSh --exclude='/dev/' --exclude='/media/*' --exclude='/sys/' --exclude='/proc/' --exclude="/tmp/" --exclude="/run/" $SRCOSMNT/ $TGTMNT - - mkdir ${TGTMNT}/dev/ - chmod 0755 ${TGTMNT}/dev - - rm ${TGTMNT}/etc/fstab - SYSTEMD_ESCAPED_DEV=$(echo ${TARGET_DEV} | sed 's|^/||' | sed 's|/|-|g') - mkdir -p ${TGTMNT}/usr/lib/systemd/system/swap.target.wants - cat > ${TGTMNT}/usr/lib/systemd/system/${SYSTEMD_ESCAPED_DEV}1.swap << EOF -[Unit] -Description=Swap Filesystem -Documentation=man:systemd.swap(5) -Documentation=http://www.freedesktop.org/wiki/Software/systemd/systemd.swap.html - -[Swap] -What=${TARGET_DEV}1 -EOF - - ln -s ../${SYSTEMD_ESCAPED_DEV}1.swap ${TGTMNT}/usr/lib/systemd/system/swap.target.wants/${SYSTEMD_ESCAPED_DEV}1.swap - - if [[ $FILESYSTEM = "btrfs" ]]; then - ROOTFLAGS="rootflags=subvol=tizen" - else - ROOTFLAGS="" - fi - - mkdir -p ${TGTMNT}/boot/extlinux - cat > ${TGTMNT}/boot/extlinux/extlinux.conf << EOF -default vesamenu.c32 -timeout 10 - -menu background splash.png -menu title Welcome to Tizen PC! -menu color border 0 #ffffffff #00000000 -menu color sel 7 #ff000000 #ffffffff -menu color title 0 #ffffffff #00000000 -menu color tabmsg 0 #ffffffff #00000000 -menu color unsel 0 #ffffffff #00000000 -menu color hotsel 0 #ff000000 #ffffffff -menu color hotkey 7 #ffffffff #ff000000 -menu color timeout_msg 0 #ffffffff #00000000 -menu color timeout 0 #ffffffff #00000000 -menu color cmdline 0 #ffffffff #00000000 -menu hidden -menu clear -label tizen - menu label Boot Tizen - kernel ../vmlinuz - append root=${TARGET_DEV}2 rw vga=current splash=silent quiet ${ROOTFLAGS} resume=${TARGET_DEV}1 -menu default -EOF - - cp /usr/share/branding/default/syslinux/syslinux-vesa-splash.jpg ${TGTMNT}/boot/extlinux/splash.png - - ln -sf /usr/share/plymouth/themes/tizen/tizen-default.script ${TGTMNT}/usr/share/plymouth/themes/tizen/tizen.script - - cat /usr/share/syslinux/mbr.bin > ${TARGET_DEV} - /sbin/extlinux -i ${TGTMNT}/boot/extlinux - - if [[ $FILESYSTEM = "btrfs" ]]; then - sed -i 's|SUBVOLUME="/"|SUBVOLUME="'${TGTMNT}'"|' /etc/snapper/configs/root - snapper create -d "Factory Default" - fi -} - -function unmount_devices { - sync - sleep 2 - if [[ $SRCOSMNT != "/" ]]; then - [ -d "$SRCOSMNT" ] && umount $SRCOSMNT - [ -d "$SRCMNT" ] && umount $SRCMNT - fi - - [ -d "$TGTMNT" ] && umount $TGTMNT -} - -function check_echo_reboot { - read key - if [[ $key != 'r' && $key != 'R' ]]; then - check_echo_reboot - fi -} - -message "This installation will wipe all data from the hard drive, hit Y key to continue or ctrl-alt-del to abort." -if [ -n "$PLYMOUTH" ]; then -plymouth watch-keystroke --command="/usr/bin/test" --keys "yY" -else -read key -if [[ $key != 'y' && $key != 'Y' ]]; then -/usr/sbin/reboot -fi -fi -if [ -n "$PLYMOUTH" ]; then -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." -fi -message "Installing on to the hard disk now, this will take a few minutes..." - -read_config -set_mounts -find_devices -partition_device -format_device -mount_devices -install_os -unmount_devices - -if [ -n "$PLYMOUTH" ]; then -plymouth hide-message --text "Installing on to the hard disk now, this will take a few minutes..." -fi - -message "Hit R key to reboot and then remove the usb stick. Enjoy!" - -if [ -n "$PLYMOUTH" ]; then - plymouth watch-keystroke --command="/usr/bin/test" --keys "rR" -else - check_echo_reboot -fi -/usr/sbin/reboot diff --git a/scripts/system-installer b/scripts/system-installer new file mode 100644 index 0000000..5d0a5cf --- /dev/null +++ b/scripts/system-installer @@ -0,0 +1,237 @@ +#!/bin/sh + +AUTOMODE= +PLYMOUTH= +REBOOT_ON_FAILURE= + +while getopts ":a" opt; do + case $opt in + a) + AUTOMODE=1 + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + ;; + esac +done + +if [ -z "$AUTOMODE" ]; then + PLYMOUTH=0 + REBOOT_ON_FAILURE=0 +else + PLYMOUTH=1 + REBOOT_ON_FAILURE=1 +fi + +function message { + if [ -n "$PLYMOUTH" -a "$PLYMOUTH" -eq 1 ]; then + plymouth display-message --text "$1" + else + echo $1 + fi +} + +function check_echo_reboot { + read key + if [[ $key != 'r' && $key != 'R' ]]; then + check_echo_reboot + fi +} + +function read_config { + local CONF_FILE="" + CONF_FILE="/etc/installer.conf" + + if [ ! -e $CONF_FILE ]; then + message "Installation failure, missing /etc/installer.conf" + test $REBOOT_ON_FAILURE -eq 1 && ( + sleep 5 + /usr/sbin/reboot + ) + exit 1 + else + . $CONF_FILE + fi +} + +function set_mounts { + SRCMNT=$(mktemp -d /media/srctmp.XXXXXX) + TGTMNT=$(mktemp -d /media/tgttmp.XXXXXX) + SRCOSMNT=$(mktemp -d /media/srcostmp.XXXXXX) +} + +function find_devices { + for i in $(ls /sys/block/*/device/model); do + dev=$(echo $i | cut -d'/' -f-4) ; + device=$(echo $i | cut -d'/' -f4) + grep -q 1 $dev/removable + if [ "$?" = "1" ]; then + TARGET_DEV="/dev/$device"; + break + fi + done + + if [ -z "$TARGET_DEV" ]; then + message "Installation failure, unable to find suitable install target media" + test $REBOOT_ON_FAILURE -eq 1 && ( + sleep 5 + /usr/sbin/reboot + ) + exit 1 + fi +} + +function partition_device { + for part in $(parted -s $TARGET_DEV print | awk '/^ / {print $1}'); do + parted -s $TARGET_DEV rm $part + done + + SIZE=`parted -ms $TARGET_DEV unit MB print | grep -i "$TARGET_DEV" | cut -d":" -f2 | sed 's/MB//i'` + parted -s $TARGET_DEV mklabel gpt + parted -s $TARGET_DEV mkpart primary 0 2000 + parted -s $TARGET_DEV mkpart primary 2001 $SIZE + parted -s $TARGET_DEV set 2 boot on + sync +} + +function format_device { + /usr/sbin/mkswap ${TARGET_DEV}1 + + /usr/sbin/mkfs.${FILESYSTEM} -L ROOTFS ${TARGET_DEV}2 + + if [[ $FILESYSTEM = "btrfs" ]]; then + mount ${TARGET_DEV}2 $TGTMNT + /usr/sbin/btrfs subvolume create ${TGTMNT}/tizen + /usr/sbin/btrfs subvolume create ${TGTMNT}/tizen/.snapshots + SUBVOLID=$(/usr/sbin/btrfs subvolume list $TGTMNT | grep 'tizen$' | awk '{ print $2 }') + echo "Setting subvolume ${SUBVOLID} as default" + /usr/sbin/btrfs subvolume set-default $SUBVOLID $TGTMNT + sync + umount $TGTMNT + fi +} + +function mount_devices { + local squash_img=/run/initramfs/live/LiveOS/squashfs.img + + if [ -e "$squash_img" ]; then + mount -oloop,ro $squash_img $SRCMNT + mount -oloop,ro $SRCMNT/LiveOS/ext3fs.img $SRCOSMNT + else + SRCOSMNT="/" + fi + + mount ${TARGET_DEV}2 $TGTMNT +} + +function install_os { + rsync -WaAHXSh --exclude='/dev/' --exclude='/lost+found/' --exclude='/media/*' --exclude='/sys/' --exclude='/proc/' --exclude="/tmp/" --exclude="/run/" $SRCOSMNT/ $TGTMNT + + mkdir ${TGTMNT}/dev/ + chmod 0755 ${TGTMNT}/dev + + rm ${TGTMNT}/etc/fstab + SYSTEMD_ESCAPED_DEV=$(echo ${TARGET_DEV} | sed 's|^/||' | sed 's|/|-|g') + mkdir -p ${TGTMNT}/usr/lib/systemd/system/swap.target.wants + cat > ${TGTMNT}/usr/lib/systemd/system/${SYSTEMD_ESCAPED_DEV}1.swap << EOF +[Unit] +Description=Swap Filesystem +Documentation=man:systemd.swap(5) +Documentation=http://www.freedesktop.org/wiki/Software/systemd/systemd.swap.html + +[Swap] +What=${TARGET_DEV}1 +EOF + + ln -s ../${SYSTEMD_ESCAPED_DEV}1.swap ${TGTMNT}/usr/lib/systemd/system/swap.target.wants/${SYSTEMD_ESCAPED_DEV}1.swap + + if [[ $FILESYSTEM = "btrfs" ]]; then + ROOTFLAGS="rootflags=subvol=tizen" + else + ROOTFLAGS="" + fi + + mkdir -p ${TGTMNT}/boot/extlinux + cat > ${TGTMNT}/boot/extlinux/extlinux.conf << EOF +default vesamenu.c32 +timeout 10 + +menu background splash.png +menu title Welcome to Tizen PC! +menu color border 0 #ffffffff #00000000 +menu color sel 7 #ff000000 #ffffffff +menu color title 0 #ffffffff #00000000 +menu color tabmsg 0 #ffffffff #00000000 +menu color unsel 0 #ffffffff #00000000 +menu color hotsel 0 #ff000000 #ffffffff +menu color hotkey 7 #ffffffff #ff000000 +menu color timeout_msg 0 #ffffffff #00000000 +menu color timeout 0 #ffffffff #00000000 +menu color cmdline 0 #ffffffff #00000000 +menu hidden +menu clear +label tizen + menu label Boot Tizen + kernel ../vmlinuz + append root=${TARGET_DEV}2 rw vga=current splash=silent quiet ${ROOTFLAGS} resume=${TARGET_DEV}1 +menu default +EOF + + cp /usr/share/branding/default/syslinux/syslinux-vesa-splash.jpg ${TGTMNT}/boot/extlinux/splash.png + + ln -sf /usr/share/plymouth/themes/tizen/tizen-default.script ${TGTMNT}/usr/share/plymouth/themes/tizen/tizen.script + + cat /usr/share/syslinux/mbr.bin > ${TARGET_DEV} + /sbin/extlinux -i ${TGTMNT}/boot/extlinux + + if [[ $FILESYSTEM = "btrfs" ]]; then + sed -i 's|SUBVOLUME="/"|SUBVOLUME="'${TGTMNT}'"|' /etc/snapper/configs/root + snapper create -d "Factory Default" + fi +} + +function unmount_devices { + sync + sleep 2 + if [[ $SRCOSMNT != "/" ]]; then + [ -d "$SRCOSMNT" ] && umount $SRCOSMNT + [ -d "$SRCMNT" ] && umount $SRCMNT + fi + + [ -d "$TGTMNT" ] && umount $TGTMNT +} + +message "This installation will wipe all data from the hard drive, hit Y key to continue or ctrl-alt-del to abort." +if [ -n "$PLYMOUTH" -a "$PLYMOUTH" -eq 1 ]; then + plymouth watch-keystroke --command="/usr/bin/test" --keys "yY" +else + read key + if [[ $key != 'y' && $key != 'Y' ]]; then + test $REBOOT_ON_FAILURE -eq 1 && /usr/sbin/reboot + fi +fi +if [ -n "$PLYMOUTH" -a "$PLYMOUTH" -eq 1 ]; then + 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." +fi + +read_config +set_mounts +find_devices +message "Installing on to the hard disk now, this will take a few minutes..." +partition_device +format_device +mount_devices +install_os +unmount_devices + +if [ -n "$PLYMOUTH" -a "$PLYMOUTH" -eq 1 ]; then + plymouth hide-message --text "Installing on to the hard disk now, this will take a few minutes..." +fi +message "Hit R key to reboot and then remove the usb stick. Enjoy!" + +if [ -n "$PLYMOUTH" -a "$PLYMOUTH" -eq 1 ]; then + plymouth watch-keystroke --command="/usr/bin/test" --keys "rR" +else + check_echo_reboot +fi +/usr/sbin/reboot diff --git a/systemd/pc-installer.service b/systemd/system-installer.service similarity index 67% rename from systemd/pc-installer.service rename to systemd/system-installer.service index 0e31613..ecf922b 100644 --- a/systemd/pc-installer.service +++ b/systemd/system-installer.service @@ -3,5 +3,5 @@ Description=Installer [Service] Type=oneshot -ExecStart=/usr/sbin/pc-installer +ExecStart=/usr/sbin/system-installer -a ExecStartPost=/usr/sbin/reboot -- 2.7.4