From 3dca414f8c53698a0170ec9c2e2f0709cad5ff4f Mon Sep 17 00:00:00 2001 From: Filippo Bedendo Bordon Date: Sat, 7 Jan 2012 20:52:28 +0100 Subject: [PATCH] Add usbinstall.sh in sudoers --- Makefile | 6 ++++-- src/usbinstall-sudoers | 11 +++++++++++ src/usbinstall.py | 5 +++-- src/usbinstall.sh | 13 ++++++++----- 4 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 src/usbinstall-sudoers mode change 100644 => 100755 src/usbinstall.py diff --git a/Makefile b/Makefile index 38d33db..37a1e71 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ dist_archive := $(distdir).tar.bz2 # Directory bindir := /usr/bin +sysconfdir := /etc datadir := /usr/share mambadir := /usr/share/openmamba localesdir := ${datadir}/locale @@ -46,16 +47,17 @@ install-dirs: @$(INSTALL_DIR) $(DESTDIR)$(bindir) @$(INSTALL_DIR) $(DESTDIR)$(mambadir)/usbinstall @$(INSTALL_DIR) $(DESTDIR)$(mambadir)/usbinstall/img + @$(INSTALL_DIR) $(DESTDIR)$(sysconfdir)/sudoers.d/ install: install-dirs install-locales $(INSTALL_PROGRAM) src/usbinstall.py $(DESTDIR)$(mambadir)/usbinstall/usbinstall.py - $(INSTALL_SCRIPT) src/usbinstall.sh $(DESTDIR)$(mambadir)/usbinstall/usbinstall.sh + $(INSTALL_SCRIPT) src/usbinstall.sh $(DESTDIR)$(bindir)/usbinstall.sh $(INSTALL_DATA) src/fdisk_template $(DESTDIR)$(mambadir)/usbinstall/fdisk_template $(INSTALL_DATA) src/img/*.png $(DESTDIR)$(mambadir)/usbinstall/img/ + ${INSTALL} -m 440 src/usbinstall-sudoers $(DESTDIR)$(sysconfdir)/sudoers.d/usbinstall # Crea un link in /usr/bin agli eseguibili in $(mambadir)/usbinstall ln -s $(mambadir)/usbinstall/usbinstall.py $(DESTDIR)$(bindir)/usbinstall.py - ln -s $(mambadir)/usbinstall/usbinstall.sh $(DESTDIR)$(bindir)/usbinstall.sh clean: diff --git a/src/usbinstall-sudoers b/src/usbinstall-sudoers new file mode 100644 index 0000000..4c7477a --- /dev/null +++ b/src/usbinstall-sudoers @@ -0,0 +1,11 @@ +# usbinstall sudoers.d file. +# +# This file MUST be edited with the 'visudo' command as root. +# +# See the sudoers man page for the details on how to write a sudoers file. +# + +# Cmnd alias specification +Cmnd_Alias USBINSTALL = /usr/bin/usbinstall.sh + +%sysadmin ALL = NOPASSWD: USBINSTALL diff --git a/src/usbinstall.py b/src/usbinstall.py old mode 100644 new mode 100755 index b1787db..5c3306c --- a/src/usbinstall.py +++ b/src/usbinstall.py @@ -1,5 +1,5 @@ +#!/usr/bin/python # -*- coding: utf-8 -*- -#!/usr/bin/env python # Copyright 2011 michiamophil (openmamba user :-) # ChangeLog: @@ -368,7 +368,8 @@ def step4(): # Show the progressBar window.p_install.show() dbus_start() - process_sh = Popen(["/usr/bin/usbinstall.sh", "start", path_dev, path_cpio, path_iso]) + # NON FUNZIONA... + process_sh = Popen(["sudo", "/usr/bin/usbinstall.sh", path_dev, path_cpio, path_iso], env={"DBUS_USBINSTALL": "1"}) # Show a list of object (step 1 and 2) diff --git a/src/usbinstall.sh b/src/usbinstall.sh index efe7a92..8e5446b 100755 --- a/src/usbinstall.sh +++ b/src/usbinstall.sh @@ -53,18 +53,22 @@ org.freedesktop.DBus.Properties.Get string:$3 string:$4` return 0 } -# Set progressbar +# Set progressbar (only if $DBUS_USBINSTALL = 1) # Arg 1: value% set_pbar() { - dbus-send --print-reply --session --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Set_progressBar int32:$1 + if [ $DBUS_USBINSTALL == 1 ]; then + dbus-send --print-reply --session --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Set_progressBar int32:$1 + fi } # Set status label # Arg 1: string set_status() { - dbus-send --print-reply --session --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Set_description "string:$1" + if [ $DBUS_USBINSTALL == 1 ]; then + dbus-send --print-reply --session --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Set_description "string:$1" + fi } ####################################(DBUS)########################################### @@ -78,7 +82,6 @@ export SELECT_USB=$1 export SELECT_BOOT=$2 export SELECT_ISO=$3 - set_status "Smonto la chiavetta" LANG=C udisks --unmount ${SELECT_USB}1 | grep failed && { echo "Error: fail to umount the usb key (${SELECT_USB}1)" @@ -118,11 +121,11 @@ set_status "Copia del file iso di openmamba in corso..." ORIG_SIZE=`stat -c %s $SELECT_ISO` cp $SELECT_ISO ./ & DEST_SIZE=0 -sleep 2 while [ $ORIG_SIZE -gt $DEST_SIZE ]; do DEST_SIZE=$(stat -c %s ./"`basename $SELECT_ISO`") percentuale=$((45 + ( 50 * $DEST_SIZE ) / $ORIG_SIZE )) set_pbar $percentuale + sleep 2 done ln -fs `basename $SELECT_ISO` ./openmamba-live.iso popd