add option to use script without sudo

This commit is contained in:
Fufezan Mihai 2021-01-27 12:28:17 +02:00
parent 9d52d4882d
commit 872b1891fd
No known key found for this signature in database
GPG Key ID: 3AC82B48170331D3
1 changed files with 13 additions and 6 deletions

View File

@ -65,6 +65,7 @@ Restore='0' # (-r) Reverse: Restore from backup # instead of installing
DoBackup='ifnone' # (-n/b) Default backup behavior is "if no backups are found"
SubDirs='all' # (-m) Directory/-ies inside X11 to modify (e.g., 'xkb locale', 'all')
InstGTK='no' # (-g) Whether to install the GTK 2.0/3.0 config (if not present)
NoSudo='no' # (-s) Do not use sudo. Helpful for local dir installation.
SetXMap='no' # (-x) Whether to run the setxkb script after installing
SetXStr='5caw us us' # (--) Shortcut string for setxkb - 'kbd loc sym' (model layout eD-variant)
## NOTE: '# (-a)' means that the value can be set by option argument '-a <value>'
@ -85,6 +86,7 @@ HelpStr="\e[1mUsage: bash ${MyNAME} [optional args] [<kbd> [<loc> <sym>]]\e[0m\n
"[-t] <mod dir prefix tag> - ${DModTag}\n"\
"[-g] Install GTK 2.0/3.0 edit config? - ${InstGTK}\n"\
"[-x] Run the setxkbmap script? - ${SetXMap}\n"\
"[-s] Install without using sudo? - ${NoSudo}\n"\
"[--] [Setxkb ShortStr <kbd loc sym>] - ${SetXStr}\n"
#~ "( - <val> : Default settings)\n"
@ -138,16 +140,17 @@ MyError()
#~ }
#~ if [ "$#" == 0 ]; then PrintHelpAndExit 2; fi # No args
while getopts "obngxm:i:c:d:t:r:h?" cmdarg; do
while getopts "obngxsm:i:c:d:t:r:h?" cmdarg; do
case $cmdarg in
o) WriteSys='yes' ;;
b) DoBackup='yes' ;;
n) DoBackup='no' ;;
g) InstGTK='yes' ;;
x) SetXMap='yes' ;;
s) NoSudo='yes' ;;
m) SubDirs="$OPTARG" ;;
i) InstDir="$OPTARG" ;;
c) X11DIR="$OPTARG" ;;
c) X11DIR="$OPTARG" ;;
d) DModDir="$OPTARG" ;;
t) DModTag="$OPTARG" ;;
r) Restore="$OPTARG" ;;
@ -199,10 +202,14 @@ fi
## Check for root privileges (if not root, sudo command); note that root is only needed in some cases!
DoSudo=''
if [ "$EUID" -ne 0 ]; then # not root, so test for and use sudo instead (but some distros don't have it!)
#[ command -v sudo >/dev/null 2>&1 ] || MyError "Root access needed - sudo won't run!"
( command -v sudo >/dev/null 2>&1 ) || MyWarning "Root/superuser access may be needed!"
DoSudo='sudo'
if [ ${NoSudo} = 'yes' ]; then
MyPoint "Not using sudo."
else
if [ "$EUID" -ne 0 ]; then # not root, so test for and use sudo instead (but some distros don't have it!)
#[ command -v sudo >/dev/null 2>&1 ] || MyError "Root access needed - sudo won't run!"
( command -v sudo >/dev/null 2>&1 ) || MyWarning "Root/superuser access may be needed!"
DoSudo='sudo'
fi
fi
## Perform the actual backup(s)