├── .git-filters └── keywords ├── .git-hooks ├── commit-msg ├── install.sh ├── post-commit └── pre-commit ├── LICENSE ├── Mk ├── HELP ├── USAGE ├── clean_directories ├── clean_symlinks ├── die ├── git_import ├── git_tag ├── make_directories ├── make_stage ├── make_symlinks ├── pkgcenter_readconf └── xargs ├── README.md ├── dwatch-json-io.conf ├── dwatch-json-net.conf ├── freebsd ├── Mk │ ├── HELP_FREEBSD │ ├── HELP_PACKAGE │ ├── USAGE_FREEBSD │ ├── USAGE_PACKAGE │ ├── convert │ ├── manifest.subr │ ├── pkgcc │ ├── pkgname │ ├── pkgorigin │ ├── pkgtag │ └── pkgtagname ├── create ├── dwatch-json │ ├── LICENSE │ ├── MANIFEST │ ├── Makefile │ ├── catalog.mk │ └── pkgcenter.conf ├── skel │ ├── MANIFEST │ ├── Makefile │ ├── Makefile.ng │ ├── Makefile.old │ ├── PLIST │ ├── pkgcenter.conf │ └── stage │ │ ├── +COMMENT │ │ └── +DESC └── unpack ├── graf ├── logs ├── rotate └── stats ├── grafio ├── cron.d │ └── grafio ├── dashboards │ └── block-i-o.json ├── etc │ ├── grafio.conf.sample │ ├── grafio.subr.sample │ └── stats.conf.sample ├── grafio └── rc.d │ ├── grafio │ └── grafio_stats ├── grafnet ├── cron.d │ └── grafnet ├── dashboards │ ├── device-i-o-rates-b-s.json │ ├── device-i-o-rates-bps.json │ └── device-i-o.json ├── etc │ ├── grafnet.conf.sample │ ├── grafnet.subr.sample │ └── stats.conf.sample ├── grafnet └── rc.d │ ├── grafnet │ └── grafnet_stats ├── json-io ├── json-io-config ├── json-io-config-raw ├── json-io-raw ├── json-io-top ├── json-io-top-raw ├── json-net ├── json-net-config ├── json-net-config-raw ├── json-net-raw ├── json-net-top └── json-net-top-raw /.git-filters/keywords: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ############################################################ IDENT(1) 3 | # 4 | # $Title: Filter to expand/delete keywords before/after commit (respectively) $ 5 | # 6 | ############################################################ INFORMATION 7 | # 8 | # System requirements: awk(1) date(1) file(1) git(1) printf(1)* rm(1) 9 | # * Most sh(1) variations implement printf as built-in. 10 | # 11 | ############################################################ CONFIGURATION 12 | 13 | # 14 | # List of keywords to expand/delete (separated by whitespace) 15 | # 16 | KEYWORDS=" 17 | FrauBSD 18 | " # END-QUOTE 19 | 20 | # 21 | # Pre-expanded keyword values 22 | # NB: $file is actual filename while $gitfile uses escape-sequences 23 | # 24 | _Author='$NAME' 25 | _Branch='$BRANCH' 26 | _Date='$DATE' 27 | _FrauBSD='${REPO#FrauBSD/}/$gitfile $DATE $NAME' 28 | _Header='$gitfile $DATE $NAME' 29 | _Origin='$ORIGIN' 30 | _Project='$PROJECT' 31 | _RCSfile='${gitfile##*/}' 32 | _Source='$gitfile' 33 | 34 | ############################################################ GLOBALS 35 | 36 | # 37 | # Required parts 38 | # 39 | NAME=$( git config user.name ) DATE=$( date +"%F %T %z" ) 40 | : ${NAME:=unknown} ${DATE:=0000-00-00 00:00:00 -0000} 41 | 42 | # 43 | # Command-line options 44 | # 45 | DELETE= # -d 46 | 47 | # 48 | # Miscellaneous 49 | # 50 | TMPFILE="/tmp/${0##*/}.$$" 51 | 52 | ############################################################ FUNCTIONS 53 | 54 | DEBUG() 55 | { 56 | local fmt="$1" 57 | [ ! "$DEBUG" ] && return 58 | [ ! "$fmt" ] && return 59 | shift 1 # fmt 60 | printf "DEBUG: $fmt\n" "$@" 61 | } 62 | 63 | ############################################################ MAIN 64 | 65 | # 66 | # Command-line options 67 | # 68 | while getopts d flag; do 69 | case "$flag" in 70 | d) DELETE=1 ;; 71 | esac 72 | done 73 | shift $(( $OPTIND - 1 )) 74 | 75 | # 76 | # Get origin URL 77 | # 78 | ORIGIN=$( git config remote.origin.url ) 79 | 80 | # 81 | # Repository name 82 | # 83 | PROJECT="${ORIGIN##*:}" 84 | REPO="${PROJECT%.[Gg][Ii][Tt]}" 85 | 86 | # 87 | # Get current branch name (required by `-d' to delete keywords) 88 | # 89 | IFS= read -r BRANCH < /dev/null 2>&1' EXIT 98 | for file in "$@"; do 99 | [ -e "$file" -a ! -d "$file" ] || continue 100 | gitfile=$( git diff --cached --name-only -- "$file" ) 101 | 102 | # 103 | # Only operate on files we know to be safe 104 | # 105 | case "$( file -b "$file" 2> /dev/null )" in 106 | *ASCII*text*) : fall through ;; 107 | *script*text*) : fall through ;; 108 | *source*text*) : fall through ;; 109 | *program*text*) : fall through ;; 110 | *document*text) : fall through ;; 111 | *) 112 | DEBUG "$gitfile (skipped)" 113 | continue 114 | esac 115 | 116 | # 117 | # Expand keywords (`-d' resets values to branch context) 118 | # 119 | if [ "$DELETE" ]; then 120 | for keyword in $KEYWORDS; do 121 | regex="\\\$$keyword: [^$]+\\\$" 122 | read value <<-EOF 123 | $( git grep -hIE "$regex" "$BRANCH" -- "$file" ) 124 | EOF 125 | case "$value" in 126 | "") eval $keyword="\"\\\$$keyword\\\$\"" ;; 127 | *) value="${value#*\$$keyword: }" 128 | value="\$$keyword: ${value%%\$*}\$" 129 | eval $keyword='"$value"' 130 | esac 131 | done 132 | else 133 | for keyword in $KEYWORDS; do 134 | eval value=\"\$_$keyword\" 135 | eval $keyword=\"\\\$$keyword:\ $value\ \\\$\" 136 | done 137 | fi 138 | 139 | # 140 | # For debugging purposes, show which edits are going to be made 141 | # 142 | needs_editing= 143 | [ "$DEBUG" ] && print_file_debug=1 144 | for keyword in $KEYWORDS; do 145 | if [ "$print_file_debug" ]; then 146 | print_file_debug= 147 | printf "DEBUG: %s " "$gitfile" 148 | fi 149 | awk '/\$'$keyword'(: [^$]*)?\$/ { exit found++ } 150 | END { exit !found }' "$file" || continue 151 | needs_editing=1 152 | [ "$DEBUG" ] && echo "(edit)" 153 | break 154 | done 155 | if [ ! "$needs_editing" ]; then 156 | [ "$DEBUG" ] && echo "(no keywords)" 157 | continue 158 | fi 159 | 160 | # 161 | # Edit the file, optionally with debug information 162 | # 163 | status=U+ 164 | [ "$DELETE" ] && status=U- 165 | cp -f "$file" "$TMPFILE" || exit 166 | while IFS= read -r LINE; do 167 | for keyword in $KEYWORDS; do 168 | line_modified= 169 | eval value=\"\$$keyword\" 170 | case "$LINE" in 171 | *"\$$keyword: "*'$'*) 172 | L="${LINE%%\$$keyword: *}" 173 | R="${LINE#"$L\$$keyword: "}" 174 | R="${R#*\$}" 175 | LINE="$L$value$R" 176 | line_modified=1 ;; 177 | *"\$$keyword\$"*) 178 | L="${LINE%%\$$keyword\$*}" 179 | R="${LINE#"$L\$$keyword\$"}" 180 | LINE="$L$value$R" 181 | line_modified=1 ;; 182 | esac 183 | if [ "$line_modified" ]; then 184 | if [ "$DEBUG" ]; then 185 | echo " $value" >&3 186 | else 187 | printf "%-3s %-8s %s\n" "$status" \ 188 | "$keyword" "$gitfile" >&3 189 | fi 190 | fi 191 | done 192 | printf "%s\n" "$LINE" 193 | done < "$TMPFILE" 3>&1 > "$file" 194 | done 195 | 196 | ################################################################################ 197 | # END 198 | ################################################################################ 199 | # 200 | # $Copyright: 2015-2018 The FrauBSD Project. All rights reserved. $ 201 | # $FrauBSD: dwatch-json/.git-filters/keywords 2018-09-20 14:43:47 -0700 freebsdfrau $ 202 | # 203 | ################################################################################ 204 | -------------------------------------------------------------------------------- /.git-hooks/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ############################################################ IDENT(1) 3 | # 4 | # $Title: Hook to run after EDITOR exits, following `git commit' $ 5 | # 6 | ############################################################ INFORMATION 7 | # 8 | # System requirements: awk(1) git(1) xargs(1) 9 | # See also: .git-filters/keywords 10 | # 11 | ############################################################ MAIN 12 | 13 | DEBUG(){ [ ! "$DEBUG" ] || echo "DEBUG: $*"; } 14 | DEBUG "$0 $*" 15 | 16 | # Test the commit message file for content (indicating commit not aborted) 17 | DEBUG "Checking commit message..." 18 | awk '!/^[[:space:]]*(#|$)/{exit found++}END{exit !found}' "$1" && 19 | { DEBUG "Committing!"; exit 0; } 20 | DEBUG "Commit aborted!" 21 | 22 | # Commit aborted: Unset keywords in modified text-files 23 | DEBUG "Keyword modifications..." 24 | git diff --cached --name-only -z --diff-filter=ACM | 25 | xargs -0 .git-filters/keywords -d -- 26 | DEBUG "End List" 27 | 28 | # Update the staging files 29 | git diff --cached --name-only -z --diff-filter=ACM | 30 | xargs -0 git add -u -v -- 31 | 32 | ################################################################################ 33 | # END 34 | ################################################################################ 35 | # 36 | # $Copyright: 2015-2017 The FrauBSD Project. All rights reserved. $ 37 | # $FrauBSD: dwatch-json/.git-hooks/commit-msg 2018-09-20 14:43:47 -0700 freebsdfrau $ 38 | # 39 | ################################################################################ 40 | -------------------------------------------------------------------------------- /.git-hooks/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ############################################################ IDENT(1) 3 | # 4 | # $Title: Script to enable client side hooks $ 5 | # $Copyright: 2017 Devin Teske. All rights reserved. $ 6 | # $FrauBSD: dwatch-json/.git-hooks/install.sh 2018-09-20 14:43:47 -0700 freebsdfrau $ 7 | # 8 | ############################################################ GLOBALS 9 | 10 | pgm="${0##*/}" # Program basename 11 | progdir="${0%/*}" # Program directory 12 | 13 | # 14 | # Global exit status 15 | # 16 | SUCCESS=0 17 | FAILURE=1 18 | 19 | # 20 | # Stdout processing 21 | # 22 | CONSOLE= 23 | [ -t 0 ] && CONSOLE=1 # Output is to a terminal (vs pipe, etc.) 24 | 25 | # 26 | # ANSI 27 | # 28 | ESC=$( :| awk 'BEGIN { printf "%c", 27 }' ) 29 | ANSI_BLD_ON="${CONSOLE:+$ESC[1m}" 30 | ANSI_BLD_OFF="${CONSOLE:+$ESC[22m}" 31 | ANSI_GRN_ON="${CONSOLE:+$ESC[32m}" 32 | ANSI_FGC_OFF="${CONSOLE:+$ESC[39m}" 33 | 34 | # 35 | # Command-line options 36 | # 37 | FORCE= # -f 38 | 39 | ############################################################ FUNCTIONS 40 | 41 | usage() 42 | { 43 | local optfmt="\t%-5s %s\n" 44 | exec >&2 45 | printf "Usage: %s [OPTIONS]\n" "$pgm" 46 | printf "OPTIONS:\n" 47 | printf "$optfmt" "-f" \ 48 | "Force. Do not skip any steps for any reason." 49 | exit $FAILURE 50 | } 51 | 52 | have() 53 | { 54 | type "$@" > /dev/null 2>&1 55 | } 56 | 57 | eval2() 58 | { 59 | echo "$ANSI_BLD_ON$ANSI_GRN_ON==>$ANSI_FGC_OFF $*$ANSI_BLD_OFF" 60 | eval "$@" 61 | } 62 | 63 | eval3() 64 | { 65 | echo "$ANSI_BLD_ON$ANSI_GRN_ON==>$ANSI_FGC_OFF $*$ANSI_BLD_OFF" >&3 66 | eval "$@" 67 | } 68 | 69 | ############################################################ MAIN 70 | 71 | set -e # Make all errors fatal 72 | exec 3<&1 73 | 74 | # 75 | # Process command-line options 76 | # 77 | while getopts f flag; do 78 | case "$flag" in 79 | f) FORCE=1 ;; 80 | *) usage # NOTREACHED 81 | esac 82 | done 83 | shift $(( $OPTIND - 1 )) 84 | 85 | # 86 | # Information 87 | # 88 | eval2 : "progdir='$progdir'" 89 | 90 | # 91 | # Make symlinks in .git directory 92 | # 93 | linkdir="$progdir/../.git/hooks" 94 | for file in $( find "$progdir" \ 95 | -type f -and \ 96 | -not -name '*.sh' \ 97 | -and -not -name '.*' \ 98 | -and -not -name '*[^[:alnum:]_-]*' \ 99 | | sed -e 's#.*/##' 100 | ); do 101 | [ -x "$progdir/$file" ] || continue 102 | link="$linkdir/$file" 103 | target="../../.git-hooks/$file" 104 | if [ ! "$FORCE" ] && have readlink && [ -L "$link" ]; then 105 | linktarget=$( readlink "$link" ) 106 | if [ "$linktarget" = "$target" ]; then 107 | echo "\`$link' -> \`$target'" 108 | continue 109 | fi 110 | fi 111 | eval2 ln -sfv \"\$target\" \"\$linkdir/\" 112 | done 113 | 114 | # 115 | # Make sure name/email are set 116 | # 117 | name=$( eval3 git config user.name ) || : 118 | if [ "$FORCE" -o ! "$name" ]; then 119 | default="${name:-$( id -nu )}" 120 | read -p "User name [$default]: " name 121 | git config user.name "${name:-$default}" 122 | else 123 | echo "User name: $name" 124 | fi 125 | email=$( eval3 git config user.email ) || : 126 | if [ "$FORCE" -o ! "$email" ]; then 127 | default="${email:-$( id -nu )@$( hostname )}" 128 | read -p "User email [$default]: " email 129 | git config user.email "${email:-$default}" 130 | else 131 | echo "User email: $email" 132 | fi 133 | 134 | # 135 | # Done 136 | # 137 | eval2 : SUCCESS 138 | exit $SUCCESS 139 | 140 | ################################################################################ 141 | # END 142 | ################################################################################ 143 | -------------------------------------------------------------------------------- /.git-hooks/post-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ############################################################ IDENT(1) 3 | # 4 | # $Title: Hook to run after a successful `git commit' $ 5 | # 6 | ############################################################ INFORMATION 7 | # 8 | # System requirements: git(1) xargs(1) ls(1) 9 | # 10 | ############################################################ MAIN 11 | 12 | DEBUG(){ [ ! "$DEBUG" ] || echo "DEBUG: $*"; } 13 | DEBUG "$0 $*" 14 | 15 | # Do a simple `ls -l' of recently committed files 16 | DEBUG "Listing committed files..." 17 | git diff-tree --name-only -z -r HEAD~1..HEAD | xargs -0 ls -l -- 18 | DEBUG "End List" 19 | 20 | ################################################################################ 21 | # END 22 | ################################################################################ 23 | # 24 | # $Copyright: 2015-2017 The FrauBSD Project. All rights reserved. $ 25 | # $FrauBSD: dwatch-json/.git-hooks/post-commit 2018-09-20 14:43:47 -0700 freebsdfrau $ 26 | # 27 | ################################################################################ 28 | -------------------------------------------------------------------------------- /.git-hooks/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ############################################################ IDENT(1) 3 | # 4 | # $Title: Hook to run before `git commit' $ 5 | # 6 | ############################################################ INFORMATION 7 | # 8 | # System requirements: git(1) xargs(1) 9 | # See also: .git-filters/keywords 10 | # 11 | ############################################################ MAIN 12 | 13 | DEBUG(){ [ ! "$DEBUG" ] || echo "DEBUG: $*"; } 14 | DEBUG "$0 $*" 15 | 16 | # Set keywords in modified text-files prior to commit 17 | DEBUG "Keyword modifications..." 18 | git diff --cached --name-only -z --diff-filter=ACM | 19 | xargs -0 .git-filters/keywords -- 20 | DEBUG "End List" 21 | 22 | # Update the staging files 23 | git diff --cached --name-only -z --diff-filter=ACM | 24 | xargs -0 git add -u -v -- 25 | 26 | ################################################################################ 27 | # END 28 | ################################################################################ 29 | # 30 | # $Copyright: 2015-2017 The FrauBSD Project. All rights reserved. $ 31 | # $FrauBSD: dwatch-json/.git-hooks/pre-commit 2018-09-20 14:43:47 -0700 freebsdfrau $ 32 | # 33 | ################################################################################ 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2018-2022, The FrauBSD Project 4 | All rights reserved. 5 | 6 | $FrauBSD: dwatch-json/LICENSE 2022-08-04 13:17:58 -0700 freebsdfrau $ 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright notice, this 12 | list of conditions and the following disclaimer. 13 | 14 | * Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation 16 | and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /Mk/HELP: -------------------------------------------------------------------------------- 1 | Generic Targets: 2 | noargs|all|help|targets Print this text and exit 3 | usage Print more detailed information on each target 4 | Global Building Targets: 5 | all_all Build all packages (works best on Linux) 6 | depend_all Perform `make depend' for all packages 7 | forcedepend_all Perform `make forcedepend' for all packages 8 | Global Maintenance Targets: 9 | clean_all Perform `make clean' for all packags 10 | distclean_all Perform `make distclean' for all packages 11 | pull_all Perform `make pull' for all packages 12 | commit_all Perform `make commit' for all packages 13 | Git Maintenance Targets: 14 | pull An alias to `git pull' 15 | tag_all Perform `make tag' for all packages 16 | forcetag_all Perform `make forcetag' for all packages 17 | Git Addition Targets: 18 | import Import current working directory to git 19 | commit An alias to `git commit' 20 | -------------------------------------------------------------------------------- /Mk/USAGE: -------------------------------------------------------------------------------- 1 | Generic Targets 2 | 3 | all (or no arguments) 4 | help 5 | targets 6 | Print summary information about available targets. 7 | 8 | usage 9 | Print this text and exit. 10 | 11 | Global Building Targets: 12 | 13 | all_all 14 | Performs `make all' in all package directories, attempting to 15 | build each/every package. 16 | 17 | NOTE: Some packages may fail to build on certain operating systems. 18 | For example, it is currently not possible to build a Linux 19 | RPM on FreeBSD. 20 | 21 | depend_all 22 | Performs `make depend' in all package directories, copying static 23 | file dependencies (if configured) from the `depend' tree into the 24 | given package sub-directory. 25 | 26 | forcedepend_all 27 | Performs `make forcedepend' in all package directories, forcing the 28 | copy of file dependencies (if configured) from the `depend' tree 29 | overwriting local copies in the given package sub-directory. 30 | 31 | Global Maintenance Targets: 32 | 33 | clean_all 34 | Performs `make clean' in all package directories. 35 | 36 | distclean_all 37 | Performs `make distclean' in all package directories. 38 | 39 | WARNING: This is intended to remove any/all compiled packages, 40 | returning the repository to an SCM-clean state. 41 | 42 | pull_all 43 | Performs `make pull' in all package directories. 44 | 45 | commit_all 46 | Performs `make commit' in all package directories. 47 | 48 | Git Maintenance Targets: 49 | 50 | pull 51 | An alias for `git pull'. 52 | 53 | tag_all 54 | Performs `make tag' in all package directories, tagging files for a 55 | given package to the current package version. 56 | 57 | forcetag_all 58 | Performs `make forcetag' in all package directories, tagging files 59 | for a given package to the current package version even if already 60 | tagged at a lower revision with the same tag. 61 | 62 | Git Addition Targets: 63 | 64 | commit 65 | An alias to `git commit'. 66 | 67 | import 68 | Import current working directory to git. 69 | 70 | -------------------------------------------------------------------------------- /Mk/clean_directories: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script for removing a list of directories via Makefiles $ 7 | # $Copyright: 1999-2017 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/Mk/clean_directories 2022-08-04 17:31:11 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: clean_directories PATH ... 13 | # 14 | ############################################################ GLOBALS 15 | 16 | # 17 | # Global exit status 18 | # 19 | SUCCESS=0 20 | FAILURE=1 21 | 22 | # 23 | # Utility pathnames 24 | # 25 | : ${RMDIR:=rmdir} 26 | : ${RM:=rm} 27 | 28 | ############################################################ FUNCTIONS 29 | 30 | eval2() 31 | { 32 | echo "$*" 33 | eval "$@" 34 | } 35 | 36 | ############################################################ MAIN 37 | 38 | # 39 | # Remove directory path(s) 40 | # 41 | while [ $# -ge 1 ]; do 42 | [ -d "$1" ] && eval2 $RMDIR "$1" 43 | shift 1 44 | done 45 | 46 | ################################################################################ 47 | # END 48 | ################################################################################ 49 | -------------------------------------------------------------------------------- /Mk/clean_symlinks: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script for removing a list of symbolic links via Makefiles $ 7 | # $Copyright: 1999-2017 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/Mk/clean_symlinks 2022-08-04 17:31:11 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: clean_symlinks SYMLINK_FILE SYMLINK_TARGET ... 13 | # 14 | # NB: Only the SYMLINK_FILE is deleted 15 | # 16 | ############################################################ GLOBALS 17 | 18 | # 19 | # Global exit status 20 | # 21 | SUCCESS=0 22 | FAILURE=1 23 | 24 | # 25 | # Utility pathnames 26 | # 27 | : ${RM:=rm} 28 | 29 | ############################################################ FUNCTIONS 30 | 31 | eval2() 32 | { 33 | echo "$*" 34 | eval "$@" 35 | } 36 | 37 | ############################################################ MAIN 38 | 39 | # 40 | # Remove symlink_file path(s) 41 | # 42 | while [ $# -ge 2 ]; do 43 | eval2 $RM -f "$1" 44 | shift 2 45 | done 46 | 47 | ################################################################################ 48 | # END 49 | ################################################################################ 50 | -------------------------------------------------------------------------------- /Mk/die: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script for generating errors from Makefiles $ 7 | # $Copyright: 1999-2017 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/Mk/die 2022-08-04 17:31:11 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: die [FORMAT [ARGUMENT ...]] 13 | # 14 | ############################################################ GLOBALS 15 | 16 | # 17 | # Global exit status 18 | # 19 | SUCCESS=0 20 | FAILURE=1 21 | 22 | ############################################################ FUNCTIONS 23 | 24 | # err FORMAT [ARGUMENT ...] 25 | # 26 | # Print a message to stderr. 27 | # 28 | err() 29 | { 30 | local fmt="$1" 31 | shift 1 # fmt 32 | [ "$fmt" ] || return $SUCCESS 33 | printf "$fmt\n" "$@" >&2 34 | } 35 | 36 | # die [FORMAT [ARGUMENT ...]] 37 | # 38 | # Optionally print a message to stderr before exiting with failure status. 39 | # 40 | die() 41 | { 42 | err "$@" 43 | exit $FAILURE 44 | } 45 | 46 | ############################################################ MAIN 47 | 48 | die "$@" 49 | 50 | ################################################################################ 51 | # END 52 | ################################################################################ 53 | -------------------------------------------------------------------------------- /Mk/git_import: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script for importing current working directory to git $ 7 | # $Copyright: 1999-2019 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/Mk/git_import 2022-08-04 17:31:11 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: git_import [-a] 13 | # 14 | ############################################################ GLOBALS 15 | 16 | # 17 | # Global exit status 18 | # 19 | SUCCESS=0 20 | FAILURE=1 21 | 22 | # 23 | # Command-line options 24 | # 25 | AUTO= # -a 26 | 27 | # 28 | # Utility pathnames 29 | # 30 | : ${GIT:=git} 31 | 32 | # 33 | # Miscellaneous 34 | # 35 | MESSAGE= 36 | 37 | ############################################################ FUNCTIONS 38 | 39 | eval2() 40 | { 41 | echo "$*" 42 | eval "$@" 43 | } 44 | 45 | ############################################################ MAIN 46 | 47 | set -e 48 | 49 | # 50 | # Process command-line options 51 | # 52 | while getopts a flag; do 53 | case "$flag" in 54 | a) AUTO=1 ;; 55 | *) echo "Usage: ${0##*/} [-a]" >&2 56 | exit $FAILURE 57 | esac 58 | done 59 | shift $(( $OPTIND - 1 )) 60 | 61 | # 62 | # Clean before import to prevent importing +MANIFEST et al. 63 | # 64 | make clean 65 | 66 | # 67 | # Automation 68 | # 69 | if [ "$AUTO" ]; then 70 | NAME=$( git config user.name ) 71 | MESSAGE="Autoimport by $NAME" 72 | fi 73 | 74 | # 75 | # Import src directory without verification 76 | # 77 | if [ -d "$SRCDIR" ]; then 78 | echo $GIT add -v "$SRCDIR" 79 | added=$( $GIT add -v "$SRCDIR" ) 80 | if [ "$added" ]; then 81 | [ ! "$MESSAGE" ] || printf "Commit message:\n%s\n\n" "$MESSAGE" 82 | eval2 $GIT commit --no-verify ${MESSAGE:+-m \"\$MESSAGE\"} 83 | fi 84 | fi 85 | 86 | # 87 | # Clean everything else to prevent importing compiled package 88 | # 89 | make distclean 90 | 91 | # 92 | # Import everything else 93 | # 94 | echo $GIT add -v . 95 | added=$( $GIT add -v . ) 96 | if [ "$added" ]; then 97 | [ ! "$MESSAGE" ] || printf "Commit message:\n%s\n\n" "$MESSAGE" 98 | eval2 $GIT commit ${MESSAGE:+-m \"\$MESSAGE\"} 99 | fi 100 | 101 | ################################################################################ 102 | # END 103 | ################################################################################ 104 | -------------------------------------------------------------------------------- /Mk/git_tag: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script for tagging git repositories from Makefiles $ 7 | # $Copyright: 1999-2022 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/Mk/git_tag 2022-08-04 17:31:11 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: git_tag [OPTIONS] TAG 13 | # OPTIONS: 14 | # -f Force. Allow tagging of files already tagged at a lower revision 15 | # with the same tag. 16 | # 17 | ############################################################ GLOBALS 18 | 19 | pgm="${0##*/}" # Program basename 20 | 21 | # 22 | # Global exit status 23 | # 24 | SUCCESS=0 25 | FAILURE=1 26 | 27 | # 28 | # OS Glue 29 | # 30 | : ${UNAME_s:=$( uname -s )} 31 | 32 | # 33 | # Utility pathnames 34 | # 35 | : ${CP:=cp} 36 | : ${GIT:=git} 37 | 38 | # 39 | # Command-line options 40 | # 41 | DELETE= # -d 42 | FORCE= # -f 43 | LIST= # -l 44 | UNPUSH= # -u 45 | 46 | ############################################################ FUNCTIONS 47 | 48 | eval2() 49 | { 50 | echo "$*" 51 | eval "$@" 52 | } 53 | 54 | ############################################################ FUNCTIONS 55 | 56 | if ! type realpath > /dev/null 2>&1; then 57 | case "$UNAME_s" in 58 | Darwin) 59 | realpath() 60 | { 61 | perl -le 'use Cwd; print Cwd::abs_path(@ARGV)' -- "$@" 62 | } 63 | ;; 64 | *) 65 | realpath() 66 | { 67 | readlink -f "$@" 68 | } 69 | esac 70 | fi 71 | 72 | ############################################################ MAIN 73 | 74 | # 75 | # Process command-line arguments 76 | # 77 | while getopts dflu flag; do 78 | case "$flag" in 79 | d) DELETE=1 ;; 80 | f) FORCE=1 ;; 81 | l) LIST=1 ;; 82 | u) UNPUSH=1 ;; 83 | esac 84 | done 85 | shift $(( $OPTIND - 1 )) 86 | 87 | # 88 | # Validate number of arguments 89 | # 90 | [ $# -lt 1 ] && exit $SUCCESS 91 | [ "$1" ] || exit $SUCCESS 92 | 93 | # 94 | # Process `-l' flag 95 | # 96 | if [ "$LIST" ]; then 97 | eval2 $GIT tag -l "$@" 98 | exit 99 | fi 100 | 101 | # 102 | # Process `-d' flag 103 | # 104 | if [ "$DELETE" ]; then 105 | eval2 $GIT tag -d "$@" 106 | rv=$? 107 | [ "$UNPUSH" ] || exit $rv 108 | fi 109 | 110 | # 111 | # Process `-u' flag 112 | # 113 | if [ "$UNPUSH" ]; then 114 | for tag in "$@"; do 115 | eval2 $GIT push origin ":refs/tags/$tag" 116 | done 117 | exit 118 | fi 119 | 120 | # 121 | # Build commit message 122 | # 123 | path=$( realpath "$0" ) 124 | PKGCENTER="${path%"/Mk/$pgm"}" 125 | path="${PWD#"${PKGCENTER%/*}/"}" 126 | commitmsg="$pgm${FORCE:+ -f} in $path" 127 | commitmsg=$( echo "$commitmsg" | awk 'gsub(/'\''/,"&\\\\&&")||1' ) 128 | 129 | # 130 | # Tag everything 131 | # 132 | eval2 $GIT tag -a ${FORCE:+-f} -m "'$commitmsg'" "$@" 133 | 134 | ################################################################################ 135 | # END 136 | ################################################################################ 137 | -------------------------------------------------------------------------------- /Mk/make_directories: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script for creating a list of directories from Makefiles $ 7 | # $Copyright: 1999-2017 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/Mk/make_directories 2022-08-04 17:31:11 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: make_directories PATH ... 13 | # 14 | ############################################################ GLOBALS 15 | 16 | # 17 | # Global exit status 18 | # 19 | SUCCESS=0 20 | FAILURE=1 21 | 22 | # 23 | # Utility pathnames 24 | # 25 | : ${MKDIR:=mkdir} 26 | : ${TOUCH:=touch} 27 | 28 | ############################################################ FUNCTIONS 29 | 30 | eval2() 31 | { 32 | echo "$*" 33 | eval "$@" 34 | } 35 | 36 | ############################################################ MAIN 37 | 38 | # 39 | # Check for sentinel 40 | # 41 | [ -e .dirs_created ] && exit $SUCCESS 42 | 43 | # 44 | # Validate number of arguments 45 | # 46 | if [ $# -lt 1 ]; then 47 | $TOUCH .dirs_created 48 | exit 49 | fi 50 | 51 | # 52 | # Create directory path(s) 53 | # 54 | set -e 55 | while [ $# -ge 1 ]; do 56 | eval2 $MKDIR -p "$1" 57 | shift 1 58 | done 59 | 60 | # 61 | # Create sentinel 62 | # 63 | $TOUCH .dirs_created 64 | 65 | ################################################################################ 66 | # END 67 | ################################################################################ 68 | -------------------------------------------------------------------------------- /Mk/make_stage: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script for managing staging dependencies from Makefiles $ 7 | # $Copyright: 1999-2022 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/Mk/make_stage 2022-08-04 17:31:11 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: make_stage [OPTIONS] SOURCE_FILE DEST_FILE ... 13 | # OPTIONS: 14 | # -f Force. Attempt to copy SOURCE_FILE even if it doesn't exist. 15 | # 16 | # NB: If SOURCE_FILE begins with `-g' then it `-g' is stripped and the 17 | # remaining text is treated as a glob. 18 | # 19 | ############################################################ GLOBALS 20 | 21 | # 22 | # Global exit status 23 | # 24 | SUCCESS=0 25 | FAILURE=1 26 | 27 | # 28 | # Utility pathnames 29 | # 30 | : ${CP:=cp} 31 | : ${MKDIR:=mkdir} 32 | 33 | # 34 | # Command-line arguments 35 | # 36 | FROM= 37 | TO= 38 | 39 | # 40 | # Command-line options 41 | # 42 | FORCE= 43 | 44 | # 45 | # Miscellaneous 46 | # 47 | DESTDIR= 48 | 49 | ############################################################ FUNCTIONS 50 | 51 | eval2() 52 | { 53 | echo "$*" 54 | eval "$@" 55 | } 56 | 57 | ############################################################ MAIN 58 | 59 | # 60 | # Process command-line options 61 | # 62 | while getopts f flag; do 63 | case "$flag" in 64 | f) FORCE=1 ;; 65 | esac 66 | done 67 | shift $(( $OPTIND - 1 )) 68 | 69 | # 70 | # Validate number of arguments 71 | # 72 | [ $# -ge 2 ] || exit $SUCCESS 73 | 74 | # 75 | # Copy staging dependencies 76 | # 77 | set -e 78 | while [ $# -ge 2 ]; do 79 | FROM="$1" TO="$2" 80 | shift 2 81 | case "$FROM" in 82 | \(*\)) 83 | glob=1 84 | FROM="${FROM#(}" 85 | FROM="${FROM%)}" 86 | ;; 87 | *) 88 | glob= 89 | esac 90 | if [ "$glob" ]; then 91 | FROM="${FROM#-g}" 92 | [ -d "$TO" ] || eval2 $MKDIR -p "$TO" 93 | for from in $FROM; do 94 | name="${from##*/}" 95 | to="$TO/$name" 96 | [ "$FORCE" ] || [ "$from" -nt "$to" -o ! -e "$to" ] || 97 | continue 98 | eval2 $CP -f "$from" "$to" 99 | done 100 | else 101 | case "$TO" in */*) DESTDIR="${TO%/*}" 102 | [ -d "$DESTDIR" ] || eval2 $MKDIR -p "$DESTDIR" ;; 103 | esac 104 | [ "$FORCE" ] || [ "$FROM" -nt "$TO" -o ! -e "$TO" ] || continue 105 | eval2 $CP -f "$FROM" "$TO" 106 | fi 107 | done 108 | 109 | ################################################################################ 110 | # END 111 | ################################################################################ 112 | -------------------------------------------------------------------------------- /Mk/make_symlinks: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script for creating a list of symbolic links from Makefiles $ 7 | # $Copyright: 1999-2017 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/Mk/make_symlinks 2022-08-04 17:31:11 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: make_symlinks SYMLINK_FILE SYMLINK_TARGET ... 13 | # 14 | ############################################################ GLOBALS 15 | 16 | # 17 | # Global exit status 18 | # 19 | SUCCESS=0 20 | FAILURE=1 21 | 22 | # 23 | # Utility pathnames 24 | # 25 | : ${LN:=ln} 26 | : ${TOUCH:=touch} 27 | 28 | ############################################################ FUNCTIONS 29 | 30 | eval2() 31 | { 32 | echo "$*" 33 | eval "$@" 34 | } 35 | 36 | ############################################################ MAIN 37 | 38 | # 39 | # Check sentinel 40 | # 41 | [ -e .symlinks_created ] && exit $SUCCESS 42 | 43 | # 44 | # Validate number of arguments 45 | # 46 | if [ $# -lt 2 ]; then 47 | $TOUCH .symlinks_created 48 | exit 49 | fi 50 | 51 | # 52 | # Create symbolic link(s) 53 | # 54 | set -e 55 | while [ $# -ge 2 ]; do 56 | eval2 $LN -sf "$2" "$1" 57 | shift 2 58 | done 59 | 60 | # 61 | # Create sentinel 62 | # 63 | $TOUCH .symlinks_created 64 | 65 | ################################################################################ 66 | # END 67 | ################################################################################ 68 | -------------------------------------------------------------------------------- /Mk/pkgcenter_readconf: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script for reading directives from pkgcenter.conf files $ 7 | # $Copyright: 1999-2017 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/Mk/pkgcenter_readconf 2022-08-04 17:31:11 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: pkgcenter_readconf PKGCENTER_CONF DIRECTIVE 13 | # 14 | ############################################################ GLOBALS 15 | 16 | # 17 | # Global exit status 18 | # 19 | SUCCESS=0 20 | FAILURE=1 21 | 22 | # 23 | # Utility pathnames 24 | # 25 | : ${AWK:=awk} 26 | 27 | # 28 | # Command-line arguments 29 | # 30 | PKGCENTER_CONF="$1" 31 | DIRECTIVE="$2" 32 | 33 | ############################################################ MAIN 34 | 35 | # 36 | # Validate command-line arguments 37 | # 38 | [ -f "$PKGCENTER_CONF" ] || exit $SUCCESS 39 | 40 | # 41 | # Read configuration file 42 | # 43 | echo "Reading $DIRECTIVE from $PKGCENTER_CONF..." >&2 44 | . "$PKGCENTER_CONF" > /dev/null && 45 | eval echo '"${'"$DIRECTIVE"'}"' | $AWK '!/^[[:space:]]*(#|$)/' 46 | 47 | ################################################################################ 48 | # END 49 | ################################################################################ 50 | -------------------------------------------------------------------------------- /Mk/xargs: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script for using xargs(1) from Makefiles $ 7 | # $Copyright: 1999-2017 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/Mk/xargs 2022-08-04 17:31:11 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: xargs ... 13 | # 14 | ############################################################ GLOBALS 15 | 16 | # 17 | # Utility pathnames 18 | # 19 | : ${UNAME:=uname} 20 | : ${XARGS:=xargs} 21 | 22 | # 23 | # OS Glue 24 | # 25 | case "${UNAME_s:=$( uname -s )}" in 26 | Linux|CYGWIN*) 27 | GNU_XARGS=1 ;; 28 | *) 29 | GNU_XARGS= ;; 30 | esac 31 | 32 | ############################################################ MAIN 33 | 34 | $XARGS ${GNU_XARGS:+-r} "$@" 35 | 36 | ################################################################################ 37 | # END 38 | ################################################################################ 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [//]: # ($FrauBSD: dwatch-json/README.md 2022-08-04 13:22:25 -0700 freebsdfrau $) 2 | 3 | # Welcome to [FrauBSD.org/dwatch-json](https://fraubsd.org/dwatch-json)! 4 | 5 | DTrace modules/daemons for FreeBSD's dwatch(1) to produce JSON logs 6 | 7 | ## Foreword 8 | 9 | The following is required before using `git commit` in this project. 10 | 11 | > `$ .git-hooks/install.sh` 12 | 13 | This will ensure the FrauBSD keyword is expanded/updated for each commit. 14 | 15 | -------------------------------------------------------------------------------- /dwatch-json-io.conf: -------------------------------------------------------------------------------- 1 | # vi: set filetype=sh :: Vi/ViM 2 | ############################################################ IDENT(1) 3 | # 4 | # $Title: Configuration file for `dwatch -X json-io-config[-raw] ...' $ 5 | # $Copyright: 2018-2022 Devin Teske. All rights reserved. $ 6 | # $FrauBSD: dwatch-json/dwatch-json-io.conf 2022-08-22 15:36:11 -0700 freebsdfrau $ 7 | # 8 | ############################################################ INFORMATION 9 | # 10 | # Output sample: 11 | # {"report_type":"$REPORT_TYPE","hostname":"$HOSTNAME","epoch":1538360226, 12 | # "name":"...",...} 13 | # 14 | ############################################################ DEFAULTS 15 | 16 | # 17 | # DTrace probe 18 | # Default: profile-10s 19 | # 20 | #PROBE= 21 | 22 | # 23 | # Report handle for kafka consumer 24 | # Default: ${PROFILE%-raw} 25 | # 26 | #REPORT_TYPE= 27 | 28 | # 29 | # Hostname for kafka consumer 30 | # Default: $HOSTNAME 31 | # 32 | #HOSTNAME= 33 | 34 | # 35 | # DTrace predicate for all stats 36 | # Default: (set by `-k name' and/or `-t test' dwatch options) 37 | # Example: execname == "sshd" 38 | # 39 | #EVENT_TEST= 40 | 41 | ############################################################ ENDPOINTS 42 | 43 | # 44 | # For each variable, you will get: 45 | # Counting specific conditions. 46 | # 47 | # Any bytes matching $EVENT_TEST that fail to match the DTrace clause defined 48 | # in each variable will increment the unmatched globals. 49 | # 50 | 51 | #diskA='this->device_entry == "ada0"' 52 | #diskB='this->device_entry == "ada1"' 53 | 54 | ################################################################################ 55 | # END 56 | ################################################################################ 57 | -------------------------------------------------------------------------------- /dwatch-json-net.conf: -------------------------------------------------------------------------------- 1 | # vi: set filetype=sh :: Vi/ViM 2 | ############################################################ IDENT(1) 3 | # 4 | # $Title: Configuration file for `dwatch -X json-net-config[-raw] ...' $ 5 | # $Copyright: 2018 Devin Teske. All rights reserved. $ 6 | # $FrauBSD: dwatch-json/dwatch-json-net.conf 2018-10-01 16:22:27 -0700 freebsdfrau $ 7 | # 8 | ############################################################ INFORMATION 9 | # 10 | # Output sample: 11 | # {"report_type":"$REPORT_TYPE","hostname":"$HOSTNAME","epoch":1538360226, 12 | # "tcp_rcvd":12,"tcp_sent":34,"udp_rcvd":56,"udp_sent":78[,...]} 13 | # 14 | ############################################################ DEFAULTS 15 | 16 | # 17 | # DTrace probe 18 | # Default: profile-10s 19 | # 20 | #PROBE= 21 | 22 | # 23 | # Report handle for kafka consumer 24 | # Default: ${PROFILE%-raw} 25 | # 26 | #REPORT_TYPE= 27 | 28 | # 29 | # Hostname for kafka consumer 30 | # Default: $HOSTNAME 31 | # 32 | #HOSTNAME= 33 | 34 | # 35 | # DTrace predicate for all stats 36 | # Default: (set by `-k name' and/or `-t test' dwatch options) 37 | # Example: execname == "sshd" 38 | # 39 | #EVENT_TEST= 40 | 41 | ############################################################ ENDPOINTS 42 | 43 | # 44 | # For each variable, you will get: 45 | # _tcp_rcvd 46 | # _tcp_sent 47 | # _udp_rcvd 48 | # _udp_sent 49 | # Counting the bytes for specific conditions. 50 | # 51 | # Any bytes matching $EVENT_TEST that fail to match the DTrace clause defined 52 | # in each variable will increment the {tcp,udp}_{rcvd,sent} globals. 53 | # 54 | 55 | #hostA='this->remote == "1.2.3.4"' 56 | #hostB='this->remote == "2.3.4.5"' 57 | #hostC='this->remote == "3.4.5.6"' 58 | 59 | #serviceA='this->lport == 22' 60 | #serviceB='this->lport == 80 || this->lport == 443' 61 | #serviceC='this->local == "1.2.3.4" && this->lport == 8080' 62 | 63 | #jail0="jid == 0" # not a jail but the host 64 | #jail1="jid == $( jls -j jail1 jid )" || exit 65 | #jail2="jid == $( jls -j jail2 jid ) && execname == \"sshd\"" || exit 66 | 67 | ################################################################################ 68 | # END 69 | ################################################################################ 70 | -------------------------------------------------------------------------------- /freebsd/Mk/HELP_FREEBSD: -------------------------------------------------------------------------------- 1 | Generic Targets: 2 | noargs|all|help|targets Print this text and exit 3 | usage Print more detailed information on each target 4 | Global Building Targets: 5 | all_freebsd Build all packages 6 | depend_freebsd Perform `make depend' for all packages 7 | forcedepend_freebsd Perform `make forcedepend' for all packages 8 | Global Maintenance Targets: 9 | clean_freebsd Perform `make clean' for all packags 10 | distclean_freebsd Perform `make distclean' for all packages 11 | pull_freebsd Perform `make pull' for all packages 12 | commit_freebsd Perform `make commit' for all packages 13 | Git Maintenance Targets: 14 | pull An alias to `git pull' 15 | tag_freebsd Perform `make tag' for all packages 16 | forcetag_freebsd Perform `make forcetag' for all packages 17 | taglist_freebsd Perform `make taglist' for all packages 18 | Git Addition Targets: 19 | import Import current working directory to git 20 | commit An alias to `git commit' 21 | -------------------------------------------------------------------------------- /freebsd/Mk/HELP_PACKAGE: -------------------------------------------------------------------------------- 1 | Generic Targets: 2 | help|targets Print this text and exit 3 | usage Print more detailed information on each target 4 | Package Building Targets: 5 | noargs|all A pseudonym for: dirs symlinks depend package 6 | dirs Create pre-configured directories, if any 7 | symlinks Create pre-configured symbolic-links, if any 8 | depend Copy pre-configured file dependencies, if any 9 | forcedepend Like depend, but ignore local modification times 10 | package Compile MANIFEST into +MANIFEST and generate archive 11 | Package Maintenance Targets: 12 | clean Delete generated files, pre-configured symlinks/dirs 13 | distclean Like clean but also deletes the compiled package 14 | Git Maintenance Targets: 15 | pull An alias to `git pull' 16 | tag Tag git revisions given package name in MANIFEST 17 | forcetag Like tag but always update tag to latest revisions 18 | taglist List tags for the given package name in MANIFEST 19 | Git Addition Targets: 20 | import Import current working directory to git 21 | commit An alias to `git commit' 22 | -------------------------------------------------------------------------------- /freebsd/Mk/USAGE_FREEBSD: -------------------------------------------------------------------------------- 1 | Generic Targets 2 | 3 | all (or no arguments) 4 | help 5 | targets 6 | Print summary information about available targets. 7 | 8 | usage 9 | Print this text and exit. 10 | 11 | Global Building Targets: 12 | 13 | all_freebsd 14 | Performs `make all' in all package directories, attempting to 15 | build each/every package. 16 | 17 | depend_freebsd 18 | Performs `make depend' in all package directories, copying static 19 | file dependencies (if configured) from the `depend' tree into the 20 | given package sub-directory. 21 | 22 | forcedepend_freebsd 23 | Performs `make forcedepend' in all package directories, forcing the 24 | copy of file dependencies (if configured) from the `depend' tree 25 | overwriting local copies in the given package sub-directory. 26 | 27 | Global Maintenance Targets: 28 | 29 | clean_freebsd 30 | Performs `make clean' in all package directories. 31 | 32 | distclean_freebsd 33 | Performs `make distclean' in all package directories. 34 | 35 | WARNING: This is intended to remove any/all compiled packages, 36 | returning the repository to an SCM-clean state. 37 | 38 | pull_freebsd 39 | Performs `make pull' in all package directories. 40 | 41 | commit_freebsd 42 | Performs `make commit' in all package directories. 43 | 44 | Git Maintenance Targets: 45 | 46 | pull 47 | An alias for `git pull'. 48 | 49 | tag_freebsd 50 | Performs `make tag' in all package directories, tagging files for a 51 | given package to the current package version. 52 | 53 | forcetag_freebsd 54 | Performs `make forcetag' in all package directories, tagging files 55 | for a given package to the current package version even if already 56 | tagged at a lower revision with the same tag. 57 | 58 | taglist_freebsd 59 | Performs `make taglist' in all package directories, listing tags 60 | for each package. 61 | 62 | Git Addition Targets: 63 | 64 | commit 65 | An alias to `git commit'. 66 | 67 | import 68 | Import current working directory to git. 69 | 70 | -------------------------------------------------------------------------------- /freebsd/Mk/USAGE_PACKAGE: -------------------------------------------------------------------------------- 1 | Generic Targets 2 | 3 | help 4 | targets 5 | Print summary information about available targets. 6 | 7 | usage 8 | Print this text and exit. 9 | 10 | Package Building Targets: 11 | 12 | all (or no arguments) 13 | A pseudonym for the separate targets (in the order shown): dirs, 14 | symlinks, depend, and package (each described below). 15 | 16 | dirs 17 | Creates statically configured directories. This feature is used 18 | most often when a package contains empty directories which should 19 | not be committed to CVS. By default, DIRS is not configured. 20 | 21 | symlinks 22 | Creates statically configured symbolic-links. This feature is used 23 | most often when a package contains symbolic-links which should not 24 | be committed to CVS. By default, SYMLINKS is not configured. 25 | 26 | depend 27 | Copies statically configured file dependencies from source to 28 | destination when the source exists and is newer than the 29 | destination. This feature is used most often when a package 30 | contains files in-common with one or more releases for other 31 | Operating Systems. By default, DEPEND is not configured. 32 | 33 | forcedepend 34 | Like depend, but forces the copying of all configured file 35 | dependencies. Useful when you want to make sure that your local 36 | tree is up-to-date with the latest external dependencies. Unlike 37 | depend, if any dependency source file is missing an error is 38 | generated causing premature termination. 39 | 40 | package 41 | Compiles PLIST into +CONTENTS and packages up the source directory, 42 | producing a compressed tar archive in the current working directory 43 | named appropriately given the name provided in the PLIST file. 44 | 45 | Package Maintenance Targets: 46 | 47 | clean 48 | Delete generated files, statically configured symbolic-links and 49 | directories that were created previously. 50 | 51 | distclean 52 | Performs a clean (see above) and then deletes compressed tar 53 | archives in the current working directory. 54 | 55 | Git Maintenance Targets: 56 | 57 | pull 58 | An alias for `git pull'. 59 | 60 | tag 61 | Tag current git revisions with an appropriate tag given the package 62 | name and version in the MANIFEST file. 63 | 64 | forcetag 65 | Like tag but force tagging of files even if already tagged at a 66 | lower revision with the same tag. 67 | 68 | taglist 69 | List tags for the given package name in the MANIFEST file. 70 | 71 | Git Addition Targets: 72 | 73 | commit 74 | An alias to `git commit'. 75 | 76 | import 77 | Import current working directory to git. 78 | 79 | -------------------------------------------------------------------------------- /freebsd/Mk/convert: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script to convert packing-list format(s) $ 7 | # $Copyright: 1999-2017 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/freebsd/Mk/convert 2022-08-04 17:31:11 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: convert [-fh] input [output [stagedir]] 13 | # OPTIONS: 14 | # -f Force. Allow overwriting files that already exist. 15 | # -h Print this message to stderr and exit. 16 | # 17 | ############################################################ INCLUDES 18 | 19 | progdir="${0%/*}" 20 | . "$progdir/manifest.subr" || exit 21 | 22 | ############################################################ GLOBALS 23 | 24 | pgm="${0##*/}" # Program basename 25 | 26 | # 27 | # Command-line options 28 | # 29 | FORCE= # -f 30 | 31 | ############################################################ FUNCTIONS 32 | 33 | # err FORMAT [ARGUMENT ...] 34 | # 35 | # Print a message to stderr. 36 | # 37 | err() 38 | { 39 | local fmt="$1" 40 | shift 1 # fmt 41 | [ "$fmt" ] || return $SUCCESS 42 | printf "$fmt\n" "$@" >&2 43 | } 44 | 45 | # die [FORMAT [ARGUMENT ...]] 46 | # 47 | # Optionally print a message to stderr before exiting with failure status. 48 | # 49 | die() 50 | { 51 | err "$@" 52 | exit $FAILURE 53 | } 54 | 55 | # usage 56 | # 57 | # Prints a short syntax statement and exits. 58 | # 59 | usage() 60 | { 61 | err "Usage: %s [-fh] input [output [stagedir]]" "$pgm" 62 | local optfmt="\t%-7s%s" 63 | err "OPTIONS:" 64 | err "$optfmt" "-f" "Force. Allow overwriting files that already exist." 65 | err "$optfmt" "-h" "Print this message to stderr and exit." 66 | die 67 | } 68 | 69 | ############################################################ MAIN 70 | 71 | # 72 | # Process command-line options 73 | # 74 | while getopts hoaf flag; do 75 | case "$flag" in 76 | h|\?) usage ;; 77 | f) FORCE=1 ;; 78 | esac 79 | done 80 | shift $(( $OPTIND - 1 )) 81 | 82 | # 83 | # Validate number of arguments 84 | # 85 | [ $# -gt 0 ] || usage 86 | [ $# -le 3 ] || usage 87 | 88 | # 89 | # Process command-line arguments 90 | # 91 | INPUT="$1" OUTPUT="$2" STAGEDIR="$3" 92 | 93 | # 94 | # Convert packing-list format 95 | # 96 | case "$INPUT" in 97 | *PLIST|*CONTENTS) die "Conversion to MANIFEST currently unsupported" ;; 98 | *) # MANIFEST 99 | manifest_read "$INPUT" || exit 100 | if ! manifest_read "$INPUT" || [ ! "$_keys" ]; then 101 | err "ERROR: Unable to parse JSON input file \`%s'" "$INPUT" 102 | die "ERROR: Exiting" 103 | fi 104 | 105 | if [ ! "$OUTPUT" ]; then 106 | case "$INPUT" in 107 | */*) OUTPUT="${INPUT%/*}/PLIST" ;; 108 | *) OUTPUT="PLIST" 109 | esac 110 | fi 111 | echo "Converting $INPUT to $OUTPUT for pkg_tools..." 112 | 113 | if [ ! "$STAGEDIR" ]; then 114 | case "$OUTPUT" in 115 | */*) STAGEDIR="${OUTPUT%/*}" ;; 116 | *) STAGEDIR="." 117 | esac 118 | fi 119 | STAGEDIR="${STAGEDIR%/}" 120 | echo "Auxiliary files will be created in \`$STAGEDIR'" 121 | 122 | IGNORE= 123 | 124 | # 125 | # +COMMENT 126 | # 127 | if [ "$comment" ]; then 128 | FILE="$STAGEDIR/+COMMENT" 129 | echo "==> Creating ${FILE##*/}" 130 | if [ -e "$FILE" ]; then 131 | err "ERROR: File \`%s' already exists" "$FILE" 132 | [ "$FORCE" ] || 133 | die "ERROR: Exiting (use \`-f' to override)" 134 | err "ERROR: Proceeding anyway (\`-f' was passed)" 135 | fi 136 | if ! echo "$comment" > "$FILE"; then 137 | err "ERROR: Could not create file \`%s'" "$FILE" 138 | die "ERROR: Exiting" 139 | fi 140 | IGNORE="$IGNORE ${FILE##*/}" 141 | fi 142 | 143 | # 144 | # +DESC 145 | # 146 | if [ "$desc" ]; then 147 | FILE="$STAGEDIR/+DESC" 148 | echo "==> Creating ${FILE##*/}" 149 | if [ -e "$FILE" ]; then 150 | err "ERROR: File \`%s' already exists" "$FILE" 151 | [ "$FORCE" ] || 152 | die "ERROR: Exiting (use \`-f' to override)" 153 | err "ERROR: Proceeding anyway (\`-f' was passed)" 154 | fi 155 | replaceall "$desc" "\\n" "$NL" desc 156 | if ! echo "$desc" > "$FILE"; then 157 | err "ERROR: Could not create file \`%s'" "$FILE" 158 | die "ERROR: Exiting" 159 | fi 160 | IGNORE="$IGNORE ${FILE##*/}" 161 | fi 162 | 163 | # 164 | # +DISPLAY 165 | # 166 | if [ "$message" ]; then 167 | FILE="$STAGEDIR/+DISPLAY" 168 | echo "==> Creating ${FILE##*/}" 169 | if [ -e "$FILE" ]; then 170 | err "ERROR: File \`%s' already exists" "$FILE" 171 | [ "$FORCE" ] || 172 | die "ERROR: Exiting (use \`-f' to override)" 173 | err "ERROR: Proceeding anyway (\`-f' was passed)" 174 | fi 175 | replaceall "$message" "\\n" "$NL" message 176 | if ! echo "$message" > "$FILE"; then 177 | err "ERROR: Could not create file \`%s'" "$FILE" 178 | die "ERROR: Exiting" 179 | fi 180 | IGNORE="$IGNORE ${FILE##*/}" 181 | fi 182 | 183 | # 184 | # +{POST-,}{DE,}INSTALL scripts 185 | # 186 | n=1 187 | while [ $n -le ${scripts_len:-0} ]; do 188 | eval file=\"\$scripts_$n\" script=\"\$scripts_${n}_value\" 189 | n=$(( $n + 1 )) 190 | case "$file" in 191 | install) FILE=+INSTALL ;; 192 | deinstall) FILE=+DEINSTALL ;; 193 | pre-install) FILE=+INSTALL ;; 194 | post-install) FILE=+POST-INSTALL ;; 195 | pre-deinstall) FILE=+DEINSTALL ;; 196 | post-deinstall) FILE=+POST-DEINSTALL ;; 197 | *) continue 198 | esac 199 | FILE="$STAGEDIR/$FILE" 200 | echo "==> Creating ${FILE##*/}" 201 | if [ -e "$FILE" ]; then 202 | err "ERROR: File \`%s' already exists" "$FILE" 203 | [ "$FORCE" ] || 204 | die "ERROR: Exiting (use \`-f' to override)" 205 | err "ERROR: Proceeding anyway (\`-f' was passed)" 206 | fi 207 | replaceall "$script" "\\n" "$NL" script 208 | if ! echo "#!/bin/sh" > "$FILE"; then 209 | err "ERROR: Could not create file \`%s'" "$FILE" 210 | die "ERROR: Exiting" 211 | fi 212 | if ! echo "$script" >> "$FILE"; then 213 | err "ERROR: Could not append to file \`%s'" "$FILE" 214 | die "ERROR: Exiting" 215 | fi 216 | if ! chmod +x "$FILE"; then 217 | err "ERROR: Could not make \`%s' executable" "$FILE" 218 | die "ERROR: Exiting" 219 | fi 220 | IGNORE="$IGNORE ${FILE##*/}" 221 | done 222 | 223 | # 224 | # PLIST ($OUTPUT) 225 | # 226 | FILE="$OUTPUT" 227 | echo "==> Creating ${FILE##*/}" 228 | if [ -e "$FILE" ]; then 229 | err "ERROR: File \`%s' already exists" "$FILE" 230 | [ "$FORCE" ] || die "ERROR: Exiting (use \`-f' to override)" 231 | err "ERROR: Proceeding anyway (\`-f' was passed)" 232 | fi 233 | if ! echo "@comment PKG_FORMAT_REVISION:1.1" > "$FILE"; then 234 | err "ERROR: Could not create file \`%s'" "$FILE" 235 | die "ERROR: Exiting" 236 | fi 237 | if ! cat <<-EOF >> "$FILE" 238 | @name $name-$version 239 | @comment ORIGIN:$origin 240 | @owner root 241 | @group wheel 242 | @cwd / 243 | EOF 244 | then 245 | err "ERROR: Could not append to file \`%s'" "$FILE" 246 | die "ERROR: Exiting" 247 | fi 248 | n=1 249 | while [ $n -le ${deps_len:-0} ]; do 250 | eval dep=\"\$deps_$n\" deporigin= 251 | eval dep_len=\"\$deps_${n}_len\" k=1 252 | while [ $k -le ${dep_len:-0} ]; do 253 | eval kk=\"\$deps_${n}_$k\" 254 | eval kv=\"\$deps_${n}_${k}_value\" 255 | case "$kk" in 256 | origin) deporigin="$kv" ;; 257 | version) dep="$dep-$kv" ;; 258 | esac 259 | k=$(( $k + 1 )) 260 | done 261 | echo "@pkgdep $dep" 262 | echo "@comment DEPORIGIN:$deporigin" 263 | n=$(( $n + 1 )) 264 | done >> "$FILE" || { 265 | err "ERROR: Could not append to file \`%s'" "$FILE" 266 | die "ERROR: Exiting" 267 | } 268 | n=1 269 | while [ $n -le ${files_len:-0} ]; do 270 | eval file=\"\$files_$n\" 271 | echo "${file#/}" 272 | n=$(( $n + 1 )) 273 | done >> "$FILE" || { 274 | err "ERROR: Could not append to file \`%s'" "$FILE" 275 | die "ERROR: Exiting" 276 | } 277 | n=1 278 | while [ $n -le ${directories_len:-0} ]; do 279 | eval directory=\"\$directories_$n\" 280 | echo "@dirrm $directory" 281 | n=$(( $n + 1 )) 282 | done >> "$FILE" || { 283 | err "ERROR: Could not append to file \`%s'" "$FILE" 284 | die "ERROR: Exiting" 285 | } 286 | if ! echo "@cwd ." >> "$FILE"; then 287 | err "ERROR: Could not append to file \`%s'" "$FILE" 288 | die "ERROR: Exiting" 289 | fi 290 | for ignore in $IGNORE; do 291 | echo "@ignore" 292 | echo "$ignore" 293 | done >> "$FILE" || { 294 | err "ERROR: Could not append to file \`%s'" "$FILE" 295 | die "ERROR: Exiting" 296 | } 297 | 298 | esac 299 | 300 | exit $SUCCESS 301 | 302 | ################################################################################ 303 | # END 304 | ################################################################################ 305 | -------------------------------------------------------------------------------- /freebsd/Mk/pkgname: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script for getting the package name from a BSD-style packing-list $ 7 | # $Copyright: 1999-2017 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/freebsd/Mk/pkgname 2022-08-04 17:31:11 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: pkgname PLIST 13 | # 14 | ############################################################ INCLUDES 15 | 16 | progdir="${0%/*}" 17 | . "$progdir/manifest.subr" || exit 18 | 19 | ############################################################ GLOBALS 20 | 21 | # 22 | # Global exit status 23 | # 24 | SUCCESS=0 25 | FAILURE=1 26 | 27 | # 28 | # Utility pathnames 29 | # 30 | : ${AWK:=awk} 31 | 32 | ############################################################ MAIN 33 | 34 | # 35 | # Validate number of arguments 36 | # 37 | [ $# -gt 0 ] || exit $SUCCESS 38 | 39 | # 40 | # Get the package name 41 | # 42 | FILE="$1" 43 | case "$FILE" in 44 | *PLIST|*CONTENTS) 45 | $AWK ' 46 | sub(/^@name[[:space:]]+/, "") { print; exit found++ } 47 | END { exit !found } 48 | ' "$FILE" 49 | ;; 50 | *) # MANIFEST 51 | manifest_read -r "(name|version)" "$FILE" || exit 52 | echo "$name${version:+-}$version" 53 | esac 54 | 55 | ################################################################################ 56 | # END 57 | ################################################################################ 58 | -------------------------------------------------------------------------------- /freebsd/Mk/pkgorigin: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script for getting the package origin from a BSD-style packing-list $ 7 | # $Copyright: 1999-2017 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/freebsd/Mk/pkgorigin 2022-08-04 17:31:11 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: pkgorigin PLIST 13 | # 14 | ############################################################ INCLUDES 15 | 16 | progdir="${0%/*}" 17 | . "$progdir/manifest.subr" || exit 18 | 19 | ############################################################ GLOBALS 20 | 21 | # 22 | # Global exit status 23 | # 24 | SUCCESS=0 25 | FAILURE=1 26 | 27 | # 28 | # Utility pathnames 29 | # 30 | : ${AWK:=awk} 31 | 32 | ############################################################ MAIN 33 | 34 | # 35 | # Validate number of arguments 36 | # 37 | [ $# -gt 0 ] || exit $SUCCESS 38 | 39 | # 40 | # Get the package origin 41 | # 42 | FILE="$1" 43 | case "$FILE" in 44 | *PLIST|*CONTENTS) 45 | $AWK -v regex="^@comment[[:space:]]+ORIGIN:" ' 46 | sub(regex, "") { 47 | gsub(/[[:space:]]+/, "_") 48 | print 49 | exit found++ 50 | } 51 | END { exit !found } 52 | ' "$FILE" 53 | ;; 54 | *) # MANIFEST 55 | manifest_read -r origin "$FILE" || exit 56 | echo "$origin" 57 | esac 58 | 59 | ################################################################################ 60 | # END 61 | ################################################################################ 62 | -------------------------------------------------------------------------------- /freebsd/Mk/pkgtag: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script for getting the package tag from a package name $ 7 | # $Copyright: 1999-2022 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/freebsd/Mk/pkgtag 2022-08-22 15:43:26 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: pkgtag NAME 13 | # 14 | ############################################################ GLOBALS 15 | 16 | # 17 | # Global exit status 18 | # 19 | SUCCESS=0 20 | FAILURE=1 21 | 22 | # 23 | # OS Glue 24 | # 25 | : ${UNAME_s:=$( uname -s )} 26 | 27 | # 28 | # Utility pathnames 29 | # 30 | : ${AWK:=awk} 31 | 32 | ############################################################ FUNCTIONS 33 | 34 | if ! type realpath > /dev/null 2>&1; then 35 | case "$UNAME_s" in 36 | Darwin) 37 | realpath() 38 | { 39 | perl -le 'use Cwd; print Cwd::abs_path(@ARGV)' -- "$@" 40 | } 41 | ;; 42 | *) 43 | realpath() 44 | { 45 | readlink -f "$@" 46 | } 47 | esac 48 | fi 49 | 50 | ############################################################ MAIN 51 | 52 | # 53 | # Validate number of arguments 54 | # 55 | [ $# -gt 0 ] || exit $SUCCESS 56 | 57 | # 58 | # Build the tag prefix 59 | # 60 | PWD=$( realpath "$PWD" ) 61 | if [ "$PKGCENTER" ]; then 62 | PKGCENTER=$( realpath "$PKGCENTER" ) 63 | else 64 | PKGCENTER="$PWD" 65 | while [ "$PKGCENTER" ]; do 66 | [ -e "$PKGCENTER/Mk/pkgcenter_readconf" ] && break 67 | case "$PKGCENTER" in 68 | */*) PKGCENTER="${PKGCENTER%/*}" ;; 69 | *) PKGCENTER= 70 | esac 71 | done 72 | fi 73 | TAGPREFIX="${PWD#${PKGCENTER%/*}/}" # Remove everything leading up to pkgcenter 74 | TAGPREFIX="${TAGPREFIX%/*}" 75 | 76 | # 77 | # Remove the repo name 78 | # 79 | TAGPREFIX="${TAGPREFIX#*/}" 80 | 81 | # 82 | # Replace bad characters with underscore 83 | # 84 | echo "${TAGPREFIX:+$TAGPREFIX/}$1" | $AWK '{ 85 | gsub("/", "-") 86 | gsub(/[^[:alnum:]]!&+,=_-]/, "_") 87 | print 88 | }' 89 | 90 | ################################################################################ 91 | # END 92 | ################################################################################ 93 | -------------------------------------------------------------------------------- /freebsd/Mk/pkgtagname: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script for getting the package tag name from a packing-list $ 7 | # $Copyright: 1999-2022 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/freebsd/Mk/pkgtagname 2022-08-22 15:43:26 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: pkgtagname PLIST 13 | # 14 | ############################################################ INCLUDES 15 | 16 | progdir="${0%/*}" 17 | . "$progdir/manifest.subr" || exit 18 | 19 | ############################################################ GLOBALS 20 | 21 | # 22 | # Global exit status 23 | # 24 | SUCCESS=0 25 | FAILURE=1 26 | 27 | # 28 | # OS Glue 29 | # 30 | : ${UNAME_s:=$( uname -s )} 31 | 32 | # 33 | # Utility pathnames 34 | # 35 | : ${AWK:=awk} 36 | 37 | ############################################################ FUNCTIONS 38 | 39 | if ! type realpath > /dev/null 2>&1; then 40 | case "$UNAME_s" in 41 | Darwin) 42 | realpath() 43 | { 44 | perl -le 'use Cwd; print Cwd::abs_path(@ARGV)' -- "$@" 45 | } 46 | ;; 47 | *) 48 | realpath() 49 | { 50 | readlink -f "$@" 51 | } 52 | esac 53 | fi 54 | 55 | ############################################################ MAIN 56 | 57 | # 58 | # Validate number of arguments 59 | # 60 | [ $# -gt 0 ] || exit $SUCCESS 61 | 62 | # 63 | # Build the tag prefix 64 | # 65 | PWD=$( realpath "$PWD" ) 66 | if [ "$PKGCENTER" ]; then 67 | PKGCENTER=$( realpath "$PKGCENTER" ) 68 | else 69 | PKGCENTER="$PWD" 70 | while [ "$PKGCENTER" ]; do 71 | [ -e "$PKGCENTER/Mk/pkgcenter_readconf" ] && break 72 | case "$PKGCENTER" in 73 | */*) PKGCENTER="${PKGCENTER%/*}" ;; 74 | *) PKGCENTER= 75 | esac 76 | done 77 | fi 78 | TAGPREFIX="${PWD#${PKGCENTER%/*}/}" # Remove everything leading up to pkgcenter 79 | TAGPREFIX="${TAGPREFIX%/*}" 80 | 81 | # 82 | # Remove the repo name 83 | # 84 | TAGPREFIX="${TAGPREFIX#*/}" 85 | 86 | # 87 | # Get the package name and return a suitable tag name 88 | # 89 | FILE="$1" 90 | case "$FILE" in 91 | *PLIST|*CONTENTS) 92 | $AWK -v prefix="${TAGPREFIX:+$TAGPREFIX/}" ' 93 | BEGIN { gsub("/", "-", prefix) } 94 | sub(/^@name[[:space:]]+/, "") { 95 | sub(/-[^-]*$/, "") 96 | gsub(/[^[:alnum:]]!&+,=_-]/, "_") 97 | print prefix $0 98 | exit found++ 99 | } 100 | END { exit !found } 101 | ' "$FILE" 102 | ;; 103 | *) # MANIFEST 104 | manifest_read -r name "$FILE" || exit 105 | echo "${TAGPREFIX:+$TAGPREFIX/}$name" | $AWK '{ 106 | gsub("/", "-") 107 | gsub(/[^[:alnum:]]!&+,=_-]/, "_") 108 | print 109 | }' 110 | esac 111 | 112 | ################################################################################ 113 | # END 114 | ################################################################################ 115 | -------------------------------------------------------------------------------- /freebsd/create: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- tab-width: 4 -*- ;; Emacs 3 | # vi: set noexpandtab :: Vi/ViM 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Script to create a new package $ 7 | # $Copyright: 1999-2017 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/freebsd/create 2022-08-23 12:14:14 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # Usage: create.sh [OPTIONS] package-dir ... 13 | # OPTIONS: 14 | # -h Print this message to stderr and exit. 15 | # -f Force. Allow creation over a directory that already exists. 16 | # 17 | ############################################################ GLOBALS 18 | 19 | pgm="${0##*/}" # Program basename 20 | progdir="${0%/*}" # Program directory 21 | 22 | # 23 | # Global exit status 24 | # 25 | SUCCESS=0 26 | FAILURE=1 27 | 28 | # 29 | # OS Glue 30 | # 31 | : ${UNAME_s:=$( uname -s )} 32 | 33 | # 34 | # Command-line options 35 | # 36 | FORCE= # -f 37 | 38 | ############################################################ FUNCTIONS 39 | 40 | # err FORMAT [ARGUMENT ...] 41 | # 42 | # Print a message to stderr. 43 | # 44 | err() 45 | { 46 | local fmt="$1" 47 | shift 1 # fmt 48 | [ "$fmt" ] || return $SUCCESS 49 | printf "$fmt\n" "$@" >&2 50 | } 51 | 52 | # die [FORMAT [ARGUMENT ...]] 53 | # 54 | # Optionally print a message to stderr before exiting with failure status. 55 | # 56 | die() 57 | { 58 | err "$@" 59 | exit $FAILURE 60 | } 61 | 62 | # usage 63 | # 64 | # Prints a short syntax statement and exits. 65 | # 66 | usage() 67 | { 68 | local optfmt="\t%-4s %s\n" 69 | exec >&2 70 | printf "Usage: %s [OPTIONS] package-dir ...\n" "$pgm" 71 | printf "OPTIONS:\n" 72 | printf "$optfmt" "-h" \ 73 | "Print this message to stderr and exit." 74 | printf "$optfmt" "-f" \ 75 | "Force. Allow creation over a directory that already exists." 76 | die 77 | } 78 | 79 | if ! type realpath > /dev/null 2>&1; then 80 | case "$UNAME_s" in 81 | Darwin) 82 | realpath() 83 | { 84 | perl -le 'use Cwd; print Cwd::abs_path(@ARGV)' -- "$@" 85 | } 86 | ;; 87 | *) 88 | realpath() 89 | { 90 | readlink -f "$@" 91 | } 92 | esac 93 | fi 94 | 95 | ############################################################ MAIN 96 | 97 | # 98 | # Process command-line options 99 | # 100 | while getopts fh flag; do 101 | case "$flag" in 102 | f) FORCE=1 ;; 103 | *) usage # NOTREACHED 104 | esac 105 | done 106 | shift $(( $OPTIND - 1 )) 107 | 108 | # 109 | # Validate number of arguments 110 | # 111 | [ $# -gt 0 ] || usage 112 | 113 | # 114 | # Loop over each remaining package-dir argument(s) 115 | # 116 | while [ $# -gt 0 ]; do 117 | 118 | DEST="$1" 119 | shift 1 120 | 121 | # 122 | # Get the package name and proper Makefile from pathname 123 | # 124 | NAME="${DEST##*/}" 125 | if [ "$DEST" -a ! "$NAME" ]; then 126 | DEST="${DEST%/*}" 127 | NAME="${DEST##*/}" 128 | fi 129 | if [ "$NAME" ]; then 130 | printf "===> Creating \`%s'\n" "$DEST" 131 | else 132 | usage # NOTREACHED 133 | fi 134 | 135 | # 136 | # Detect older package creation (used later in Makefile fixup) 137 | # 138 | ar_opt=J 139 | case "$( realpath "$DEST" )" in 140 | */RELENG_[1-4][_/]*) ar_opt=z ;; 141 | */RELENG_[5-9][_/]*) ar_opt=j ;; 142 | esac 143 | 144 | # 145 | # Make sure that the directory we are going to create doesn't already 146 | # exist. If it does, issue an error and skip this package (unless `-f' 147 | # is passed). 148 | # 149 | # Otherwise, create the destination. 150 | # 151 | printf "Creating package repository directory: " 152 | if [ -e "$DEST" ]; then 153 | printf "\n" 154 | err "ERROR: Directory \`%s' already exists" "$DEST" 155 | if [ ! "$FORCE" ]; then 156 | err "ERROR: Skipping package (use \`-f' to override)" 157 | continue 158 | else 159 | err "ERROR: Proceeding anyway (\`-f' was passed)" 160 | fi 161 | fi 162 | if ! mkdir -p "$DEST"; then 163 | printf "\n" 164 | err "ERROR: Could not create directory \`%s'" "$DEST" 165 | die "ERROR: Exiting" 166 | fi 167 | printf "%s\n" "$DEST" 168 | 169 | # 170 | # Create the `stage' directory within the package repository 171 | # 172 | printf "Creating package \`stage' directory...\n" 173 | if ! mkdir -p "$DEST/stage"; then 174 | err "ERROR: Could not create directory \`%s/stage'" "$DEST" 175 | die "ERROR: Exiting" 176 | fi 177 | 178 | # 179 | # Extract skeleton directory into package repository 180 | # 181 | printf "Copying \`skel' structure into package repository...\n" 182 | tar co --exclude CVS -f - -C "$progdir/skel" . | tar xkvf - -C "$DEST" 183 | 184 | # 185 | # Makefile fixup: move in the appropriate Makefile 186 | # 187 | printf "Adjusting for archive format...\n" 188 | case "$ar_opt" in 189 | z) if [ ! -e "$DEST/Makefile" ] || \ 190 | cmp "$DEST/Makefile" "$progdir/skel/Makefile"; then 191 | mv -vf "$DEST/Makefile.old" "$DEST/Makefile" 192 | else 193 | rm -vf "$DEST/Makefile.old" 194 | fi 195 | rm -vf "$DEST/Makefile.ng" "$DEST/MANIFEST" 196 | ;; 197 | j) rm -vf "$DEST/Makefile.old" "$DEST/Makefile.ng" "$DEST/MANIFEST" ;; 198 | J) rm -vf "$DEST/Makefile.old" 199 | if [ ! -e "$DEST/Makefile" ] || 200 | cmp "$DEST/Makefile" "$progdir/skel/Makefile" 201 | then 202 | mv -vf "$DEST/Makefile.ng" "$DEST/Makefile" 203 | else 204 | rm -vf "$DEST/Makefile.ng" 205 | fi 206 | rm -vf "$DEST/PLIST" "$DEST/stage/+COMMENT" "$DEST/stage/+DESC" 207 | ;; 208 | esac 209 | 210 | # 211 | # That's it (onto the next, back at the top). 212 | # 213 | printf "Done.\n" 214 | done 215 | 216 | ################################################################################ 217 | # END 218 | ################################################################################ 219 | -------------------------------------------------------------------------------- /freebsd/dwatch-json/LICENSE: -------------------------------------------------------------------------------- 1 | This package has a single license: BSD2CLAUSE (BSD 2-clause Simplified License). 2 | -------------------------------------------------------------------------------- /freebsd/dwatch-json/MANIFEST: -------------------------------------------------------------------------------- 1 | // -*- tab-width: 4 -*- ;; Emacs 2 | // vi: set noexpandtab :: Vi/ViM 3 | // vi: set filetype=javascript :: 4 | { 5 | //////////////////////////////////////////////////// HEADER 6 | 7 | "name":"dwatch-json", 8 | "origin":"sysutils/dwatch-json", 9 | "version":"1.2", 10 | "comment":"FreeBSD dwatch suite to produce JSON stats", 11 | "maintainer":"dteske@FreeBSD.org", 12 | "www":"https://fraubsd.org/dwatch-json/", 13 | "abi":"FreeBSD:13:*", 14 | "arch":"freebsd:13:*", 15 | "prefix":"/usr/local", 16 | "licenselogic":"single", 17 | "licenses":["BSD2CLAUSE"], 18 | 19 | //////////////////////////////////////////////////// DESCRIPTION 20 | 21 | "desc":"DTrace suite for FreeBSD dwatch(1) to produce JSON stats. 22 | JSON (JavaScript Object Notation) is easily consumed by log aggregators such as 23 | Kafka and Telegraf and visualizers like Grafana and Vizceral. It is also easily 24 | parsed, filtered, and transformed with jq. 25 | 26 | With this package you can get data out of the kernel for use in such tools, 27 | aggregators, and visualizers. 28 | 29 | Included in this package are service suites which help automate the collection 30 | of statistics for time-series graphing (with Grafana for example). The suites 31 | consist of general daemons, sample configs, statistics-gathering daemons 32 | (utilizing telegraf), log-rotation tools, default cron.d entries for calling 33 | said tools, and many convenience features including full service(8) integration 34 | and rc.conf(5) support. 35 | 36 | WWW: https://fraubsd.org/dwatch-json/", 37 | "categories":["sysutils"], 38 | 39 | //////////////////////////////////////////////////// OPTIONS 40 | 41 | "options":{"DOCS":"on"}, 42 | 43 | //////////////////////////////////////////////////// FILES 44 | 45 | "files":[ 46 | "/usr/local/etc/cron.d/grafio", 47 | "/usr/local/etc/cron.d/grafnet", 48 | "/usr/local/etc/dwatch-json-io.conf.sample", 49 | "/usr/local/etc/dwatch-json-net.conf.sample", 50 | "/usr/local/etc/grafio/grafio.conf.sample", 51 | "/usr/local/etc/grafio/grafio.subr.sample", 52 | "/usr/local/etc/grafio/stats.conf.sample", 53 | "/usr/local/etc/grafnet/grafnet.conf.sample", 54 | "/usr/local/etc/grafnet/grafnet.subr.sample", 55 | "/usr/local/etc/grafnet/stats.conf.sample", 56 | "/usr/local/etc/rc.d/grafio", 57 | "/usr/local/etc/rc.d/grafio_stats", 58 | "/usr/local/etc/rc.d/grafnet", 59 | "/usr/local/etc/rc.d/grafnet_stats", 60 | "/usr/local/libexec/dwatch/json-io", 61 | "/usr/local/libexec/dwatch/json-io-config", 62 | "/usr/local/libexec/dwatch/json-io-config-raw", 63 | "/usr/local/libexec/dwatch/json-io-raw", 64 | "/usr/local/libexec/dwatch/json-io-top", 65 | "/usr/local/libexec/dwatch/json-io-top-raw", 66 | "/usr/local/libexec/dwatch/json-net", 67 | "/usr/local/libexec/dwatch/json-net-config", 68 | "/usr/local/libexec/dwatch/json-net-config-raw", 69 | "/usr/local/libexec/dwatch/json-net-raw", 70 | "/usr/local/libexec/dwatch/json-net-top", 71 | "/usr/local/libexec/dwatch/json-net-top-raw", 72 | "/usr/local/sbin/gio", 73 | "/usr/local/sbin/gn", 74 | "/usr/local/sbin/grafio", 75 | "/usr/local/sbin/grafio-logs", 76 | "/usr/local/sbin/grafio-rotate", 77 | "/usr/local/sbin/grafio_stats", 78 | "/usr/local/sbin/grafnet", 79 | "/usr/local/sbin/grafnet-logs", 80 | "/usr/local/sbin/grafnet-rotate", 81 | "/usr/local/sbin/grafnet_stats", 82 | "/usr/local/share/doc/dwatch-json/README.md", 83 | "/usr/local/share/examples/grafio/dashboards/block-i-o.json", 84 | "/usr/local/share/examples/grafnet/dashboards/device-i-o-rates-b-s.json", 85 | "/usr/local/share/examples/grafnet/dashboards/device-i-o-rates-bps.json", 86 | "/usr/local/share/examples/grafnet/dashboards/device-i-o.json", 87 | "/usr/local/share/licenses/dwatch-json-1.2/BSD2CLAUSE", 88 | "/usr/local/share/licenses/dwatch-json-1.2/LICENSE", 89 | "/usr/local/share/licenses/dwatch-json-1.2/catalog.mk", 90 | ], 91 | 92 | //////////////////////////////////////////////////// DIRECTORIES 93 | 94 | "directories":{ 95 | "/usr":"n", 96 | "/usr/local":"n", 97 | "/usr/local/etc":"n", 98 | "/usr/local/etc/cron.d":"n", 99 | "/usr/local/etc/grafnet":"y", 100 | "/usr/local/etc/grafio":"y", 101 | "/usr/local/etc/rc.d":"n", 102 | "/usr/local/libexec":"n", 103 | "/usr/local/libexec/dwatch":"y", 104 | "/usr/local/sbin":"n", 105 | "/usr/local/share":"n", 106 | "/usr/local/share/doc":"n", 107 | "/usr/local/share/doc/dwatch-json":"y", 108 | "/usr/local/share/examples":"n", 109 | "/usr/local/share/examples/grafio":"y", 110 | "/usr/local/share/examples/grafio/dashboards":"y", 111 | "/usr/local/share/examples/grafnet":"y", 112 | "/usr/local/share/examples/grafnet/dashboards":"y", 113 | "/usr/local/share/licenses":"n", 114 | "/usr/local/share/licenses/dwatch-json-1.2":"y", 115 | "/var":"n", 116 | "/var/log":"n", 117 | "/var/log/grafnet":"y", 118 | "/var/log/grafio":"y", 119 | "/var/run":"n", 120 | "/var/run/grafnet":"y", 121 | "/var/run/grafio":"y", 122 | }, 123 | 124 | //////////////////////////////////////////////////// SCRIPTS 125 | 126 | "lua_scripts":{ 127 | "post-install":[ 128 | "-- args: etc/dwatch-json-io.conf.sample\n args = {}\n for arg in string.gmatch(\"etc/dwatch-json-io.conf.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if not pkg.stat(target_file) then\n pkg.copy(sample_file, target_file)\n end", 129 | "-- args: etc/dwatch-json-net.conf.sample\n args = {}\n for arg in string.gmatch(\"etc/dwatch-json-net.conf.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if not pkg.stat(target_file) then\n pkg.copy(sample_file, target_file)\n end", 130 | "-- args: etc/grafio/grafio.conf.sample\n args = {}\n for arg in string.gmatch(\"etc/grafio/grafio.conf.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if not pkg.stat(target_file) then\n pkg.copy(sample_file, target_file)\n end", 131 | "-- args: etc/grafio/grafio.subr.sample\n args = {}\n for arg in string.gmatch(\"etc/grafio/grafio.subr.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if not pkg.stat(target_file) then\n pkg.copy(sample_file, target_file)\n end", 132 | "-- args: etc/grafio/stats.conf.sample\n args = {}\n for arg in string.gmatch(\"etc/grafio/stats.conf.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if not pkg.stat(target_file) then\n pkg.copy(sample_file, target_file)\n end", 133 | "-- args: etc/grafnet/grafnet.conf.sample\n args = {}\n for arg in string.gmatch(\"etc/grafnet/grafnet.conf.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if not pkg.stat(target_file) then\n pkg.copy(sample_file, target_file)\n end", 134 | "-- args: etc/grafnet/grafnet.subr.sample\n args = {}\n for arg in string.gmatch(\"etc/grafnet/grafnet.subr.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if not pkg.stat(target_file) then\n pkg.copy(sample_file, target_file)\n end", 135 | "-- args: etc/grafnet/stats.conf.sample\n args = {}\n for arg in string.gmatch(\"etc/grafnet/stats.conf.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if not pkg.stat(target_file) then\n pkg.copy(sample_file, target_file)\n end", 136 | ], 137 | "pre-deinstall":[ 138 | "-- args: etc/dwatch-json-io.conf.sample\n args = {}\n for arg in string.gmatch(\"etc/dwatch-json-io.conf.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if pkg.filecmp(sample_file, target_file) == 0 then\n os.remove(target_file)\n else\n if not pkg.pkg_upgrade then\n pkg.print_msg(\"You may need to manually remove \" .. target_file .. \" if it is no longer needed.\")\n end\n end", 139 | "-- args: etc/dwatch-json-net.conf.sample\n args = {}\n for arg in string.gmatch(\"etc/dwatch-json-net.conf.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if pkg.filecmp(sample_file, target_file) == 0 then\n os.remove(target_file)\n else\n if not pkg.pkg_upgrade then\n pkg.print_msg(\"You may need to manually remove \" .. target_file .. \" if it is no longer needed.\")\n end\n end", 140 | "-- args: etc/grafio/grafio.conf.sample\n args = {}\n for arg in string.gmatch(\"etc/grafio/grafio.conf.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if pkg.filecmp(sample_file, target_file) == 0 then\n os.remove(target_file)\n else\n if not pkg.pkg_upgrade then\n pkg.print_msg(\"You may need to manually remove \" .. target_file .. \" if it is no longer needed.\")\n end\n end", 141 | "-- args: etc/grafio/grafio.subr.sample\n args = {}\n for arg in string.gmatch(\"etc/grafio/grafio.subr.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if pkg.filecmp(sample_file, target_file) == 0 then\n os.remove(target_file)\n else\n if not pkg.pkg_upgrade then\n pkg.print_msg(\"You may need to manually remove \" .. target_file .. \" if it is no longer needed.\")\n end\n end", 142 | "-- args: etc/grafio/stats.conf.sample\n args = {}\n for arg in string.gmatch(\"etc/grafio/stats.conf.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if pkg.filecmp(sample_file, target_file) == 0 then\n os.remove(target_file)\n else\n if not pkg.pkg_upgrade then\n pkg.print_msg(\"You may need to manually remove \" .. target_file .. \" if it is no longer needed.\")\n end\n end", 143 | "-- args: etc/grafnet/grafnet.conf.sample\n args = {}\n for arg in string.gmatch(\"etc/grafnet/grafnet.conf.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if pkg.filecmp(sample_file, target_file) == 0 then\n os.remove(target_file)\n else\n if not pkg.pkg_upgrade then\n pkg.print_msg(\"You may need to manually remove \" .. target_file .. \" if it is no longer needed.\")\n end\n end", 144 | "-- args: etc/grafnet/grafnet.subr.sample\n args = {}\n for arg in string.gmatch(\"etc/grafnet/grafnet.subr.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if pkg.filecmp(sample_file, target_file) == 0 then\n os.remove(target_file)\n else\n if not pkg.pkg_upgrade then\n pkg.print_msg(\"You may need to manually remove \" .. target_file .. \" if it is no longer needed.\")\n end\n end", 145 | "-- args: etc/grafnet/stats.conf.sample\n args = {}\n for arg in string.gmatch(\"etc/grafnet/stats.conf.sample\", \"%S+\") do\n table.insert(args, arg)\n end\n sample_file = pkg.prefixed_path(args[1])\n if args[2] == nil then\n target_file = string.gsub(sample_file,'%.sample$', \"\")\n else\n target_file = pkg.prefixed_path(args[2])\n end\n if pkg.filecmp(sample_file, target_file) == 0 then\n os.remove(target_file)\n else\n if not pkg.pkg_upgrade then\n pkg.print_msg(\"You may need to manually remove \" .. target_file .. \" if it is no longer needed.\")\n end\n end", 146 | ], 147 | }, 148 | } 149 | //////////////////////////////////////////////////////////////////////////////// 150 | // END 151 | //////////////////////////////////////////////////////////////////////////////// 152 | // 153 | // $Copyright: 2014-2022 Devin Teske. All rights reserved. $ 154 | // $FrauBSD: dwatch-json/freebsd/dwatch-json/MANIFEST 2022-08-31 10:25:39 -0700 freebsdfrau $ 155 | // 156 | //////////////////////////////////////////////////////////////////////////////// 157 | -------------------------------------------------------------------------------- /freebsd/dwatch-json/Makefile: -------------------------------------------------------------------------------- 1 | # -*- tab-width: 4 -*- ;; Emacs 2 | # vi: set noexpandtab :: Vi/ViM 3 | # vi: set syntax=make :: 4 | ################################################################################ 5 | ################################ CONFIGURATION ################################# 6 | ################################################################################ 7 | 8 | PKGCENTER = ../.. 9 | MANIFEST = ./MANIFEST 10 | PLIST = $(MANIFEST) 11 | STAGEDIR = ./stage 12 | PKGCENTER_CONF = ./pkgcenter.conf 13 | 14 | ################################################################################ 15 | ############################# TARGET DEPENDENCIES ############################# 16 | ################################################################################ 17 | 18 | # 19 | # Environment 20 | # 21 | ENVIRON = PKGCENTER=$(PKGCENTER) \ 22 | MANIFEST=$(MANIFEST) \ 23 | PLIST=$(PLIST) \ 24 | STAGEDIR=$(STAGEDIR) \ 25 | PKGCENTER_CONF=$(PKGCENTER_CONF) 26 | 27 | # 28 | # Macro for reading pkgcenter.conf 29 | # 30 | SOURCE_CONF = $(ENVIRON) $(PKGCENTER)/Mk/pkgcenter_readconf $(PKGCENTER_CONF) 31 | 32 | # 33 | # Pulled from pkgcenter.conf -- configured above. 34 | # 35 | DIRS = $(SOURCE_CONF) DIRS | $(PKGCENTER)/Mk/xargs 36 | SYMLINKS = $(SOURCE_CONF) SYMLINKS | $(PKGCENTER)/Mk/xargs -n 1024 37 | STAGE = $(SOURCE_CONF) STAGE | $(PKGCENTER)/Mk/xargs -n 1024 38 | 39 | ################################################################################ 40 | ############################### GLOBAL VARIABLES ############################### 41 | ################################################################################ 42 | 43 | # 44 | # Package tools 45 | # 46 | PKGCC = $(PKGCENTER)/freebsd/Mk/pkgcc 47 | PKGCCFLAGS = -y 48 | CONVERT = $(PKGCENTER)/freebsd/Mk/convert 49 | CONVERTFLAGS = -f 50 | TAR = tar 51 | TARFLAGS = c --exclude CVS -f 52 | TARSUFFIX = tar 53 | ZIP = xz 54 | ZIPSUFFIX = xz 55 | SUFFIX = pkg 56 | 57 | # 58 | # Generated files 59 | # 60 | GENERATED_FILES = \ 61 | $(STAGEDIR)/+MANIFEST \ 62 | $(STAGEDIR)/+COMPACT_MANIFEST 63 | 64 | # 65 | # Package Specifics 66 | # 67 | CWD = $$($(PWD)) 68 | NAME = $$($(PKGCENTER)/freebsd/Mk/pkgname "$(PLIST)") 69 | TAG = $$($(PKGCENTER)/freebsd/Mk/pkgtag "$(NAME)") 70 | TAGNAME = $$($(PKGCENTER)/freebsd/Mk/pkgtagname "$(PLIST)") 71 | ORIGIN = $$($(PKGCENTER)/freebsd/Mk/pkgorigin "$(PLIST)") 72 | 73 | # 74 | # Standard utility pathnames 75 | # 76 | CAT = cat 77 | GIT = git 78 | MKDIR = mkdir 79 | MV = mv 80 | PWD = pwd 81 | RM = rm 82 | 83 | ################################################################################ 84 | ############################## FUNCTION VARIABLES ############################## 85 | ################################################################################ 86 | 87 | EVAL2 = eval2(){ echo "$$@"; eval "$$@"; } 88 | 89 | ################################################################################ 90 | ################################ BUILD TARGETS ################################ 91 | ################################################################################ 92 | 93 | # 94 | # Package Building Targets 95 | # 96 | 97 | .PHONY: all dirs symlinks stage forcestage plist check_name package 98 | 99 | all: package 100 | 101 | dirs: 102 | @echo "Creating directories..." 103 | @$(DIRS) $(PKGCENTER)/Mk/make_directories 104 | 105 | symlinks: 106 | @echo "Creating symbolic links..." 107 | @$(SYMLINKS) $(PKGCENTER)/Mk/make_symlinks 108 | 109 | stage: 110 | @echo "Copying stage dependencies..." 111 | @$(EVAL2); [ -e "$(STAGEDIR)" ] || eval2 $(MKDIR) -p $(STAGEDIR) 112 | @$(STAGE) $(PKGCENTER)/Mk/make_stage 113 | 114 | forcestage: 115 | @echo "Copying [all] dependencies..." 116 | @$(EVAL2); [ -e "$(STAGEDIR)" ] || eval2 $(MKDIR) -p $(STAGEDIR) 117 | @$(STAGE) $(PKGCENTER)/Mk/make_stage -f 118 | 119 | $(PLIST): 120 | @$(EVAL2); [ "$(PLIST)" = "$(MANIFEST)" -o \ 121 | "$(PLIST)" -nt "$(MANIFEST)" ] || eval2 $(CONVERT) \ 122 | $(CONVERTFLAGS) $(MANIFEST) $(PLIST) $(STAGEDIR) 123 | 124 | plist: $(PLIST) 125 | 126 | check_name: plist 127 | @[ "$(NAME)" ] || $(PKGCENTER)/Mk/die \ 128 | "ERROR: Package $(PLIST) has no package name" 129 | 130 | package: stage dirs symlinks pkg 131 | 132 | pkg: check_name 133 | $(PKGCC) $(PKGCCFLAGS) $(PLIST) $(STAGEDIR) 134 | @$(EVAL2); cwd=$(CWD); name=$(NAME); \ 135 | eval2 cd $(STAGEDIR) || exit; \ 136 | TARFILE=$$cwd/$$name.$(TARSUFFIX); \ 137 | if tar --help 2>&1 | grep -q bsdtar; then \ 138 | vers=$$( tar --version 2> /dev/null ); \ 139 | case "$${vers#"$${vers%%[0-9]*}"}" in \ 140 | [0-2].*) TRANSFORM=':^[^+]:/~:' ;; \ 141 | *) TRANSFORM=':^[^+]:/~:S' ;; \ 142 | esac; \ 143 | TARFLAGS2="-s '$$TRANSFORM' -P"; \ 144 | else \ 145 | TARFLAGS2="--transform 's:^[^+]:/&:S' -P"; \ 146 | fi; \ 147 | eval2 $(TAR) $(TARFLAGS) $$TARFILE $$TARFLAGS2 * || exit; \ 148 | ! type "$(ZIP)" > /dev/null 2>&1 && exit; \ 149 | eval2 $(ZIP) $$TARFILE || exit; \ 150 | eval2 $(MV) -f $$TARFILE.$(ZIPSUFFIX) $$cwd/$$name.$(SUFFIX) 151 | @[ "$(ORIGIN)" ] || echo "WARNING: Empty or missing package origin" 152 | 153 | # 154 | # Package Maintenance Targets 155 | # 156 | 157 | .PHONY: clean distclean 158 | 159 | clean: 160 | $(RM) -f $(GENERATED_FILES) 161 | @$(SYMLINKS) $(PKGCENTER)/Mk/clean_symlinks && \ 162 | $(RM) -f .symlinks_created 163 | @$(DIRS) $(PKGCENTER)/Mk/clean_directories && \ 164 | $(RM) -f .dirs_created 165 | [ -e .keep-stage ] || $(RM) -Rf $(STAGEDIR) 166 | @$(EVAL2); [ "$(MANIFEST)" = "$(PLIST)" ] || eval2 $(RM) -f $(PLIST) 167 | 168 | distclean: clean 169 | $(RM) -f *.$(TARSUFFIX) *.$(SUFFIX) 170 | 171 | # 172 | # Git Maintenance Targets 173 | # 174 | 175 | .PHONY: check_tag tag forcetag untag unpublish taglist 176 | 177 | check_tag: 178 | @[ "$(TAG)" ] || $(PKGCENTER)/Mk/die \ 179 | "ERROR: Package $(PLIST) has invalid package name" 180 | 181 | tag: check_tag 182 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag "$(TAG)" 183 | 184 | forcetag: check_tag 185 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -f "$(TAG)" 186 | 187 | untag: check_tag 188 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -d "$(TAG)" 189 | 190 | unpublish: check_tag 191 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -u "$(TAG)" 192 | 193 | taglist: 194 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -l "$(TAGNAME)-*" 195 | 196 | # 197 | # Git Addition Targets 198 | # 199 | 200 | .PHONY: import commit pull push autoimport 201 | 202 | import: 203 | @$(ENVIRON) $(PKGCENTER)/Mk/git_import 204 | 205 | autoimport: 206 | @$(ENVIRON) $(PKGCENTER)/Mk/git_import -a 207 | 208 | commit: 209 | @$(GIT) commit 210 | 211 | push: 212 | @$(GIT) push origin $$( git branch | awk '$$1=="*"{print $$2}' ) --tags 213 | 214 | pull: 215 | @$(GIT) pull 216 | 217 | # 218 | # Generic Targets 219 | # 220 | 221 | .PHONY: usage targets help 222 | 223 | usage: 224 | @$(CAT) $(PKGCENTER)/freebsd/Mk/USAGE_PACKAGE 225 | 226 | targets help: 227 | @$(CAT) $(PKGCENTER)/freebsd/Mk/HELP_PACKAGE 228 | 229 | ################################################################################ 230 | # END 231 | ################################################################################ 232 | -------------------------------------------------------------------------------- /freebsd/dwatch-json/catalog.mk: -------------------------------------------------------------------------------- 1 | _LICENSE=BSD2CLAUSE 2 | _LICENSE_NAME=BSD 2-clause Simplified License 3 | _LICENSE_PERMS=dist-mirror dist-sell pkg-mirror pkg-sell auto-accept 4 | _LICENSE_GROUPS=FSF OSI COPYFREE 5 | _LICENSE_DISTFILES=FrauBSD-dwatch-json-1.2_GH0.tar.gz 6 | -------------------------------------------------------------------------------- /freebsd/dwatch-json/pkgcenter.conf: -------------------------------------------------------------------------------- 1 | # -*- tab-width: 4 -*- ;; Emacs 2 | # vi: set noexpandtab :: Vi/ViM 3 | # vi: set filetype=sh :: 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Package staging configuration $ 7 | # $Copyright: 1999-2022 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/freebsd/dwatch-json/pkgcenter.conf 2022-08-31 10:25:39 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # This file is entirely optional. You can safely delete it if you do not need 13 | # any of the optional features that it provides. 14 | # 15 | # The pkgcenter Makefile(s) will automatically export following macros into the 16 | # shell environment before sourcing this configuration file (which is actually 17 | # a shell script): 18 | # 19 | # Macro Description 20 | # PKGCENTER Relative pathname to top-level pkgcenter directory. 21 | # PLIST Package packing list (usually `./PLIST'). 22 | # MANIFEST Package packing list (usually `./MANIFEST'). 23 | # STAGEDIR Package stage directory (usually `./stage'). 24 | # PKGCENTER_CONF Path to this file. 25 | # 26 | ############################################################ CONFIGURATION 27 | 28 | # 29 | # Directories to create before (and clean up after) creating the package. 30 | # NOTE: Be careful to list sub-directories in depth-first order. 31 | # 32 | DIRS=" 33 | # Directory 34 | $STAGEDIR/var/log/grafio 35 | $STAGEDIR/var/log/grafnet 36 | $STAGEDIR/var/run/grafio 37 | $STAGEDIR/var/run/grafnet 38 | " 39 | 40 | # 41 | # Symlinks to be created before (and cleaned up after) creating the package. 42 | # NOTE: Only the symlink, not the target, will be removed on clean-up. 43 | # 44 | SYMLINKS=" 45 | # Symbolic-link Target 46 | $STAGEDIR/usr/local/sbin/gio grafio 47 | $STAGEDIR/usr/local/sbin/gn grafnet 48 | " 49 | 50 | # 51 | # External staging dependencies to ``pull-in'' when creating the package. 52 | # WARNING: source will overwrite destination if touched. 53 | # 54 | PKGNAM=dwatch-json-1.2 55 | PREFIX=/usr/local 56 | SRCDIR=$PKGCENTER 57 | STAGE=" 58 | # Source Destination 59 | (catalog.mk\ LICENSE) $STAGEDIR$PREFIX/share/licenses/$PKGNAM 60 | $SRCDIR/LICENSE $STAGEDIR$PREFIX/share/licenses/$PKGNAM/BSD2CLAUSE 61 | ($SRCDIR/README.md) $STAGEDIR$PREFIX/share/doc/${PKGNAM%-*} 62 | 63 | $SRCDIR/graf/logs $STAGEDIR$PREFIX/sbin/grafnet-logs 64 | $SRCDIR/graf/rotate $STAGEDIR$PREFIX/sbin/grafnet-rotate 65 | $SRCDIR/graf/stats $STAGEDIR$PREFIX/sbin/grafnet_stats 66 | $SRCDIR/grafnet/grafnet $STAGEDIR$PREFIX/sbin/grafnet 67 | ($SRCDIR/grafio/dashboards/*) $STAGEDIR$PREFIX/share/examples/grafio/dashboards 68 | ($SRCDIR/grafnet/cron.d/*) $STAGEDIR$PREFIX/etc/cron.d 69 | ($SRCDIR/grafnet/dashboards/*) $STAGEDIR$PREFIX/share/examples/grafnet/dashboards 70 | ($SRCDIR/grafnet/etc/*) $STAGEDIR$PREFIX/etc/grafnet 71 | ($SRCDIR/grafnet/rc.d/*) $STAGEDIR$PREFIX/etc/rc.d 72 | 73 | $SRCDIR/graf/logs $STAGEDIR$PREFIX/sbin/grafio-logs 74 | $SRCDIR/graf/rotate $STAGEDIR$PREFIX/sbin/grafio-rotate 75 | $SRCDIR/graf/stats $STAGEDIR$PREFIX/sbin/grafio_stats 76 | $SRCDIR/grafio/grafio $STAGEDIR$PREFIX/sbin/grafio 77 | ($SRCDIR/grafio/cron.d/*) $STAGEDIR$PREFIX/etc/cron.d 78 | ($SRCDIR/grafio/etc/*) $STAGEDIR$PREFIX/etc/grafio 79 | ($SRCDIR/grafio/rc.d/*) $STAGEDIR$PREFIX/etc/rc.d 80 | 81 | ($SRCDIR/json-*) $STAGEDIR$PREFIX/libexec/dwatch 82 | 83 | $SRCDIR/dwatch-json-io.conf $STAGEDIR$PREFIX/etc/dwatch-json-io.conf.sample 84 | $SRCDIR/dwatch-json-net.conf $STAGEDIR$PREFIX/etc/dwatch-json-net.conf.sample 85 | " 86 | 87 | ################################################################################ 88 | # END 89 | ################################################################################ 90 | -------------------------------------------------------------------------------- /freebsd/skel/MANIFEST: -------------------------------------------------------------------------------- 1 | // -*- tab-width: 4 -*- ;; Emacs 2 | // vi: set noexpandtab :: Vi/ViM 3 | // vi: set filetype=javascript :: 4 | { 5 | //////////////////////////////////////////////////// HEADER 6 | 7 | "name":"pkgname", 8 | "origin":"origin/pkgname", 9 | "categories":["origin"], 10 | 11 | "comment":"", 12 | "licenselogic":"single", 13 | "version":"x.y", 14 | 15 | "maintainer":"flast@freebsd.org", 16 | "www":"https://freebsd.org/", 17 | 18 | "arch":"freebsd:13:x86:64", // "freebsd:13:*" for independent arch 19 | "prefix":"/install/root", 20 | 21 | //////////////////////////////////////////////////// DESCRIPTION 22 | 23 | "desc":" 24 | 25 | WWW: https://fraubsd.org/", 26 | 27 | //////////////////////////////////////////////////// DEPENDENCIES 28 | 29 | "deps":{ 30 | "dep1":{"origin":"category1/dep1","version":"a.b"}, 31 | "dep2":{"origin":"category2/dep2","version":"x.y"}, 32 | }, 33 | "shlibs_required":[ 34 | "libA.so", 35 | "libB.so", 36 | "libC.so.1", 37 | "libD.so.2", 38 | ], 39 | "options":{ 40 | "OPT1":"off", 41 | "OPT2":"off", 42 | "OPT3":"off", 43 | }, 44 | 45 | //////////////////////////////////////////////////// FILES 46 | 47 | "files":[ 48 | "/install/root/bin/file1", 49 | "/install/root/bin/file2", 50 | "/install/root/bin/file3", 51 | ], 52 | 53 | //////////////////////////////////////////////////// DIRECTORIES 54 | 55 | "directories":{ 56 | "/install/root/bin":"y", 57 | "/install/root/bin/foo":"n", 58 | }, 59 | 60 | //////////////////////////////////////////////////// SCRIPTS 61 | 62 | "scripts":{ 63 | "post-install":"", 64 | "pre-deinstall":"", 65 | "post-deinstall":"", 66 | }, 67 | 68 | //////////////////////////////////////////////////// MESSAGE 69 | 70 | "message":"", 71 | } 72 | //////////////////////////////////////////////////////////////////////////////// 73 | // END 74 | //////////////////////////////////////////////////////////////////////////////// 75 | // 76 | // $Copyright: 2017-2022 The FrauBSD Project. All rights reserved. $ 77 | // $FrauBSD: dwatch-json/freebsd/skel/MANIFEST 2022-08-23 12:14:14 -0700 freebsdfrau $ 78 | // 79 | //////////////////////////////////////////////////////////////////////////////// 80 | -------------------------------------------------------------------------------- /freebsd/skel/Makefile: -------------------------------------------------------------------------------- 1 | # -*- tab-width: 4 -*- ;; Emacs 2 | # vi: set noexpandtab :: Vi/ViM 3 | # vi: set syntax=make :: 4 | ################################################################################ 5 | ################################ CONFIGURATION ################################# 6 | ################################################################################ 7 | 8 | PKGCENTER = ../.. 9 | MANIFEST = ./MANIFEST 10 | PLIST = ./PLIST 11 | STAGEDIR = ./stage 12 | PKGCENTER_CONF = ./pkgcenter.conf 13 | 14 | ################################################################################ 15 | ############################# TARGET DEPENDENCIES ############################# 16 | ################################################################################ 17 | 18 | # 19 | # Environment 20 | # 21 | ENVIRON = PKGCENTER=$(PKGCENTER) \ 22 | MANIFEST=$(MANIFEST) \ 23 | PLIST=$(PLIST) \ 24 | STAGEDIR=$(STAGEDIR) \ 25 | PKGCENTER_CONF=$(PKGCENTER_CONF) 26 | 27 | # 28 | # Macro for reading pkgcenter.conf 29 | # 30 | SOURCE_CONF = $(ENVIRON) $(PKGCENTER)/Mk/pkgcenter_readconf $(PKGCENTER_CONF) 31 | 32 | # 33 | # Pulled from pkgcenter.conf -- configured above. 34 | # 35 | DIRS = $(SOURCE_CONF) DIRS | $(PKGCENTER)/Mk/xargs 36 | SYMLINKS = $(SOURCE_CONF) SYMLINKS | $(PKGCENTER)/Mk/xargs -n 1024 37 | STAGE = $(SOURCE_CONF) STAGE | $(PKGCENTER)/Mk/xargs -n 1024 38 | 39 | ################################################################################ 40 | ############################### GLOBAL VARIABLES ############################### 41 | ################################################################################ 42 | 43 | # 44 | # Package tools 45 | # 46 | PKGCC = $(PKGCENTER)/freebsd/Mk/pkgcc 47 | PKGCCFLAGS = -y 48 | CONVERT = $(PKGCENTER)/freebsd/Mk/convert 49 | CONVERTFLAGS = -f 50 | TAR = tar 51 | TARFLAGS = c --exclude CVS -f 52 | TARSUFFIX = tar 53 | ZIP = bzip2 54 | ZIPSUFFIX = bz2 55 | SUFFIX = tbz 56 | 57 | # 58 | # Generated files 59 | # 60 | GENERATED_FILES = \ 61 | $(STAGEDIR)/+CONTENTS \ 62 | $(STAGEDIR)/+COMMENT \ 63 | $(STAGEDIR)/+DESC \ 64 | $(STAGEDIR)/+DISPLAY \ 65 | $(STAGEDIR)/+INSTALL \ 66 | $(STAGEDIR)/+POST-INSTALL \ 67 | $(STAGEDIR)/+DEINSTALL \ 68 | $(STAGEDIR)/+POST-DEINSTALL 69 | 70 | # 71 | # Package Specifics 72 | # 73 | CWD = $$($(PWD)) 74 | NAME = $$($(PKGCENTER)/freebsd/Mk/pkgname "$(PLIST)") 75 | TAG = $$($(PKGCENTER)/freebsd/Mk/pkgtag "$(NAME)") 76 | TAGNAME = $$($(PKGCENTER)/freebsd/Mk/pkgtagname "$(PLIST)") 77 | ORIGIN = $$($(PKGCENTER)/freebsd/Mk/pkgorigin "$(PLIST)") 78 | 79 | # 80 | # Standard utility pathnames 81 | # 82 | CAT = cat 83 | GIT = git 84 | MKDIR = mkdir 85 | MV = mv 86 | PWD = pwd 87 | RM = rm 88 | 89 | ################################################################################ 90 | ############################## FUNCTION VARIABLES ############################## 91 | ################################################################################ 92 | 93 | EVAL2 = eval2(){ echo "$$@"; eval "$$@"; } 94 | 95 | ################################################################################ 96 | ################################ BUILD TARGETS ################################ 97 | ################################################################################ 98 | 99 | # 100 | # Package Building Targets 101 | # 102 | 103 | .PHONY: all dirs symlinks stage forcestage plist check_name package 104 | 105 | all: stage dirs symlinks package 106 | 107 | dirs: 108 | @echo "Creating directories..." 109 | @$(DIRS) $(PKGCENTER)/Mk/make_directories 110 | 111 | symlinks: 112 | @echo "Creating symbolic links..." 113 | @$(SYMLINKS) $(PKGCENTER)/Mk/make_symlinks 114 | 115 | stage: 116 | @echo "Copying stage dependencies..." 117 | @$(EVAL2); [ -e "$(STAGEDIR)" ] || eval2 $(MKDIR) -p $(STAGEDIR) 118 | @$(STAGE) $(PKGCENTER)/Mk/make_stage 119 | 120 | forcestage: 121 | @echo "Copying [all] dependencies..." 122 | @$(EVAL2); [ -e "$(STAGEDIR)" ] || eval2 $(MKDIR) -p $(STAGEDIR) 123 | @$(STAGE) $(PKGCENTER)/Mk/make_stage -f 124 | 125 | $(PLIST): 126 | @$(EVAL2); [ "$(PLIST)" = "$(MANIFEST)" -o \ 127 | "$(PLIST)" -nt "$(MANIFEST)" ] || eval2 $(CONVERT) \ 128 | $(CONVERTFLAGS) $(MANIFEST) $(PLIST) $(STAGEDIR) 129 | 130 | plist: $(PLIST) 131 | 132 | check_name: plist 133 | @[ "$(NAME)" ] || $(PKGCENTER)/Mk/die \ 134 | "ERROR: Package $(PLIST) has no package name" 135 | 136 | package: check_name 137 | $(PKGCC) $(PKGCCFLAGS) $(PLIST) $(STAGEDIR) 138 | @$(EVAL2); cwd=$(CWD); name=$(NAME); \ 139 | eval2 cd $(STAGEDIR) || exit; \ 140 | TARFILE=$$cwd/$$name.$(TARSUFFIX); \ 141 | eval2 $(TAR) $(TARFLAGS) $$TARFILE * || exit; \ 142 | ! type "$(ZIP)" > /dev/null 2>&1 && exit; \ 143 | eval2 $(ZIP) $$TARFILE || exit; \ 144 | eval2 $(MV) -f $$TARFILE.$(ZIPSUFFIX) $$cwd/$$name.$(SUFFIX) 145 | @[ "$(ORIGIN)" ] || echo "WARNING: Empty or missing package origin" 146 | 147 | # 148 | # Package Maintenance Targets 149 | # 150 | 151 | .PHONY: clean distclean 152 | 153 | clean: 154 | $(RM) -f $(GENERATED_FILES) 155 | @$(SYMLINKS) $(PKGCENTER)/Mk/clean_symlinks && \ 156 | $(RM) -f .symlinks_created 157 | @$(DIRS) $(PKGCENTER)/Mk/clean_directories && \ 158 | $(RM) -f .dirs_created 159 | [ -e .keep-stage ] || $(RM) -Rf $(STAGEDIR) 160 | @$(EVAL2); [ "$(MANIFEST)" = "$(PLIST)" ] || eval2 $(RM) -f $(PLIST) 161 | 162 | distclean: clean 163 | $(RM) -f *.$(TARSUFFIX) *.$(SUFFIX) 164 | 165 | # 166 | # Git Maintenance Targets 167 | # 168 | 169 | .PHONY: check_tag tag forcetag untag unpublish taglist 170 | 171 | check_tag: 172 | @[ "$(TAG)" ] || $(PKGCENTER)/Mk/die \ 173 | "ERROR: Package $(PLIST) has invalid package name" 174 | 175 | tag: check_tag 176 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag "$(TAG)" 177 | 178 | forcetag: check_tag 179 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -f "$(TAG)" 180 | 181 | untag: check_tag 182 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -d "$(TAG)" 183 | 184 | unpublish: check_tag 185 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -u "$(TAG)" 186 | 187 | taglist: 188 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -l "$(TAGNAME)-*" 189 | 190 | # 191 | # Git Addition Targets 192 | # 193 | 194 | .PHONY: import commit pull push autoimport 195 | 196 | import: 197 | @$(ENVIRON) $(PKGCENTER)/Mk/git_import 198 | 199 | autoimport: 200 | @$(ENVIRON) $(PKGCENTER)/Mk/git_import -a 201 | 202 | commit: 203 | @$(GIT) commit 204 | 205 | push: 206 | @$(GIT) push origin $$( git branch | awk '$$1=="*"{print $$2}' ) --tags 207 | 208 | pull: 209 | @$(GIT) pull 210 | 211 | # 212 | # Generic Targets 213 | # 214 | 215 | .PHONY: usage targets help 216 | 217 | usage: 218 | @$(CAT) $(PKGCENTER)/freebsd/Mk/USAGE_PACKAGE 219 | 220 | targets help: 221 | @$(CAT) $(PKGCENTER)/freebsd/Mk/HELP_PACKAGE 222 | 223 | ################################################################################ 224 | # END 225 | ################################################################################ 226 | -------------------------------------------------------------------------------- /freebsd/skel/Makefile.ng: -------------------------------------------------------------------------------- 1 | # -*- tab-width: 4 -*- ;; Emacs 2 | # vi: set noexpandtab :: Vi/ViM 3 | # vi: set syntax=make :: 4 | ################################################################################ 5 | ################################ CONFIGURATION ################################# 6 | ################################################################################ 7 | 8 | PKGCENTER = ../.. 9 | MANIFEST = ./MANIFEST 10 | PLIST = $(MANIFEST) 11 | STAGEDIR = ./stage 12 | PKGCENTER_CONF = ./pkgcenter.conf 13 | 14 | ################################################################################ 15 | ############################# TARGET DEPENDENCIES ############################# 16 | ################################################################################ 17 | 18 | # 19 | # Environment 20 | # 21 | ENVIRON = PKGCENTER=$(PKGCENTER) \ 22 | MANIFEST=$(MANIFEST) \ 23 | PLIST=$(PLIST) \ 24 | STAGEDIR=$(STAGEDIR) \ 25 | PKGCENTER_CONF=$(PKGCENTER_CONF) 26 | 27 | # 28 | # Macro for reading pkgcenter.conf 29 | # 30 | SOURCE_CONF = $(ENVIRON) $(PKGCENTER)/Mk/pkgcenter_readconf $(PKGCENTER_CONF) 31 | 32 | # 33 | # Pulled from pkgcenter.conf -- configured above. 34 | # 35 | DIRS = $(SOURCE_CONF) DIRS | $(PKGCENTER)/Mk/xargs 36 | SYMLINKS = $(SOURCE_CONF) SYMLINKS | $(PKGCENTER)/Mk/xargs -n 1024 37 | STAGE = $(SOURCE_CONF) STAGE | $(PKGCENTER)/Mk/xargs -n 1024 38 | 39 | ################################################################################ 40 | ############################### GLOBAL VARIABLES ############################### 41 | ################################################################################ 42 | 43 | # 44 | # Package tools 45 | # 46 | PKGCC = $(PKGCENTER)/freebsd/Mk/pkgcc 47 | PKGCCFLAGS = -y 48 | CONVERT = $(PKGCENTER)/freebsd/Mk/convert 49 | CONVERTFLAGS = -f 50 | TAR = tar 51 | TARFLAGS = c --exclude CVS -f 52 | TARSUFFIX = tar 53 | ZIP = xz 54 | ZIPSUFFIX = xz 55 | SUFFIX = txz 56 | 57 | # 58 | # Generated files 59 | # 60 | GENERATED_FILES = \ 61 | $(STAGEDIR)/+MANIFEST \ 62 | $(STAGEDIR)/+COMPACT_MANIFEST 63 | 64 | # 65 | # Package Specifics 66 | # 67 | CWD = $$($(PWD)) 68 | NAME = $$($(PKGCENTER)/freebsd/Mk/pkgname "$(PLIST)") 69 | TAG = $$($(PKGCENTER)/freebsd/Mk/pkgtag "$(NAME)") 70 | TAGNAME = $$($(PKGCENTER)/freebsd/Mk/pkgtagname "$(PLIST)") 71 | ORIGIN = $$($(PKGCENTER)/freebsd/Mk/pkgorigin "$(PLIST)") 72 | 73 | # 74 | # Standard utility pathnames 75 | # 76 | CAT = cat 77 | GIT = git 78 | MKDIR = mkdir 79 | MV = mv 80 | PWD = pwd 81 | RM = rm 82 | 83 | ################################################################################ 84 | ############################## FUNCTION VARIABLES ############################## 85 | ################################################################################ 86 | 87 | EVAL2 = eval2(){ echo "$$@"; eval "$$@"; } 88 | 89 | ################################################################################ 90 | ################################ BUILD TARGETS ################################ 91 | ################################################################################ 92 | 93 | # 94 | # Package Building Targets 95 | # 96 | 97 | .PHONY: all dirs symlinks stage forcestage plist check_name package 98 | 99 | all: stage dirs symlinks package 100 | 101 | dirs: 102 | @echo "Creating directories..." 103 | @$(DIRS) $(PKGCENTER)/Mk/make_directories 104 | 105 | symlinks: 106 | @echo "Creating symbolic links..." 107 | @$(SYMLINKS) $(PKGCENTER)/Mk/make_symlinks 108 | 109 | stage: 110 | @echo "Copying stage dependencies..." 111 | @$(EVAL2); [ -e "$(STAGEDIR)" ] || eval2 $(MKDIR) -p $(STAGEDIR) 112 | @$(STAGE) $(PKGCENTER)/Mk/make_stage 113 | 114 | forcestage: 115 | @echo "Copying [all] dependencies..." 116 | @$(EVAL2); [ -e "$(STAGEDIR)" ] || eval2 $(MKDIR) -p $(STAGEDIR) 117 | @$(STAGE) $(PKGCENTER)/Mk/make_stage -f 118 | 119 | $(PLIST): 120 | @$(EVAL2); [ "$(PLIST)" = "$(MANIFEST)" -o \ 121 | "$(PLIST)" -nt "$(MANIFEST)" ] || eval2 $(CONVERT) \ 122 | $(CONVERTFLAGS) $(MANIFEST) $(PLIST) $(STAGEDIR) 123 | 124 | plist: $(PLIST) 125 | 126 | check_name: plist 127 | @[ "$(NAME)" ] || $(PKGCENTER)/Mk/die \ 128 | "ERROR: Package $(PLIST) has no package name" 129 | 130 | package: check_name 131 | $(PKGCC) $(PKGCCFLAGS) $(PLIST) $(STAGEDIR) 132 | @$(EVAL2); cwd=$(CWD); name=$(NAME); \ 133 | eval2 cd $(STAGEDIR) || exit; \ 134 | TARFILE=$$cwd/$$name.$(TARSUFFIX); \ 135 | if tar --help 2>&1 | grep -q bsdtar; then \ 136 | vers=$$( tar --version 2> /dev/null ); \ 137 | case "$${vers#"$${vers%%[0-9]*}"}" in \ 138 | [0-2].*) TRANSFORM=':^[^+]:/~:' ;; \ 139 | *) TRANSFORM=':^[^+]:/~:S' ;; \ 140 | esac; \ 141 | TARFLAGS2="-s '$$TRANSFORM' -P"; \ 142 | else \ 143 | TARFLAGS2="--transform 's:^[^+]:/&:S' -P"; \ 144 | fi; \ 145 | eval2 $(TAR) $(TARFLAGS) $$TARFILE $$TARFLAGS2 * || exit; \ 146 | ! type "$(ZIP)" > /dev/null 2>&1 && exit; \ 147 | eval2 $(ZIP) $$TARFILE || exit; \ 148 | eval2 $(MV) -f $$TARFILE.$(ZIPSUFFIX) $$cwd/$$name.$(SUFFIX) 149 | @[ "$(ORIGIN)" ] || echo "WARNING: Empty or missing package origin" 150 | 151 | # 152 | # Package Maintenance Targets 153 | # 154 | 155 | .PHONY: clean distclean 156 | 157 | clean: 158 | $(RM) -f $(GENERATED_FILES) 159 | @$(SYMLINKS) $(PKGCENTER)/Mk/clean_symlinks && \ 160 | $(RM) -f .symlinks_created 161 | @$(DIRS) $(PKGCENTER)/Mk/clean_directories && \ 162 | $(RM) -f .dirs_created 163 | [ -e .keep-stage ] || $(RM) -Rf $(STAGEDIR) 164 | @$(EVAL2); [ "$(MANIFEST)" = "$(PLIST)" ] || eval2 $(RM) -f $(PLIST) 165 | 166 | distclean: clean 167 | $(RM) -f *.$(TARSUFFIX) *.$(SUFFIX) 168 | 169 | # 170 | # Git Maintenance Targets 171 | # 172 | 173 | .PHONY: check_tag tag forcetag untag unpublish taglist 174 | 175 | check_tag: 176 | @[ "$(TAG)" ] || $(PKGCENTER)/Mk/die \ 177 | "ERROR: Package $(PLIST) has invalid package name" 178 | 179 | tag: check_tag 180 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag "$(TAG)" 181 | 182 | forcetag: check_tag 183 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -f "$(TAG)" 184 | 185 | untag: check_tag 186 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -d "$(TAG)" 187 | 188 | unpublish: check_tag 189 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -u "$(TAG)" 190 | 191 | taglist: 192 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -l "$(TAGNAME)-*" 193 | 194 | # 195 | # Git Addition Targets 196 | # 197 | 198 | .PHONY: import commit pull push autoimport 199 | 200 | import: 201 | @$(ENVIRON) $(PKGCENTER)/Mk/git_import 202 | 203 | autoimport: 204 | @$(ENVIRON) $(PKGCENTER)/Mk/git_import -a 205 | 206 | commit: 207 | @$(GIT) commit 208 | 209 | push: 210 | @$(GIT) push origin $$( git branch | awk '$$1=="*"{print $$2}' ) --tags 211 | 212 | pull: 213 | @$(GIT) pull 214 | 215 | # 216 | # Generic Targets 217 | # 218 | 219 | .PHONY: usage targets help 220 | 221 | usage: 222 | @$(CAT) $(PKGCENTER)/freebsd/Mk/USAGE_PACKAGE 223 | 224 | targets help: 225 | @$(CAT) $(PKGCENTER)/freebsd/Mk/HELP_PACKAGE 226 | 227 | ################################################################################ 228 | # END 229 | ################################################################################ 230 | -------------------------------------------------------------------------------- /freebsd/skel/Makefile.old: -------------------------------------------------------------------------------- 1 | # -*- tab-width: 4 -*- ;; Emacs 2 | # vi: set noexpandtab :: Vi/ViM 3 | # vi: set syntax=make :: 4 | ################################################################################ 5 | ################################ CONFIGURATION ################################# 6 | ################################################################################ 7 | 8 | PKGCENTER = ../.. 9 | MANIFEST = ./MANIFEST 10 | PLIST = ./PLIST 11 | STAGEDIR = ./stage 12 | PKGCENTER_CONF = ./pkgcenter.conf 13 | 14 | ################################################################################ 15 | ############################# TARGET DEPENDENCIES ############################# 16 | ################################################################################ 17 | 18 | # 19 | # Environment 20 | # 21 | ENVIRON = PKGCENTER=$(PKGCENTER) \ 22 | MANIFEST=$(MANIFEST) \ 23 | PLIST=$(PLIST) \ 24 | STAGEDIR=$(STAGEDIR) \ 25 | PKGCENTER_CONF=$(PKGCENTER_CONF) 26 | 27 | # 28 | # Macro for reading pkgcenter.conf 29 | # 30 | SOURCE_CONF = $(ENVIRON) $(PKGCENTER)/Mk/pkgcenter_readconf $(PKGCENTER_CONF) 31 | 32 | # 33 | # Pulled from pkgcenter.conf -- configured above. 34 | # 35 | DIRS = $(SOURCE_CONF) DIRS | $(PKGCENTER)/Mk/xargs 36 | SYMLINKS = $(SOURCE_CONF) SYMLINKS | $(PKGCENTER)/Mk/xargs -n 1024 37 | STAGE = $(SOURCE_CONF) STAGE | $(PKGCENTER)/Mk/xargs -n 1024 38 | 39 | ################################################################################ 40 | ############################### GLOBAL VARIABLES ############################### 41 | ################################################################################ 42 | 43 | # 44 | # Package tools 45 | # 46 | PKGCC = $(PKGCENTER)/freebsd/Mk/pkgcc 47 | PKGCCFLAGS = -y 48 | CONVERT = $(PKGCENTER)/freebsd/Mk/convert 49 | CONVERTFLAGS = -f 50 | TAR = tar 51 | TARFLAGS = c --exclude CVS -f 52 | TARSUFFIX = tar 53 | ZIP = gzip 54 | ZIPSUFFIX = gz 55 | SUFFIX = tgz 56 | 57 | # 58 | # Generated files 59 | # 60 | GENERATED_FILES = \ 61 | $(STAGEDIR)/+CONTENTS \ 62 | $(STAGEDIR)/+COMMENT \ 63 | $(STAGEDIR)/+DESC \ 64 | $(STAGEDIR)/+DISPLAY \ 65 | $(STAGEDIR)/+INSTALL \ 66 | $(STAGEDIR)/+POST-INSTALL \ 67 | $(STAGEDIR)/+DEINSTALL \ 68 | $(STAGEDIR)/+POST-DEINSTALL 69 | 70 | # 71 | # Package Specifics 72 | # 73 | CWD = $$($(PWD)) 74 | NAME = $$($(PKGCENTER)/freebsd/Mk/pkgname "$(PLIST)") 75 | TAG = $$($(PKGCENTER)/freebsd/Mk/pkgtag "$(NAME)") 76 | TAGNAME = $$($(PKGCENTER)/freebsd/Mk/pkgtagname "$(PLIST)") 77 | ORIGIN = $$($(PKGCENTER)/freebsd/Mk/pkgorigin "$(PLIST)") 78 | 79 | # 80 | # Standard utility pathnames 81 | # 82 | CAT = cat 83 | GIT = git 84 | MKDIR = mkdir 85 | MV = mv 86 | PWD = pwd 87 | RM = rm 88 | 89 | ################################################################################ 90 | ############################## FUNCTION VARIABLES ############################## 91 | ################################################################################ 92 | 93 | EVAL2 = eval2(){ echo "$$@"; eval "$$@"; } 94 | 95 | ################################################################################ 96 | ################################ BUILD TARGETS ################################ 97 | ################################################################################ 98 | 99 | # 100 | # Package Building Targets 101 | # 102 | 103 | .PHONY: all dirs symlinks stage forcestage plist check_name package 104 | 105 | all: stage dirs symlinks package 106 | 107 | dirs: 108 | @echo "Creating directories..." 109 | @$(DIRS) $(PKGCENTER)/Mk/make_directories 110 | 111 | symlinks: 112 | @echo "Creating symbolic links..." 113 | @$(SYMLINKS) $(PKGCENTER)/Mk/make_symlinks 114 | 115 | stage: 116 | @echo "Copying stage dependencies..." 117 | @$(EVAL2); [ -e "$(STAGEDIR)" ] || eval2 $(MKDIR) -p $(STAGEDIR) 118 | @$(STAGE) $(PKGCENTER)/Mk/make_stage 119 | 120 | forcestage: 121 | @echo "Copying [all] dependencies..." 122 | @$(EVAL2); [ -e "$(STAGEDIR)" ] || eval2 $(MKDIR) -p $(STAGEDIR) 123 | @$(STAGE) $(PKGCENTER)/Mk/make_stage -f 124 | 125 | $(PLIST): 126 | @$(EVAL2); [ "$(PLIST)" = "$(MANIFEST)" -o \ 127 | "$(PLIST)" -nt "$(MANIFEST)" ] || eval2 $(CONVERT) \ 128 | $(CONVERTFLAGS) $(MANIFEST) $(PLIST) $(STAGEDIR) 129 | 130 | plist: $(PLIST) 131 | 132 | check_name: plist 133 | @[ "$(NAME)" ] || $(PKGCENTER)/Mk/die \ 134 | "ERROR: Package $(PLIST) has no package name" 135 | 136 | package: check_name 137 | $(PKGCC) $(PKGCCFLAGS) $(PLIST) $(STAGEDIR) 138 | @$(EVAL2); cwd=$(CWD); name=$(NAME); \ 139 | eval2 cd $(STAGEDIR) || exit; \ 140 | TARFILE=$$cwd/$$name.$(TARSUFFIX); \ 141 | eval2 $(TAR) $(TARFLAGS) $$TARFILE * || exit; \ 142 | ! type "$(ZIP)" > /dev/null 2>&1 && exit; \ 143 | eval2 $(ZIP) $$TARFILE || exit; \ 144 | eval2 $(MV) -f $$TARFILE.$(ZIPSUFFIX) $$cwd/$$name.$(SUFFIX) 145 | @[ "$(ORIGIN)" ] || echo "WARNING: Empty or missing package origin" 146 | 147 | # 148 | # Package Maintenance Targets 149 | # 150 | 151 | .PHONY: clean distclean 152 | 153 | clean: 154 | $(RM) -f $(GENERATED_FILES) 155 | @$(SYMLINKS) $(PKGCENTER)/Mk/clean_symlinks && \ 156 | $(RM) -f .symlinks_created 157 | @$(DIRS) $(PKGCENTER)/Mk/clean_directories && \ 158 | $(RM) -f .dirs_created 159 | [ -e .keep-stage ] || $(RM) -Rf $(STAGEDIR) 160 | @$(EVAL2); [ "$(MANIFEST)" = "$(PLIST)" ] || eval2 $(RM) -f $(PLIST) 161 | 162 | distclean: clean 163 | $(RM) -f *.$(TARSUFFIX) *.$(SUFFIX) 164 | 165 | # 166 | # Git Maintenance Targets 167 | # 168 | 169 | .PHONY: check_tag tag forcetag untag unpublish taglist 170 | 171 | check_tag: 172 | @[ "$(TAG)" ] || $(PKGCENTER)/Mk/die \ 173 | "ERROR: Package $(PLIST) has invalid package name" 174 | 175 | tag: check_tag 176 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag "$(TAG)" 177 | 178 | forcetag: check_tag 179 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -f "$(TAG)" 180 | 181 | untag: check_tag 182 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -d "$(TAG)" 183 | 184 | unpublish: check_tag 185 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -u "$(TAG)" 186 | 187 | taglist: 188 | @$(ENVIRON) $(PKGCENTER)/Mk/git_tag -l "$(TAGNAME)-*" 189 | 190 | # 191 | # Git Addition Targets 192 | # 193 | 194 | .PHONY: import commit pull push autoimport 195 | 196 | import: 197 | @$(ENVIRON) $(PKGCENTER)/Mk/git_import 198 | 199 | autoimport: 200 | @$(ENVIRON) $(PKGCENTER)/Mk/git_import -a 201 | 202 | commit: 203 | @$(GIT) commit 204 | 205 | push: 206 | @$(GIT) push origin $$( git branch | awk '$$1=="*"{print $$2}' ) --tags 207 | 208 | pull: 209 | @$(GIT) pull 210 | 211 | # 212 | # Generic Targets 213 | # 214 | 215 | .PHONY: usage targets help 216 | 217 | usage: 218 | @$(CAT) $(PKGCENTER)/freebsd/Mk/USAGE_PACKAGE 219 | 220 | targets help: 221 | @$(CAT) $(PKGCENTER)/freebsd/Mk/HELP_PACKAGE 222 | 223 | ################################################################################ 224 | # END 225 | ################################################################################ 226 | -------------------------------------------------------------------------------- /freebsd/skel/PLIST: -------------------------------------------------------------------------------- 1 | @comment PKG_FORMAT_REVISION:1.1 2 | @name pkgname-x.y 3 | @comment ORIGIN:origin/pkgname 4 | @owner root 5 | @group wheel 6 | @pkgdep dependency-x.y 7 | @comment DEPORIGIN:deporigin/dependency 8 | @cwd /install/root 9 | file1 10 | file2 11 | file3 12 | dir/file4 13 | dir/file5 14 | dir/file6 15 | @dirrm dir 16 | @cwd . 17 | @ignore 18 | +COMMENT 19 | @ignore 20 | +DESC 21 | @ignore 22 | +INSTALL 23 | @ignore 24 | +POST-INSTALL 25 | @ignore 26 | +DEINSTALL 27 | @ignore 28 | +POST-DEINSTALL 29 | -------------------------------------------------------------------------------- /freebsd/skel/pkgcenter.conf: -------------------------------------------------------------------------------- 1 | # -*- tab-width: 4 -*- ;; Emacs 2 | # vi: set noexpandtab :: Vi/ViM 3 | # vi: set filetype=sh :: 4 | ############################################################ IDENT(1) 5 | # 6 | # $Title: Package staging configuration $ 7 | # $Copyright: 1999-2022 Devin Teske. All rights reserved. $ 8 | # $FrauBSD: dwatch-json/freebsd/skel/pkgcenter.conf 2022-08-23 12:14:14 -0700 freebsdfrau $ 9 | # 10 | ############################################################ INFORMATION 11 | # 12 | # This file is entirely optional. You can safely delete it if you do not need 13 | # any of the optional features that it provides. 14 | # 15 | # The pkgcenter Makefile(s) will automatically export following macros into the 16 | # shell environment before sourcing this configuration file (which is actually 17 | # a shell script): 18 | # 19 | # Macro Description 20 | # PKGCENTER Relative pathname to top-level pkgcenter directory. 21 | # PLIST Package packing list (usually `./PLIST'). 22 | # MANIFEST Package packing list (usually `./MANIFEST'). 23 | # STAGEDIR Package stage directory (usually `./stage'). 24 | # PKGCENTER_CONF Path to this file. 25 | # 26 | ############################################################ CONFIGURATION 27 | 28 | # 29 | # Directories to create before (and clean up after) creating the package. 30 | # NOTE: Be careful to list sub-directories in depth-first order. 31 | # 32 | DIRS=" 33 | # Directory 34 | " 35 | 36 | # 37 | # Symlinks to be created before (and cleaned up after) creating the package. 38 | # NOTE: Only the symlink, not the target, will be removed on clean-up. 39 | # 40 | SYMLINKS=" 41 | # Symbolic-link Target 42 | " 43 | 44 | # 45 | # External staging dependencies to ``pull-in'' when creating the package. 46 | # WARNING: source will overwrite destination if touched. 47 | # 48 | PREFIX=/usr/local 49 | SRCDIR=$PKGCENTER 50 | STAGE=" 51 | # Source Destination 52 | " 53 | 54 | ################################################################################ 55 | # END 56 | ################################################################################ 57 | -------------------------------------------------------------------------------- /freebsd/skel/stage/+COMMENT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrauBSD/dwatch-json/086ab512ab420bfcee2e9d50936793026df7da12/freebsd/skel/stage/+COMMENT -------------------------------------------------------------------------------- /freebsd/skel/stage/+DESC: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrauBSD/dwatch-json/086ab512ab420bfcee2e9d50936793026df7da12/freebsd/skel/stage/+DESC -------------------------------------------------------------------------------- /graf/logs: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ############################################################ IDENT(1) 3 | # 4 | # $Title: Script to list program suite log files from service $ 5 | # $Copyright: 2022 Devin Teske. All rights reserved. $ 6 | # $FrauBSD$ 7 | # 8 | ############################################################ PROGRAM 9 | 10 | pgm="${0##*/}" # Program basename 11 | _pgm="${pgm%-*}" # Program suite 12 | 13 | ############################################################ CONFIGURATION 14 | 15 | LOGFILE="/var/log/$_pgm/$_pgm.log" 16 | 17 | ############################################################ GLOBALS 18 | 19 | # 20 | # Global exit status 21 | # 22 | SUCCESS=0 23 | FAILURE=1 24 | 25 | # 26 | # OS Glue 27 | # 28 | : "${UNAME_s:=$( uname -s )}" 29 | 30 | # 31 | # Output format 32 | # 33 | modified=$( date +%s ) || exit 34 | case "$UNAME_s" in 35 | Linux) modified=$( date -d@$modified ) ;; 36 | *) modified=$( date -r$modified ) 37 | esac || exit 38 | OFMT="%-${#modified}s %8s %5s %s\n" 39 | 40 | ############################################################ FUNCTIONS 41 | 42 | usage() 43 | { 44 | local fmt="$1" 45 | local optfmt="\t%-5s %s\n" 46 | exec >&2 47 | if [ "$fmt" ]; then 48 | shift 1 # fmt 49 | printf "%s: $fmt\n" "$pgm" "$@" 50 | fi 51 | printf "Usage: %s [-h]\n" "$pgm" 52 | printf "Options:\n" 53 | printf "$optfmt" "-h" "Print usage statement and exit." 54 | exit $FAILURE 55 | } 56 | 57 | ############################################################ MAIN 58 | 59 | # 60 | # Process command-line options 61 | # 62 | while getopts h flag; do 63 | case "$flag" in 64 | *) usage # NOTREACHED 65 | esac 66 | done 67 | shift $(( $OPTIND - 1 )) 68 | 69 | # 70 | # Check command-line arguments 71 | # 72 | [ $# -eq 0 ] || usage "Too many arguments" # NOTREACHED 73 | 74 | # 75 | # Print header 76 | # 77 | printf "$OFMT" DATE LINES SIZE FILE 78 | 79 | # 80 | # List files 81 | # 82 | for file in $( ls -rt "$LOGFILE"* 2> /dev/null ); do 83 | size=$( du -Ah "$file" | awk '{print $1}' ) 84 | case "$UNAME_s" in 85 | Linux) modified=$( stat -c%Y "$file" 2> /dev/null ) && 86 | modified=$( date -d@$modified 2> /dev/null ) ;; 87 | *) modified=$( stat -f%m "$file" 2> /dev/null ) && 88 | modified=$( date -r$modified 2> /dev/null ) 89 | esac || continue 90 | case "$file" in 91 | *.gz) lines=$( zcat "$file" | awk 'END{print NR}' ) ;; 92 | *.bz|*.bz2) lines=$( bzcat "$file" | awk 'END{print NR}' ) ;; 93 | *.xz) lines=$( xzcat "$file" | awk 'END{print NR}' ) ;; 94 | *) lines=$( awk 'END{print NR}' "$file" ) 95 | esac 96 | printf "$OFMT" "$modified" "$lines" "$size" "$file" 97 | done 98 | 99 | exit $SUCCESS 100 | 101 | ################################################################################ 102 | # END 103 | ################################################################################ 104 | -------------------------------------------------------------------------------- /graf/rotate: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ############################################################ IDENT(1) 3 | # 4 | # $Title: Script to rotate log files $ 5 | # $Copyright: 2022 Devin Teske. All rights reserved. $ 6 | # $FrauBSD$ 7 | # 8 | ############################################################ PROGRAM 9 | 10 | pgm="${0##*/}" # Program basename 11 | _pgm="${pgm%-*}" # Program suite 12 | 13 | ############################################################ CONFIGURATION 14 | 15 | LOGFILE="/var/log/$_pgm/$_pgm.log" 16 | NLOGFILES=14 17 | 18 | ############################################################ GLOBALS 19 | 20 | # 21 | # Global exit status 22 | # 23 | FAILURE=1 24 | 25 | ############################################################ FUNCTIONS 26 | 27 | quietly(){ "$@" > /dev/null 2>&1; } 28 | 29 | usage() 30 | { 31 | local fmt="$1" 32 | local optfmt="\t%-5s %s\n" 33 | exec >&2 34 | if [ "$fmt" ]; then 35 | shift 1 # fmt 36 | printf "%s: $fmt\n" "$pgm" "$@" 37 | fi 38 | printf "Usage: %s [-h]\n" "$pgm" 39 | printf "Options:\n" 40 | printf "$optfmt" "-h" "Print usage statement and exit." 41 | exit $FAILURE 42 | } 43 | 44 | ############################################################ MAIN 45 | 46 | # 47 | # Process command-line options 48 | # 49 | while getopts h flag; do 50 | case "$flag" in 51 | *) usage # NOTREACHED 52 | esac 53 | done 54 | shift $(( $OPTIND - 1 )) 55 | 56 | # 57 | # Check command-line arguments 58 | # 59 | [ $# -eq 0 ] || usage "Too many arguments" # NOTREACHED 60 | 61 | # 62 | # Rotate 63 | # 64 | quietly rm -f "$LOGFILE.$NLOGFILES.gz" 65 | n=$NLOGFILES 66 | while [ $n -ge 0 ]; do 67 | n=$(( $n - 1 )) 68 | quietly mv "$LOGFILE.$n.gz" "$LOGFILE.$(( $n + 1 )).gz" 69 | done 70 | quietly cp -f "$LOGFILE" "$LOGFILE.0" 71 | quietly gzip "$LOGFILE.0" 72 | 73 | # 74 | # Truncate 75 | # 76 | :> "$LOGFILE" 77 | 78 | ################################################################################ 79 | # END 80 | ################################################################################ 81 | -------------------------------------------------------------------------------- /graf/stats: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ############################################################ IDENT(1) 3 | # 4 | # $Title: Script to launch telegraf to send JSON log to InfluxDB $ 5 | # $Copyright: 2022 Devin Teske. All rights reserved. $ 6 | # $FrauBSD$ 7 | # 8 | ############################################################ INFORMATION 9 | # 10 | # See CONF file for setting which JSON log gets processed, which database host 11 | # to send the data to (does not necessarily have to be InfluxDB), and how to 12 | # treat the JSON data that is to be sent. 13 | # 14 | ############################################################ PROGRAM 15 | 16 | pgm="${0##*/}" # Program basename 17 | _pgm="${pgm%_*}" # Program suite 18 | 19 | ############################################################ CONFIGURATION 20 | 21 | CONF="$_pgm/stats.conf" 22 | LOGFILE="/var/log/$_pgm/stats.log" 23 | ERRLOGFILE="/var/run/$_pgm/stats.stderr" 24 | PIDFILE="/var/run/$_pgm/stats.pid" 25 | 26 | ############################################################ ENVIRONMENT 27 | 28 | # 29 | # Adjust PATH 30 | # NB: So we can find telegraf in MAIN 31 | # 32 | if ! type telegraf > /dev/null 2>&1; then 33 | for dir in \ 34 | /usr/local/bin \ 35 | ; do 36 | [ -e "$dir/telegraf" ] || continue 37 | PATH="$PATH${PATH:+:}$dir" 38 | done 39 | # ... otherwise let the error come through 40 | fi 41 | 42 | ############################################################ GLOBALS 43 | 44 | # 45 | # Global exit status 46 | # 47 | SUCCESS=0 48 | FAILURE=1 49 | 50 | # 51 | # OS Glue 52 | # 53 | CONFDIR=/etc 54 | case "${UNAME_s:=$( uname -s )}" in 55 | FreeBSD) CONFDIR=/usr/local/etc ;; 56 | esac 57 | 58 | ############################################################ FUNCTIONS 59 | 60 | usage() 61 | { 62 | echo "Usage: $pgm" >&2 63 | exit $FAILURE 64 | } 65 | 66 | ############################################################ MAIN 67 | 68 | [ $# -eq 0 ] || usage # NOTREACHED 69 | 70 | # 71 | # Launch telegraf to send file to influxdb 72 | # 73 | telegraf --config "$CONFDIR/$CONF" >> "$LOGFILE" 2>> "$ERRLOGFILE" & 74 | 75 | # 76 | # Create pid file 77 | # 78 | pid=$! 79 | echo $pid > "$PIDFILE" 80 | 81 | # 82 | # Yield time so telegraf has time to parse the config file for syntax errors 83 | # 84 | sleep 0.25 85 | 86 | # 87 | # Generate exit status 88 | # 89 | kill -0 $pid 90 | 91 | ################################################################################ 92 | # END 93 | ################################################################################ 94 | -------------------------------------------------------------------------------- /grafio/cron.d/grafio: -------------------------------------------------------------------------------- 1 | ############################################################ IDENT(1) 2 | # 3 | # $Title: crontab(5) to rotate grafio service logs $ 4 | # $Copyright: 2022 Devin Teske. All rights reserved. $ 5 | # $FrauBSD: dwatch-json/grafio/cron.d/grafio 2022-08-22 15:36:11 -0700 freebsdfrau $ 6 | # 7 | ############################################################ CRONTAB(5) 8 | 9 | #minute hour mday month wday who command 10 | 0 3 * * * root grafio-rotate 11 | 12 | ################################################################################ 13 | # END 14 | ################################################################################ 15 | -------------------------------------------------------------------------------- /grafio/etc/grafio.conf.sample: -------------------------------------------------------------------------------- 1 | # vi: set filetype=sh :: Vi/ViM 2 | ############################################################ IDENT(1) 3 | # 4 | # $Title: Configuration file for `grafio' service $ 5 | # $Copyright: 2014-2022 Devin Teske. All rights reserved. $ 6 | # $FrauBSD: dwatch-json/grafio/etc/grafio.conf.sample 2022-08-22 15:36:11 -0700 freebsdfrau $ 7 | # 8 | ############################################################ INFORMATION 9 | # 10 | # Log sample: 11 | # {"report_type":"$REPORT_TYPE","hostname":"$HOSTNAME","epoch":1538360226, 12 | # "name":"...",...} 13 | # 14 | # For each variable, you will get: 15 | # Counting specific conditions. 16 | # 17 | # Any events matching $EVENT_TEST that fail to match the DTrace clause defined 18 | # in each variable will increment the unmatched globals. 19 | # 20 | # Example: 21 | # diskA='this->device_entry == "ada0"' 22 | # diskB='this->device_entry == "ada1"' 23 | # 24 | ############################################################ INCLUDES 25 | 26 | . /usr/local/etc/grafio/grafio.subr || exit 27 | 28 | ############################################################ DEFAULTS 29 | 30 | # 31 | # Variables to ignore 32 | # Default: (None) 33 | # 34 | ignore DISKS 35 | 36 | # 37 | # DTrace probe 38 | # Default: profile-10s 39 | # 40 | #PROBE= 41 | 42 | # 43 | # Report handle for kafka consumer 44 | # Default: ${PROFILE%-raw} 45 | # 46 | #REPORT_TYPE= 47 | 48 | # 49 | # Hostname for kafka consumer 50 | # Default: $HOSTNAME 51 | # 52 | #HOSTNAME= 53 | 54 | # 55 | # DTrace predicate for all stats 56 | # Default: (set by `-k name' and/or `-t test' dwatch options) 57 | # Example: execname == "cam" 58 | # 59 | #EVENT_TEST= 60 | 61 | # 62 | # Label for unmatched stats 63 | # Default: unlabeled 64 | # 65 | #UNMATCHED_LABEL="Unknown" 66 | 67 | ############################################################ DISKS 68 | 69 | # 70 | # Probe system disks and their labels 71 | # 72 | ignore KERN_DISKS disk 73 | KERN_DISKS=$( sysctl -n kern.disks ) 74 | for disk in $KERN_DISKS; do 75 | setvar ${disk}_label "$( descr $disk )" 76 | done 77 | 78 | # 79 | # Configure all disks 80 | # 81 | DISKS=" 82 | # VARNAME;DEVNAME[;LABEL] 83 | 84 | # System disks 85 | $( 86 | for disk in $KERN_DISKS; do 87 | var=$( echo "$disk" | awk '{ 88 | sub(/^[0-9]/, "_&") 89 | gsub(/[^[a-zA-Z0-9]_]/, "") 90 | print 91 | }' ) 92 | getvar "${var}_label" label 93 | printf '%s;%s;%s\n' "$var" "$disk" "$label" 94 | done 95 | ) 96 | 97 | # Additional disks 98 | 99 | 100 | " # END-QUOTE 101 | 102 | ############################################################ MAIN 103 | 104 | # 105 | # Test against configured disks 106 | # 107 | test_disks DISKS 108 | 109 | ################################################################################ 110 | # END 111 | ################################################################################ 112 | -------------------------------------------------------------------------------- /grafio/etc/grafio.subr.sample: -------------------------------------------------------------------------------- 1 | #- 2 | # $Title: grafnet config helpers $ 3 | # $Copyright: 2022 Devin Teske. All rights reserved. $ 4 | # $FrauBSD: dwatch-json/grafio/etc/grafio.subr.sample 2022-08-22 15:36:11 -0700 freebsdfrau $ 5 | # 6 | ############################################################ ENVIRONMENT 7 | 8 | : "${PATH:=/usr/bin:/usr/sbin}" 9 | 10 | ############################################################ GLOBALS 11 | 12 | ignore(){ local IFS=" "; IGNORE="$IGNORE${IGNORE:+ }$*"; } 13 | 14 | # 15 | # Separator 16 | # 17 | SEP=';' 18 | ignore SEP 19 | 20 | # 21 | # Literal newline 22 | # NB: Variable ignored by suite 23 | # 24 | NL=" 25 | " # END-QUOTE 26 | 27 | ############################################################ FUNCTIONS 28 | 29 | descr() 30 | { 31 | diskinfo -v "$1" | awk -v disk="$1" ' 32 | /descr.$/ { mfr = $1 } 33 | /Attachment$/ { at = $1 } 34 | END { 35 | descr = sprintf("%s %s %s", mfr, at, disk) 36 | gsub(/ /, " ", descr) 37 | sub(/^[[:space:]]*/, "", descr) 38 | sub(/[[:space:]]*$/, "", descr) 39 | print descr 40 | } 41 | ' # END-QUOTE 42 | } 43 | 44 | warn() 45 | { 46 | local fmt="$1" 47 | local caller="${__funcname:-${funcname:-${_pgm:-$pgm}}}" 48 | shift 1 # fmt 49 | printf "%s: $fmt\n" "$caller" "$@" >&2 50 | } 51 | 52 | getvar() 53 | { 54 | local __var_to_get="$1" __var_to_set="$2" 55 | [ "$__var_to_set" ] || local value 56 | eval [ \"\${$__var_to_get+set}\" ] 57 | local __retval=$? 58 | eval ${__var_to_set:-value}=\"\${$__var_to_get}\" 59 | [ "$__var_to_set" ] || { [ "$value" ] && echo "$value"; } 60 | return $__retval 61 | } 62 | 63 | varlines() 64 | { 65 | getvar "$1" | awk '! /^[[:space:]]*(#|$)/ { 66 | sub(/^[[:space:]]*/, "") 67 | sub(/[[:space:]]*$/, "") 68 | print 69 | }' 70 | } 71 | 72 | replaceall() 73 | { 74 | local __left="" __right="$1" 75 | local __find="$2" __replace="$3" __var_to_set="$4" 76 | while : forever; do 77 | case "$__right" in *$__find*) 78 | __left="$__left${__right%%$__find*}$__replace" 79 | __right="${__right#*$__find}" 80 | continue 81 | esac 82 | break 83 | done 84 | __left="$__left${__right#*$__find}" 85 | if [ "$__var_to_set" ]; then 86 | setvar "$__var_to_set" "$__left" 87 | else 88 | echo "$__left" 89 | fi 90 | } 91 | 92 | shell_escape() 93 | { 94 | local __string="$1" __var_to_set="$2" 95 | replaceall "$__string" "'" "'\\''" "$__var_to_set" 96 | } 97 | 98 | reparse() 99 | { 100 | local __parseIFS="${1:-$IFS}" 101 | [ $# -gt 0 ] && shift 1 # parseIFS 102 | local __map= 103 | while [ $# -gt 0 ]; do 104 | if [ "$1" != "--" ]; then 105 | __map="$__map $1" 106 | else 107 | shift 1 # -- 108 | break 109 | fi 110 | shift 1 111 | done 112 | local __map_entry 113 | local __var_name_to_get 114 | local __var_name_to_set 115 | local __var_value_to_set 116 | local IFS="$__parseIFS" 117 | set -- $* 118 | IFS=" $NL " # NB: Parent IFS may simply be \n 119 | for __map_entry in $__map; do 120 | __var_name_to_set="${__map_entry%%=*}" 121 | __var_name_to_get="${__map_entry#*=}" 122 | eval "__var_value_to_set=\"\${$__var_name_to_get}\"" 123 | shell_escape "$__var_value_to_set" __var_value_to_set 124 | echo "$__var_name_to_set='$__var_value_to_set'; " 125 | done 126 | } 127 | 128 | ############################################################ GENERATORS 129 | 130 | # 131 | # Generate disk tests from contents of variable given by name as $1 132 | # 133 | test_disks() 134 | { 135 | local __funcname=test_disks 136 | local __rv=0 # SUCCESS 137 | local __var_to_get="$1" 138 | local __line __test 139 | local __fields="__varname=1 __devname=2 __label=3" 140 | local __varname __devname __label 141 | 142 | local IFS="$NL" 143 | for __line in $( varlines "$__var_to_get" ); do 144 | eval "$( reparse "$SEP" $__fields -- "$__line" )" 145 | if [ ! -e "/dev/$__devname" ]; then 146 | warn "/dev/%s: No such file or directory" "$__devname" 147 | return ${FAILURE:-1} 148 | fi 149 | __test="this->device_entry == \"$__devname\"" 150 | setvar "$__varname" "$__test" 151 | [ "$__label" ] && setvar "${__varname}_label" "$__label" 152 | done 153 | 154 | return $__rv 155 | } 156 | 157 | ################################################################################ 158 | # END 159 | ################################################################################ 160 | -------------------------------------------------------------------------------- /grafio/etc/stats.conf.sample: -------------------------------------------------------------------------------- 1 | [[outputs.influxdb]] 2 | database = "grafio_stats" 3 | urls = ["http://ip_or_host:8086"] 4 | skip_database_creation = true 5 | [[inputs.tail]] 6 | files = ["/var/log/grafio/grafio.log"] 7 | data_format = "json" 8 | json_time_key = "epoch" 9 | json_time_format = "unix" 10 | json_timezone = "America/Los_Angeles" 11 | tag_keys = [ 12 | "hostname", 13 | "name" 14 | ] 15 | -------------------------------------------------------------------------------- /grafio/rc.d/grafio: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $FrauBSD: dwatch-json/grafio/rc.d/grafio 2022-08-22 15:36:11 -0700 freebsdfrau $ 4 | # 5 | 6 | # PROVIDE: grafio 7 | # KEYWORD: nojail shutdown 8 | 9 | . /etc/rc.subr 10 | 11 | name=grafio 12 | desc="Manage DTrace-driven disk I/O statistics collection service" 13 | rcvar=${name}_enable 14 | load_rc_config $name 15 | 16 | command=/usr/local/sbin/$name 17 | pidfile=/var/run/$name/$name.pid 18 | procname=dtrace 19 | edit_cmd=suite_cmd 20 | list_cmd=suite_cmd 21 | logs_cmd=suite_cmd 22 | rotate_cmd=suite_cmd 23 | show_cmd=suite_cmd 24 | trace_cmd=suite_cmd 25 | extra_commands="edit list logs rotate show tail trace" 26 | 27 | vargv() 28 | { 29 | pargs ${1:-$$} | awk -v start=${2:-2} ' 30 | ! match($0, /^argv\[[0-9]+]: /) { next } 31 | { 32 | n = substr($0, 6, RLENGTH - 3) 33 | argv[n] = substr($0, RSTART + RLENGTH) 34 | gsub(/'\''/, "&\\\\&&", argv[n]) 35 | } 36 | n >= start { printf "'\'%s\'' ", argv[n] } 37 | ' # END-QUOTE 38 | } 39 | 40 | suite_cmd() 41 | { 42 | # NB: eval is safe [vargv encapsulation + extra_commands filter] 43 | eval $command $( vargv ) 44 | } 45 | 46 | run_rc_command "$1" 47 | -------------------------------------------------------------------------------- /grafio/rc.d/grafio_stats: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $FrauBSD: dwatch-json/grafio/rc.d/grafio_stats 2022-08-22 15:36:11 -0700 freebsdfrau $ 4 | # 5 | 6 | # PROVIDE: grafio_stats 7 | # KEYWORD: nojail shutdown 8 | 9 | . /etc/rc.subr 10 | 11 | name=grafio_stats 12 | _name=${name%_*} # Program suite 13 | rcvar=${name}_enable 14 | command=/usr/local/sbin/$name 15 | pidfile=/var/run/$_name/stats.pid 16 | procname=telegraf 17 | 18 | load_rc_config $name 19 | run_rc_command "$1" 20 | -------------------------------------------------------------------------------- /grafnet/cron.d/grafnet: -------------------------------------------------------------------------------- 1 | ############################################################ IDENT(1) 2 | # 3 | # $Title: crontab(5) to rotate grafnet service logs $ 4 | # $Copyright: 2022 Devin Teske. All rights reserved. $ 5 | # $FrauBSD: dwatch-json/grafnet/cron.d/grafnet 2022-08-04 14:58:00 -0700 freebsdfrau $ 6 | # 7 | ############################################################ CRONTAB(5) 8 | 9 | #minute hour mday month wday who command 10 | 0 3 * * * root grafnet-rotate 11 | 12 | ################################################################################ 13 | # END 14 | ################################################################################ 15 | -------------------------------------------------------------------------------- /grafnet/etc/grafnet.conf.sample: -------------------------------------------------------------------------------- 1 | # vi: set filetype=sh :: Vi/ViM 2 | ############################################################ IDENT(1) 3 | # 4 | # $Title: Configuration file for `grafnet' service $ 5 | # $Copyright: 2018-2022 Devin Teske. All rights reserved. $ 6 | # $FrauBSD: dwatch-json/grafnet/etc/grafnet.conf.sample 2022-08-10 21:54:33 -0700 freebsdfrau $ 7 | # 8 | ############################################################ INFORMATION 9 | # 10 | # Log sample: 11 | # {"report_type":"$REPORT_TYPE","hostname":"$HOSTNAME","epoch":1538360226, 12 | # "name":"...","tcp_rcvd":12,"tcp_sent":34,"udp_rcvd":56,"udp_sent":78} 13 | # 14 | # For each variable, you will get: 15 | # _tcp_rcvd 16 | # _tcp_sent 17 | # _udp_rcvd 18 | # _udp_sent 19 | # Counting the bytes for specific conditions. 20 | # 21 | # Any bytes matching $EVENT_TEST that fail to match the DTrace clause defined 22 | # in each variable will increment the {tcp,udp}_{rcvd,sent} globals. 23 | # 24 | # Example: 25 | # hostA='this->remote == "1.2.3.4"' 26 | # hostB='this->remote == "2.3.4.5"' 27 | # hostC='this->remote == "3.4.5.6"' 28 | # 29 | ############################################################ INCLUDES 30 | 31 | . /usr/local/etc/grafnet/grafnet.subr || exit 32 | 33 | ############################################################ DEFAULTS 34 | 35 | # 36 | # Variables to ignore 37 | # Default: (None) 38 | # 39 | ignore CLIENTS GATEWAYS SERVICES CLIENT_SERVICES JAILS 40 | 41 | # 42 | # DTrace probe 43 | # Default: profile-10s 44 | # 45 | #PROBE= 46 | 47 | # 48 | # Report handle for kafka consumer 49 | # Default: ${PROFILE%-raw} 50 | # 51 | #REPORT_TYPE= 52 | 53 | # 54 | # Hostname for kafka consumer 55 | # Default: $HOSTNAME 56 | # 57 | #HOSTNAME= 58 | 59 | # 60 | # DTrace predicate for all stats 61 | # Default: (set by `-k name' and/or `-t test' dwatch options) 62 | # Example: execname == "sshd" 63 | # 64 | #EVENT_TEST= 65 | 66 | # 67 | # Label for unmatched stats 68 | # Default: $HOSTNAME $REPORT_TYPE 69 | # 70 | UNMATCHED_LABEL="Unknown" 71 | 72 | ############################################################ SERVICE DEFNS 73 | 74 | apfs="this->lport == 548" 75 | http="this->lport == 80" 76 | https="this->lport == 443" 77 | l2tp="this->lport == 500 || this->lport == 1701 || this->lport == 4500" 78 | webs="$http || $https" 79 | 80 | ignore apfs http https l2tp webs 81 | # 82 | # (above) Optional: Show/Hide global per-service statistics 83 | # 84 | # For example, removing "apfs" from ignore will get you apfs_tcp_sent and 85 | # related statistics representing APFS traffic for all APFS packets, from all 86 | # source to all destinations. 87 | # 88 | # This may be desirable or undesirable based on your situation. For example, 89 | # if you do not configure CLIENTS or SERVICES below against any of these 90 | # defined services but you do handle such packets, it may be desirable to get 91 | # per-service global stats. However, since packets can be counted multiple 92 | # times for different stats, perhaps the global will appear as duplicate noise 93 | # in a time-series graph that is grouped by tag name without filter. 94 | # 95 | # At any event, there is no guarantee that these services are even utilized and 96 | # to presume that stats on them would be useful may be incorrect. 97 | # 98 | # Therefore, the default is to hide these service definitions from the stats 99 | # produced by the service while still defining them for use below in CLIENTS 100 | # and SERVICES. 101 | # 102 | 103 | ############################################################ CLIENTS 104 | 105 | # 106 | # Per-client statistics with optional service-exclude list 107 | # 108 | # NB: Some clients may be chatty and you want to ignore some traffic. For 109 | # example, excluding APFS traffic to a Time Machine backup server. To 110 | # achieve this, a default-empty comma-separated list of services-to-exclude 111 | # can be given after the hostname (before the optional label). 112 | # NB: For readability, each service listed in the EXCLUDE list can be preceded 113 | # with a single minus (`-') to make it clear that said service is being 114 | # subtracted from the statistics defined for the particular client. 115 | # 116 | CLIENTS=" 117 | # VARNAME;HOSTNAME;EXCLUDE[;LABEL] 118 | 119 | # Desktops 120 | 121 | # Infra 122 | 123 | # Phones 124 | 125 | # Printers 126 | 127 | # Tablets 128 | 129 | # TVs 130 | 131 | # Nuclear reactors 132 | 133 | " # END-QUOTE 134 | 135 | ############################################################ SERVICES 136 | 137 | # 138 | # Per-service statistics 139 | # NB: These are services hosted by this host or a jail on this host 140 | # 141 | SERVICES=" 142 | # VARNAME;HOSTNAME;SVCNAME[;LABEL] 143 | 144 | # Host VPN 145 | 146 | # Phone VPNs 147 | 148 | # Tablet VPNs 149 | 150 | # Shaper Origin VPNs 151 | 152 | " # END-QUOTE 153 | 154 | # 155 | # Per-client service statistics 156 | # 157 | CLIENT_SERVICES=" 158 | # VARNAME;CLIENT;SVCNAME[;LABEL] 159 | 160 | # Desktop Time Machine Backup 161 | 162 | # Polywell experiment backups 163 | 164 | " # END-QUOTE 165 | 166 | ############################################################ JAILS 167 | 168 | # 169 | # Per-jail statistics 170 | # 171 | # NB: These are jails on this host 172 | # 173 | JAILS=" 174 | # VARNAME;JAILNAME[;LABEL] 175 | 176 | # Grafana 177 | 178 | # Mail 179 | 180 | # Sharing 181 | 182 | # Time Machine 183 | 184 | # VPN 185 | 186 | # Honeypot 187 | 188 | " # END-QUOTE 189 | 190 | ############################################################ MAIN 191 | 192 | set -e # errexit 193 | 194 | # 195 | # Tests against packet local address 196 | # NB: local in this context is the address recipient for received packets or 197 | # the address sender for sent packets. 198 | # 199 | test_local JAILS 200 | 201 | # 202 | # Tests against packet remote address 203 | # NB: remote in this context is the address recipient for sent packets or the 204 | # address sender for received packets. 205 | # 206 | test_remote CLIENTS 207 | 208 | # 209 | # Test against both packet local address and local port 210 | # 211 | test_local_svc SERVICES 212 | 213 | # 214 | # Test against both packet remote address and local port 215 | # 216 | test_remote_svc CLIENT_SERVICES 217 | 218 | ################################################################################ 219 | # END 220 | ################################################################################ 221 | -------------------------------------------------------------------------------- /grafnet/etc/grafnet.subr.sample: -------------------------------------------------------------------------------- 1 | #- 2 | # $Title: grafnet config helpers $ 3 | # $Copyright: 2022 Devin Teske. All rights reserved. $ 4 | # $FrauBSD: dwatch-json/grafnet/etc/grafnet.subr.sample 2022-08-10 18:26:33 -0700 freebsdfrau $ 5 | # 6 | ############################################################ ENVIRONMENT 7 | 8 | : "${PATH:=/usr/bin:/usr/sbin}" 9 | 10 | ############################################################ GLOBALS 11 | 12 | ignore(){ local IFS=" "; IGNORE="$IGNORE${IGNORE:+ }$*"; } 13 | 14 | # 15 | # Separator 16 | # 17 | SEP=';' 18 | ignore SEP 19 | 20 | # 21 | # Literal newline 22 | # NB: Variable ignored by suite 23 | # 24 | NL=" 25 | " # END-QUOTE 26 | 27 | ############################################################ FUNCTIONS 28 | 29 | ip4of() 30 | { 31 | local a 32 | case "$1" in 33 | [0-9]*) echo "$1" ;; # Already A 34 | *) a=$( host -t A "$1" ) && 35 | echo "$a" | awk '{print $NF}' 36 | esac 37 | } 38 | 39 | ip6of() 40 | { 41 | local aaaa 42 | case "$1" in 43 | \[*\]) echo "$1" ;; # Already encapsulated AAAA 44 | *:*) echo "[$1]" ;; # Already AAAA 45 | *) aaaa=$( host -t AAAA "$1" ) && 46 | echo "$aaaa" | awk '{printf "[%s]\n", $NF}' 47 | esac 48 | } 49 | 50 | jidof() 51 | { 52 | case "$1" in 53 | [0-9]*) echo "$1" ;; # Already a JID 54 | *) jls -j "$1" jid 55 | esac 56 | } 57 | 58 | warn() 59 | { 60 | local fmt="$1" 61 | local caller="${__funcname:-${funcname:-${_pgm:-$pgm}}}" 62 | shift 1 # fmt 63 | printf "%s: $fmt\n" "$caller" "$@" >&2 64 | } 65 | 66 | getvar() 67 | { 68 | local __var_to_get="$1" __var_to_set="$2" 69 | [ "$__var_to_set" ] || local value 70 | eval [ \"\${$__var_to_get+set}\" ] 71 | local __retval=$? 72 | eval ${__var_to_set:-value}=\"\${$__var_to_get}\" 73 | [ "$__var_to_set" ] || { [ "$value" ] && echo "$value"; } 74 | return $__retval 75 | } 76 | 77 | varlines() 78 | { 79 | getvar "$1" | awk '! /^[[:space:]]*(#|$)/ { 80 | sub(/^[[:space:]]*/, "") 81 | sub(/[[:space:]]*$/, "") 82 | print 83 | }' 84 | } 85 | 86 | replaceall() 87 | { 88 | local __left="" __right="$1" 89 | local __find="$2" __replace="$3" __var_to_set="$4" 90 | while : forever; do 91 | case "$__right" in *$__find*) 92 | __left="$__left${__right%%$__find*}$__replace" 93 | __right="${__right#*$__find}" 94 | continue 95 | esac 96 | break 97 | done 98 | __left="$__left${__right#*$__find}" 99 | if [ "$__var_to_set" ]; then 100 | setvar "$__var_to_set" "$__left" 101 | else 102 | echo "$__left" 103 | fi 104 | } 105 | 106 | shell_escape() 107 | { 108 | local __string="$1" __var_to_set="$2" 109 | replaceall "$__string" "'" "'\\''" "$__var_to_set" 110 | } 111 | 112 | reparse() 113 | { 114 | local __parseIFS="${1:-$IFS}" 115 | [ $# -gt 0 ] && shift 1 # parseIFS 116 | local __map= 117 | while [ $# -gt 0 ]; do 118 | if [ "$1" != "--" ]; then 119 | __map="$__map $1" 120 | else 121 | shift 1 # -- 122 | break 123 | fi 124 | shift 1 125 | done 126 | local __map_entry 127 | local __var_name_to_get 128 | local __var_name_to_set 129 | local __var_value_to_set 130 | local IFS="$__parseIFS" 131 | set -- $* 132 | IFS=" $NL " # NB: Parent IFS may simply be \n 133 | for __map_entry in $__map; do 134 | __var_name_to_set="${__map_entry%%=*}" 135 | __var_name_to_get="${__map_entry#*=}" 136 | eval "__var_value_to_set=\"\${$__var_name_to_get}\"" 137 | shell_escape "$__var_value_to_set" __var_value_to_set 138 | echo "$__var_name_to_set='$__var_value_to_set'; " 139 | done 140 | } 141 | 142 | ############################################################ GENERATORS 143 | 144 | # 145 | # Generate local host tests from contents of variable given by name as $1 146 | # 147 | test_local() 148 | { 149 | local __funcname=test_local 150 | local __rv=0 # SUCCESS 151 | local __var_to_get="$1" 152 | local __line __test 153 | local __fields="__varname=1 __name=2 __label=3" 154 | local __varname __name __label 155 | 156 | local IFS="$NL" 157 | for __line in $( varlines "$__var_to_get" ); do 158 | eval "$( reparse "$SEP" $__fields -- "$__line" )" 159 | if ! __test="this->local == \"$( ip4of $__name )\""; then 160 | __rv=$? 161 | warn "ip4of: Error resolving \`%s'" "$__name" 162 | return $__rv 163 | fi 164 | setvar "$__varname" "$__test" 165 | [ "$__label" ] && setvar "${__varname}_label" "$__label" 166 | done 167 | 168 | return $__rv 169 | } 170 | 171 | # 172 | # Generate remote client tests from contents of variable given by name as $1 173 | # 174 | # Note that it [currently] does no good to test this->local against 175 | # such hosts because dtrace_tcp(4) states rather clearly: 176 | # 177 | # The tcp:::send() and tcp:::receive() probes fire when the host 178 | # sends or receives a TCP packet, respectively. As with the 179 | # dtrace_udp(4) provider, tcp probes fire only for packets sent by 180 | # or to the local host; forwarded packets are handled in the IP 181 | # layer and are only visible to the dtrace_ip(4) provider. 182 | # 183 | # As for UDP, while we do trap fbt::soreceive_dgram:entry, running: 184 | # 185 | # dwatch -yFX json-net-raw | grep dgram 186 | # 187 | # or 188 | # 189 | # dwatch -FX json-net-raw | 190 | # awk '/dgram/&&sub(/.*{/,"{")' | 191 | # jq -c '[.remote,"=>",.local]' 192 | # 193 | # Shows that local will never be any of the above remote hosts 194 | # (local will always be the gateway or destination of the UDP packet 195 | # received at this function-boundary -- soreceive_dgram). 196 | # 197 | # The same goes for TCP as we can see as: 198 | # 199 | # dwatch -FX json-net-raw | 200 | # awk '/tcp:/&&sub(/.*{/,"{")' | 201 | # jq -c '.|select(.local=="testip")' 202 | # 203 | # Shows us that just like the case for UDP, there is no need to test 204 | # local as it will never match one of the above remote hosts. Further- 205 | # more, changing ".local" to ".remote" above should show both SEND and 206 | # RCVD events for TCP. 207 | # 208 | test_remote() 209 | { 210 | local __funcname=test_remote 211 | local __rv=0 # SUCCESS 212 | local __var_to_get="$1" 213 | local __line __test __not 214 | local __fields="__varname=1 __name=2 __exclude=3 __label=4" 215 | local __varname __name __exclude __label 216 | local __svcname __svctest 217 | 218 | local IFS="$NL" 219 | for __line in $( varlines "$__var_to_get" ); do 220 | eval "$( reparse "$SEP" $__fields -- "$__line" )" 221 | if ! __test="this->remote == \"$( ip4of $__name )\""; then 222 | __rv=$? 223 | warn "ip4of: Error resolving \`%s'" "$__name" 224 | return $__rv 225 | fi 226 | __not= 227 | IFS="," 228 | for __svcname in $__exclude; do 229 | __svcname="${__svcname#-}" # Trim leading `-' 230 | getvar "$__svcname" __svctest || 231 | warn "Unknown service \`%s'" "$__svcname" 232 | __not="$__not || ($__svctest)" 233 | done 234 | __not="${__not# || }" 235 | [ "$__not" ] && __test="$__test && ! ($__not)" 236 | setvar "$__varname" "$__test" 237 | [ "$__label" ] && setvar "${__varname}_label" "$__label" 238 | done 239 | 240 | return $__rv 241 | } 242 | 243 | # 244 | # Generate local service tests from contents of variable given by name as $1 245 | # 246 | test_local_svc() 247 | { 248 | local __funcname=test_local_svc 249 | local __rv=0 # SUCCESS 250 | local __var_to_get="$1" 251 | local __line __test __svctest 252 | local __fields="__varname=1 __svchost=2 __svcname=3 __label=4" 253 | local __varname __svchost __svcname __label 254 | 255 | local IFS="$NL" 256 | for __line in $( varlines "$__var_to_get" ); do 257 | eval "$( reparse "$SEP" $__fields -- "$__line" )" 258 | if ! __test="this->local == \"$( ip4of $__svchost )\""; then 259 | __rv=$? 260 | warn "ip4of: Error resolving \`%s'" "$__svchost" 261 | return $__rv 262 | fi 263 | if getvar "$__svcname" __svctest; then 264 | [ "$__svctest" ] && __test="$__test && ($__svctest)" 265 | else 266 | __rv=$? 267 | warn "Unknown service \`%s'" "$__svcname" 268 | return $__rv 269 | fi 270 | setvar "$__varname" "$__test" 271 | [ "$__label" ] && setvar "${__varname}_label" "$__label" 272 | done 273 | 274 | return $__rv 275 | } 276 | 277 | # 278 | # Generate remote service tests from contents of variable given by name as $1 279 | # NB: This is traffic from a certain remote client to a particular service 280 | # 281 | test_remote_svc() 282 | { 283 | local __funcname=test_remote_svc 284 | local __rv=0 # SUCCESS 285 | local __var_to_get="$1" 286 | local __line __test __svctest 287 | local __fields="__varname=1 __client=2 __svcname=3 __label=4" 288 | local __varname __client __svcname __label 289 | 290 | local IFS="$NL" 291 | for __line in $( varlines "$__var_to_get" ); do 292 | eval "$( reparse "$SEP" $__fields -- "$__line" )" 293 | if ! __test="this->remote == \"$( ip4of $__client )\""; then 294 | __rv=$? 295 | warn "ip4of: Error resolving \`%s'" "$__client" 296 | return $__rv 297 | fi 298 | if getvar "$__svcname" __svctest; then 299 | [ "$__svctest" ] && __test="$__test && ($__svctest)" 300 | else 301 | __rv=$? 302 | warn "Unknown service \`%s'" "$__svcname" 303 | return $__rv 304 | fi 305 | setvar "$__varname" "$__test" 306 | [ "$__label" ] && setvar "${__varname}_label" "$__label" 307 | done 308 | 309 | return $__rv 310 | } 311 | 312 | ################################################################################ 313 | # END 314 | ################################################################################ 315 | -------------------------------------------------------------------------------- /grafnet/etc/stats.conf.sample: -------------------------------------------------------------------------------- 1 | [[outputs.influxdb]] 2 | database = "grafnet_stats" 3 | urls = ["http://ip_or_host:8086"] 4 | skip_database_creation = true 5 | [[inputs.tail]] 6 | files = ["/var/log/grafnet/grafnet.log"] 7 | data_format = "json" 8 | json_time_key = "epoch" 9 | json_time_format = "unix" 10 | json_timezone = "America/Los_Angeles" 11 | tag_keys = [ 12 | "hostname", 13 | "name" 14 | ] 15 | -------------------------------------------------------------------------------- /grafnet/rc.d/grafnet: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $FrauBSD: dwatch-json/grafnet/rc.d/grafnet 2022-08-22 15:48:30 -0700 freebsdfrau $ 4 | # 5 | 6 | # PROVIDE: grafnet 7 | # REQUIRE: NETWORKING 8 | # KEYWORD: nojail shutdown 9 | 10 | . /etc/rc.subr 11 | 12 | name=grafnet 13 | desc="Manage DTrace-driven network statistics collection service" 14 | rcvar=${name}_enable 15 | load_rc_config $name 16 | 17 | command=/usr/local/sbin/$name 18 | pidfile=/var/run/$name/$name.pid 19 | procname=dtrace 20 | edit_cmd=suite_cmd 21 | list_cmd=suite_cmd 22 | logs_cmd=suite_cmd 23 | rotate_cmd=suite_cmd 24 | show_cmd=suite_cmd 25 | trace_cmd=suite_cmd 26 | extra_commands="edit list logs rotate show tail trace" 27 | 28 | vargv() 29 | { 30 | pargs ${1:-$$} | awk -v start=${2:-2} ' 31 | ! match($0, /^argv\[[0-9]+]: /) { next } 32 | { 33 | n = substr($0, 6, RLENGTH - 3) 34 | argv[n] = substr($0, RSTART + RLENGTH) 35 | gsub(/'\''/, "&\\\\&&", argv[n]) 36 | } 37 | n >= start { printf "'\'%s\'' ", argv[n] } 38 | ' # END-QUOTE 39 | } 40 | 41 | suite_cmd() 42 | { 43 | # NB: eval is safe [vargv encapsulation + extra_commands filter] 44 | eval $command $( vargv ) 45 | } 46 | 47 | run_rc_command "$1" 48 | -------------------------------------------------------------------------------- /grafnet/rc.d/grafnet_stats: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $FrauBSD: dwatch-json/grafnet/rc.d/grafnet_stats 2022-08-04 17:30:02 -0700 freebsdfrau $ 4 | # 5 | 6 | # PROVIDE: grafnet_stats 7 | # REQUIRE: NETWORKING 8 | # KEYWORD: nojail shutdown 9 | 10 | . /etc/rc.subr 11 | 12 | name=grafnet_stats 13 | _name=${name%_*} # Program suite 14 | rcvar=${name}_enable 15 | command=/usr/local/sbin/$name 16 | pidfile=/var/run/$_name/stats.pid 17 | procname=telegraf 18 | 19 | load_rc_config $name 20 | run_rc_command "$1" 21 | -------------------------------------------------------------------------------- /json-io: -------------------------------------------------------------------------------- 1 | # -*- tab-width: 4 -*- ;; Emacs 2 | # vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM 3 | ############################################################ IDENT(1) 4 | # 5 | # $Title: dwatch(8) JSON module for dtrace_io(4) $ 6 | # $Copyright: 2014-2022 Devin Teske. All rights reserved. $ 7 | # $FrauBSD: dwatch-json/json-io 2022-08-22 15:36:11 -0700 freebsdfrau $ 8 | # $Version: 1.0 $ 9 | # 10 | ############################################################ DESCRIPTION 11 | # 12 | # Produce JSON custom log format for disk I/O 13 | # 14 | ############################################################ PROBE 15 | 16 | _RAW_PROFILE=$PROFILE-raw 17 | load_profile $_RAW_PROFILE 18 | 19 | ############################################################ MAIN 20 | 21 | if [ "$DEBUG$EXIT_AFTER_COMPILE" ]; then 22 | eval dwatch $ARGV -qX $_RAW_PROFILE 23 | exit 24 | fi 25 | 26 | info "Watching '$PROBE' ..." 27 | eval dwatch $ARGV -qX $_RAW_PROFILE | awk ' 28 | sub(/^.*: /, "") { print; fflush() } 29 | ' # END-QUOTE 30 | exit $SUCCESS 31 | 32 | ################################################################################ 33 | # END 34 | ################################################################################ 35 | -------------------------------------------------------------------------------- /json-io-config: -------------------------------------------------------------------------------- 1 | # -*- tab-width: 4 -*- ;; Emacs 2 | # vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM 3 | ############################################################ IDENT(1) 4 | # 5 | # $Title: dwatch(8) JSON module for dtrace_io(4) $ 6 | # $Copyright: 2014-2022 Devin Teske. All rights reserved. $ 7 | # $FrauBSD: dwatch-json/json-io-config 2022-08-22 15:36:11 -0700 freebsdfrau $ 8 | # $Version: 1.0 $ 9 | # 10 | ############################################################ DESCRIPTION 11 | # 12 | # Produce JSON custom log format for disk I/O 13 | # 14 | ############################################################ GLOBALS 15 | 16 | eval "$( echo "$EVENT_TEST" | awk -v argv="$ARGV" ' 17 | function set(var, value) 18 | { 19 | gsub(/'\''/,"&\\\\&&", value) 20 | printf "%s='\''%s'\''\n", var, value 21 | } 22 | $0 { buf = buf $0 } 23 | END { 24 | # 25 | # EVENT_TEST for -k "ssh" 26 | # execname == "ssh" 27 | # 28 | head = buf 29 | tail = "" 30 | while (match(head, /execname == "[^"]*"/)) { 31 | tail = substr(head, 1, RSTART - 1) 32 | repl = substr(head, RSTART, RLENGTH) 33 | head = substr(head, RSTART + RLENGTH) 34 | if (sub(/ \|\|[[:space:]]*\(/, "", head)) 35 | sub(/\)$/, "", head) 36 | sub(/^execname == "/, "", repl) 37 | sub(/"$/, "", repl) 38 | argv = argv " -k \"" repl "\"" 39 | } 40 | buf = tail head 41 | 42 | # 43 | # EVENT_TEST for -k "ssh*" 44 | # strstr(execname, "ssh") == execname 45 | # 46 | head = buf 47 | tail = "" 48 | while (match(head, "strstr\\(execname, \"[^\"]*\"\\) == " \ 49 | "execname")) \ 50 | { 51 | tail = substr(head, 1, RSTART - 1) 52 | repl = substr(head, RSTART, RLENGTH) 53 | head = substr(head, RSTART + RLENGTH) 54 | if (sub(/ \|\|[[:space:]]*\(/, "", head)) 55 | sub(/\)$/, "", head) 56 | sub(/^strstr\(execname, "/, "", repl) 57 | sub(/"\) == execname$/, "", repl) 58 | argv = argv " -k \"" repl "*\"" 59 | } 60 | buf = tail head 61 | 62 | # 63 | # EVENT_TEST for -k "*ssh" 64 | # strstr(execname, "ssh") == (execname + strlen(execname) - 3) 65 | # 66 | head = buf 67 | tail = "" 68 | while (match(head, "strstr\\(execname, \"[^\"]*\"\\) == " \ 69 | "\\(execname \\+ strlen\\(execname\\) - " \ 70 | "[[:digit:]]+\\)")) \ 71 | { 72 | tail = substr(head, 1, RSTART - 1) 73 | repl = substr(head, RSTART, RLENGTH) 74 | head = substr(head, RSTART + RLENGTH) 75 | if (sub(/ \|\|[[:space:]]*\(/, "", head)) 76 | sub(/\)$/, "", head) 77 | sub(/^strstr\(execname, "/, "", repl) 78 | sub("\"\\) == \\(execname \\+ strlen\\(execname\\)" \ 79 | " - [[:digit:]]+\\)", "", repl) 80 | argv = argv " -k \"*" repl "\"" 81 | } 82 | buf = tail head 83 | 84 | set("EVENT_TEST", buf) 85 | set("ARGV", argv) 86 | } 87 | ' )" 88 | 89 | ############################################################ PROBE 90 | 91 | _RAW_PROFILE=$PROFILE-raw 92 | load_profile $_RAW_PROFILE 93 | 94 | ############################################################ MAIN 95 | 96 | if [ "$DEBUG$EXIT_AFTER_COMPILE" ]; then 97 | eval dwatch $ARGV -qX $_RAW_PROFILE 98 | exit 99 | fi 100 | 101 | info "Watching '$PROBE' ..." 102 | eval dwatch $ARGV -qX $_RAW_PROFILE $PROBE_ARG | awk ' 103 | sub(/^.*: /, "")||1 { print; fflush() } 104 | ' # END-QUOTE 105 | exit $SUCCESS 106 | 107 | ################################################################################ 108 | # END 109 | ################################################################################ 110 | -------------------------------------------------------------------------------- /json-io-config-raw: -------------------------------------------------------------------------------- 1 | # -*- tab-width: 4 -*- ;; Emacs 2 | # vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM 3 | ############################################################ IDENT(1) 4 | # 5 | # $Title: dwatch(8) JSON module for dtrace_io(4) $ 6 | # $Copyright: 2014-2022 Devin Teske. All rights reserved. $ 7 | # $FrauBSD: dwatch-json/json-io-config-raw 2022-08-22 15:36:11 -0700 freebsdfrau $ 8 | # $Version: 1.0 $ 9 | # 10 | ############################################################ DESCRIPTION 11 | # 12 | # Produce JSON custom log format for disk I/O 13 | # 14 | ############################################################ PROBE 15 | 16 | : "${PROBE_SECONDS:=10}" 17 | : "${PROBE:=profile-${PROBE_SECONDS}s}" 18 | 19 | ############################################################ INCLUDES 20 | 21 | . /usr/share/bsdconfig/strings.subr || exit 22 | 23 | ############################################################ FUNCTIONS 24 | 25 | # 26 | # JSON helpers 27 | # 28 | jfmt(){ printf "\\\\\"%s\\\\\":$1" "$2" "$3"; } 29 | jraw(){ jfmt %s "$1" "$2"; } 30 | jstr(){ jraw "$1" "\\\"$2\\\""; } 31 | _jstr(){ printf ,; jstr "$@"; } 32 | _jraw(){ printf ,; jraw "$@"; } 33 | 34 | ############################################################ CONFIG 35 | 36 | IFS=" $NL" # space tab newline 37 | 38 | # 39 | # Defaults 40 | # 41 | : "${JSON_IO_CONFIG:=/usr/local/etc/dwatch-${PROFILE%-config*}.conf}" 42 | : "${HOSTNAME:=$( hostname )}" 43 | : "${REPORT_TYPE:=${PROFILE%-raw}}" 44 | : "${TAG_NAME:=name}" 45 | : "${UNMATCHED_LABEL:=}" 46 | 47 | # 48 | # Tabulate variables prior to loading config 49 | # 50 | vars_ignore="$( set | awk ' 51 | match($0, /^[a-zA-Z_][a-zA-Z0-9_]*=/) { 52 | print substr($0, 1, RLENGTH - 1) 53 | } 54 | ' ) vars_ignore" 55 | 56 | # 57 | # Load config file 58 | # 59 | # NB: Allowing the config to tell us which vars we should unset via IGNORE 60 | # NB: Making sure to nullify IGNORE before we load the config 61 | # 62 | IGNORE= 63 | . "$JSON_IO_CONFIG" || exit 64 | 65 | # 66 | # Set default values 67 | # 68 | : "${UNMATCHED_LABEL:=unlabeled}" 69 | 70 | # 71 | # Determine which variables were set by config 72 | # NB: Ignoring variables set prior to loading config [vars_ignore] 73 | # NB: Ignoring "*_label" variables 74 | # 75 | vars_ignore="IGNORE $IGNORE $vars_ignore" 76 | export vars_ignore # for awk(1) ENVIRON 77 | confvars=$( set | awk ' 78 | BEGIN { 79 | confvars = "" 80 | delete env 81 | nvars = split(ENVIRON["vars_ignore"], vars, /[[:space:]]+/) 82 | for (n = 1; n <= nvars; n++) ignore[vars[n]] 83 | } 84 | match($0, /^[a-zA-Z_][a-zA-Z0-9_]*=/) { 85 | name = substr($0, 1, RLENGTH - 1) 86 | if (name in ignore) next 87 | if (name ~ /_label$/) next 88 | confvars = confvars " " name 89 | } 90 | END { print substr(confvars, 2) } 91 | ' ) 92 | 93 | ############################################################ OVERRIDES 94 | 95 | # 96 | # Override dwatch(1) settings 97 | # 98 | MAX_ARGS=0 # -B num 99 | MAX_DEPTH=0 # -K num 100 | 101 | # 102 | # Unsupported dwatch(1) features 103 | # 104 | unset EXECREGEX # -z regex 105 | unset GROUP # -g group 106 | unset PID # -p pid 107 | unset PROBE_COALESCE # -F 108 | unset PSTREE # -R 109 | unset USER # -u user 110 | 111 | ############################################################ EVENT ACTION 112 | 113 | _EVENT_TEST="${EVENT_TEST:+($EVENT_TEST)}" 114 | _EVENT_TEST="${CUSTOM_TEST:+$CUSTOM_TEST${EVENT_TEST:+ && }}$_EVENT_TEST" 115 | if [ "$JID" ]; then 116 | pr_id="curthread->td_proc->p_ucred->cr_prison->pr_id" 117 | _EVENT_TEST="$pr_id == $JID${_EVENT_TEST:+ && ($_EVENT_TEST)}" 118 | unset JID 119 | fi 120 | EVENT_TEST="cpu == 0" 121 | CUSTOM_TEST= 122 | 123 | _CONF_OTHER= 124 | IFS=" " 125 | nconf=0 126 | for var in $confvars; do 127 | nconf=$(( $nconf + 1 )) 128 | eval val=\"\$$var\" 129 | _CONF_OTHER="$_CONF_OTHER || ($val)" 130 | done 131 | [ "$_CONF_OTHER" ] && _CONF_OTHER="!(${_CONF_OTHER# || })" 132 | 133 | ############################################################ ACTIONS 134 | 135 | BIO_COMMANDS=" 136 | BIO_CMD0 137 | BIO_CMD1 138 | BIO_CMD2 139 | BIO_DELETE 140 | BIO_FLUSH 141 | BIO_GETATTR 142 | BIO_READ 143 | BIO_WRITE 144 | BIO_ZONE 145 | " # END-QUOTE 146 | 147 | BIO_CMD_LIST=$( echo "$BIO_COMMANDS" | awk ' 148 | /^[[:space:]]*(#|$)/ { next } 149 | { 150 | sub(/#.*/, "") 151 | sub(/^[[:space:]]*/, "") 152 | sub(/[[:space:]]*$/, "") 153 | n = split($0, f, /[[:space:]]+/) 154 | for (i = 1; i <= n; i++) list = list " " f[i] 155 | } 156 | END { print substr(list, 2) } 157 | ' ) 158 | 159 | bio_cmd_list=$( echo "$BIO_CMD_LIST" | awk '{ 160 | sub(/^BIO_/, "") 161 | gsub(/ BIO_/, " ") 162 | print tolower($0) 163 | }' ) 164 | 165 | stat_list="start done error" 166 | 167 | bytes_list="read_bytes bytes_read write_bytes bytes_written" 168 | 169 | exec 9<bio_length :\n" 267 | printf "\tbio_cmd == BIO_WRITE ? %s_write_bytes +=" "$var" 268 | printf " this->bio_length :\n" 269 | printf "\t0;\n\n" 270 | 271 | printf "inline int %s_add_bio_cmd_done_bytes[" "$var" 272 | printf "int bio_cmd, uint64_t bytes] =\n" 273 | printf "\tbio_cmd == BIO_READ ? %s_bytes_read +=" "$var" 274 | printf " bytes :\n" 275 | printf "\tbio_cmd == BIO_WRITE ? %s_bytes_written +=" "$var" 276 | printf " bytes :\n" 277 | printf "\t0;\n\n" 278 | 279 | for stat in $stat_list; do 280 | printf "inline int %s_increment_bio_cmd_%s" \ 281 | "$var" "$stat" 282 | printf "[int bio_cmd] =\n" 283 | for cmd in $BIO_CMD_LIST; do 284 | key=$var_$( echo "${cmd#BIO_}" | 285 | awk '{print tolower($0)}' ) 286 | printf "\tbio_cmd == %s ? %s_%s_%s++ :\n" \ 287 | "$cmd" "$var" "$key" "$stat" 288 | done 289 | printf "\t%s_unknown_%s++;\n" "$var" "$stat" 290 | printf "\n" 291 | done 292 | done 293 | ) 294 | 295 | BEGIN /* probe ID $ID */ 296 | {${TRACE:+ 297 | printf("<$ID>");} 298 | set_globals_to[0]; 299 | $( IFS=" " 300 | for var in $confvars; do 301 | printf "\n\t%s_set_globals_to[0];" "$var" 302 | done 303 | ) 304 | } 305 | 306 | /****************************** I/O ******************************/ 307 | 308 | io:::start, io:::done /* probe ID $(( $ID + 1 )) */ 309 | {${TRACE:+ 310 | printf("<$(( $ID + 1 ))>");} 311 | this->bio = (struct bio *)args[0]; 312 | } 313 | 314 | io:::start, io:::done /this->bio != NULL/ /* probe ID $(( $ID + 2 )) */ 315 | {${TRACE:+ 316 | printf("<$(( $ID + 2 ))>"); 317 | } 318 | /* 319 | * struct bio * 320 | */ 321 | this->bufinfo = xlate ((struct bio *)this->bio); 322 | this->b_flags = (int)this->bufinfo.b_flags; 323 | this->b_error = this->b_flags & BIO_ERROR == BIO_ERROR ? 1 : 0; 324 | this->bio_cmd = (int)this->bufinfo.b_cmd; 325 | this->bio_length = (long)this->bufinfo.b_bcount; 326 | 327 | /* 328 | * struct devstat * 329 | */ 330 | this->devinfo = xlate ((struct devstat *)args[1]); 331 | this->device_entry = device_name[this->devinfo]; 332 | this->device_if = device_if[(int)this->devinfo.dev_type]; 333 | this->device_type = device_type[(int)this->devinfo.dev_type]; 334 | 335 | /* De-duplicate events */ 336 | this->bio = (this->device_entry == "[0,-1]" ? NULL : this->bio); 337 | } 338 | 339 | $( IFS=" " 340 | id=$(( $ID + 3 )) 341 | for var in $confvars; do 342 | eval val=\"\$$var\" 343 | 344 | printf "io:::start\n" 345 | printf "\t/this->bio != NULL" 346 | [ "$_EVENT_TEST" ] && printf " && %s" "$_EVENT_TEST" 347 | printf " && (%s)/\n" "$val" 348 | printf "\t/* probe ID %u */\n" "$id" 349 | printf "{${TRACE:+\n\tprintf(\"<$id>\");}\n" 350 | printf "\t%s_increment_bio_cmd_start[this->bio_cmd];\n" "$var" 351 | printf "\t%s_add_bio_cmd_start_bytes[this->bio_cmd," "$var" 352 | printf " this->bio_length];\n" 353 | printf "}\n\n" 354 | id=$(( $id + 1 )) 355 | 356 | printf "io:::done\n" 357 | printf "\t/this->bio != NULL" 358 | [ "$_EVENT_TEST" ] && printf " && %s" "$_EVENT_TEST" 359 | printf " && (%s)/\n" "$val" 360 | printf "\t/* probe ID %u */\n" "$id" 361 | printf "{${TRACE:+\n\tprintf(\"<$id>\");}\n" 362 | printf "\t%s_increment_bio_cmd_done[this->bio_cmd];\n" "$var" 363 | printf "\t%s_add_bio_cmd_done_bytes[this->bio_cmd," "$var" 364 | printf " this->bio_length];\n" 365 | printf "}\n\n" 366 | id=$(( $id + 1 )) 367 | 368 | printf "io:::start, io:::done /this->bio != NULL &&\n" 369 | printf "\tthis->b_error" 370 | [ "$_EVENT_TEST" ] && printf " && %s" "$_EVENT_TEST" 371 | printf " && (%s)/\n" "$val" 372 | printf "\t/* probe ID %u */\n" "$id" 373 | printf "{${TRACE:+\n\tprintf(\"<$id>\");}\n" 374 | printf "\t%s_increment_bio_cmd_error[this->bio_cmd];\n" "$var" 375 | printf "}\n\n" 376 | id=$(( $id + 1 )) 377 | done 378 | ) 379 | 380 | io:::start /this->bio != NULL${_EVENT_TEST:+ && 381 | $_EVENT_TEST}${_CONF_OTHER:+ && 382 | $_CONF_OTHER}/ 383 | /* probe ID $(( $ID + 3 + $nconf * 3 )) */ 384 | {${TRACE:+ 385 | printf("<$(( $ID + 3 + $nconf * 3 ))>"); 386 | } 387 | increment_bio_cmd_start[this->bio_cmd]; 388 | add_bio_cmd_start_bytes[this->bio_cmd, this->bio_length]; 389 | } 390 | 391 | io:::done /this->bio != NULL${_EVENT_TEST:+ && 392 | $_EVENT_TEST}${_CONF_OTHER:+ && 393 | $_CONF_OTHER}/ 394 | /* probe ID $(( $ID + 4 + $nconf * 3 )) */ 395 | {${TRACE:+ 396 | printf("<$(( $ID + 4 + $nconf * 3 ))>"); 397 | } 398 | increment_bio_cmd_done[this->bio_cmd]; 399 | add_bio_cmd_done_bytes[this->bio_cmd, this->bio_length]; 400 | } 401 | 402 | io:::start, io:::done /this->bio != NULL && 403 | this->b_flags & BIO_ERROR == BIO_ERROR${_EVENT_TEST:+ && 404 | $_EVENT_TEST}${_CONF_OTHER:+ && 405 | $_CONF_OTHER}/ 406 | /* probe ID $(( $ID + 5 + $nconf * 3 )) */ 407 | {${TRACE:+ 408 | printf("<$(( $ID + 5 ))>");} 409 | increment_bio_cmd_error[this->bio_cmd]; 410 | } 411 | EOF 412 | ACTIONS=$( cat <&9 ) 413 | ID=$(( $ID + 6 + $nconf * 3 )) 414 | 415 | ############################################################ EVENT TAG 416 | 417 | # The EVENT_TAG is run inside the print action after the timestamp has been 418 | # printed. By default, `UID.GID CMD[PID]: ' of the process is printed. 419 | 420 | EVENT_TAG="printf(\"%s: \", \"${PROFILE%-raw}\")" 421 | 422 | ############################################################ EVENT DETAILS 423 | 424 | SECONDS="walltimestamp / 1000000000" 425 | 426 | exec 9<bio_flags = 37 | strjoin(this->bio_flags, 38 | strjoin(this->bio_flags == "" ? "" : (flags & flag) == flag ? "|" : "", 39 | bio_flag_string[flags & flag])); 40 | 41 | /****************************** I/O ******************************/ 42 | 43 | $PROBE /(struct bio *)args[0] != NULL/ /* probe ID $ID */ 44 | {${TRACE:+ 45 | printf("<$ID>"); 46 | } 47 | /* 48 | * dtrace_io(4) 49 | */ 50 | this->event = probename; 51 | 52 | /* 53 | * struct bio * 54 | */ 55 | this->bufinfo = xlate ((struct bio *)args[0]); 56 | this->bio_cmd = bio_cmd_string[(int)this->bufinfo.b_cmd]; 57 | this->b_flags = (int)this->bufinfo.b_flags; 58 | this->bio_flags = bio_flag_string[this->b_flags & BIO_ERROR]; 59 | this->bio_flags = strjoin(this->bio_flags, this->bufinfo.b_error ? 60 | strjoin(this->bio_flags == "" ? 61 | bio_flag_string[BIO_ERROR] : "", 62 | strjoin("#", lltostr(this->bufinfo.b_error))) : 63 | ""); 64 | append_bio_flag[this->b_flags, BIO_DONE]; 65 | append_bio_flag[this->b_flags, BIO_ONQUEUE]; 66 | append_bio_flag[this->b_flags, BIO_ORDERED]; 67 | append_bio_flag[this->b_flags, BIO_UNMAPPED]; 68 | append_bio_flag[this->b_flags, BIO_TRANSIENT_MAPPING]; 69 | append_bio_flag[this->b_flags, BIO_VLIST]; 70 | this->bio_flags = this->bio_flags == "" ? "-" : this->bio_flags; 71 | this->bio_length = (long)this->bufinfo.b_bcount; 72 | 73 | /* 74 | * struct devstat * 75 | */ 76 | this->devinfo = xlate ((struct devstat *)args[1]); 77 | this->device_type = device_type[(int)this->devinfo.dev_type]; 78 | this->device_if = device_if[(int)this->devinfo.dev_type]; 79 | this->device_entry = strjoin(this->devinfo.dev_name, 80 | lltostr(this->devinfo.dev_minor)); 81 | } 82 | EOF 83 | ACTIONS=$( cat <&9 ) 84 | ID=$(( $ID + 1 )) 85 | 86 | ############################################################ EVENT DETAILS 87 | 88 | exec 9<event, 95 | this->device_type, 96 | this->device_if, 97 | this->device_entry, 98 | this->bio_cmd, 99 | this->bio_flags, 100 | this->bio_length); 101 | 102 | this->event = ""; 103 | EOF 104 | EVENT_DETAILS=$( cat <&9 ) 105 | 106 | ################################################################################ 107 | # END 108 | ################################################################################ 109 | -------------------------------------------------------------------------------- /json-io-top: -------------------------------------------------------------------------------- 1 | # -*- tab-width: 4 -*- ;; Emacs 2 | # vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM 3 | ############################################################ IDENT(1) 4 | # 5 | # $Title: dwatch(8) JSON module for dtrace_io(4) $ 6 | # $Copyright: 2014-2022 Devin Teske. All rights reserved. $ 7 | # $FrauBSD: dwatch-json/json-io-top 2022-08-22 15:36:11 -0700 freebsdfrau $ 8 | # $Version: 1.0 $ 9 | # 10 | ############################################################ DESCRIPTION 11 | # 12 | # Produce JSON custom log format for disk I/O 13 | # 14 | ############################################################ GLOBALS 15 | 16 | eval "$( echo "$EVENT_TEST" | awk -v argv="$ARGV" ' 17 | function set(var, value) 18 | { 19 | gsub(/'\''/,"&\\\\&&", value) 20 | printf "%s='\''%s'\''\n", var, value 21 | } 22 | $0 { buf = buf $0 } 23 | END { 24 | # 25 | # EVENT_TEST for -k "ssh" 26 | # execname == "ssh" 27 | # 28 | head = buf 29 | tail = "" 30 | while (match(head, /execname == "[^"]*"/)) { 31 | tail = substr(head, 1, RSTART - 1) 32 | repl = substr(head, RSTART, RLENGTH) 33 | head = substr(head, RSTART + RLENGTH) 34 | if (sub(/ \|\|[[:space:]]*\(/, "", head)) 35 | sub(/\)$/, "", head) 36 | sub(/^execname == "/, "", repl) 37 | sub(/"$/, "", repl) 38 | argv = argv " -k \"" repl "\"" 39 | } 40 | buf = tail head 41 | 42 | # 43 | # EVENT_TEST for -k "ssh*" 44 | # strstr(execname, "ssh") == execname 45 | # 46 | head = buf 47 | tail = "" 48 | while (match(head, "strstr\\(execname, \"[^\"]*\"\\) == " \ 49 | "execname")) \ 50 | { 51 | tail = substr(head, 1, RSTART - 1) 52 | repl = substr(head, RSTART, RLENGTH) 53 | head = substr(head, RSTART + RLENGTH) 54 | if (sub(/ \|\|[[:space:]]*\(/, "", head)) 55 | sub(/\)$/, "", head) 56 | sub(/^strstr\(execname, "/, "", repl) 57 | sub(/"\) == execname$/, "", repl) 58 | argv = argv " -k \"" repl "*\"" 59 | } 60 | buf = tail head 61 | 62 | # 63 | # EVENT_TEST for -k "*ssh" 64 | # strstr(execname, "ssh") == (execname + strlen(execname) - 3) 65 | # 66 | head = buf 67 | tail = "" 68 | while (match(head, "strstr\\(execname, \"[^\"]*\"\\) == " \ 69 | "\\(execname \\+ strlen\\(execname\\) - " \ 70 | "[[:digit:]]+\\)")) \ 71 | { 72 | tail = substr(head, 1, RSTART - 1) 73 | repl = substr(head, RSTART, RLENGTH) 74 | head = substr(head, RSTART + RLENGTH) 75 | if (sub(/ \|\|[[:space:]]*\(/, "", head)) 76 | sub(/\)$/, "", head) 77 | sub(/^strstr\(execname, "/, "", repl) 78 | sub("\"\\) == \\(execname \\+ strlen\\(execname\\)" \ 79 | " - [[:digit:]]+\\)", "", repl) 80 | argv = argv " -k \"*" repl "\"" 81 | } 82 | buf = tail head 83 | 84 | set("EVENT_TEST", buf) 85 | set("ARGV", argv) 86 | } 87 | ' )" 88 | 89 | ############################################################ PROBE 90 | 91 | _RAW_PROFILE=$PROFILE-raw 92 | load_profile $_RAW_PROFILE 93 | 94 | ############################################################ MAIN 95 | 96 | if [ "$DEBUG$EXIT_AFTER_COMPILE" ]; then 97 | eval dwatch $ARGV -qX $_RAW_PROFILE 98 | exit 99 | fi 100 | 101 | info "Watching '$PROBE' ..." 102 | eval dwatch $ARGV -qX $_RAW_PROFILE $PROBE_ARG | awk ' 103 | sub(/^.*: /, "") { print; fflush() } 104 | ' # END-QUOTE 105 | exit $SUCCESS 106 | 107 | ################################################################################ 108 | # END 109 | ################################################################################ 110 | -------------------------------------------------------------------------------- /json-io-top-raw: -------------------------------------------------------------------------------- 1 | # -*- tab-width: 4 -*- ;; Emacs 2 | # vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM 3 | ############################################################ IDENT(1) 4 | # 5 | # $Title: dwatch(8) JSON module for dtrace_io(4) $ 6 | # $Copyright: 2014-2022 Devin Teske. All rights reserved. $ 7 | # $FrauBSD: dwatch-json/json-io-top-raw 2022-08-22 15:36:11 -0700 freebsdfrau $ 8 | # $Version: 1.0 $ 9 | # 10 | ############################################################ DESCRIPTION 11 | # 12 | # Produce JSON custom log format for disk I/O 13 | # 14 | ############################################################ PROBE 15 | 16 | : "${PROBE_SECONDS:=10}" 17 | : ${PROBE:=profile-${PROBE_SECONDS}s} 18 | 19 | ############################################################ FUNCTIONS 20 | 21 | # 22 | # JSON helpers 23 | # 24 | jfmt(){ printf "\\\\\"%s\\\\\":$1" "$2" "$3"; } 25 | jraw(){ jfmt %s "$1" "$2"; } 26 | jstr(){ jraw "$1" "\\\"$2\\\""; } 27 | _jstr(){ printf ,; jstr "$@"; } 28 | _jraw(){ printf ,; jraw "$@"; } 29 | 30 | ############################################################ OVERRIDES 31 | 32 | MAX_ARGS=0 # -B num 33 | MAX_DEPTH=0 # -K num 34 | 35 | # 36 | # Unsupported features 37 | # 38 | unset EXECREGEX # -z regex 39 | unset GROUP # -g group 40 | unset PID # -p pid 41 | unset PROBE_COALESCE # -F 42 | unset PSTREE # -R 43 | unset USER # -u user 44 | 45 | ############################################################ EVENT ACTION 46 | 47 | _EVENT_TEST="${EVENT_TEST:+($EVENT_TEST)}" 48 | _EVENT_TEST="${CUSTOM_TEST:+$CUSTOM_TEST${EVENT_TEST:+ && }}$_EVENT_TEST" 49 | if [ "$JID" ]; then 50 | pr_id="curthread->td_proc->p_ucred->cr_prison->pr_id" 51 | _EVENT_TEST="$pr_id == $JID${_EVENT_TEST:+ && ($_EVENT_TEST)}" 52 | unset JID 53 | fi 54 | EVENT_TEST="cpu == 0" 55 | CUSTOM_TEST= 56 | 57 | ############################################################ ACTIONS 58 | 59 | BIO_COMMANDS=" 60 | BIO_CMD0 61 | BIO_CMD1 62 | BIO_CMD2 63 | BIO_DELETE 64 | BIO_FLUSH 65 | BIO_GETATTR 66 | BIO_READ 67 | BIO_WRITE 68 | BIO_ZONE 69 | " # END-QUOTE 70 | 71 | BIO_CMD_LIST=$( echo "$BIO_COMMANDS" | awk ' 72 | /^[[:space:]]*(#|$)/ { next } 73 | { 74 | sub(/#.*/, "") 75 | sub(/^[[:space:]]*/, "") 76 | sub(/[[:space:]]*$/, "") 77 | n = split($0, f, /[[:space:]]+/) 78 | for (i = 1; i <= n; i++) list = list " " f[i] 79 | } 80 | END { print substr(list, 2) } 81 | ' ) 82 | 83 | bio_cmd_list=$( echo "$BIO_CMD_LIST" | awk '{ 84 | sub(/^BIO_/, "") 85 | gsub(/ BIO_/, " ") 86 | print tolower($0) 87 | }' ) 88 | 89 | bytes_list="read_bytes bytes_read write_bytes bytes_written" 90 | 91 | stat_list="start done error" 92 | 93 | exec 9<");} 161 | set_globals_to[0]; 162 | } 163 | 164 | /****************************** I/O ******************************/ 165 | 166 | io:::start, io:::done /* probe ID $(( $ID + 1 )) */ 167 | {${TRACE:+ 168 | printf("<$(( $ID + 1 ))>");} 169 | this->bio = (struct bio *)args[0]; 170 | } 171 | 172 | io:::start, io:::done /this->bio != NULL/ /* probe ID $(( $ID + 2 )) */ 173 | {${TRACE:+ 174 | printf("<$(( $ID + 2 ))>"); 175 | } 176 | /* 177 | * struct bio * 178 | */ 179 | this->bufinfo = xlate ((struct bio *)this->bio); 180 | this->b_flags = (int)this->bufinfo.b_flags; 181 | this->b_error = this->b_flags & BIO_ERROR == BIO_ERROR ? 1 : 0; 182 | this->bio_cmd = (int)this->bufinfo.b_cmd; 183 | this->bio_length = (long)this->bufinfo.b_bcount; 184 | 185 | /* 186 | * struct devstat * 187 | */ 188 | this->devinfo = xlate ((struct devstat *)args[1]); 189 | this->device_entry = device_name[this->devinfo]; 190 | this->device_if = device_if[(int)this->devinfo.dev_type]; 191 | this->device_type = device_type[(int)this->devinfo.dev_type]; 192 | 193 | /* De-duplicate events */ 194 | this->bio = (this->device_entry == "[0,-1]" ? NULL : this->bio); 195 | } 196 | 197 | io:::start /this->bio != NULL${_EVENT_TEST:+ && 198 | $_EVENT_TEST}/ 199 | /* probe ID $(( $ID + 3 )) */ 200 | {${TRACE:+ 201 | printf("<$(( $ID + 3 ))>"); 202 | } 203 | increment_bio_cmd_start[this->bio_cmd]; 204 | add_bio_cmd_start_bytes[this->bio_cmd, this->bio_length]; 205 | } 206 | 207 | io:::done /this->bio != NULL${_EVENT_TEST:+ && 208 | $_EVENT_TEST}/ 209 | /* probe ID $(( $ID + 4 )) */ 210 | {${TRACE:+ 211 | printf("<$(( $ID + 4 ))>"); 212 | } 213 | increment_bio_cmd_done[this->bio_cmd]; 214 | add_bio_cmd_done_bytes[this->bio_cmd, this->bio_length]; 215 | } 216 | 217 | io:::start, io:::done /this->bio != NULL && 218 | this->b_error${_EVENT_TEST:+ && 219 | $_EVENT_TEST}/ 220 | /* probe ID $(( $ID + 5 )) */ 221 | {${TRACE:+ 222 | printf("<$(( $ID + 5 ))>"); 223 | } 224 | increment_bio_cmd_error[this->bio_cmd]; 225 | } 226 | EOF 227 | ACTIONS=$( cat <&9 ) 228 | ID=$(( $ID + 6 )) 229 | 230 | ############################################################ EVENT TAG 231 | 232 | # The EVENT_TAG is run inside the print action after the timestamp has been 233 | # printed. By default, `UID.GID CMD[PID]: ' of the process is printed. 234 | 235 | EVENT_TAG="printf(\"${PROFILE%-raw}: \")" 236 | 237 | ############################################################ EVENT DETAILS 238 | 239 | : ${HOSTNAME:=$( hostname )} 240 | 241 | SECONDS="walltimestamp / 1000000000" 242 | 243 | exec 9<"; 59 | 60 | #pragma D binding "1.13" sa_data_port 61 | inline uint16_t sa_data_port[sa_family_t af, char data[sa_data_size]] = 62 | af == AF_INET ? ((data[0] & 0xFF) << 8) + (data[1] & 0xFF) : 63 | af == AF_INET6 ? ((data[0] & 0xFF) << 8) + (data[1] & 0xFF) : 64 | 0; 65 | 66 | #pragma D binding "1.13" translator 67 | translator sainfo_t < struct sockaddr *SA > { 68 | sa_family = SA == NULL ? 0 : SA->sa_family; 69 | addr = SA == NULL ? 70 | sa_data_addr[0, sa_dummy_data] : 71 | sa_data_addr[SA->sa_family, SA->sa_data]; 72 | port = SA == NULL ? 73 | sa_data_port[0, sa_dummy_data] : 74 | sa_data_port[SA->sa_family, SA->sa_data]; 75 | }; 76 | 77 | /****************************** TCP ******************************/ 78 | 79 | tcp:::send, 80 | tcp:::receive /* probe ID $ID */ 81 | {${TRACE:+ 82 | printf("<$ID>");} 83 | this->length = (uint32_t)args[2]->ip_plength - 84 | (uint8_t)args[4]->tcp_offset; 85 | } 86 | 87 | tcp:::debug-user /* probe ID $(( $ID + 1 )) */ 88 | {${TRACE:+ 89 | printf("<$(( $ID + 1 ))>"); 90 | } 91 | /* 92 | * tcpsinfo_t * 93 | */ 94 | this->local = args[0]->tcps_laddr; 95 | this->lport = args[0]->tcps_lport; 96 | this->remote = args[0]->tcps_raddr; 97 | this->rport = args[0]->tcps_rport; 98 | 99 | /* 100 | * IPv6 support 101 | */ 102 | this->local6 = strstr(this->local, ":") != NULL ? 1 : 0; 103 | this->remote6 = strstr(this->remote, ":") != NULL ? 1 : 0; 104 | this->local = strjoin(strjoin(this->local6 ? "[" : "", 105 | this->local), this->local6 ? "]" : ""); 106 | this->remote = strjoin(strjoin(this->remote6 ? "[" : "", 107 | this->remote), this->remote6 ? "]" : ""); 108 | 109 | this->family = "tcp"; 110 | this->event = prureq_string[arg1]; 111 | this->inet = 1; 112 | } 113 | 114 | tcp:::state-change /* probe ID $(( $ID + 2 )) */ 115 | {${TRACE:+ 116 | printf("<$(( $ID + 2 ))>"); 117 | } 118 | /* 119 | * tcpsinfo_t * 120 | */ 121 | this->local = args[3]->tcps_laddr; 122 | this->lport = (uint16_t)args[3]->tcps_lport; 123 | this->remote = args[3]->tcps_raddr; 124 | this->rport = (uint16_t)args[3]->tcps_rport; 125 | this->to_state = (int32_t)args[3]->tcps_state; 126 | 127 | /* 128 | * tcplsinfo_t * 129 | */ 130 | this->from_state = (int32_t)args[5]->tcps_state; 131 | 132 | /* 133 | * IPv6 support 134 | */ 135 | this->local6 = strstr(this->local, ":") != NULL ? 1 : 0; 136 | this->remote6 = strstr(this->remote, ":") != NULL ? 1 : 0; 137 | this->local = strjoin(strjoin(this->local6 ? "[" : "", 138 | this->local), this->local6 ? "]" : ""); 139 | this->remote = strjoin(strjoin(this->remote6 ? "[" : "", 140 | this->remote), this->remote6 ? "]" : ""); 141 | 142 | this->family = "tcp"; 143 | this->event = this->to_state == TCPS_CLOSED ? "CLOSE" : ""; 144 | this->length = 0; 145 | this->inet = 1; 146 | } 147 | 148 | /****************************** UDP ******************************/ 149 | 150 | /* 151 | * UDP send(2) [syscall] stacks: 152 | * sys_write -> dofilewrite -> soo_write -> sosend -> sosend_dgram -> udp:send 153 | * sys_sendto -> sendit -> kern_sendit -> sosend -> sosend_dgram -> udp:send 154 | * sys_sendmsg -> sendit -> kern_sendit -> sosend -> sosend_dgram -> udp:send 155 | */ 156 | 157 | udp:::send /* probe ID $(( $ID + 3 )) */ 158 | {${TRACE:+ 159 | printf("<$(( $ID + 3 ))>"); 160 | } 161 | /* 162 | * ipinfo_t * 163 | */ 164 | this->local = args[2]->ip_saddr; 165 | this->remote = args[2]->ip_daddr; 166 | 167 | /* 168 | * udpinfo_t * 169 | */ 170 | this->length = (uint32_t)args[4]->udp_length - sizeof(struct udphdr); 171 | this->lport = args[4]->udp_sport; 172 | this->rport = args[4]->udp_dport; 173 | 174 | /* 175 | * IPv6 support 176 | */ 177 | this->local6 = strstr(this->local, ":") != NULL ? 1 : 0; 178 | this->remote6 = strstr(this->remote, ":") != NULL ? 1 : 0; 179 | this->local = strjoin(strjoin(this->local6 ? "[" : "", 180 | this->local), this->local6 ? "]" : ""); 181 | this->remote = strjoin(strjoin(this->remote6 ? "[" : "", 182 | this->remote), this->remote6 ? "]" : ""); 183 | 184 | this->family = "udp"; 185 | this->event = "SEND"; 186 | this->inet = 1; 187 | } 188 | 189 | /* 190 | * UDP recv(2) [syscall] stacks: 191 | * sys_read -> dofileread -> soreceive -> soreceive_dgram 192 | * sys_recvfrom -> kern_recvit -> soreceive -> soreceive_dgram 193 | * sys_recvmsg -> kern_recvit -> soreceive -> soreceive_dgram 194 | */ 195 | 196 | syscall::read:entry, 197 | syscall::recvfrom:entry, 198 | syscall::recvmsg:entry 199 | /* probe ID $(( $ID + 4 )) */ 200 | {${TRACE:+ 201 | printf("<$(( $ID + 4 ))>"); 202 | } 203 | this->inet = 0; 204 | } 205 | 206 | fbt:kernel:soreceive_dgram:entry /* probe ID $(( $ID + 5 )) */ 207 | {${TRACE:+ 208 | printf("<$(( $ID + 5 ))>"); 209 | } 210 | this->udps = (struct socket *)args[0]; 211 | this->af = this->udps->so_proto->pr_domain->dom_family; 212 | this->psa = (struct sockaddr **)args[1]; 213 | this->sa = (struct sockaddr *)NULL; 214 | 215 | this->so_pcb = this->udps->so_pcb; 216 | this->udpsinfo = xlate ((struct inpcb *)this->so_pcb); 217 | 218 | /* UDP receive local */ 219 | this->local = this->udpsinfo.udps_laddr; 220 | this->local6 = this->af == AF_INET6; 221 | this->local = strjoin(strjoin(this->local6 ? "[" : "", 222 | this->local), this->local6 ? "]" : ""); 223 | this->lport = this->udpsinfo.udps_lport; 224 | 225 | this->family = "udp"; 226 | this->event = "RCVD"; 227 | this->inet = ( 228 | this->af == AF_INET ? 1 : 229 | this->af == AF_INET6 ? 1 : 230 | 0 231 | ); 232 | } 233 | 234 | fbt:kernel:soreceive_dgram:return /this->inet/ /* probe ID $(( $ID + 6 )) */ 235 | {${TRACE:+ 236 | printf("<$(( $ID + 6 ))>"); 237 | } 238 | this->sa = this->psa == NULL ? NULL : *this->psa; 239 | this->sainfo = xlate ((struct sockaddr *)this->sa); 240 | 241 | /* UDP receive remote */ 242 | this->remote = this->sainfo.addr; 243 | this->remote6 = this->sainfo.sa_family == AF_INET6; 244 | this->remote = strjoin(strjoin(this->remote6 ? "[" : "", 245 | this->remote), this->remote6 ? "]" : ""); 246 | this->rport = this->sainfo.port; 247 | } 248 | 249 | syscall::read:return, 250 | syscall::recvfrom:return, 251 | syscall::recvmsg:return 252 | /this->inet/ /* probe ID $(( $ID + 7 )) */ 253 | {${TRACE:+ 254 | printf("<$(( $ID + 7 ))>"); 255 | } 256 | this->length = (uint32_t)((int)arg0 < 0 ? 0 : arg0); 257 | this->inet = (this->length > 0); 258 | } 259 | EOF 260 | ACTIONS=$( cat <&9 ) 261 | ID=$(( $ID + 8 )) 262 | 263 | ############################################################ EVENT DETAILS 264 | 265 | exec 9<family, 272 | this->local, 273 | this->lport, 274 | this->event, 275 | this->remote, 276 | this->rport, 277 | this->length); 278 | 279 | this->event = ""; 280 | this->inet = 0; 281 | EOF 282 | EVENT_DETAILS=$( cat <&9 ) 283 | 284 | ################################################################################ 285 | # END 286 | ################################################################################ 287 | -------------------------------------------------------------------------------- /json-net-top: -------------------------------------------------------------------------------- 1 | # -*- tab-width: 4 -*- ;; Emacs 2 | # vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM 3 | ############################################################ IDENT(1) 4 | # 5 | # $Title: dwatch(8) JSON module for network activity $ 6 | # $Copyright: 2014-2022 Devin Teske. All rights reserved. $ 7 | # $FrauBSD: dwatch-json/json-net-top 2022-08-04 13:17:58 -0700 freebsdfrau $ 8 | # $Version: 0.3.1 $ 9 | # 10 | ############################################################ DESCRIPTION 11 | # 12 | # Produce JSON custom log format for network activity 13 | # 14 | ############################################################ GLOBALS 15 | 16 | eval "$( echo "$EVENT_TEST" | awk -v argv="$ARGV" ' 17 | function set(var, value) 18 | { 19 | gsub(/'\''/,"&\\\\&&", value) 20 | printf "%s='\''%s'\''\n", var, value 21 | } 22 | $0 { buf = buf $0 } 23 | END { 24 | # 25 | # EVENT_TEST for -k "ssh" 26 | # execname == "ssh" 27 | # 28 | head = buf 29 | tail = "" 30 | while (match(head, /execname == "[^"]*"/)) { 31 | tail = substr(head, 1, RSTART - 1) 32 | repl = substr(head, RSTART, RLENGTH) 33 | head = substr(head, RSTART + RLENGTH) 34 | if (sub(/ \|\|[[:space:]]*\(/, "", head)) 35 | sub(/\)$/, "", head) 36 | sub(/^execname == "/, "", repl) 37 | sub(/"$/, "", repl) 38 | argv = argv " -k \"" repl "\"" 39 | } 40 | buf = tail head 41 | 42 | # 43 | # EVENT_TEST for -k "ssh*" 44 | # strstr(execname, "ssh") == execname 45 | # 46 | head = buf 47 | tail = "" 48 | while (match(head, "strstr\\(execname, \"[^\"]*\"\\) == " \ 49 | "execname")) \ 50 | { 51 | tail = substr(head, 1, RSTART - 1) 52 | repl = substr(head, RSTART, RLENGTH) 53 | head = substr(head, RSTART + RLENGTH) 54 | if (sub(/ \|\|[[:space:]]*\(/, "", head)) 55 | sub(/\)$/, "", head) 56 | sub(/^strstr\(execname, "/, "", repl) 57 | sub(/"\) == execname$/, "", repl) 58 | argv = argv " -k \"" repl "*\"" 59 | } 60 | buf = tail head 61 | 62 | # 63 | # EVENT_TEST for -k "*ssh" 64 | # strstr(execname, "ssh") == (execname + strlen(execname) - 3) 65 | # 66 | head = buf 67 | tail = "" 68 | while (match(head, "strstr\\(execname, \"[^\"]*\"\\) == " \ 69 | "\\(execname \\+ strlen\\(execname\\) - " \ 70 | "[[:digit:]]+\\)")) \ 71 | { 72 | tail = substr(head, 1, RSTART - 1) 73 | repl = substr(head, RSTART, RLENGTH) 74 | head = substr(head, RSTART + RLENGTH) 75 | if (sub(/ \|\|[[:space:]]*\(/, "", head)) 76 | sub(/\)$/, "", head) 77 | sub(/^strstr\(execname, "/, "", repl) 78 | sub("\"\\) == \\(execname \\+ strlen\\(execname\\)" \ 79 | " - [[:digit:]]+\\)", "", repl) 80 | argv = argv " -k \"*" repl "\"" 81 | } 82 | buf = tail head 83 | 84 | set("EVENT_TEST", buf) 85 | set("ARGV", argv) 86 | } 87 | ' )" 88 | 89 | ############################################################ PROBE 90 | 91 | _RAW_PROFILE=$PROFILE-raw 92 | load_profile $_RAW_PROFILE 93 | 94 | ############################################################ MAIN 95 | 96 | if [ "$DEBUG$EXIT_AFTER_COMPILE" ]; then 97 | eval dwatch $ARGV -qX $_RAW_PROFILE 98 | exit 99 | fi 100 | 101 | info "Watching '$PROBE' ..." 102 | eval dwatch $ARGV -qX $_RAW_PROFILE $PROBE_ARG | awk ' 103 | sub(/^.*: /, "") { print; fflush() } 104 | ' # END-QUOTE 105 | exit $SUCCESS 106 | 107 | ################################################################################ 108 | # END 109 | ################################################################################ 110 | -------------------------------------------------------------------------------- /json-net-top-raw: -------------------------------------------------------------------------------- 1 | # -*- tab-width: 4 -*- ;; Emacs 2 | # vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM 3 | ############################################################ IDENT(1) 4 | # 5 | # $Title: dwatch(8) JSON module for network activity $ 6 | # $Copyright: 2014-2022 Devin Teske. All rights reserved. $ 7 | # $FrauBSD: dwatch-json/json-net-top-raw 2022-08-04 13:17:58 -0700 freebsdfrau $ 8 | # $Version: 0.3 $ 9 | # 10 | ############################################################ DESCRIPTION 11 | # 12 | # Produce JSON custom log format for network activity 13 | # 14 | ############################################################ PROBE 15 | 16 | : ${PROBE:=profile-10s} 17 | 18 | ############################################################ OVERRIDES 19 | 20 | MAX_ARGS=0 # -B num 21 | MAX_DEPTH=0 # -K num 22 | 23 | # 24 | # Unsupported features 25 | # 26 | unset EXECREGEX # -z regex 27 | unset GROUP # -g group 28 | unset PID # -p pid 29 | unset PROBE_COALESCE # -F 30 | unset PSTREE # -R 31 | unset USER # -u user 32 | 33 | ############################################################ EVENT ACTION 34 | 35 | _EVENT_TEST="${EVENT_TEST:+($EVENT_TEST)}" 36 | _EVENT_TEST="${CUSTOM_TEST:+$CUSTOM_TEST${EVENT_TEST:+ && }}$_EVENT_TEST" 37 | if [ "$JID" ]; then 38 | pr_id="curthread->td_proc->p_ucred->cr_prison->pr_id" 39 | _EVENT_TEST="$pr_id == $JID${_EVENT_TEST:+ && ($_EVENT_TEST)}" 40 | unset JID 41 | fi 42 | EVENT_TEST="cpu == 0" 43 | CUSTOM_TEST= 44 | 45 | ############################################################ ACTIONS 46 | 47 | exec 9<");} 62 | tcp_rcvd = tcp_sent = 0; 63 | udp_rcvd = udp_sent = 0; 64 | } 65 | 66 | /****************************** TCP ******************************/ 67 | 68 | tcp:::receive /* probe ID $(( $ID + 1 )) */ 69 | {${TRACE:+ 70 | printf("<$(( $ID + 1 ))>");} 71 | this->length = (uint32_t)args[2]->ip_plength - 72 | (uint8_t)args[4]->tcp_offset; 73 | } 74 | 75 | tcp:::debug-user 76 | /arg1 == PRU_RCVD${_EVENT_TEST:+ && ($_EVENT_TEST)}/ 77 | /* probe ID $(( $ID + 2 )) */ 78 | {${TRACE:+ 79 | printf("<$(( $ID + 2 ))>");} 80 | tcp_rcvd += this->length; 81 | this->length = 0; 82 | } 83 | 84 | tcp:::send ${_EVENT_TEST:+/ $_EVENT_TEST / }/* probe ID $(( $ID + 3 )) */ 85 | {${TRACE:+ 86 | printf("<$(( $ID + 3 ))>");} 87 | tcp_sent += (uint32_t)args[2]->ip_plength - 88 | (uint8_t)args[4]->tcp_offset; 89 | } 90 | 91 | /****************************** UDP ******************************/ 92 | 93 | udp:::send ${_EVENT_TEST:+/ $_EVENT_TEST / }/* probe ID $(( $ID + 4 )) */ 94 | {${TRACE:+ 95 | printf("<$(( $ID + 4 ))>");} 96 | udp_sent += (uint16_t)args[4]->udp_length; 97 | } 98 | 99 | udp:::receive /* probe ID $(( $ID + 5 )) */ 100 | {${TRACE:+ 101 | printf("<$(( $ID + 5 ))>"); 102 | } 103 | /* 104 | * csinfo_t * 105 | */ 106 | urecv_inpcb = (struct inpcb *)args[1]->cs_cid; 107 | urecv_socket = urecv_inpcb->inp_socket; 108 | 109 | /* 110 | * udpinfo_t * 111 | */ 112 | urecv_length = (uint16_t)args[4]->udp_length; 113 | } 114 | 115 | fbt::soreceive_dgram:entry 116 | /args[0] == urecv_socket${_EVENT_TEST:+ && ($_EVENT_TEST)}/ 117 | /* probe ID $(( $ID + 6 )) */ 118 | {${TRACE:+ 119 | printf("<$(( $ID + 6 ))>");} 120 | udp_rcvd += urecv_length; 121 | urecv_length = 0; 122 | } 123 | EOF 124 | ACTIONS=$( cat <&9 ) 125 | ID=$(( $ID + 7 )) 126 | 127 | ############################################################ EVENT TAG 128 | 129 | # The EVENT_TAG is run inside the print action after the timestamp has been 130 | # printed. By default, `UID.GID CMD[PID]: ' of the process is printed. 131 | 132 | EVENT_TAG="printf(\"${PROFILE%-raw}: \")" 133 | 134 | ############################################################ EVENT DETAILS 135 | 136 | : ${HOSTNAME:=$( hostname )} 137 | 138 | exec 9<