Gentoo Archives: gentoo-commits

From: "Matthias Schwarzott (zzam)" <zzam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-vdr r640 - in gentoo-vdr-scripts/trunk: . usr/share/vdr/bin
Date: Wed, 30 Jul 2008 15:34:21
Message-Id: E1KODgv-0000t1-Tx@stork.gentoo.org
1 Author: zzam
2 Date: 2008-07-30 15:34:17 +0000 (Wed, 30 Jul 2008)
3 New Revision: 640
4
5 Added:
6 gentoo-vdr-scripts/trunk/usr/share/vdr/bin/vdrshutdown-really.sh
7 Removed:
8 gentoo-vdr-scripts/trunk/usr/share/vdr/bin/vdrshutdown-gate.sh
9 Modified:
10 gentoo-vdr-scripts/trunk/ChangeLog
11 Log:
12 Move old user-part of shutdown to sudo entry point.
13
14 Modified: gentoo-vdr-scripts/trunk/ChangeLog
15 ===================================================================
16 --- gentoo-vdr-scripts/trunk/ChangeLog 2008-07-30 15:33:20 UTC (rev 639)
17 +++ gentoo-vdr-scripts/trunk/ChangeLog 2008-07-30 15:34:17 UTC (rev 640)
18 @@ -2,6 +2,10 @@
19 # $Id$
20
21 30 Jul 2008; Matthias Schwarzott <zzam@g.o> ++,
22 + -usr/share/vdr/bin/vdrshutdown-gate.sh:
23 + Move old user-part of shutdown to sudo entry point.
24 +
25 + 30 Jul 2008; Matthias Schwarzott <zzam@g.o> ++,
26 -usr/share/vdr/bin/vdrshutdown-really.sh:
27 Moved old root-part of shutdown to temp name.
28
29
30 Deleted: gentoo-vdr-scripts/trunk/usr/share/vdr/bin/vdrshutdown-gate.sh
31 ===================================================================
32 --- gentoo-vdr-scripts/trunk/usr/share/vdr/bin/vdrshutdown-gate.sh 2008-07-30 15:33:20 UTC (rev 639)
33 +++ gentoo-vdr-scripts/trunk/usr/share/vdr/bin/vdrshutdown-gate.sh 2008-07-30 15:34:17 UTC (rev 640)
34 @@ -1,287 +0,0 @@
35 -#!/bin/sh
36 -# $Id$
37 -# Author:
38 -# Matthias Schwarzott <zzam@×××.de>
39 -# Various other contributors from gentoo.de
40 -#
41 -# some ideas from ctvdr's shutdownvdr by Tobias Grimm <tg@××××××.net>
42 -#
43 -
44 -# This script is called by vdr when triggering shutdown
45 -# called from vdr with: vdr -s vdrshutdown-gate.sh
46 -
47 -# It calls all shell-scripts located under /usr/share/vdr/shutdown
48 -# for checking if shutdown should be allowed.
49 -# A lot of functions defined in here can be used
50 -# from within these scripts.
51 -
52 -#fork to background
53 -if [ -z "${EXECUTED_BY_VDR_BG}" ]; then
54 - exec /usr/share/vdr/bin/vdr-bg.sh "${0}" "${@}"
55 - exit
56 -fi
57 -
58 -# should be default paths on a machine build with vdr ebuilds
59 -SVDRPCMD=/usr/bin/svdrpsend.pl
60 -NVRAM_WAKEUP=/usr/bin/nvram-wakeup
61 -HOOKDIR=/usr/share/vdr/shutdown
62 -
63 -. /usr/share/vdr/inc/functions.sh
64 -include shutdown-functions
65 -
66 -read_caps
67 -
68 -VDR_TIMER_NEXT="${1}"
69 -VDR_TIMER_DELTA="${2}"
70 -VDR_TIMER_CHANNEL="${3}"
71 -VDR_TIMER_FILENAME="${4}"
72 -VDR_USERSHUTDOWN="${5}"
73 -
74 -: ${SHUTDOWN_DEFAULT_RETRY_TIME:=10}
75 -
76 -if [ "${DEBUG}" -ge 1 ]; then
77 - exec </dev/null >/tmp/vdrshutdown-gate-log 2>&1
78 - echo Started debug output of $0 $@
79 - nr=0
80 - for f; do
81 - nr=$(($nr+1))
82 - echo "param #${nr} - ${f}"
83 - done
84 - set -x
85 -fi
86 -
87 -
88 -queue_add_wait() {
89 - : ${qindex:=1}
90 - eval svdrpqueue_${qindex}="\"sleep $1\""
91 - qindex=$(($qindex+1))
92 -}
93 -
94 -svdrp_add_queue() {
95 - : ${qindex:=1}
96 - logger "vdrshutdown-gate sending per svdrp: $1"
97 - eval svdrpqueue_${qindex}="\"${SVDRPCMD} $1\""
98 - qindex=$(($qindex+1))
99 -}
100 -
101 -svdrp_queue_handler() {
102 - local i=1
103 - local ITEM
104 - while [ $i -lt $qindex ]; do
105 - # retry until success
106 - eval ITEM=\$svdrpqueue_${i}
107 - while ! ${ITEM}; do
108 - sleep 1
109 - done
110 - i=$(($i+1))
111 - done
112 -}
113 -
114 -mesg() {
115 - ${SVDRPCMD} MESG ${1}
116 -}
117 -
118 -mesg_q() {
119 - svdrp_add_queue "MESG ${1}"
120 -}
121 -
122 -retry_shutdown() {
123 - local when=${TRY_AGAIN}
124 -
125 - if [ -n "${CAP_SHUTDOWN_SVDRP}" ]; then
126 - if [ "${when}" -gt 5 ]; then
127 - svdrp_add_queue "DOWN $(($when-5))"
128 - else
129 - svdrp_add_queue "DOWN"
130 - fi
131 - return
132 - fi
133 -
134 - if [ "${CAP_SHUTDOWN_AUTO_RETRY:-0}" = "1" ]; then
135 - # vdr itself will retry shutdown in a reasonable time
136 - return
137 - fi
138 -
139 - # shutdown retry must be simulated by sleep and the power key
140 - #as vdr itself is not able
141 - queue_add_wait ${when}m
142 - svdrp_add_queue "hitk power"
143 - return
144 -}
145 -
146 -is_auto_shutdown() {
147 - [ "${VDR_USERSHUTDOWN}" = "0" ]
148 -}
149 -
150 -is_user_shutdown() {
151 - [ "${VDR_USERSHUTDOWN}" = "1" ]
152 -}
153 -
154 -is_forced_shutdown() {
155 - [ "${THIS_SHUTDOWN_IS_FORCED}" = "1" ]
156 -}
157 -
158 -is_shutdown_aborted() {
159 - [ "${SHUTDOWN_ABORT}" = "1" ]
160 -}
161 -
162 -forced_tests_count_greater_zero() {
163 - [ "${SHUTDOWN_FORCE_COUNT}" -gt 0 ]
164 -}
165 -
166 -set_retry_time() {
167 - local TIME="${1}"
168 - if [ "${TRY_AGAIN}" -lt "${TIME}" ]; then
169 - TRY_AGAIN=${TIME}
170 - fi
171 -}
172 -
173 -shutdown_abort_common() {
174 - ABORT_MESSAGE="${1}"
175 - SHUTDOWN_ABORT="1"
176 - set_retry_time "${SHUTDOWN_DEFAULT_RETRY_TIME}"
177 -}
178 -
179 -shutdown_abort() {
180 - shutdown_abort_common "${1}"
181 - disable_forced_shutdown
182 -}
183 -
184 -shutdown_abort_can_force() {
185 - if is_forced_shutdown; then
186 - # this is the forced way, ignore this abort
187 - echo FORCED: ${1}
188 - SHUTDOWN_FORCE_COUNT=$(($SHUTDOWN_FORCE_COUNT+1))
189 - else
190 - shutdown_abort_common "${1}"
191 - fi
192 -}
193 -
194 -shutdown_abort_exit() {
195 - local ABORT_MESSAGE="${1}"
196 - local EXITCODE=1
197 -
198 - mesg_q "Shutdown aborted: ${ABORT_MESSAGE}"
199 - exit_cleanup ${EXITCODE}
200 -}
201 -
202 -
203 -
204 -
205 -init_forced_shutdown() {
206 - SHUTDOWN_CAN_FORCE=0
207 - THIS_SHUTDOWN_IS_FORCED="0"
208 -
209 - # only continue if user-shutdown
210 - if ! is_user_shutdown; then
211 - return 0
212 - fi
213 -
214 -
215 -
216 - # detect if this could be a forced shutdown
217 - local shutdown_force_file=${shutdown_data_dir}/last-shutdown-abort
218 -
219 - local LAST_SHUTDOWN_ABORT=0
220 - if [ -f "${shutdown_force_file}" ]; then
221 - LAST_SHUTDOWN_ABORT=$(cat "${shutdown_force_file}")
222 - fi
223 - NOW=$(date +%s)
224 - local DISTANCE=$(($NOW-$LAST_SHUTDOWN_ABORT))
225 - if [ "${DISTANCE}" -lt "${SHUTDOWN_FORCE_DETECT_INTERVALL:-60}" ]; then
226 - THIS_SHUTDOWN_IS_FORCED="1"
227 - fi
228 -
229 - [ -f "${shutdown_force_file}" ] && rm "${shutdown_force_file}"
230 - SHUTDOWN_FORCE_COUNT=0
231 - SHUTDOWN_CAN_FORCE=1
232 -}
233 -
234 -disable_forced_shutdown() {
235 - SHUTDOWN_CAN_FORCE="0"
236 -}
237 -
238 -write_force_file() {
239 - local shutdown_force_file=${shutdown_data_dir}/last-shutdown-abort
240 - echo "${NOW}" > "${shutdown_force_file}"
241 -}
242 -
243 -check_forced_shutdown_possible_next_time() {
244 - if [ "${SHUTDOWN_CAN_FORCE}" = "1" ]; then
245 - write_force_file
246 - queue_add_wait 1s
247 - mesg_q "You can force a shutdown with pressing power again"
248 - fi
249 -}
250 -
251 -exit_cleanup() {
252 - svdrp_queue_handler &
253 - exit ${1}
254 -}
255 -
256 -execute_hooks() {
257 - local HOOK
258 - for HOOK in $HOOKDIR/pre-shutdown-*.sh; do
259 - [ -r "${HOOK}" ] || continue
260 - sh -n "${HOOK}" || continue
261 - . "${HOOK}"
262 - done
263 -}
264 -
265 -check_auto_retry() {
266 - if [ "${TRY_AGAIN}" -gt 0 -a "${ENABLE_AUTO_RETRY}" = 1 ]; then
267 - queue_add_wait 1s
268 - retry_shutdown ${TRY_AGAIN}
269 - fi
270 -}
271 -
272 -disable_auto_retry() {
273 - ENABLE_AUTO_RETRY=0
274 -}
275 -
276 -init() {
277 - SHUTDOWN_ABORT=0
278 - TRY_AGAIN=0
279 - ENABLE_AUTO_RETRY=1
280 -}
281 -
282 -
283 -init
284 -init_forced_shutdown
285 -execute_hooks
286 -
287 -if is_shutdown_aborted; then
288 - mesg_q "No Shutdown: ${ABORT_MESSAGE}"
289 - check_forced_shutdown_possible_next_time
290 - check_auto_retry
291 -
292 - exit_cleanup 0
293 -fi
294 -
295 -# You have to edit sudo-permissions to grant vdr permission to execute
296 -# privileged commands. Start visudo and add a line like
297 -# vdr ALL= NOPASSWD: /usr/share/vdr/bin/vdrshutdown-really.sh
298 -
299 -
300 -sudo /usr/share/vdr/bin/vdrshutdown-really.sh "$@"
301 -case $? in
302 -0) ;;
303 -1) mesg_q "sudo failed"
304 - mesg_q "call emerge --config gentoo-vdr-scripts"
305 - exit_cleanup 1
306 - ;;
307 -*) mesg_q "setting wakeup time not successful"
308 - exit_cleanup 1
309 - ;;
310 -esac
311 -rm "${shutdown_data_dir}/shutdown-time-written"
312 -date +%s > "${shutdown_data_dir}/shutdown-time-written"
313 -
314 -if is_forced_shutdown && forced_tests_count_greater_zero; then
315 - mesg_q "User enforced shutdown"
316 -else
317 - mesg_q "Shutting down"
318 -fi
319 -
320 -exit_cleanup 0
321 -
322
323 Copied: gentoo-vdr-scripts/trunk/usr/share/vdr/bin/vdrshutdown-really.sh (from rev 638, gentoo-vdr-scripts/trunk/usr/share/vdr/bin/vdrshutdown-gate.sh)
324 ===================================================================
325 --- gentoo-vdr-scripts/trunk/usr/share/vdr/bin/vdrshutdown-really.sh (rev 0)
326 +++ gentoo-vdr-scripts/trunk/usr/share/vdr/bin/vdrshutdown-really.sh 2008-07-30 15:34:17 UTC (rev 640)
327 @@ -0,0 +1,287 @@
328 +#!/bin/sh
329 +# $Id$
330 +# Author:
331 +# Matthias Schwarzott <zzam@×××.de>
332 +# Various other contributors from gentoo.de
333 +#
334 +# some ideas from ctvdr's shutdownvdr by Tobias Grimm <tg@××××××.net>
335 +#
336 +
337 +# This script is called by vdr when triggering shutdown
338 +# called from vdr with: vdr -s vdrshutdown-gate.sh
339 +
340 +# It calls all shell-scripts located under /usr/share/vdr/shutdown
341 +# for checking if shutdown should be allowed.
342 +# A lot of functions defined in here can be used
343 +# from within these scripts.
344 +
345 +#fork to background
346 +if [ -z "${EXECUTED_BY_VDR_BG}" ]; then
347 + exec /usr/share/vdr/bin/vdr-bg.sh "${0}" "${@}"
348 + exit
349 +fi
350 +
351 +# should be default paths on a machine build with vdr ebuilds
352 +SVDRPCMD=/usr/bin/svdrpsend.pl
353 +NVRAM_WAKEUP=/usr/bin/nvram-wakeup
354 +HOOKDIR=/usr/share/vdr/shutdown
355 +
356 +. /usr/share/vdr/inc/functions.sh
357 +include shutdown-functions
358 +
359 +read_caps
360 +
361 +VDR_TIMER_NEXT="${1}"
362 +VDR_TIMER_DELTA="${2}"
363 +VDR_TIMER_CHANNEL="${3}"
364 +VDR_TIMER_FILENAME="${4}"
365 +VDR_USERSHUTDOWN="${5}"
366 +
367 +: ${SHUTDOWN_DEFAULT_RETRY_TIME:=10}
368 +
369 +if [ "${DEBUG}" -ge 1 ]; then
370 + exec </dev/null >/tmp/vdrshutdown-gate-log 2>&1
371 + echo Started debug output of $0 $@
372 + nr=0
373 + for f; do
374 + nr=$(($nr+1))
375 + echo "param #${nr} - ${f}"
376 + done
377 + set -x
378 +fi
379 +
380 +
381 +queue_add_wait() {
382 + : ${qindex:=1}
383 + eval svdrpqueue_${qindex}="\"sleep $1\""
384 + qindex=$(($qindex+1))
385 +}
386 +
387 +svdrp_add_queue() {
388 + : ${qindex:=1}
389 + logger "vdrshutdown-gate sending per svdrp: $1"
390 + eval svdrpqueue_${qindex}="\"${SVDRPCMD} $1\""
391 + qindex=$(($qindex+1))
392 +}
393 +
394 +svdrp_queue_handler() {
395 + local i=1
396 + local ITEM
397 + while [ $i -lt $qindex ]; do
398 + # retry until success
399 + eval ITEM=\$svdrpqueue_${i}
400 + while ! ${ITEM}; do
401 + sleep 1
402 + done
403 + i=$(($i+1))
404 + done
405 +}
406 +
407 +mesg() {
408 + ${SVDRPCMD} MESG ${1}
409 +}
410 +
411 +mesg_q() {
412 + svdrp_add_queue "MESG ${1}"
413 +}
414 +
415 +retry_shutdown() {
416 + local when=${TRY_AGAIN}
417 +
418 + if [ -n "${CAP_SHUTDOWN_SVDRP}" ]; then
419 + if [ "${when}" -gt 5 ]; then
420 + svdrp_add_queue "DOWN $(($when-5))"
421 + else
422 + svdrp_add_queue "DOWN"
423 + fi
424 + return
425 + fi
426 +
427 + if [ "${CAP_SHUTDOWN_AUTO_RETRY:-0}" = "1" ]; then
428 + # vdr itself will retry shutdown in a reasonable time
429 + return
430 + fi
431 +
432 + # shutdown retry must be simulated by sleep and the power key
433 + #as vdr itself is not able
434 + queue_add_wait ${when}m
435 + svdrp_add_queue "hitk power"
436 + return
437 +}
438 +
439 +is_auto_shutdown() {
440 + [ "${VDR_USERSHUTDOWN}" = "0" ]
441 +}
442 +
443 +is_user_shutdown() {
444 + [ "${VDR_USERSHUTDOWN}" = "1" ]
445 +}
446 +
447 +is_forced_shutdown() {
448 + [ "${THIS_SHUTDOWN_IS_FORCED}" = "1" ]
449 +}
450 +
451 +is_shutdown_aborted() {
452 + [ "${SHUTDOWN_ABORT}" = "1" ]
453 +}
454 +
455 +forced_tests_count_greater_zero() {
456 + [ "${SHUTDOWN_FORCE_COUNT}" -gt 0 ]
457 +}
458 +
459 +set_retry_time() {
460 + local TIME="${1}"
461 + if [ "${TRY_AGAIN}" -lt "${TIME}" ]; then
462 + TRY_AGAIN=${TIME}
463 + fi
464 +}
465 +
466 +shutdown_abort_common() {
467 + ABORT_MESSAGE="${1}"
468 + SHUTDOWN_ABORT="1"
469 + set_retry_time "${SHUTDOWN_DEFAULT_RETRY_TIME}"
470 +}
471 +
472 +shutdown_abort() {
473 + shutdown_abort_common "${1}"
474 + disable_forced_shutdown
475 +}
476 +
477 +shutdown_abort_can_force() {
478 + if is_forced_shutdown; then
479 + # this is the forced way, ignore this abort
480 + echo FORCED: ${1}
481 + SHUTDOWN_FORCE_COUNT=$(($SHUTDOWN_FORCE_COUNT+1))
482 + else
483 + shutdown_abort_common "${1}"
484 + fi
485 +}
486 +
487 +shutdown_abort_exit() {
488 + local ABORT_MESSAGE="${1}"
489 + local EXITCODE=1
490 +
491 + mesg_q "Shutdown aborted: ${ABORT_MESSAGE}"
492 + exit_cleanup ${EXITCODE}
493 +}
494 +
495 +
496 +
497 +
498 +init_forced_shutdown() {
499 + SHUTDOWN_CAN_FORCE=0
500 + THIS_SHUTDOWN_IS_FORCED="0"
501 +
502 + # only continue if user-shutdown
503 + if ! is_user_shutdown; then
504 + return 0
505 + fi
506 +
507 +
508 +
509 + # detect if this could be a forced shutdown
510 + local shutdown_force_file=${shutdown_data_dir}/last-shutdown-abort
511 +
512 + local LAST_SHUTDOWN_ABORT=0
513 + if [ -f "${shutdown_force_file}" ]; then
514 + LAST_SHUTDOWN_ABORT=$(cat "${shutdown_force_file}")
515 + fi
516 + NOW=$(date +%s)
517 + local DISTANCE=$(($NOW-$LAST_SHUTDOWN_ABORT))
518 + if [ "${DISTANCE}" -lt "${SHUTDOWN_FORCE_DETECT_INTERVALL:-60}" ]; then
519 + THIS_SHUTDOWN_IS_FORCED="1"
520 + fi
521 +
522 + [ -f "${shutdown_force_file}" ] && rm "${shutdown_force_file}"
523 + SHUTDOWN_FORCE_COUNT=0
524 + SHUTDOWN_CAN_FORCE=1
525 +}
526 +
527 +disable_forced_shutdown() {
528 + SHUTDOWN_CAN_FORCE="0"
529 +}
530 +
531 +write_force_file() {
532 + local shutdown_force_file=${shutdown_data_dir}/last-shutdown-abort
533 + echo "${NOW}" > "${shutdown_force_file}"
534 +}
535 +
536 +check_forced_shutdown_possible_next_time() {
537 + if [ "${SHUTDOWN_CAN_FORCE}" = "1" ]; then
538 + write_force_file
539 + queue_add_wait 1s
540 + mesg_q "You can force a shutdown with pressing power again"
541 + fi
542 +}
543 +
544 +exit_cleanup() {
545 + svdrp_queue_handler &
546 + exit ${1}
547 +}
548 +
549 +execute_hooks() {
550 + local HOOK
551 + for HOOK in $HOOKDIR/pre-shutdown-*.sh; do
552 + [ -r "${HOOK}" ] || continue
553 + sh -n "${HOOK}" || continue
554 + . "${HOOK}"
555 + done
556 +}
557 +
558 +check_auto_retry() {
559 + if [ "${TRY_AGAIN}" -gt 0 -a "${ENABLE_AUTO_RETRY}" = 1 ]; then
560 + queue_add_wait 1s
561 + retry_shutdown ${TRY_AGAIN}
562 + fi
563 +}
564 +
565 +disable_auto_retry() {
566 + ENABLE_AUTO_RETRY=0
567 +}
568 +
569 +init() {
570 + SHUTDOWN_ABORT=0
571 + TRY_AGAIN=0
572 + ENABLE_AUTO_RETRY=1
573 +}
574 +
575 +
576 +init
577 +init_forced_shutdown
578 +execute_hooks
579 +
580 +if is_shutdown_aborted; then
581 + mesg_q "No Shutdown: ${ABORT_MESSAGE}"
582 + check_forced_shutdown_possible_next_time
583 + check_auto_retry
584 +
585 + exit_cleanup 0
586 +fi
587 +
588 +# You have to edit sudo-permissions to grant vdr permission to execute
589 +# privileged commands. Start visudo and add a line like
590 +# vdr ALL= NOPASSWD: /usr/share/vdr/bin/vdrshutdown-really.sh
591 +
592 +
593 +sudo /usr/share/vdr/bin/vdrshutdown-really.sh "$@"
594 +case $? in
595 +0) ;;
596 +1) mesg_q "sudo failed"
597 + mesg_q "call emerge --config gentoo-vdr-scripts"
598 + exit_cleanup 1
599 + ;;
600 +*) mesg_q "setting wakeup time not successful"
601 + exit_cleanup 1
602 + ;;
603 +esac
604 +rm "${shutdown_data_dir}/shutdown-time-written"
605 +date +%s > "${shutdown_data_dir}/shutdown-time-written"
606 +
607 +if is_forced_shutdown && forced_tests_count_greater_zero; then
608 + mesg_q "User enforced shutdown"
609 +else
610 + mesg_q "Shutting down"
611 +fi
612 +
613 +exit_cleanup 0
614 +
615
616
617 Property changes on: gentoo-vdr-scripts/trunk/usr/share/vdr/bin/vdrshutdown-really.sh
618 ___________________________________________________________________
619 Name: svn:keywords
620 + Id
621 Name: svn:mergeinfo
622 +