mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-23 19:26:33 +00:00
Provide a GUI elevation dialog for GNU/Linux (#440)
Fixes: https://github.com/resin-io/etcher/issues/439 Fixes: https://github.com/resin-io/etcher/issues/412 Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
parent
e9164df384
commit
bedda41843
@ -1,6 +1,6 @@
|
||||
[Desktop Entry]
|
||||
Name=Etcher
|
||||
Exec=etcher.wrapper
|
||||
Exec=elevate.wrapper
|
||||
Comment=Burn images to SD cards & USB drives, safe & easy
|
||||
Icon=icon
|
||||
Type=Application
|
||||
|
@ -134,7 +134,8 @@ function app_dir_create {
|
||||
cp ./Etcher.desktop $output_directory
|
||||
cp ./assets/icon.png $output_directory
|
||||
cp -rf $source_directory/* $output_directory/usr/bin
|
||||
cp ./scripts/desktopintegration $output_directory/usr/bin/etcher.wrapper
|
||||
cp ./scripts/desktopintegration $output_directory/usr/bin/elevate.wrapper
|
||||
cp ./scripts/elevate-linux.sh $output_directory/usr/bin/elevate
|
||||
}
|
||||
|
||||
function installer {
|
||||
|
74
scripts/elevate-linux.sh
Executable file
74
scripts/elevate-linux.sh
Executable file
@ -0,0 +1,74 @@
|
||||
#!/bin/bash
|
||||
|
||||
###
|
||||
# Copyright 2016 Resin.io
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
###
|
||||
|
||||
set -e
|
||||
|
||||
binary=usr/bin/etcher
|
||||
|
||||
error() {
|
||||
if [ -x /usr/bin/zenity ] ; then
|
||||
LD_LIBRARY_PATH="" zenity --error --text "${1}" 2>/dev/null
|
||||
elif [ -x /usr/bin/kdialog ] ; then
|
||||
LD_LIBRARY_PATH="" kdialog --msgbox "${1}" 2>/dev/null
|
||||
elif [ -x /usr/bin/Xdialog ] ; then
|
||||
LD_LIBRARY_PATH="" Xdialog --msgbox "${1}" 2>/dev/null
|
||||
else
|
||||
echo "${1}"
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check if we're running as root
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
./$binary
|
||||
else
|
||||
|
||||
# Determine a unique mountpoint based on the current mount point.
|
||||
mountpoint=$(mount | grep $(basename $APPIMAGE) | awk '{ print $3 }')-elevated
|
||||
|
||||
# We remount the AppImage to be able to workaround FUSE a
|
||||
# security measure of not allowing root to run binaries
|
||||
# from FUSE mounted filesystems.
|
||||
#
|
||||
# - The `ro` option is required, since otherwise `mount` will
|
||||
# refuse to mount the same AppImage in two different locations.
|
||||
#
|
||||
# - We don't want to go through the desktop integration helper
|
||||
# again, so we call the `etcher` binary directly.
|
||||
#
|
||||
# - We need to wait for a little bit for `umount` to be
|
||||
# successfull, otherwise it complains with an `EBUSY` error.
|
||||
runcommand="mkdir -p $mountpoint && mount -o loop -o ro $APPIMAGE $mountpoint && $mountpoint/$binary; sleep 1; umount $mountpoint"
|
||||
|
||||
# We prefer gksudo since it gives a nicer looking dialog
|
||||
if command -v gksudo 2>/dev/null; then
|
||||
gksudo --preserve-env --description "Etcher" -- sh -c "$runcommand"
|
||||
elif command -v kdesudo 2>/dev/null; then
|
||||
kdesudo -d --comment "Etcher" -- sh -c "$runcommand"
|
||||
elif command -v pkexec 2>/dev/null; then
|
||||
|
||||
# We need to inherit DISPLAY and XAUTHORITY, otherwise
|
||||
# pkexec will not know how to run X11 applications.
|
||||
# See http://askubuntu.com/a/332847
|
||||
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY sh -c "$runcommand"
|
||||
|
||||
else
|
||||
error "Please install gksudo, kdesudo, or pkexec to run this application."
|
||||
fi
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user