diff options
author | Nicolas Zingilé <nicolas.zingile@open.eurogiciel.org> | 2014-10-27 17:53:55 +0100 |
---|---|---|
committer | Stephane Desneux <stephane.desneux@open.eurogiciel.org> | 2014-10-27 17:41:00 +0100 |
commit | 849cf3840a1feae5710b71e74a480ff7e3e3a4fd (patch) | |
tree | 57d66513b55c156dc79ed4073f0fe77dc7948bad | |
parent | b0461ebffb78765aad7e613fbbdc85bcc3e275a9 (diff) | |
download | system-installer-849cf3840a1feae5710b71e74a480ff7e3e3a4fd.tar.gz system-installer-849cf3840a1feae5710b71e74a480ff7e3e3a4fd.tar.bz2 system-installer-849cf3840a1feae5710b71e74a480ff7e3e3a4fd.zip |
initial packagingsubmit/tizen_common/20141027.182159submit/tizen_3.0.2014.q3_common/20141027.182244accepted/tizen/common/20141027.182351accepted/tizen/3.0.2014.q3/common/20141027.182404tizen_3.0.2014.q3_common
Signed-off-by: Nicolas Zingilé <nicolas.zingile@open.eurogiciel.org>
-rw-r--r-- | packaging/system-installer.manifest | 5 | ||||
-rw-r--r-- | packaging/system-installer.spec | 62 | ||||
-rw-r--r-- | scripts/.dialogrc | 144 | ||||
-rwxr-xr-x | scripts/dialog-helper | 17 | ||||
-rwxr-xr-x | scripts/disk-util | 38 | ||||
-rwxr-xr-x | scripts/keyboard-util | 19 | ||||
-rwxr-xr-x | scripts/system-installer | 154 | ||||
-rw-r--r-- | scripts/system-installer.conf | 9 | ||||
-rwxr-xr-x | scripts/url-util | 112 | ||||
-rwxr-xr-x | scripts/wifi | 202 | ||||
-rwxr-xr-x | scripts/wifi-util | 42 | ||||
-rw-r--r-- | systemd/system-installer.service | 12 |
12 files changed, 816 insertions, 0 deletions
diff --git a/packaging/system-installer.manifest b/packaging/system-installer.manifest new file mode 100644 index 0000000..017d22d --- /dev/null +++ b/packaging/system-installer.manifest @@ -0,0 +1,5 @@ +<manifest> + <request> + <domain name="_"/> + </request> +</manifest> diff --git a/packaging/system-installer.spec b/packaging/system-installer.spec new file mode 100644 index 0000000..1cfb9c6 --- /dev/null +++ b/packaging/system-installer.spec @@ -0,0 +1,62 @@ +Name: system-installer +Version: 2.0 +Release: 0 +License: GPL-2.0 +Summary: Tizen installer +Group: Base/Utilities +Source: %{name}-%{version}.tar.xz +Source1001: system-installer.manifest +Requires: bmap-tools +Requires: curl +Requires: dialog +Requires: rsync +Requires: util-linux +BuildArch: noarch + + +%description +Installs a Tizen image from an USB stick to a local hard-disk. + + +%prep +%setup -q +cp %{SOURCE1001} . + + +%build + + +%install + +install -d %{buildroot}/%{_prefix}/lib/%{name} +install -d %{buildroot}/%{_sysconfdir} +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 0644 scripts/system-installer.conf %{buildroot}/%{_sysconfdir}/system-installer.conf +install -m 0775 scripts/dialog-helper %{buildroot}/%{_prefix}/lib/%{name}/dialog-helper +install -m 0775 scripts/wifi %{buildroot}/%{_prefix}/lib/%{name}/wifi +install -m 0775 scripts/disk-util %{buildroot}/%{_prefix}/lib/%{name}/disk-util +install -m 0775 scripts/url-util %{buildroot}/%{_prefix}/lib/%{name}/url-util +install -m 0775 scripts/wifi-util %{buildroot}/%{_prefix}/lib/%{name}/wifi-util +install -m 0775 scripts/keyboard-util %{buildroot}/%{_prefix}/lib/%{name}/keyboard-util +install -m 0775 scripts/system-installer %{buildroot}/%{_sbindir}/system-installer +install -m 0644 scripts/.dialogrc %{buildroot}/root/.dialogrc +ln -sf ../system-installer.service %{buildroot}/%{_unitdir}/default.target.wants/system-installer.service + + +%files +%manifest %{name}.manifest +%defattr(-,root,root) +%config %{_sysconfdir}/system-installer.conf +%{_unitdir}/system-installer.service +%{_unitdir}/default.target.wants/system-installer.service +%{_sbindir}/system-installer +%{_prefix}/lib/%{name}/dialog-helper +%{_prefix}/lib/%{name}/wifi +%{_prefix}/lib/%{name}/disk-util +%{_prefix}/lib/%{name}/url-util +%{_prefix}/lib/%{name}/wifi-util +%{_prefix}/lib/%{name}/keyboard-util +/root/.dialogrc 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 <file>" +# +# +# Types of values: +# +# Number - <number> +# String - "string" +# Boolean - <ON|OFF> +# 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..acbc142 --- /dev/null +++ b/scripts/dialog-helper @@ -0,0 +1,17 @@ +#!/bin/bash + +TMP_FILE="/tmp/dialog-helper.$$" +DIALOG=/usr/bin/dialog + +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/disk-util b/scripts/disk-util new file mode 100755 index 0000000..a4bdaa0 --- /dev/null +++ b/scripts/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} +utilspath=/usr/lib/system-installer + +. $utilspath/dialog-helper + +target_array=() +for i in /sys/block/*/device; do + [ -d "$i/slaves" ] && continue + dev=$(echo $i | cut -d'/' -f-4) + outdev=$(echo $i | cut -d'/' -f4) + grep -q 1 "$dev/removable" + if [ "$?" = "1" ]; then + target_array+=("/dev/$outdev") + fi +done + +if (( "${#target_array[@]}" == "1" )); then + TARGET="${target_array[0]}" +elif (( "${#target_array[@]}" > "1" )); then + install_dest="Installation destination device :" + dialog_helper --no-items --menu "${install_dest}" 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" 24 70 + exit 1 +fi + +cat << EOC > $outfile +$TARGET +EOC + +exit 0 diff --git a/scripts/keyboard-util b/scripts/keyboard-util new file mode 100755 index 0000000..570d4b2 --- /dev/null +++ b/scripts/keyboard-util @@ -0,0 +1,19 @@ +#!/bin/bash + +# Select a keyboard layout in a menu + +outfile=${1:-/dev/stdout} +utilspath=/usr/lib/system-installer + +. $utilspath/dialog-helper + +trap "exit 1" SIGINT + +layouts='es de fr uk us' +dialog_helper --no-items --menu "Choose your keyboard layout" 15 70 15 $(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 new file mode 100755 index 0000000..01d46c9 --- /dev/null +++ b/scripts/system-installer @@ -0,0 +1,154 @@ +#!/bin/bash +# -*- coding: utf-8 -*- +# vim: ts=4 sw=4 et ai si +# +# Copyright (c) 2014 Intel, Inc. +# License: GPLv2 +# Authors: Thibault Guittet <thibault.guittet@open.eurogiciel.org> +# Nicolas Zingilé <nicolas.zingile@open.eurogiciel.org> +# Stéphane Desneux <stephane.desneux@open.euurogiciel.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License, version 2, +# as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +# 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. + +echo -e "2\t2\t2\t2" > /proc/sys/kernel/printk + +chvt 2 + +export HOME="/root" + +# Used to retrieve output of the other scripts +output_data_file="/tmp/system-installer.$$" + +# Configuration file of system-installer +conf_file="/etc/system-installer.conf" + +# Used to signal a bmaptool failure during download/flash +bmaptool_failure="" + +# util executables paths +utilspath=/usr/lib/system-installer +url_util=$utilspath/url-util +wifi_util_util=$utilspath/wifi-util +kbd_util=$utilspath/keyboard-util +disk_util=$utilspath/disk-util + +. $utilspath/dialog-helper + +# Simply read the configuration in $conf_file, exit if not found +function read_config { + + if [ ! -e $conf_file ]; then + $DIALOG --msgbox "Installation failure, missing $conf_file" 24 70 + sigint_handler + else + . $conf_file + fi +} + +# 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 { + 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 +} + +# Let the user choose between available keyboard layouts, then execute loadkeys +function select_keyboard_layout { + while :; do + $kbd_util "$output_data_file" && break + [ $? -eq 1 ] && sigint_handler + done + KEYBOARD_LAYOUT=$(cat "$output_data_file") + rm -f "$output_data_file" 2>/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 { + echo "Checking for internet connection, please wait" + sleep 5 + until curl --connect-timeout 10 -s "http://download.tizen.org/" > /dev/null; do + while :; do + $wifi_util && break + [ $? -eq 1 ] && sigint_handler + done + echo "Checking for internet connection, please wait" + done +} + +function sigint_handler { + local txt="" + if [ "$bmaptool_failure" = "yes" ]; then + txt+="Bmaptool failed to flash your device." + else + txt+="The installation was interrupted.\n\n\n" + fi + txt+="Press 'Yes' to reboot the device.\nPress 'No' to restart the installation." + $DIALOG --yesno "$txt" 15 70 && /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 + +[ -z "$KEYBOARD_LAYOUT" ] && select_keyboard_layout + +if [ -z "$IMAGE_URL" ]; then + test_connection + while :; do + $url_util "$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 + +if [ -z "$OUTDEV" ]; then + while :; do + $disk_util "$output_data_file" && break + [ $? -eq 1 ] && sigint_handler + done + OUTDEV=$(cat "$output_data_file") +elif [ ! -b "$OUTDEV" ]; then + $DIALOG --msgbox "The output device is not a block device." 15 70 + sigint_handler +fi + +rm -f "$output_data_file" 2>/dev/null + +# os install confirmation +os_install_lost="Do you want to proceed with the installation ? All your data on the target device will be lost." +$DIALOG --yesno "${os_install_lost}" 15 70 || sigint_handler + +# Download and install the image" +install_os + +# Reboot the device" +os_password="The default password is 'tizen'. Hit Enter to reboot and then remove the usb stick." +$DIALOG --msgbox "$os_password" 15 70 && /usr/sbin/reboot -f diff --git a/scripts/system-installer.conf b/scripts/system-installer.conf new file mode 100644 index 0000000..168f784 --- /dev/null +++ b/scripts/system-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/url-util b/scripts/url-util new file mode 100755 index 0000000..68839d4 --- /dev/null +++ b/scripts/url-util @@ -0,0 +1,112 @@ +#!/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. + +#!/bin/bash + +outfile=${1:-/dev/stdout} + +BASE_URL="http://download.tizen.org/" +IMAGE_URL+=$BASE_URL +DIALOG_RESULT= +DIALOG=/usr/bin/dialog + +BACK_STRING="..(parent)" + +tmpdir=$(mktemp -d /tmp/$(basename $0).XXXXXXXX) +tmpfile=$(mktemp /tmp/dialog.XXXXXXXX) +trap "rm -rf $tmpdir $tmpfile" STOP INT QUIT EXIT +pushd $tmpdir &>/dev/null + +function select_topdir() { + $DIALOG --no-items --item-help --menu "Select image type" 15 70 15 \ + "releases" "Official Tizen release : daily, weekly, milestones" \ + "snapshots/tizen" "Tizen snapshots of main project for all Tizen profiles" \ + "snapshots/devel" "Tizen snapshots of devel project for all Tizen profiles" \ + "prerelease" "Prerelease images" 2>$tmpfile + ret=$? + + [[ $ret == 0 ]] && { DIALOG_RESULT=$(cat $tmpfile); return 0; } + DIALOG_RESULT= + return 1 +} + +function select_image() { + dir=$1 + + declare -a items + + readarray items < <(for x in $dir/*; do + [[ ! -d $x ]] && continue + [[ -z "$(ls -d $x/* 2>/dev/null)" ]] && continue + basename $x + done | sort -r) + + if [[ ${#items[@]} == 0 ]]; then + DIALOG_RESULT= + return 0 + fi + + items[${#items[@]}]="$BACK_STRING" + + $DIALOG --no-items --menu "Select subdirectory ($dir)" 15 70 15 $(echo "${items[@]}") 2>$tmpfile + ret=$? + + [[ $ret == 0 ]] && { DIALOG_RESULT=$(cat $tmpfile); return 0; } + DIALOG_RESULT= + return 1 +} + +function do_sync() { + dialog_pid=$1 + current_pid=$$ + + echo -e "\nFetching images locations... Please wait...\n" + + rsync -a --relative --include=*/ --include=*.raw.* --exclude=* download.tizen.org::all/$curdir | grep -v ^d 2>/dev/null | awk '{print $5}' 2>/dev/null | while read x; do + ## exit from the url-util script if dialog process is terminated + if [ ! -e /proc/$dialog_pid ]; then + kill $current_pid + exit 1 + fi + mkdir -p $(dirname $x) + touch $x + echo $(basename $x) + done + + echo "DONE - killing $dialog_pid" + + [[ -n "$dialog_pid" ]] && kill $dialog_pid +} + +####################################################### + +select_topdir || exit 1 +curdir=$DIALOG_RESULT + +touch sync.out +$DIALOG --title "Fetching images locations" --tailbox sync.out 24 70 & +do_sync $! >>sync.out + +initial_dir=$curdir +while [ 1 ]; do + select_image $curdir || exit 1 + if [[ "$DIALOG_RESULT" == "${BACK_STRING}" ]]; then + curdir=$(dirname $curdir) + elif [[ -z "$DIALOG_RESULT" ]]; then + break + else + curdir="$curdir/$DIALOG_RESULT" + fi +done + +IMAGE_URL+=$(echo $curdir/*.raw.*) + +popd &>/dev/null + +cat << EOC > $outfile +$(echo "$IMAGE_URL") +EOC diff --git a/scripts/wifi b/scripts/wifi new file mode 100755 index 0000000..5c54acc --- /dev/null +++ b/scripts/wifi @@ -0,0 +1,202 @@ +#!/bin/bash + +# Helper script to activate/desactivate WLAN from command line + +# Usage : +# wifi connect <ssid> <passphrase> +# wifi disconnect <ssid> +# 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="" # <ssid><service> + +function error() { + echo ERROR: "$@" >&2 + cat << EOF >&2 +Usage: + $script connect <ssid> [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 -e "\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 <<EOF >"$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 + ;; + connected) + wifi_connected && exit 0 + exit 1 + ;; + *) + error "Command line doesn't have any option !" +esac diff --git a/scripts/wifi-util b/scripts/wifi-util new file mode 100755 index 0000000..1f20d20 --- /dev/null +++ b/scripts/wifi-util @@ -0,0 +1,42 @@ +#!/bin/bash + +# Offer a dialog interface for simple wifi connection +# Exit with value 2 if SIGINT is sent. + +data_out="/tmp/wifi-config.$$" +utilspath=/usr/lib/system-installer +wifi=$utilspath/wifi + +. $utilspath/dialog-helper + +ssid="" +passphrase="" + +trap "exit 2" SIGINT + +while [ 1 ]; do + $wifi scan > $data_out + ap=$(grep "wifi_" "$data_out" | sed "s/^\* /\t/" | sed "s/^\*R/\t/" | 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 access point'" 24 70 24 $ap + ssid="$DIALOGRES" + fi + + if [ -z "$passphrase" ]; then + dialog_helper --inputbox "Network's passphrase (leave empty if none)" 24 70 + passphrase="$DIALOGRES" + fi + + $wifi connect "$ssid" "$passphrase" | dialog --progressbox "Wifi connecting..." 40 100 + if [ ${PIPESTATUS[0]} -eq 0 ]; then + $DIALOG --msgbox "You are connected" 15 70 + exit 0 + else + ssid="" + passphrase="" + $DIALOG --yesno "Connection failed. Do you want to retry ? (This may take some time)" 24 70 && continue + exit 1 + fi +done diff --git a/systemd/system-installer.service b/systemd/system-installer.service new file mode 100644 index 0000000..60ea476 --- /dev/null +++ b/systemd/system-installer.service @@ -0,0 +1,12 @@ +[Unit] +Description=Installer +After=getty@tty2.service connman.service wpa_supplicant.service + +[Service] +Type=oneshot +ExecStart=/usr/sbin/system-installer +ExecStartPost=/usr/sbin/reboot +StandardInput=tty +TTYPath=/dev/tty2 +TTYReset=yes +TTYVHangup=yes |