소개
스크립트 노호의 사용은-인터럽트 구동 DBUS에서 특정 메시지 폴링을, 그리고 그것을 종료 / 재부팅에 대한 요청을 볼 때마다, 그것은 패키지 관리자 여부 등 시험 할 것이다 dpkg
또는 apt
실행 중입니다. 이들이 실행 중이면 종료 요청이 취소됩니다.
설정
친구가 명령 줄을 건드리고 싶지 않다고 언급 했으므로 그의 컴퓨터에 ssh하거나 수동으로 설치해야합니다.
수동 설정
mkdir $HOME/bin
- 스크립트 소스를 복사하여 이름이 지정된 파일로 저장하십시오.
preventShutdown.sh
- 스크립트는 실행 가능해야합니다. 사용
chmod +x $HOME/bin/preventShutdown.sh
그렇게하기
- Startup Applications 앱을 사용하거나
.desktop
파일을 수동으로 배치하여 Unity / Gnome에 로그인 할 때 실행할 루틴 목록에 스크립트를 추가합니다.$HOME/.config/autostart
대체 설정
sudo apt-get install git
cd /opt
sudo git clone https://github.com/SergKolo/sergrep.git
sudo chmod +x /opt/sergrep/*
스크립트를 시작 응용 프로그램으로 추가하십시오.
스크립트 소스
#! /bin/bash
##########################
# AUTHOR: Serg Kolo
# Date: Saturday, December 26th, 2015
# Description: Script to notify user and prevent
# shutdown or reboot
# if any update or package manager
# are running.
# TESTED ON: 14.04.3 LTS, Trusty Tahr
# WRITTEN FOR: http://askubuntu.com/q/702156/295286
# VERSION: 2, removed xdotool, using dbus method
# changed to C-style of organizing code
#########################
# Copyright (c) 2015 Serg Kolo
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Uncomment the line bellow if needed for debugging
# set -x
###########################
# VARIABLES
###########################
DISPLAY=:0 # has to be set since we are using notify-send
###########################
# MAIN
###########################
#
# Basic idea : This runs dbus-monitor which waits for
# "RebootRequested" memberf from com.canonical.Unity.Session ,
# which apprears only when the user clicks the shutdown option
# from the Unity's top right drop down box. Why RebootRequested ?
# Because this message is guaranteed to pop up once user presses
# the shutdown button.
# The while loop with read command does the big job.
# dbus-monitor sends initial message , so we want to filter only
# The output that contains the string we need, hence the case...esac
# structure employed here. Once we get the proper message.
# we check whether update-manager or package managers are running
# If there is one instance, then call CancelAction method
# and send notification to the user.
# Both dbus-monitor and while loop run continuously. This
# can be launcher as script in `/etc/rc.local` or `/etc/rc2.d`
# or preferably (!) in `/etc/xdg/autostart/` .
# Here is sample /etc/xdg/autostart/preventShutdown.desktop file
#
# [Desktop Entry]
# Type=Application
# Name=Prevent-Update
# Exec=/home/$USER/bin/preventShutdown.sh
# OnlyShowIn=GNOME;Unity;
# Terminal=false
#
# Remember to make this file as well as script be root-owned with
# chmod +x /path/to/Script.
# It is preferred to store the script in user's personal $HOME/bin
# folder.
# Make sure to edit $HOME/.profile file to include that into $PATH
# variable
interupt()
{
qdbus com.canonical.Unity /com/canonical/Unity/Session com.canonical.Unity.Session.CancelAction
notify-send "<<< UPDATE IN PROGRESS; DO NOT SHUT DOWN>>>"
wall <<< "<<< UPDATE IN PROGRESS; DO NOT SHUT DOWN>>>"
}
main()
{
dbus-monitor --profile "interface='com.canonical.Unity.Session',type=signal" |
while read -r line;
do
case "$line" in
*RebootRequested*)
pgrep update-manager || pgrep apt-get || pgrep dpkg
if [ $? -eq 0 ]; then
interupt
fi
;;
esac
done
}
main
System Settings -> Power