dinosudo – alternativa CLI para executar aplicativos gráficos como root enquanto logado como

Publicado por Luís Fernando C. Cavalheiro (última atualização em 13/02/2018)

[ Hits: 3.404 ]

Homepage: https://github.com/lcavalheiro/

Download dinosudo.sh




Uma alternativa puramente de linha de comando ao gksudo e ao kdesudo, o dinosudo permite que o usuário execute aplicativos gráficos como root enquanto logado como usuário comum.

  



Esconder código-fonte

#!/bin/bash
#
# dinosudo: allows normal user run graphical applications as root
#
# Copyright (C) 2018 Luís Fernando Carvalho Cavalheiro (dino at gnulinux dot net dot br)
#
# This program 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 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
# 
# Version history
# — 0.1 (20180213)
# Script started.
#
# Set needed variables:
VERSION='0.1 (20180213)'
CURRENTUSER=$(whoami)
ROOTDISPLAY=$DISPLAY
#
# Check if user supplied any argument to script
if [ $# -eq 0 ] ; then
    echo "dinosudo requires an application to run as root!"
    exit 1
fi
#
# Check if user supplied more than one argument to script
if [ $# -gt 1 ] ; then
    echo "You cannot run more than one application per dinosudo evocation!"
    exit 1
fi
#
# Check if user supplied -h or --help option and if yes print help screen
if [ "$1" == "-h" -o "$1" == "--help" ] ; then
    cat << EOF

    dinosudo  Copyright (C) 2018  Luís Fernando Carvalho Cavalheiro
    This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type 'show c' for details.

    dinosudo: allows normal use run graphical applications as root
    Version: $VERSION

    Usage
    
    $ dinosudo [ARG | -h | --help]

    Where:
    — ARG must be an application that is installed on your computer. You
    can run one and only one application for dinosudo instance.
    — -h or --help show this help.

EOF
    exit 0
fi
#
# Check if command is installed on computer:
if ! [ -x "$(command -v $1)" ] ; then
    echo "You cannot run an application that isn't installed in your computer!" >&2
    exit 1
fi
#
# Running graphical application
su --login -c "HOME=/root ; DISPLAY=$ROOTDISPLAY ; cp /home/$CURRENTUSER/.Xauthority /root/ ; $1"

Scripts recomendados

Script para verficar se um pacote está instalado no Slackware

Script para enviar email, avisando quando alguem loga na maquina

Montar e desmontar ISOs do Debian e adicionar CD/DVDs ao repositório

Remoção da sessão convidado do Ubuntu 16.04

Paradise-Script


  

Comentários
[1] Comentário enviado por eldermarco em 15/02/2018 - 07:21h

Não é muito o caso aí, mas pode-se tratar os argumentos passados pelo usuário com o comando getopt. Para scripts que recebem bastante argumentos, acaba se tornando um comando indispensável.

[2] Comentário enviado por albfneto em 20/02/2018 - 13:00h

Isso é muito bom! Baixei e favoritado.
funcionará em Sabayon e OpenSUSE? Vou testar.
¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
Albfneto,
Ribeirão Preto, S.P., Brasil.
Usuário Linux, Linux Counter: #479903.
Distros Favoritas: [i] Sabayon, Gentoo, OpenSUSE, Mageia e OpenMandriva[/i].

[3] Comentário enviado por removido em 08/03/2018 - 19:53h

Problema:

# sudo thunar /var/cache/sbopkg/
# No protocol specified
# Thunar: Não foi possível abrir a tela:


Método 1

# sudo cp /home/SEU_USUARIO/.Xauthority /root/

DEPOIS NÃO PODE USAR => # rm -Rf /root/.* ou # rm -Rf /root/.Xauthority

# sudo thunar /var/cache/sbopkg/



Método 2

# rm -Rf /root/.Xauthority

echo "#!/bin/bash

/usr/bin/xhost +
" > /usr/local/bin/habilitar_xhost.sh

chmod +x /usr/local/bin/habilitar_xhost.sh


Usar no usuário comum:

echo "[Desktop Entry]
Encoding=UTF-8
Version=0.9.4
Type=Application
Name=habilitar_xhost
Comment= Permite que o usuário execute aplicativos gráficos como root enquanto logado como usuário comum.
Exec=/usr/local/bin/habilitar_xhost.sh
OnlyShowIn=XFCE;
StartupNotify=false
Terminal=false
Hidden=false
" > ~/.config/autostart/habilitar_xhost.desktop


# reboot

Método 3

$xhost +

# sudo thunar /var/cache/sbopkg/



Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts