diff --git a/build-dist b/build-dist index 4bde3c6..394bfd0 100755 --- a/build-dist +++ b/build-dist @@ -15,6 +15,7 @@ if [[ $(rustup toolchain list | grep -c stable) -eq 0 ]]; then fi cd $DIR/target curl -o core.tar.gz -L https://github.com/alexheretic/apart-core/archive/v$APART_CORE_VERSION.tar.gz +echo '82fa2c04808c3f5e2caf1cf22b20797ba2d9510e2fa3f96cfabfdc0e3fee9f83 core.tar.gz' | sha256sum -c tar xf core.tar.gz (cd apart-core-$APART_CORE_VERSION && rustup run stable cargo build --release) cp apart-core-$APART_CORE_VERSION/target/release/apart-core lib/apart-gtk/ @@ -54,9 +55,8 @@ cp $DIR/icon/apart.svg share/icons/hicolor/scalable/apps/ mkdir -p share/icons/hicolor/48x48/apps/ cp $DIR/icon/apart.png share/icons/hicolor/48x48/apps/ mkdir -p share/polkit-1/actions -cp $DIR/misc/apart.policy share/polkit-1/actions/ +cp $DIR/misc/*.policy share/polkit-1/actions/ mkdir -p bin -cp $DIR/misc/apart-gtk-polkit bin/ ln -s ../lib/apart-gtk/src/app.py bin/apart-gtk diff --git a/misc/apart-gtk-polkit b/misc/apart-gtk-polkit deleted file mode 100755 index 40e6aa3..0000000 --- a/misc/apart-gtk-polkit +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -if [ $(which pkexec) ]; then - pkexec --disable-internal-agent "/usr/bin/apart-gtk" "$@" -else - /usr/bin/apart-gtk "$@" -fi diff --git a/misc/apart.desktop b/misc/apart.desktop index 9b678a8..3786468 100644 --- a/misc/apart.desktop +++ b/misc/apart.desktop @@ -3,7 +3,7 @@ Name=Apart GenericName=Partition Clone, Backup And Restore X-GNOME-FullName=Apart Partition Clone, Backup And Restore Comment=Backup/Clone partition and restore from saved images -Exec=/usr/bin/apart-gtk-polkit %f +Exec=/usr/bin/apart-gtk %f Icon=apart Terminal=false Type=Application diff --git a/misc/apart.policy b/misc/com.github.alexheretic.pkexec.apart-gtk.policy similarity index 73% rename from misc/apart.policy rename to misc/com.github.alexheretic.pkexec.apart-gtk.policy index 0aeb628..ecf91c9 100644 --- a/misc/apart.policy +++ b/misc/com.github.alexheretic.pkexec.apart-gtk.policy @@ -3,7 +3,7 @@ "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN" "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd"> - + Authentication is required to run Apart apart-gtk @@ -11,7 +11,6 @@ auth_admin auth_admin - /usr/bin/apart-gtk - true + /usr/lib/apart-gtk/apart-core diff --git a/src/apartcore.py b/src/apartcore.py index e44be9a..b539b30 100644 --- a/src/apartcore.py +++ b/src/apartcore.py @@ -56,10 +56,17 @@ def __init__(self, listeners: List[MessageListener] = None): # Current default is apart-core binary stored in the directory above these sources apart_core_cmd = os.environ.get('APART_GTK_CORE_CMD') or \ os.path.dirname(os.path.realpath(__file__)) + '/../apart-core' + try: - self.process = subprocess.Popen([apart_core_cmd, self.ipc_address]) + if os.geteuid() == 0: + self.process = subprocess.Popen([apart_core_cmd, self.ipc_address]) + else: + self.process = subprocess.Popen(['pkexec', apart_core_cmd, self.ipc_address]) except FileNotFoundError: - sys.stderr.write('apart-core command not found at \'' + apart_core_cmd + '\'') + if os.geteuid() == 0: + print('apart-core command not found at \'' + apart_core_cmd + '\'', file=sys.stderr) + else: + print('pkexec command not found, install polkit or run as root', file=sys.stderr) self.zmq_context.destroy() sys.exit(1) diff --git a/src/app.py b/src/app.py index 5186557..12a2643 100755 --- a/src/app.py +++ b/src/app.py @@ -12,7 +12,7 @@ # App versions, "major.minor", major => new stuff, minor => fixes -__version__ = '0.2' +__version__ = '0.3' class LoadingBody(Gtk.Grid): @@ -63,11 +63,6 @@ def on_delete(self, arg1=None, arg2=None): def main(): - if os.getuid() != 0 and os.environ.get('APART_GTK_NON_ROOT') != 'Y': - # Normally it only makes sense to run apart->partclone as root - # Use APART_GTK_NON_ROOT=Y if otherwise - print('Root privileges are required to clone & restore partitions', file=sys.stderr) - sys.exit(1) win = Window() win.connect("delete-event", Gtk.main_quit) diff --git a/start-test-app b/start-test-app index 00fcfa7..05ab0cf 100755 --- a/start-test-app +++ b/start-test-app @@ -1,13 +1,15 @@ #!/usr/bin/env bash -if [ ! -f apart-core/target/debug/apart-core ]; then - (cd apart-core && cargo build) +set -eu +dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +if [ ! -f $dir/apart-core/target/debug/apart-core ]; then + (cd $dir/apart-core && cargo build) fi RUST_BACKTRACE=1 \ - APART_GTK_NON_ROOT=Y \ - APART_PARTCLONE_CMD=/home/alex/project/apart-gtk/test/mockpcl \ - APART_GTK_CORE_CMD=apart-core/target/debug/apart-core \ + APART_PARTCLONE_CMD=$dir/test/mockpcl \ + APART_GTK_CORE_CMD=$dir/apart-core/target/debug/apart-core \ RUST_LOG=info \ - APART_LSBLK_CMD=/home/alex/project/apart-gtk/test/mocklsblk \ - ./src/app.py + APART_LSBLK_CMD=$dir/test/mocklsblk \ + $dir/src/app.py diff --git a/test/mockpcl b/test/mockpcl index 8c960d9..2eeef8c 100755 --- a/test/mockpcl +++ b/test/mockpcl @@ -26,7 +26,7 @@ print('File system: raw', file=sys.stderr) print('Device size: 32.2 GB = 62914560 Blocks', file=sys.stderr) print('Space in use: 32.2 GB = 62914560 Blocks', file=sys.stderr) print('Free Space: 0 Byte = 0 Blocks', file=sys.stderr) -print('Block size: 512 Byte', file=sys.stderr) +print('Block size: 512 Byte', file=sys.stderr, flush=True) def print_progress(remaining: timedelta, complete: float, rate: str): @@ -35,11 +35,7 @@ def print_progress(remaining: timedelta, complete: float, rate: str): rate=rate), file=sys.stderr) print(r'current block: 3878912, total block: 62914560, Complete: {complete:.2f}'.format(complete=complete), - file=sys.stderr) - -# def print_move_term_up2(): -# print(r'\033[2A', file=sys.stderr, end='') - + file=sys.stderr, flush=True) for loop in range(loops): remaining_secs = loops - loop - 1 @@ -52,7 +48,7 @@ for loop in range(loops): sleep(1) print('Total Time: 00:00:58, Ave. Rate: 33.3GB/min, 100.00% completed!', file=sys.stderr) -print('Syncing... ', file=sys.stderr, end='') +print('Syncing... ', file=sys.stderr, end='', flush=True) if args.o: sleep(2) # simulate restore syncing time else: diff --git a/v0.1.0.tar.gz b/v0.1.0.tar.gz new file mode 100644 index 0000000..47f4b38 Binary files /dev/null and b/v0.1.0.tar.gz differ