From: tguittet Date: Wed, 21 May 2014 15:23:52 +0000 (+0200) Subject: Adding url-utils X-Git-Tag: accepted/tizen/common/20140627.142506~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=64fa3fe196f6a98305815d9a97abcfb74823eb53;p=platform%2Fupstream%2Fsystem-installer.git Adding url-utils updated packaging Signed-off-by: Nicolas Zingilé Updating scripts Signed-off-by: tguittet lost dialog helper and start cleaning remove unused parameter in systemd service cleanup and lost select-disk-util Adding no-cancel option in dialog_helper further cleanup Signed-off-by: tguittet adding wifi-config modifications on spec file some more verifications Better colors for dialog, include wifi script and warning in system-installer Various fixes and improvements Signed-off-by: Guittet Thibault some more convenience dialogs Signed-off-by: Guittet Thibault Handle Ctrl-C/SIGINT various fixes Change-Id: I69cca6614df23c1f3c2dc4dbd53080301488788e Signed-off-by: Guittet Thibault --- diff --git a/packaging/dialog-1.2-20140219.tgz b/packaging/dialog-1.2-20140219.tgz new file mode 100644 index 0000000..3e94f0c Binary files /dev/null and b/packaging/dialog-1.2-20140219.tgz differ diff --git a/packaging/system-installer.spec b/packaging/system-installer.spec index 24d64b9..786d248 100644 --- a/packaging/system-installer.spec +++ b/packaging/system-installer.spec @@ -5,37 +5,132 @@ License: GPL-2.0 Summary: PC Installer Group: Base/Utilities Source: %{name}-%{version}.tar.xz -Requires: rsync -Requires: plymouth -Requires: syslinux-extlinux +Source2: http://invisible-island.net/dialog/dialog-1.2-20140219.tgz +Source1001: system-installer.manifest +Requires: bmap-tools Requires: btrfs-progs -Requires: snapper +Requires: curl Requires: dosfstools Requires: gptfdisk -Source1001: system-installer.manifest +Requires: plymouth +Requires: rsync +Requires: snapper +Requires: syslinux-extlinux +Requires: util-linux +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig +BuildRequires: autoconf >= 2.64, automake >= 1.11 +BuildRequires: libtool +BuildRequires: ncurses-devel +BuildRequires: findutils +Requires: %{name}-dialog %description Installs a system from a USB stick to a local hard-disk. +%package dialog + +Summary: Display interactive boxes from shell script +Group: Development/Tools +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description dialog +A program that will let you present a variety of questions or +display messages using dialog boxes from a shell script. + +%package dialog-devel +Summary: Development files for building applications with the dialog library +Group: Development/Libraries +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description dialog-devel +A program that will let you present a variety of questions or +display messages using dialog boxes from a shell script. + + %prep %setup -q cp %{SOURCE1001} . +cp %{SOURCE2} . +tar --strip-components=1 -xvzf %{SOURCE2} + %build +%configure \ + --includedir=%{_includedir}/dialog \ + --enable-included-msgs \ + --enable-nls \ + --enable-widec \ + --with-libtool \ + --with-ncurses \ + --with-ncursesw +make %{?_smp_mflags} + %install -install -d %{buildroot}/%{_sbindir} -install -d %{buildroot}/%{_sysconfdir}/installer -install -d %{buildroot}/%{_unitdir} +## for system-installer-dialog ##1 +make DESTDIR=%{buildroot} install + +find %{buildroot}%{_libdir} -name '*.la' -type f -delete -print +find %{buildroot}%{_libdir} -name '*.a' -type f -delete -print +rm -rf %{buildroot}%{_mandir} + +## for system-installer ## +install -d %{buildroot}/%{_sbindir} +install -d %{buildroot}/%{_unitdir}/default.target.wants +install -d %{buildroot}/root install -m 0644 systemd/system-installer.service %{buildroot}/%{_unitdir} install -m 0775 scripts/system-installer %{buildroot}/%{_sbindir}/system-installer -install -m 0775 scripts/installer-conf-creator %{buildroot}/%{_sbindir}/installer-conf-creator +install -m 0775 scripts/dialog-helper %{buildroot}/%{_sbindir}/dialog-helper +install -m 0775 scripts/select-disk-util %{buildroot}/%{_sbindir}/select-disk-util +install -m 0775 scripts/url-utils %{buildroot}/%{_sbindir}/url-utils +install -m 0775 scripts/wifi-config %{buildroot}/%{_sbindir}/wifi-config +install -m 0775 scripts/installer.conf %{buildroot}/%{_sbindir}/installer.conf +install -m 0775 scripts/wifi %{buildroot}/%{_sbindir}/wifi +install -m 0775 scripts/select-keyboard-layout-util %{buildroot}/%{_sbindir}/select-keyboard-layout-util +install -m 0644 scripts/.dialogrc %{buildroot}/root/.dialogrc +ln -sf ../system-installer.service %{buildroot}/%{_unitdir}/default.target.wants/system-installer.service + +## for system-installer-dialog ##1 +%post dialog -p /sbin/ldconfig + +%postun dialog -p /sbin/ldconfig + +%post dialog-devel -p /sbin/ldconfig + +%postun dialog-devel -p /sbin/ldconfig + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig %files %manifest %{name}.manifest %defattr(-,root,root) -%{_sbindir}/system-installer -%{_sbindir}/installer-conf-creator %{_unitdir}/system-installer.service +%{_unitdir}/default.target.wants/system-installer.service +%{_sbindir}/system-installer +%{_sbindir}/dialog-helper +%{_sbindir}/select-disk-util +%{_sbindir}/url-utils +%{_sbindir}/wifi-config +%{_sbindir}/installer.conf +%{_sbindir}/wifi +%{_sbindir}/select-keyboard-layout-util +/root/.dialogrc + +%files dialog +%defattr(-,root,root) +%doc README +%license COPYING +%{_bindir}/dialog +%{_libdir}/libdialog.so.* + +%files dialog-devel +%{_bindir}/dialog-config +%{_includedir}/dialog +%{_libdir}/libdialog.so diff --git a/scripts/.dialogrc b/scripts/.dialogrc new file mode 100644 index 0000000..b91333a --- /dev/null +++ b/scripts/.dialogrc @@ -0,0 +1,144 @@ +# +# Run-time configuration file for dialog +# +# Automatically generated by "dialog --create-rc " +# +# +# Types of values: +# +# Number - +# String - "string" +# Boolean - +# Attribute - (foreground,background,highlight?) + +# Set aspect-ration. +aspect = 0 + +# Set separator (for multiple widgets output). +separate_widget = "" + +# Set tab-length (for textbox tab-conversion). +tab_len = 8 + +# Make tab-traversal for checklist, etc., include the list. +visit_items = OFF + +# Shadow dialog boxes? This also turns on color. +use_shadow = OFF + +# Turn color support ON or OFF +use_colors = ON + +# Screen color +screen_color = (BLACK,BLACK,ON) + +# Shadow color +shadow_color = (BLACK,BLACK,ON) + +# Dialog box color +dialog_color = (BLUE,WHITE,OFF) + +# Dialog box title color +title_color = (BLUE,WHITE,ON) + +# Dialog box border color +border_color = (WHITE,WHITE,ON) + +# Active button color +button_active_color = (WHITE,BLUE,ON) + +# Inactive button color +button_inactive_color = dialog_color + +# Active button key color +button_key_active_color = button_active_color + +# Inactive button key color +button_key_inactive_color = (RED,WHITE,OFF) + +# Active button label color +button_label_active_color = (WHITE,BLUE,ON) + +# Inactive button label color +button_label_inactive_color = (BLACK,WHITE,ON) + +# Input box color +inputbox_color = dialog_color + +# Input box border color +inputbox_border_color = dialog_color + +# Search box color +searchbox_color = dialog_color + +# Search box title color +searchbox_title_color = title_color + +# Search box border color +searchbox_border_color = border_color + +# File position indicator color +position_indicator_color = title_color + +# Menu box color +menubox_color = dialog_color + +# Menu box border color +menubox_border_color = border_color + +# Item color +item_color = dialog_color + +# Selected item color +item_selected_color = button_active_color + +# Tag color +tag_color = title_color + +# Selected tag color +tag_selected_color = button_label_active_color + +# Tag key color +tag_key_color = button_key_inactive_color + +# Selected tag key color +tag_key_selected_color = (YELLOW,BLUE,ON) + +# Check box color +check_color = dialog_color + +# Selected check box color +check_selected_color = button_active_color + +# Up arrow color +uarrow_color = (BLUE,WHITE,ON) + +# Down arrow color +darrow_color = uarrow_color + +# Item help-text color +itemhelp_color = (WHITE,BLACK,OFF) + +# Active form text color +form_active_text_color = button_active_color + +# Form text color +form_text_color = (WHITE,CYAN,ON) + +# Readonly form item color +form_item_readonly_color = (CYAN,WHITE,ON) + +# Dialog box gauge color +gauge_color = (BLUE,WHITE,ON) + +# Dialog box border2 color +border2_color = dialog_color + +# Input box border2 color +inputbox_border2_color = dialog_color + +# Search box border2 color +searchbox_border2_color = dialog_color + +# Menu box border2 color +menubox_border2_color = dialog_color diff --git a/scripts/dialog-helper b/scripts/dialog-helper new file mode 100755 index 0000000..6b3b6a6 --- /dev/null +++ b/scripts/dialog-helper @@ -0,0 +1,16 @@ +#!/bin/bash + +TMP_FILE="/tmp/dialog-helper.$$" + +export DIALOGRES + +# Used to retrieve the result of a menu selection. +# DIALOGRES will hold the tag corresponding to the user's selection. +dialog_helper() { + dialog --stderr --no-cancel "$@" 2> "$TMP_FILE" + local rc=$? + DIALOGRES=$(cat "$TMP_FILE") + rm -f "$TMP_FILE" 2>/dev/null + [[ $rc != 0 ]] && exit 1 + return $rc +} diff --git a/scripts/installer-conf-creator b/scripts/installer-conf-creator deleted file mode 100755 index 4d7bf68..0000000 --- a/scripts/installer-conf-creator +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh -ef - -DEST=/etc/installer.conf - -pnum=0 - -if [ ! -n "$INSTALLERFW_PART_COUNT" ]; then - printf "INSTALLERFW_PART_COUNT unset, aborting\n" >&2 - exit 1 -fi - -echo CFG_DISTRO_NAME=\"${INSTALLERFW_DISTRO_NAME}\" > $DEST -echo CFG_KERNEL_OPTS=\"${INSTALLERFW_KERNEL_OPTS}\" >> $DEST -echo CFG_MOUNT_PREFIX=\"${INSTALLERFW_MOUNT_PREFIX}\" >> $DEST -echo CFG_INSTALLER_NAME=\"${INSTALLERFW_INSTALLER_NAME}\" >> $DEST -echo CFG_PTABLE_FORMAT=\"${INSTALLERFW_PTABLE_FORMAT}\" >> $DEST -echo CFG_PART_COUNT=\"${INSTALLERFW_PART_COUNT}\" >> $DEST -while [ "$pnum" -lt "$INSTALLERFW_PART_COUNT" ]; do - echo CFG_PART${pnum}_FSTYPE=\"$(eval echo \${INSTALLERFW_PART${pnum}_FSTYPE})\" >> $DEST - echo CFG_PART${pnum}_FSOPTS=\"$(eval echo \${INSTALLERFW_PART${pnum}_FSOPTS})\" >> $DEST - echo CFG_PART${pnum}_UUID=\"$(eval echo \${INSTALLERFW_PART${pnum}_UUID})\" >> $DEST - echo CFG_PART${pnum}_BOOTFLAG=\"$(eval echo \${INSTALLERFW_PART${pnum}_BOOTFLAG})\" >> $DEST - echo CFG_PART${pnum}_PARTUUID=\"$(eval echo \${INSTALLERFW_PART${pnum}_PARTUUID})\" >> $DEST - echo CFG_PART${pnum}_SIZE=\"$(eval echo \${INSTALLERFW_PART${pnum}_SIZE})\" >> $DEST - echo CFG_PART${pnum}_MOUNTPOINT=\"$(eval echo \${INSTALLERFW_PART${pnum}_MOUNTPOINT})\" >> $DEST - echo CFG_PART${pnum}_DEVNODE=\"$(eval echo \${INSTALLERFW_PART${pnum}_DEVNODE})\" >> $DEST - echo CFG_PART${pnum}_LABEL=\"$(eval echo \${INSTALLERFW_PART${pnum}_LABEL})\" >> $DEST - echo CFG_PART${pnum}_TYPE_ID=\"$(eval echo \${INSTALLERFW_PART${pnum}_TYPE_ID})\" >> $DEST - echo CFG_PART${pnum}_ALIGN=\"$(eval echo \${INSTALLERFW_PART${pnum}_ALIGN})\" >> $DEST - - pnum="$((pnum+1))" -done - diff --git a/scripts/installer.conf b/scripts/installer.conf new file mode 100644 index 0000000..168f784 --- /dev/null +++ b/scripts/installer.conf @@ -0,0 +1,9 @@ +# The complete url to the raw.bz2 image you wish to flash on the output device +IMAGE_URL="" + +# The output device used for installation +OUTDEV="" + +# The keymap layout used if you need to write a password for the wifi configuration +# and the default keymap layout for weston +KEYBOARD_LAYOUT="" diff --git a/scripts/select-disk-util b/scripts/select-disk-util new file mode 100755 index 0000000..d9046ad --- /dev/null +++ b/scripts/select-disk-util @@ -0,0 +1,38 @@ +#!/bin/bash + +# List block devices that are not removable, +# if multiple devices are found, the user will be invited to choose one. +# If no devices are found, the program exit with error code 1 + +outfile=${1:-/dev/stdout} +. /usr/sbin/dialog-helper + +trap "exit 2" SIGINT + +target_array=() +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_array+=("/dev/$device") + fi +done + +if (( "${#target_array[@]}" == "1" )); then + TARGET="${target_array[0]}" +elif (( "${#target_array[@]}" > "1" )); then + dialog_helper --no-items --menu "Installation destinaion device:" 10 40 3 $( for i in "${target_array[@]}"; do echo "$i"; done ) + TARGET="$DIALOGRES" +else + dialog --msgbox "No devices could be found, no installation possible" 10 40 + exit 1 +fi + +rm -f "${TMP_FILE}" + +cat << EOC > $outfile +$TARGET +EOC + +exit 0 diff --git a/scripts/select-keyboard-layout-util b/scripts/select-keyboard-layout-util new file mode 100755 index 0000000..1039e1b --- /dev/null +++ b/scripts/select-keyboard-layout-util @@ -0,0 +1,17 @@ +#!/bin/bash + +# Select a keyboard layout in a menu + +outfile=${1:-/dev/stdout} +. /usr/sbin/dialog-helper + +trap "exit 1" SIGINT + +layouts=$(find /usr/lib/kbd/keymaps/ -type f |sed -e '/map.gz/!d' -e "s:.*/\(.*\).map.gz:\1:" | sort -u) +dialog_helper --no-items --menu "Choose your keyboard layout" 200 30 40 $(for i in $layouts ; do echo "$i"; done) + +cat << EOC >> $outfile +$(echo "$DIALOGRES") +EOC + +exit 0 diff --git a/scripts/system-installer b/scripts/system-installer index 8151cbd..22972d5 100755 --- a/scripts/system-installer +++ b/scripts/system-installer @@ -17,421 +17,160 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. -# Own program name -PROG="${0##*/}" - -show_usage() -{ - cat <<-EOF -Usage: $PROG [options] - -Options: - -a, --automode do not ask any question and just proceed with installing to - the first persistent storage device found -EOF -} - -# Print $1, show help message and error out -fail_usage() -{ - [ -z "$1" ] || printf "%s\n" "$1" - show_usage - exit 1 -} - -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 -} - +# This script will flash an output device with a downloaded raw image +# from download.tizen.org. +# Any missing configurations will be asked to the user. +# Being connected to the internet before launching this script is +# better. If you aren't connected, a wifi configuration script will be fired. + +chvt 2 + +# The partition to resize after flashing the raw image +partition=1 +# Used to retrieve output of the other scripts +output_data_file="/tmp/system-installer.$$" +# Mount point used to change the keymap layout of weston on the device +mountpoint="/tmp/output_device_mount_point" +# Configuration file of system-installer +conf_file="/usr/sbin/installer.conf" +# Used to signal a bmaptool failure during download/flash +bmaptool_failure="" + +. /usr/sbin/dialog-helper + +# Simply read the configuration in $conf_file, exit if not found 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 - ) + if [ ! -e $conf_file ]; then + dialog --msgbox "Installation failure, missing $conf_file" 10 40 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 -} - -# Global variable for storing the partition option parameters; -params= - -function msdos_partition_options { - # the partition number - local i=$1 - # used for storing the per-part variables, - # accessed via indirect referencing - local tmp="" - - tmp="CFG_PART${i}_SIZE" - local size=${!tmp} - [ -z "$size" ] && size="1024" - if [[ "$CFG_PART_COUNT" = "$((i+1))" ]]; then - # an 'empty' value means that sfdisk will use - # the defaults, in this case expanding to the - # end of the disk - size="" - fi - params=$(printf "${params}\n%s" ",${size}") - - tmp="CFG_PART${i}_FSTYPE" - local fstype=${!tmp} - local typeid='83' - [ "$fstype" = "swap" ] && typeid='82' - params=$(printf "${params}%s" ",${typeid}") - - # handle bootflag last - tmp="CFG_PART${i}_BOOTFLAG" - local bootflag=${!tmp} - if [ "$bootflag" = "True" ]; then - params=$(printf "${params}%s" ',*') - else - params=$(printf "${params}\n") - fi -} - -function gpt_partition_options { - # the partition number - local i=$1 - # used for storing the per-part variables, - # accessed via indirect referencing - local tmp="" - - tmp="CFG_PART${i}_ALIGN" - local align=${!tmp} - [ -n "$align" ] && params=$(printf "${params}%s" " --set-alignment=${align}") - - # sgdisk uses '0' to mean 'default value' - params=$(printf "$params%s" " --new=0:0") - - tmp="CFG_PART${i}_SIZE" - local size=${!tmp} - if [[ "$CFG_PART_COUNT" = "$((i+1))" ]]; then - size="0" - fi - [ -z "$size" ] && size="1024" - [ -n "$size" ] && params=$(printf "${params}%s" ":${size}M") - - # TODO: need to handle swap partition types if encountered - - # the following GUID option does not accept default partition values, - # so partition numbering must start at index 1, not 0 - local partnum="$((i+1))" - - tmp="CFG_PART${i}_TYPE_ID" - local typeid=${!tmp} - [ -n "$typeid" ] && params=$(printf "${params}%s" " --typecode=${partnum}:${typeid}") -} - -function partition_msdos { - # make sure there is a newline in the heredoc, - # or else sfdisk fails to parse the input - /usr/sbin/sfdisk --in-order -uM ${TARGET_DEV} << EOF -${1} - -EOF - sync -} - -function partition_gpt { - /usr/sbin/sgdisk -Z ${TARGET_DEV} - /usr/sbin/sgdisk ${1} ${TARGET_DEV} - sync -} - -function format_device { - local fstype=$1 - local instfw_pnum=$2 - # the actual partition numbers begin at index 1, not 0 - local partnum="$((instfw_pnum+1))" - - # TODO: need to handle swap partitions - - /usr/sbin/mkfs.${fstype} ${TARGET_DEV}${partnum} - - if [[ ${fstype} = "btrfs" ]]; then - mount ${TARGET_DEV}${partnum} $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 + . $conf_file fi } -function mount_device { - local mountpoint=$1 - local instfw_pnum=$2 - # the actual partition numbers begin at index 1, not 0 - local partnum="$((instfw_pnum+1))" - - SRCOSMNT="/" - - # we make this substitution in extlinux.conf on the target device - [ "$mountpoint" = "/" ] && ROOTFS="${TARGET_DEV}${partnum}" - - mkdir -p ${TGTMNT}/${mountpoint} - - # for this to work, the rootfs partition entry in installer.conf - # must be first entry, or else some mount points will be hidden - # during the rsync - mount ${TARGET_DEV}${partnum} ${TGTMNT}/${mountpoint} -} - -function install_extlinux { - 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=${ROOTFS} ${CFG_KERNEL_OPTS} ${ROOTFLAGS} -menu default -EOF - - cp /usr/share/branding/default/syslinux/syslinux-vesa-splash.jpg ${TGTMNT}/boot/extlinux/splash.png - - cat /usr/share/syslinux/mbr.bin > ${TARGET_DEV} - /sbin/extlinux -i ${TGTMNT}/boot/extlinux -} - -function fixup_fstab { - local pnum=0 - local devpnum="$((pnum+1))" - local tmp="" - local srcuuid="" - local tgtuuid="" - - while [ "$pnum" -lt "$CFG_PART_COUNT" ]; do - tmp="CFG_PART${pnum}_UUID" - srcuuid=${!tmp} - - tgtuuid=$(blkid ${TARGET_DEV}${devpnum} | sed 's/.* UUID="\([^"]*\)".*/\1/') - sed -i "s/.*\(UUID=\).*${srcuuid}\(.*\)/\1${tgtuuid}\2/" ${TGTMNT}/etc/fstab - - pnum="$((pnum+1))" - devpnum="$((devpnum+1))" - done -} - -function fixup_gummiboot { - # expect the rootfs to be the last entry in installer.conf - local pnum="$((CFG_PART_COUNT-1))" - local devpnum="$((pnum+1))" - local tmp="" - local mntpoint="" - local srcpuuid="" - local tgtpuuid="" - local confs="$(ls -1 "${TGTMNT}/boot/loader/entries/")" - - tmp="CFG_PART${pnum}_PARTUUID" - srcpuuid=${!tmp} - - tgtpuuid=$(blkid ${TARGET_DEV}${devpnum} | sed 's/.* PARTUUID="\([^"]*\)".*/\1/') - - printf "%s\n" "$confs" | while IFS= read -r conf; do - sed -i "s/\(.*PARTUUID=\).*${srcpuuid}\(.*\)/\1${tgtpuuid}\2/" "${TGTMNT}/boot/loader/entries/${conf}" - done -} - +# Download the raw image, decompress it and write it on the device +# When the image is written, the partition size is modified function install_os { - rsync -WaHXSh --exclude='/dev/' --exclude='/lost+found/' --exclude='/media/*' --exclude='/sys/' --exclude='/proc/' --exclude="/tmp/" --exclude="/run/" $SRCOSMNT/ $TGTMNT - - mkdir ${TGTMNT}/dev/ - chmod 0755 ${TGTMNT}/dev - - # TODO: switch to using systemd mount units instead of the fstab - #rm ${TGTMNT}/etc/fstab - - fixup_fstab - - if [ "$CFG_PTABLE_FORMAT" = "gpt" ]; then - fixup_gummiboot + bmaptool copy "$IMAGE_URL" "$OUTDEV" |& + sed -u -e '/copied/!d;s/\r/\n/g;s/.* \([0-9]\{1,3\}\)% .*/\1/g' | + dialog --gauge "Downloading the image and copying on $OUTDEV" 10 100 0 + if [[ ${PIPESTATUS[0]} != 0 ]]; then + bmaptool_failure="yes" + sigint_handler fi - if [[ $FILESYSTEM = "btrfs" ]]; then - ROOTFLAGS="rootflags=subvol=tizen" - else - ROOTFLAGS="" - fi + local RESIZEFS=yes - if [ "$CFG_PTABLE_FORMAT" = "msdos" ]; then - install_extlinux - fi + if [ "$RESIZEFS" = "yes" ]; then + # resize first partition + # WARNING: this only works if the system is installed on a single partition + newsz=20 # GB + sfdisk -d $OUTDEV | + awk '$1=="'${OUTDEV}${partition}'" { sub("size=[^,]+","size="'${newsz}'*1024*1024*2)}1' >/tmp/newpart.lst + sfdisk $OUTDEV /dev/null + loadkeys "$KEYBOARD_LAYOUT" +} + +# Test connection to "http://download.tizen.org/", +# if we can't connect, we configure the keyboard layout (if not yet set) +# then we launch the wifi configuration script +function test_connection { + curl --connect-timeout 10 -s "http://download.tizen.org/" > /dev/null + if [[ $? != 0 ]]; then + while :; do + /usr/sbin/wifi-config && break + [ $? -eq 1 ] && sigint_handler + done + fi +} + +# Sets the keyboard layout accordingly to $KEYBOARD_LAYOUT +# in weston.ini on the device +function modify_weston_conf { + local file="${mountpoint}/etc/xdg/weston/weston.ini" + [ -f "$file" ] && sed -i -e "s/^#\[keyboard\]$/\[keyboard\]/; s/^#keymap_layout=.*/keymap_layout=$KEYBOARD_LAYOUT/" "$file" +} + +function sigint_handler { + local txt="" + if [ "$bmaptool_failure" = "yes" ]; then + txt+="Bmaptool failed to flash your device." + else + txt+="The installation was interrupted." + fi + txt+=" Do you want to reboot ? press 'Yes' to reboot and 'No' to restart the installation." + dialog --yesno "$txt" 15 40 && /usr/sbin/reboot -f + rm -f "$output_data_file" 2>/dev/null + rm -rf "$mountpoint" 2>/dev/null + [ -d "${OUTDEV}${partition}" ] && umount -l "${OUTDEV}${partition}" 2>/dev/null + exec /usr/sbin/system-installer +} + +trap "sigint_handler" SIGINT read_config -set_mounts -find_devices -message "Installing on to the hard disk now, this will take a few minutes..." - -pnum=0 -# first, generate the option list to pass to either 'sfdisk' or 'sgdisk' -while [ "$pnum" -lt "$CFG_PART_COUNT" ]; do - if [ "$CFG_PTABLE_FORMAT" = "msdos" ]; then - msdos_partition_options $pnum - elif [ "$CFG_PTABLE_FORMAT" = "gpt" ]; then - gpt_partition_options $pnum - fi - pnum="$((pnum+1))" -done -# now, do the partitioning -if [ "$CFG_PTABLE_FORMAT" = "msdos" ]; then - partition_msdos "$params" -elif [ "$CFG_PTABLE_FORMAT" = "gpt" ]; then - partition_gpt "$params" +[ -z "$KEYBOARD_LAYOUT" ] && select_keyboard_layout + +if [ -z "$IMAGE_URL" ] ;then + test_connection + while :; do + /usr/sbin/url-utils "$output_data_file" && break + [ $? -eq 1 ] && sigint_handler + done + IMAGE_URL=$(cat "$output_data_file") +elif ! curl --fail -I "$IMAGE_URL" > /dev/null ; then + echo "The image url couldn't be reached, please verify that the url is correct." + exit 1 fi -pnum="$((CFG_PART_COUNT-1))" -# NOTE: for now, partitions are processed in reverse order, and we -# expect the rootfs to be the last entry in installer.conf -while [ "$pnum" -ge "0" ]; do - tmp="CFG_PART${pnum}_FSTYPE" - fstype=${!tmp} - - format_device $fstype $pnum +if [ -z "$OUTDEV" ] ;then + while :; do + /usr/sbin/select-disk-util "$output_data_file" && break + [ $? -eq 1 ] && sigint_handler + done + OUTDEV=$(cat "$output_data_file") +elif [ ! -b "$OUTDEV" ] ; then + echo "The output device is not a block device." + exit 1 +fi - tmp="CFG_PART${pnum}_MOUNTPOINT" - mountpoint=${!tmp} +rm -f "$output_data_file" 2>/dev/null - mount_device $mountpoint $pnum +dialog --yesno "Do you whant to proceed with the installation ? All your data on the target device will be lost." 10 40 || exit 1 - pnum="$((pnum-1))" -done +# Download and install the image +install_os -unset fstype -unset mountpoint +# Mounting device +mkdir -p "$mountpoint" +mount "${OUTDEV}${partition}" "$mountpoint" -install_os -unmount_devices +modify_weston_conf -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!" +# Unmounting device +sync && sync +[ -d "${OUTDEV}${partition}" ] && umount -l "${OUTDEV}${partition}" -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 +dialog --msgbox "The default password for all users is 'tizen'. Hit Enter to reboot and then remove the usb stick." 10 40 && /usr/sbin/reboot -f diff --git a/scripts/url-utils b/scripts/url-utils new file mode 100755 index 0000000..444622a --- /dev/null +++ b/scripts/url-utils @@ -0,0 +1,133 @@ +#!/bin/bash + +# Guide a user towards a image URL with questions and exploration of +# http://download.tizen.org/. +# If you supply a file as parameter, the output will be saved in it. +# Exit with value 2 if SIGINT is sent. + +# Number of images to list (if arch x86_64, ia32 images will be also used) +N=3 + +# Some images are excluded +BLACKLIST="-e unsafe -e emul -e efi -e testing -e installer" + +# Field number used to retrieve the href value in a listing +# The fields are separated by " +HREF_FIELD_NO=6 + +outfile=${1:-/dev/stdout} +. /usr/sbin/dialog-helper +tmp_outfile="/tmp/url-utils.$$" + +# Print the href values of a directory listing +# param #1: url of a directory listing +function url_get_href_from_listing() { + curl -s -S "$1" | + grep '\[DIR\] > $tmp_outfile + fi + done + i=$(($i + 1)) + done +} + +trap "exit 2" SIGINT + +# Asks for profile +dialog_helper --no-items --menu "Choose your profile" 10 30 2 "IVI" "Common" +PROFIL="$DIALOGRES" + +# Asks for image type +dialog_helper --no-items --menu "Choose your image type" 10 30 2 "snapshot" "release" +TYPE="$DIALOGRES" + +# Deduces the architecture if not set +[ -z "$ARCH" ] && ARCH=$(lscpu |grep -q "^CPU op-mode.*64-bit.*" && echo "x86_64") + +# "base" URL +if [ "$TYPE" = "release" ]; then + # Only IVI profile is available in release/weekly + if [ "$PROFIL" = "IVI" ]; then + dialog_helper --no-items --menu "Choose your release" 10 30 2 "daily" "weekly" + URL="http://download.tizen.org/releases/$DIALOGRES/tizen/" + else + URL="http://download.tizen.org/releases/daily/tizen/" + fi +else + URL="http://download.tizen.org/snapshots/tizen/" +fi + +# This follow the (odd) naming conventions of download.tizen.org +# Also, if you have ARCH = "x86_64", images of the "ia32" architecture also will be printed +if [ "$PROFIL" = "IVI" ]; then + URL1="${URL}ivi/ivi/" +else + URL+="common/common-" + if [ "$TYPE" = "snapshot" ]; then + # Asks for display server + dialog_helper --no-items --menu "Choose your display server" 10 30 2 "X11" "Wayland" + DISPLAY="$DIALOGRES" + + if [ "$DISPLAY" = "X11" ]; then + URL+="x11-" + # For some reason a wayland folder is in a x11 image folder + BLACKLIST+=" -e wayland" + else + URL+="wayland-" + fi + else + URL+="wayland-" + fi + + if [ "$ARCH" = "x86_64" ]; then + URL2="${URL}x86_64/" + $(url_N_last_images "$URL2") + fi + + URL1="${URL}ia32/" +fi + +# If we don't print anything, the screen will be black for few seconds +dialog --infobox "Building urls..." 10 40 +$(url_N_last_images "$URL1") + +# We extract various informations from the url, the result is : +# "Tizen common-wayland-mbr-x86_64 (MM/DD/YYYY #)" +entry=$( + sed 's:\(.*/tizen_\([0-9]\{4\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\.\([0-9]*\)/images/\(.*\)/.*\):\1 "Tizen \6 (\3/\4/\2 #\5)":' $tmp_outfile | + tr '\n' ' ' +) + +rm -f "$tmp_outfile" 2>/dev/null + +if [ -z "$entry" ]; then + dialog --msgbox "No suitable image could be found, exiting" 10 40 + exit 1 +fi + +eval dialog_helper --notags --menu "\"Choose between the latests images that match your criterions\"" 16 60 6 $entry + +cat << EOC >> $outfile +$(echo "$DIALOGRES") +EOC diff --git a/scripts/wifi b/scripts/wifi new file mode 100755 index 0000000..7b682b3 --- /dev/null +++ b/scripts/wifi @@ -0,0 +1,200 @@ +#!/bin/bash + +# Helper script to activate/desactivate WLAN from command line + +# Usage : +# wifi connect +# wifi disconnect +# wifi scan +# wifi status + +##################################################### + +### global vars ### + +CONNMAN=/usr/sbin/connmanctl + +script=$(basename $0) +configpath=/var/lib/connman # connman config directory +ssid="" # ssid of wifi network to reach +passphrase="" # passphrase of wifi network to reach +service="" # service identifier of the network service to reach +fullservice="" # + +function error() { + echo ERROR: "$@" >&2 + cat << EOF >&2 +Usage: + $script connect [passphrase] + $script disconnect [ssid] + $script scan + $script status +EOF + exit 1 +} + +function wifi_enable() { + command=$($CONNMAN technologies | grep -A 4 wifi | sed -n '4p') + + if [[ $command == *True ]]; then + echo ">>> Wifi is already enabled ... Ok" + else + echo ">>> Enabling wifi ..." + command=$($CONNMAN enable wifi) + if [[ $command == Enabled* ]]; then + echo $command + else + echo ">>> Cannot enable wifi !" + exit 1 + fi + fi +} + +function wifi_disable() { + $CONNMAN disable wifi +} + +function wifi_scan() { + echo -e "\n>>> Scanning for available wifi networks..." + $CONNMAN scan wifi +} + +function wifi_connected() { + command=$($CONNMAN technologies | grep -A 4 wifi | sed -n '5p') + + if [[ $command == *True ]];then + echo -e "\n>>> Already connected to a wifi network" + return 0 + fi + return 1 +} + +function wifi_status() { + echo -e "\n>>> Wifi status:" + $CONNMAN technologies | grep -A 4 wifi + echo -e "\n>>> Available SSIDs:" + $CONNMAN services | grep wifi_ +} + +function wifi_config() { + echo -e "\n>>> Setting up wifi connection..." + + retries=5 + + while [ 1 ]; do + $CONNMAN scan wifi + echo "\n>>> Available SSIDs:" + $CONNMAN services | grep wifi_ + + fullservice=$($CONNMAN services | cut -c 5- | sed 's/ \+ /:/g' | grep "$ssid:") + if [[ -n $fullservice ]]; then + break + fi + + retries=$(( retries - 1 )) + if [[ $retries -gt 0 ]]; then + echo "waiting for $ssid to appear..." + sleep 5 + continue + fi + echo "Target ssid not found !" + exit 1 + done + + ssid=$(echo "$fullservice" | awk -F: '{print $1}') + service=$(echo "$fullservice" | awk -F: '{print $2}') + + echo "Target ssid found - config is :" + echo "SSID : $ssid" + echo "Service Id : $service" + echo "Passphrase : $passphrase" + + cat <"$configpath/$ssid.config" +[service_$service] +Name = $ssid +Type = wifi +Passphrase = $passphrase +EOF + + echo "Configuration written" +} + +function wifi_connect() { + echo -e "\n>>> Performing connection ..." + output=$($CONNMAN connect $service) + + if [[ $output == Connected* ]];then + echo "...Ok." + echo $output + else + echo "...connection failed !" + echo $output + + wifi_disconnect + echo "Check your SSID or your passphrase" + exit 1 + fi +} + +function wifi_disconnect() { + + if [[ -z "$ssid" ]]; then + $CONNMAN services | cut -c5- | sed 's/ \+ /:/g' | ( while read line; do + ssid=$(cut -f1 -d':' <<<$line) + serv=$(cut -f2 -d':' <<<$line) + if [[ "$serv" =~ ^wifi_ && -f "$configpath/$ssid.config" ]]; then + echo "Disconnecting $serv" + $CONNMAN disconnect $serv + echo "Cleaning config $ssid.config" + rm -rf "$configpath/$ssid.config" + fi + done ) + return 0 + fi + + service=$($CONNMAN services | cut -c 5- | sed 's/ \+ /:/g' | grep "^$ssid:" | awk -F: '{print $2}') + if [[ -z "$service" ]]; then + echo "... unknown service" + rm -rf "$configpath/$ssid.config" # clear config in all cases + return 1 + fi + + output=$($CONNMAN disconnect $service) + rm -rf "$configpath/$ssid.config" # clear config in all cases + if [[ $output == Disconnected* ]];then + echo "...Ok." + echo $output + else + echo "...disconnection failed !" + echo $output + return 1 + fi +} + +case $1 in + connect) + ssid=$2 + passphrase=$3 + [ -z "$ssid" ] && error "No ssid defined !" + wifi_enable + wifi_connected && exit 0 + wifi_config + wifi_connect + ;; + disconnect) + ssid=$2 + wifi_disconnect + wifi_disable + ;; + scan) + wifi_enable + wifi_scan + wifi_status + ;; + status) + wifi_status + ;; + *) + error "Command line doesn't have any option !" +esac + diff --git a/scripts/wifi-config b/scripts/wifi-config new file mode 100755 index 0000000..8d7c86c --- /dev/null +++ b/scripts/wifi-config @@ -0,0 +1,39 @@ +#!/bin/bash + +# Offer a dialog interface for simple wifi connection +# Exit with value 2 if SIGINT is sent. + +data_out="/tmp/wifi-config.$$" +. /usr/sbin/dialog-helper + +ssid="" +passphrase="" + +trap "exit 2" SIGINT + +while [ 1 ]; do + wifi scan > $data_out + ap=$(grep "wifi_" "$data_out" | sed "s/^\*A/\t/" | awk '{$(NF--)=""; print}' | sed "s/^\(.*\) $/\"\1\"/g") + rm -f $data_out 2> /dev/null + + if [ -z "$ssid" ]; then + eval dialog_helper --no-items --menu "'choose your AP'" 20 40 20 $ap + ssid="$DIALOGRES" + fi + + if [ -z "$passphrase" ]; then + dialog_helper --inputbox "Network's passphrase (leave empty if none)" 10 40 + passphrase="$DIALOGRES" + fi + + wifi connect "$ssid" "$passphrase" 2>1 | dialog --progressbox "Wifi connecting..." 40 100 + if [ $? -eq 0 ]; then + dialog --msgbox "You are connected" 10 40 + exit 0 + else + ssid="" + passphrase="" + dialog --yesno "Connection failed. Do you want to retry ?" 10 40 && continue + exit 1 + fi +done diff --git a/systemd/system-installer.service b/systemd/system-installer.service index ecf922b..21c0d27 100644 --- a/systemd/system-installer.service +++ b/systemd/system-installer.service @@ -1,7 +1,12 @@ [Unit] Description=Installer +After=getty@tty2.service [Service] Type=oneshot -ExecStart=/usr/sbin/system-installer -a +ExecStart=/usr/sbin/system-installer ExecStartPost=/usr/sbin/reboot +StandardInput=tty +TTYPath=/dev/tty2 +TTYReset=yes +TTYVHangup=yes