2008-05-10 09:34:39 -06:00
|
|
|
#!/bin/sh
|
2013-05-27 13:44:49 -06:00
|
|
|
# Name: gparted
|
2008-05-10 09:34:39 -06:00
|
|
|
# Purpose: Perform appropriate startup of GParted executable gpartedbin.
|
|
|
|
#
|
2009-10-15 10:32:29 -06:00
|
|
|
# The purpose of these startup methods is to prevent
|
2013-06-11 13:09:18 -06:00
|
|
|
# devices from being automounted, and to ensure only one
|
|
|
|
# instance of GParted is running. File system problems can
|
|
|
|
# occur if devices are mounted prior to the completion of
|
|
|
|
# GParted's operations, or if multiple partition editing
|
|
|
|
# tools are in use concurrently.
|
2008-04-21 09:22:00 -06:00
|
|
|
#
|
2015-03-10 10:56:47 -06:00
|
|
|
# Copyright (C) 2008, 2009, 2010, 2013, 2015 Curtis Gedak
|
2013-05-27 13:44:49 -06:00
|
|
|
#
|
|
|
|
# This file is part of GParted.
|
|
|
|
#
|
|
|
|
# GParted is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# GParted 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.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with GParted. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
2009-10-15 10:32:29 -06:00
|
|
|
|
2013-06-11 13:09:18 -06:00
|
|
|
#
|
|
|
|
# Only permit one instance of GParted to execute at a time
|
|
|
|
#
|
Reliably detect running gpartedbin using pidof (!54)
Debian user reported a bug [1] that when they had PS_FORMAT environment
variable set it prevented GParted running:
# export PS_FORMAT='ruser,uid,pid,ppid,pri,ni,%cpu,%mem,vsz,rss,stat,tty,start,time,command'
# gparted
The process gpartedbin is already running.
Only one gpartedbin process is permitted.
# echo $?
1
Using ps column 'command' includes the command and all it's arguments,
rather than just the command name as ps displays by default. Thus the
shell wrapper finds the grep command it's using when searching for the
gpartedbin executable.
# ps -e | grep gpartedbin
root 0 26114 14777 19 0 0.0 0.0 112712 940 S+ pts/0 10:42:02 00:00:00 grep --color=auto gpartedbin
Fix by searching for running processes using pidof. pgrep does regular
expression matching where as pidof checks program name is the same [2].
Therefore use of pidof is preferred over pgrep [3].
[1] Debian bug #864932 - gparted fails if PS_FORMAT options are
specified
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=864932
[2] Difference between pidof and pgrep?
https://stackoverflow.com/questions/52151698/difference-between-pidof-and-pgrep
[3] [PATCH] gparted.in: Use reliable way of detecting gpartedbin process
existence
https://git.alpinelinux.org/aports/tree/community/gparted/gparted.in-Use-reliable-way-of-detecting-gpartedbin-.patch
Closes !54 - Fix gparted not launching when PS_FORMAT environment
variable set
2020-02-29 08:53:23 -07:00
|
|
|
if pidof gpartedbin 1> /dev/null; then
|
2013-06-11 13:09:18 -06:00
|
|
|
echo "The process gpartedbin is already running."
|
|
|
|
echo "Only one gpartedbin process is permitted."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-06-16 00:30:30 -06:00
|
|
|
#
|
|
|
|
# Define base command for executing GParted
|
|
|
|
#
|
2017-08-05 08:43:47 -06:00
|
|
|
BASE_CMD="@sbindir@/gpartedbin $*"
|
2017-06-16 00:30:30 -06:00
|
|
|
|
|
|
|
#
|
|
|
|
# For non-root users try to get authorisation to run GParted as root.
|
|
|
|
#
|
|
|
|
if test "x`id -u`" != "x0"; then
|
|
|
|
#
|
|
|
|
# If there is no configured SU program run gpartedbin as
|
|
|
|
# non-root to display the graphical error about needing root
|
|
|
|
# privileges.
|
|
|
|
#
|
|
|
|
if test "x@gksuprog@" = "x"; then
|
|
|
|
echo "Root privileges are required for running gparted."
|
|
|
|
$BASE_CMD
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-07-17 11:31:51 -06:00
|
|
|
#
|
|
|
|
# Interim workaround to allow GParted run by root access to the
|
|
|
|
# X11 display server under Wayland. If configured with
|
|
|
|
# './configure --enable-xhost-root', the xhost command is
|
|
|
|
# available and root has not been granted access to the X11
|
|
|
|
# display via xhost, then grant access.
|
|
|
|
#
|
|
|
|
ENABLE_XHOST_ROOT=@enable_xhost_root@
|
|
|
|
GRANTED_XHOST_ROOT=no
|
|
|
|
if test "x$ENABLE_XHOST_ROOT" = 'xyes' && xhost 1> /dev/null 2>&1; then
|
|
|
|
if ! xhost | grep -qi 'SI:localuser:root$'; then
|
|
|
|
xhost +SI:localuser:root
|
|
|
|
GRANTED_XHOST_ROOT=yes
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Run gparted as root.
|
|
|
|
#
|
2017-08-05 08:43:47 -06:00
|
|
|
@gksuprog@ '@bindir@/gparted' "$@"
|
2017-07-17 11:31:51 -06:00
|
|
|
status=$?
|
|
|
|
|
|
|
|
#
|
|
|
|
# Revoke root access to the X11 display, only if we granted it.
|
|
|
|
#
|
|
|
|
if test "x$GRANTED_XHOST_ROOT" = 'xyes'; then
|
|
|
|
xhost -SI:localuser:root
|
|
|
|
fi
|
|
|
|
exit $status
|
2017-06-16 00:30:30 -06:00
|
|
|
fi
|
|
|
|
|
2013-06-09 09:46:18 -06:00
|
|
|
#
|
|
|
|
# Search PATH to determine if systemctl program can be found
|
|
|
|
# and if appropriate daemon is running.
|
|
|
|
#
|
|
|
|
HAVE_SYSTEMCTL=no
|
|
|
|
for k in '' `echo "$PATH" | sed 's,:, ,g'`; do
|
|
|
|
if test -x "$k/systemctl"; then
|
Reliably detect running gpartedbin using pidof (!54)
Debian user reported a bug [1] that when they had PS_FORMAT environment
variable set it prevented GParted running:
# export PS_FORMAT='ruser,uid,pid,ppid,pri,ni,%cpu,%mem,vsz,rss,stat,tty,start,time,command'
# gparted
The process gpartedbin is already running.
Only one gpartedbin process is permitted.
# echo $?
1
Using ps column 'command' includes the command and all it's arguments,
rather than just the command name as ps displays by default. Thus the
shell wrapper finds the grep command it's using when searching for the
gpartedbin executable.
# ps -e | grep gpartedbin
root 0 26114 14777 19 0 0.0 0.0 112712 940 S+ pts/0 10:42:02 00:00:00 grep --color=auto gpartedbin
Fix by searching for running processes using pidof. pgrep does regular
expression matching where as pidof checks program name is the same [2].
Therefore use of pidof is preferred over pgrep [3].
[1] Debian bug #864932 - gparted fails if PS_FORMAT options are
specified
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=864932
[2] Difference between pidof and pgrep?
https://stackoverflow.com/questions/52151698/difference-between-pidof-and-pgrep
[3] [PATCH] gparted.in: Use reliable way of detecting gpartedbin process
existence
https://git.alpinelinux.org/aports/tree/community/gparted/gparted.in-Use-reliable-way-of-detecting-gpartedbin-.patch
Closes !54 - Fix gparted not launching when PS_FORMAT environment
variable set
2020-02-29 08:53:23 -07:00
|
|
|
if pidof systemd 1> /dev/null; then
|
2013-06-09 09:46:18 -06:00
|
|
|
HAVE_SYSTEMCTL=yes
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2015-03-10 10:56:47 -06:00
|
|
|
#
|
|
|
|
# Check if udisks2-inhibit exists in known location
|
|
|
|
# and if appropriate daemon is running.
|
|
|
|
#
|
|
|
|
HAVE_UDISKS2_INHIBIT=no
|
|
|
|
if test -x "/usr/lib/udisks2/udisks2-inhibit"; then
|
Reliably detect running gpartedbin using pidof (!54)
Debian user reported a bug [1] that when they had PS_FORMAT environment
variable set it prevented GParted running:
# export PS_FORMAT='ruser,uid,pid,ppid,pri,ni,%cpu,%mem,vsz,rss,stat,tty,start,time,command'
# gparted
The process gpartedbin is already running.
Only one gpartedbin process is permitted.
# echo $?
1
Using ps column 'command' includes the command and all it's arguments,
rather than just the command name as ps displays by default. Thus the
shell wrapper finds the grep command it's using when searching for the
gpartedbin executable.
# ps -e | grep gpartedbin
root 0 26114 14777 19 0 0.0 0.0 112712 940 S+ pts/0 10:42:02 00:00:00 grep --color=auto gpartedbin
Fix by searching for running processes using pidof. pgrep does regular
expression matching where as pidof checks program name is the same [2].
Therefore use of pidof is preferred over pgrep [3].
[1] Debian bug #864932 - gparted fails if PS_FORMAT options are
specified
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=864932
[2] Difference between pidof and pgrep?
https://stackoverflow.com/questions/52151698/difference-between-pidof-and-pgrep
[3] [PATCH] gparted.in: Use reliable way of detecting gpartedbin process
existence
https://git.alpinelinux.org/aports/tree/community/gparted/gparted.in-Use-reliable-way-of-detecting-gpartedbin-.patch
Closes !54 - Fix gparted not launching when PS_FORMAT environment
variable set
2020-02-29 08:53:23 -07:00
|
|
|
if pidof udisksd 1> /dev/null; then
|
2015-03-10 10:56:47 -06:00
|
|
|
HAVE_UDISKS2_INHIBIT=yes
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2010-06-01 17:04:39 -06:00
|
|
|
#
|
|
|
|
# Search PATH to determine if udisks program can be found
|
|
|
|
# and if appropriate daemon is running.
|
|
|
|
#
|
|
|
|
HAVE_UDISKS=no
|
|
|
|
for k in '' `echo "$PATH" | sed 's,:, ,g'`; do
|
|
|
|
if test -x "$k/udisks"; then
|
Reliably detect running gpartedbin using pidof (!54)
Debian user reported a bug [1] that when they had PS_FORMAT environment
variable set it prevented GParted running:
# export PS_FORMAT='ruser,uid,pid,ppid,pri,ni,%cpu,%mem,vsz,rss,stat,tty,start,time,command'
# gparted
The process gpartedbin is already running.
Only one gpartedbin process is permitted.
# echo $?
1
Using ps column 'command' includes the command and all it's arguments,
rather than just the command name as ps displays by default. Thus the
shell wrapper finds the grep command it's using when searching for the
gpartedbin executable.
# ps -e | grep gpartedbin
root 0 26114 14777 19 0 0.0 0.0 112712 940 S+ pts/0 10:42:02 00:00:00 grep --color=auto gpartedbin
Fix by searching for running processes using pidof. pgrep does regular
expression matching where as pidof checks program name is the same [2].
Therefore use of pidof is preferred over pgrep [3].
[1] Debian bug #864932 - gparted fails if PS_FORMAT options are
specified
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=864932
[2] Difference between pidof and pgrep?
https://stackoverflow.com/questions/52151698/difference-between-pidof-and-pgrep
[3] [PATCH] gparted.in: Use reliable way of detecting gpartedbin process
existence
https://git.alpinelinux.org/aports/tree/community/gparted/gparted.in-Use-reliable-way-of-detecting-gpartedbin-.patch
Closes !54 - Fix gparted not launching when PS_FORMAT environment
variable set
2020-02-29 08:53:23 -07:00
|
|
|
if pidof udisks-daemon 1> /dev/null; then
|
2010-06-01 17:04:39 -06:00
|
|
|
HAVE_UDISKS=yes
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2008-04-21 09:22:00 -06:00
|
|
|
#
|
2008-05-10 09:34:39 -06:00
|
|
|
# Search PATH to determine if hal-lock program can be found
|
2009-10-15 10:32:29 -06:00
|
|
|
# and if appropriate daemon is running.
|
2008-04-21 09:22:00 -06:00
|
|
|
#
|
2008-05-10 09:34:39 -06:00
|
|
|
HAVE_HAL_LOCK=no
|
|
|
|
for k in '' `echo "$PATH" | sed 's,:, ,g'`; do
|
|
|
|
if test -x "$k/hal-lock"; then
|
Reliably detect running gpartedbin using pidof (!54)
Debian user reported a bug [1] that when they had PS_FORMAT environment
variable set it prevented GParted running:
# export PS_FORMAT='ruser,uid,pid,ppid,pri,ni,%cpu,%mem,vsz,rss,stat,tty,start,time,command'
# gparted
The process gpartedbin is already running.
Only one gpartedbin process is permitted.
# echo $?
1
Using ps column 'command' includes the command and all it's arguments,
rather than just the command name as ps displays by default. Thus the
shell wrapper finds the grep command it's using when searching for the
gpartedbin executable.
# ps -e | grep gpartedbin
root 0 26114 14777 19 0 0.0 0.0 112712 940 S+ pts/0 10:42:02 00:00:00 grep --color=auto gpartedbin
Fix by searching for running processes using pidof. pgrep does regular
expression matching where as pidof checks program name is the same [2].
Therefore use of pidof is preferred over pgrep [3].
[1] Debian bug #864932 - gparted fails if PS_FORMAT options are
specified
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=864932
[2] Difference between pidof and pgrep?
https://stackoverflow.com/questions/52151698/difference-between-pidof-and-pgrep
[3] [PATCH] gparted.in: Use reliable way of detecting gpartedbin process
existence
https://git.alpinelinux.org/aports/tree/community/gparted/gparted.in-Use-reliable-way-of-detecting-gpartedbin-.patch
Closes !54 - Fix gparted not launching when PS_FORMAT environment
variable set
2020-02-29 08:53:23 -07:00
|
|
|
if pidof hald 1> /dev/null; then
|
2008-07-27 09:31:34 -06:00
|
|
|
HAVE_HAL_LOCK=yes
|
|
|
|
break
|
|
|
|
fi
|
2008-05-10 09:34:39 -06:00
|
|
|
fi
|
|
|
|
done
|
2008-04-21 09:22:00 -06:00
|
|
|
|
2013-06-09 09:46:18 -06:00
|
|
|
#
|
|
|
|
# Use systemctl to prevent automount by masking currently unmasked mount points
|
|
|
|
#
|
|
|
|
if test "x$HAVE_SYSTEMCTL" = "xyes"; then
|
2013-10-05 11:17:56 -06:00
|
|
|
MOUNTLIST=`systemctl list-units --full --all -t mount --no-legend \
|
|
|
|
| grep -v masked | cut -f1 -d' ' \
|
|
|
|
| egrep -v '^(dev-hugepages|dev-mqueue|proc-sys-fs-binfmt_misc|run-user-.*-gvfs|sys-fs-fuse-connections|sys-kernel-config|sys-kernel-debug)'`
|
2013-06-09 09:46:18 -06:00
|
|
|
systemctl --runtime mask --quiet -- $MOUNTLIST
|
|
|
|
fi
|
|
|
|
|
2013-10-11 08:22:45 -06:00
|
|
|
#
|
|
|
|
# Create temporary blank overrides for all udev rules which automatically
|
|
|
|
# start Linux Software RAID array members.
|
|
|
|
#
|
|
|
|
# Udev stores volatile / temporary runtime rules in directory /run/udev/rules.d.
|
|
|
|
# Older versions use /dev/.udev/rules.d instead, and even older versions don't
|
|
|
|
# have such a directory at all. Volatile / temporary rules are use to override
|
|
|
|
# default rules from /lib/udev/rules.d. (Permanent local administrative rules
|
|
|
|
# in directory /etc/udev/rules.d override all others). See udev(7) manual page
|
|
|
|
# from various versions of udev for details.
|
|
|
|
#
|
|
|
|
# Default udev rules containing mdadm to incrementally start array members are
|
|
|
|
# found in 64-md-raid.rules and/or 65-md-incremental.rules, depending on the
|
|
|
|
# distribution and age. The rules may be commented out or not exist at all.
|
|
|
|
#
|
|
|
|
UDEV_TEMP_MDADM_RULES='' # List of temporary override rules files.
|
|
|
|
for udev_temp_d in /run/udev /dev/.udev; do
|
|
|
|
if test -d "$udev_temp_d"; then
|
|
|
|
test ! -d "$udev_temp_d/rules.d" && mkdir "$udev_temp_d/rules.d"
|
|
|
|
udev_mdadm_rules=`egrep -l '^[^#].*mdadm (-I|--incremental)' /lib/udev/rules.d/*.rules 2> /dev/null`
|
|
|
|
UDEV_TEMP_MDADM_RULES=`echo "$udev_mdadm_rules" | sed 's,^/lib/udev,'"$udev_temp_d"','`
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
for rule in $UDEV_TEMP_MDADM_RULES; do
|
|
|
|
touch "$rule"
|
|
|
|
done
|
|
|
|
|
2008-05-10 09:34:39 -06:00
|
|
|
#
|
2015-03-10 10:56:47 -06:00
|
|
|
# Use udisks2-inhibit if udisks2-inhibit exists and deamon running.
|
|
|
|
# Else use both udisks and hal-lock for invocation if both binaries exist and both
|
2010-07-21 10:37:58 -06:00
|
|
|
# daemons are running.
|
2010-07-21 10:32:06 -06:00
|
|
|
# Else use udisks if binary exists and daemon is running.
|
2009-10-15 10:32:29 -06:00
|
|
|
# Otherwise use hal-lock for invocation if binary exists and daemon is running.
|
|
|
|
# If the above checks fail then simply run gpartedbin.
|
2008-05-10 09:34:39 -06:00
|
|
|
#
|
2015-03-10 10:56:47 -06:00
|
|
|
if test "x$HAVE_UDISKS2_INHIBIT" = "xyes"; then
|
|
|
|
/usr/lib/udisks2/udisks2-inhibit $BASE_CMD
|
|
|
|
elif test "x$HAVE_UDISKS" = "xyes" && test "x$HAVE_HAL_LOCK" = "xyes"; then
|
2010-07-21 10:32:06 -06:00
|
|
|
udisks --inhibit -- \
|
|
|
|
hal-lock --interface org.freedesktop.Hal.Device.Storage --exclusive \
|
|
|
|
--run "$BASE_CMD"
|
|
|
|
elif test "x$HAVE_UDISKS" = "xyes"; then
|
2010-06-01 17:04:39 -06:00
|
|
|
udisks --inhibit -- $BASE_CMD
|
2009-10-15 10:32:29 -06:00
|
|
|
elif test "x$HAVE_HAL_LOCK" = "xyes"; then
|
2009-02-11 15:08:30 -07:00
|
|
|
hal-lock --interface org.freedesktop.Hal.Device.Storage --exclusive \
|
2009-10-16 10:49:31 -06:00
|
|
|
--run "$BASE_CMD"
|
2008-05-10 09:34:39 -06:00
|
|
|
else
|
2009-10-16 10:49:31 -06:00
|
|
|
$BASE_CMD
|
2008-05-10 09:34:39 -06:00
|
|
|
fi
|
2013-06-09 09:46:18 -06:00
|
|
|
|
2013-10-11 08:22:45 -06:00
|
|
|
#
|
|
|
|
# Clear any temporary override udev rules used to stop udev automatically
|
|
|
|
# starting Linux Software RAID array members.
|
|
|
|
#
|
|
|
|
for rule in $UDEV_TEMP_MDADM_RULES; do
|
|
|
|
rm -f "$rule"
|
|
|
|
done
|
|
|
|
|
2013-06-09 09:46:18 -06:00
|
|
|
#
|
|
|
|
# Use systemctl to restore that status of any mount points changed above
|
|
|
|
#
|
|
|
|
if test "x$HAVE_SYSTEMCTL" = "xyes"; then
|
|
|
|
systemctl --runtime unmask --quiet -- $MOUNTLIST
|
|
|
|
fi
|