Debian Codegraph @

libexec/container/top

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2
3 # Copyright (C) 2014-2026 Daniel Baumann <[email protected]>
4 #
5 # SPDX-License-Identifier: GPL-3.0+
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19
20 set -e
21
22 PROJECT="open-infrastructure"
23 SOFTWARE="compute-tools"
24 PROGRAM="container"
25 COMMAND="$(basenamescip-shell system . . basename. ${0})"
26
27 Parametersscip-shell shell shell-project 0.0.0 Parameters(). ()
28 {
29 GETOPT_LONGOPTIONS="delay:,"
30 GETOPT_OPTIONS="d:,"
31
32 PARAMETERS="$(getoptscip-shell system . . getopt. --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})"
33
34 if [scip-shell system . . `[`. "${?}" != "0" ]
35 then
36 echoscip-shell system . . echo. "'${COMMAND}': getopt exit" >&2
37 exit 1
38 fi
39
40 eval set -- "${PARAMETERS}"
41
42 while truescip-shell system . . true.
43 do
44 case "${1}" in
45 -d|--delay)
46 DELAY="${2}"
47 shift 2
48 ;;
49
50 --)
51 shift 1
52 break
53 ;;
54
55 *)
56 echoscip-shell system . . echo. "'${COMMAND}': getopt error" >&2
57 exit 1
58 ;;
59 esac
60 done
61 }
62
63 Usagescip-shell shell shell-project 0.0.0 Usage(). ()
64 {
65 echoscip-shell system . . echo. "Usage: ${PROGRAM} ${COMMAND} [-d|--delay DELAY]" >&2
66 echoscip-shell system . . echo.
67 echoscip-shell system . . echo. "See ${COMMAND}(1), ${PROGRAM}(1) and ${PROJECT}(7) for more information."
68
69 exit 1
70 }
71
72 Parametersscip-shell shell shell-project 0.0.0 Parameters(). "${@}"
73
74 DELAY="${DELAY:-1}"
75 HOST="$(hostnamescip-shell system . . hostname. -f 2> /dev/nullscip-shell filesystem . . `/dev/null`. || hostnamescip-shell system . . hostname.)"
76
77 # Pre hooks
78 for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
79 do
80 if [scip-shell system . . `[`. -x "${FILE}" ]
81 then
82 "${FILE}"
83 fi
84 done
85
86 # Run
87 Topscip-shell shell shell-project 0.0.0 Top(). ()
88 {
89 HOME="$(tputscip-shell system . . tput. cup 0 0)"
90 ED="$(tputscip-shell system . . tput. ed)"
91 EL="$(tputscip-shell system . . tput. el)"
92
93 printfscip-shell system . . printf. '%s%s' "${HOME}" "${ED}"
94
95 while truescip-shell system . . true.
96 do
97 ROWS="$(tputscip-shell system . . tput. lines)"
98 COLS="$(tputscip-shell system . . tput. cols)"
99 CMD="${@}"
100
101 ${SHELL:=sh} -c "${CMD}" | headscip-shell system . . head. -n ${ROWS} | while IFS= read LINE
102 do
103 printfscip-shell system . . printf. '%-*.*s%s\n' ${COLS} ${COLS} "${LINE}" "${EL}"
104 done
105
106 printfscip-shell system . . printf. '%s%s' "${ED}" "${HOME}"
107 sleepscip-shell system . . sleep. ${DELAY}
108 done
109 }
110
111 trap 'clear' EXIT HUP INT QUIT TERM
112
113 Topscip-shell shell shell-project 0.0.0 Top(). "${PROGRAM} list && printf '%-59s %-19s\n' \" Host: ${HOST}\" \"\$(date +%Y-%m-%d\ %H:%M:%S)\""
114
115 # Post hooks
116 for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
117 do
118 if [scip-shell system . . `[`. -x "${FILE}" ]
119 then
120 "${FILE}"
121 fi
122 done