Skip to content

Commit

Permalink
Rework root requirement
Browse files Browse the repository at this point in the history
Move from needing the GUI to be run as root, gparted style,
to only needing to run the apart-core as root using pkexec
removed apart-gtk-polkit, now done within app.py
reworked polkit policy, and named it a bit more standardly
fixed mockpcl flushing issues
updated build-dist & start-test-app
added apart-core integrity check
  • Loading branch information
alexheretic committed May 6, 2017
1 parent b98ff03 commit 7af1562
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 34 deletions.
4 changes: 2 additions & 2 deletions build-dist
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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


Expand Down
6 changes: 0 additions & 6 deletions misc/apart-gtk-polkit

This file was deleted.

2 changes: 1 addition & 1 deletion misc/apart.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
<action id="apart">
<action id="com.github.alexheretic.pkexec.apart-gtk">
<message>Authentication is required to run Apart</message>
<icon_name>apart-gtk</icon_name>
<defaults>
<allow_any>auth_admin</allow_any>
<allow_inactive>auth_admin</allow_inactive>
<allow_active>auth_admin</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/bin/apart-gtk</annotate>
<annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
<annotate key="org.freedesktop.policykit.exec.path">/usr/lib/apart-gtk/apart-core</annotate>
</action>
</policyconfig>
11 changes: 9 additions & 2 deletions src/apartcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 1 addition & 6 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


# App versions, "major.minor", major => new stuff, minor => fixes
__version__ = '0.2'
__version__ = '0.3'


class LoadingBody(Gtk.Grid):
Expand Down Expand Up @@ -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)

Expand Down
16 changes: 9 additions & 7 deletions start-test-app
Original file line number Diff line number Diff line change
@@ -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
10 changes: 3 additions & 7 deletions test/mockpcl
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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:
Expand Down
Binary file added v0.1.0.tar.gz
Binary file not shown.

0 comments on commit 7af1562

Please sign in to comment.