source: src-sh/pc-extractoverlay/ports-overlay/usr/local/bin/gsmartcontrol-root @ 1620346

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2
Last change on this file since 1620346 was 1620346, checked in by Kris Moore <kris@…>, 15 months ago

Initial import of PC-BSD /current/ SVN repo

  • Property mode set to 100755
File size: 4.4 KB
Line 
1#!/usr/bin/env bash
2############################################################################
3# Copyright:
4#      (C) 2008 - 2012  Alexander Shaduri <ashaduri 'at' gmail.com>
5# License: See LICENSE_zlib.txt file
6############################################################################
7
8# Run gsmartcontrol with root, asking for root password first.
9# export GSMARTCONTROL_SU to override a su command (e.g. "kdesu -c").
10
11EXEC_BIN="/usr/local/bin/gsmartcontrol";
12prog_name="gsmartcontrol"
13
14
15# Preserve quotes in arguments
16final_args_quoted="";
17for i in "$@";do
18    final_args_quoted="$final_args_quoted \"${i//\"/\\\"}\"";
19done;
20
21
22DESKTOP="auto";
23
24# Compatibility with old syntax:
25# gsmartcontrol-root [<desktop> [program_options]]
26if [ "$1" == "auto" ] || [ "$1" == "kde" ] || [ "$1" == "gnome" ] || [ "$1" == "other" ]; then
27        DESKTOP="$1";
28        shift# remove $1
29else
30        # New syntax:
31        # gsmartcontrol-root [--desktop=<auto|kde|gnome|other>] [program_options]
32
33        for arg in $*; do
34                case $arg in
35                        --desktop=*)
36                                DESKTOP="${arg#*=}";
37                                final_args_quoted="${final_args_quoted/\"$arg\"/}";
38                                ;;
39                        *)
40                                # unknown option
41                                ;;
42                esac
43        done
44fi
45
46if [ "$DESKTOP" != "auto" ] && [ "$DESKTOP" != "kde" ] && \
47                [ "$DESKTOP" != "gnome" ] && [ "$DESKTOP" != "other" ]; then
48        echo "Usage: $0 [--desktop=<auto|kde|gnome|other>] [<${prog_name}_options>]";
49        exit 1;
50fi
51
52
53# Auto-detect current desktop if auto was specified.
54if [ "$DESKTOP" = "auto" ]; then
55        # KDE_SESSION_UID is present on kde3 and kde4.
56        # Note that it may be empty (but still set)
57        if [ "${KDE_SESSION_UID+set}" = "set" ]; then
58                DESKTOP="kde";
59        # same with gnome
60        elif [ "${GNOME_DESKTOP_SESSION_ID+set}" = "set" ]; then
61                DESKTOP="gnome";
62        else
63                DESKTOP="other";
64        fi
65fi
66
67# echo $DESKTOP;
68
69
70
71
72
73# They're basically the same, only the order is different.
74# sux requires xterm to ask for the password.
75# xdg-su is basically like this script, except worse :)
76# su-to-root is a debian/ubuntu official method (although gksu is available).
77gnome_sus="pc-su qsu su-to-root gnomesu gksu kdesu beesu xdg-su sux";
78kde_sus="pc-su qsu su-to-root kdesu gnomesu gksu beesu xdg-su sux";
79other_sus="$gnome_sus";
80
81
82candidates="";
83found_su=""
84
85if [ "$DESKTOP" = "gnome" ]; then
86        candidates="$gnome_sus";
87elif [ "$DESKTOP" = "kde" ]; then
88        candidates="$kde_sus";
89elif [ "$DESKTOP" = "other" ]; then
90        candidates="$other_sus";
91fi
92
93if [ "$GSMARTCONTROL_SU" = "" ]; then
94        for subin in $candidates; do
95                which $subin >/dev/null
96                if [ $? -eq 0 ]; then
97                        found_su="$subin";
98                        break;
99                fi
100        done
101
102        if [ "$found_su" = "" ]; then
103                xmessage "Error launching ${prog_name}: No suitable su mechanism found.
104Try installing kdesu, gnomesu, gksu, beesu or sux first.";
105                exit 1;
106        fi
107fi
108
109
110# gnomesu and gksu (but not kdesu, not sure about others) fail to adopt
111# root's PATH. Since the user's PATH may not contain /usr/sbin (with smartctl)
112# on some distributions (e.g. mandriva), add it manually. We also add
113# /usr/local/sbin, since that's the default location of custom-compiled smartctl.
114# Add these directories _before_ existing PATH, so that the user is not
115# tricked into running it from some other path (we're running as root with
116# the user's env after all).
117# Add /usr/local/sbin as well (freebsd seems to require it).
118# Note that beesu won't show a GUI login box if /usr/sbin is before /usr/bin,
119# so add it first as well.
120EXTRA_PATHS="/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/sbin";
121export PATH="$EXTRA_PATHS:$PATH"
122
123
124# echo $found_su;
125
126# Examples:
127# gnomesu -c 'gsmartcontrol --no-scan'
128# kdesu -c 'gsmartcontrol --no-scan'
129# beesu -P 'gsmartcontrol --no-scan'
130# su-to-root -X -c 'gsmartcontrol --no-scan'
131# xterm -e sux -c 'gsmartcontrol --no-scan'  # sux asks for password in a terminal
132
133
134full_cmd="";
135
136if [ "$GSMARTCONTROL_SU" != "" ]; then
137        full_cmd="$GSMARTCONTROL_SU '$EXEC_BIN $final_args_quoted'";
138
139elif [ "$found_su" = "sux" ]; then
140        full_cmd="xterm -e sux -c '$EXEC_BIN $final_args_quoted'";
141
142elif [ "$found_su" = "gksu" ]; then
143        full_cmd="$found_su '$EXEC_BIN $final_args_quoted'";
144
145elif [ "$found_su" = "beesu" ]; then
146        full_cmd="$found_su -P '$EXEC_BIN $final_args_quoted'";
147
148elif [ "$found_su" = "su-to-root" ]; then
149        full_cmd="$found_su -X -c '$EXEC_BIN $final_args_quoted'";
150
151elif [ "$found_su" = "pc-su" ]; then
152        full_cmd="$found_su '$EXEC_BIN $final_args_quoted'";
153
154elif [ "$found_su" = "qsu" ]; then
155        full_cmd="$found_su '$EXEC_BIN $final_args_quoted'";
156
157else  # gnomesu, kdesu, xdg-su
158        full_cmd="$found_su -c '$EXEC_BIN $final_args_quoted'";
159fi
160
161
162# echo $full_cmd
163eval $full_cmd
164
165
166
167
Note: See TracBrowser for help on using the repository browser.