Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample code for creating JSON code for https://github.com/dlangille/SamDrucker
[dan@samdrucker:~/bin] $ ~/bin/samdrucker.sh
{
"name": "samdrucker.int.unixathome.org",
"os": "FreeBSD",
"version": "12.0-RELEASE-p10",
"repo": "pkg+http://fedex.unixathome.org/packages/120amd64-default-master-list/",
"packages": [
"apache24-2.4.41",
"apr-1.7.0.1.6.1",
"bash-5.0.11",
"bind-tools-9.14.7",
"ca_root_nss-3.47",
"curl-7.66.0",
"cyrus-sasl-2.1.27",
"db5-5.3.28_7",
"expat-2.2.8",
"gdbm-1.18.1_1",
"gettext-runtime-0.20.1",
"icu-65.1,1",
"indexinfo-0.3.1",
"jo-1.2",
"joe-4.6,1",
"json-c-0.13.1_1",
"libargon2-20190702",
"libedit-3.1.20190324,1",
"libevent-2.1.11",
"libffi-3.2.1_3",
"libidn2-2.2.0",
"liblockfile-1.16",
"liblz4-1.9.2,1",
"libnghttp2-1.39.2",
"libunistring-0.9.10_1",
"libxml2-2.9.9",
"lockfile-progs-0.1.18",
"logcheck-1.3.20",
"mime-construct-1.11_2",
"mod_php72-7.2.24",
"mysql57-client-5.7.27",
"nagios-plugins-2.2.1_8,1",
"nginx-1.16.1_4,2",
"nrpe3-3.2.1",
"p5-IPC-Signal-1.00_1",
"p5-MIME-Types-2.17",
"p5-Proc-WaitStat-1.00_1",
"pam_ssh_agent_auth-0.10.3_1",
"pcre-8.43_2",
"perl5-5.30.0",
"php72-7.2.24",
"php72-json-7.2.24",
"php72-pgsql-7.2.24",
"pkg-1.12.0",
"postfix-3.4.7_1,1",
"postgresql11-client-11.5",
"protobuf-3.9.2,1",
"py27-ply-3.11",
"py27-setuptools-41.4.0",
"python-2.7_3,2",
"python2-2_3",
"python27-2.7.17",
"readline-8.0.0",
"sudo-1.8.29",
"xtail-2.1"
]
}
#!/bin/sh
# we want to construct JSON which looks like this:
# {
# "name": "test.example.org",
# "os": "FreeBSD",
# "version": "11.3-RELEASE-p4",
# "repo": "http://pkg.freebsd.org/FreeBSD:113:amd64/latest/",
# "packages": [
# "apr-1.6.5.1.6.1_1",
# "bacula9-client-9.4.3",
# "bash-5.0.7",
# "rsync-3.1.3_1",
# "serf-1.3.9_3",
# "sqlite3-3.29.0_1"
# ]
# }
#
# I am using the FreeBSD textproc/jo:
#
# $ jo -p name=`hostname` os=`uname` version=`uname -r` repo=`pkg -vv | grep url | cut -f2 -d \"`
# {
# "name": "samdrucker.int.unixathome.org",
# "os": "FreeBSD",
# "version": "12.0-RELEASE-p10",
# "repo": "pkg+http://fedex.unixathome.org/packages/120amd64-default-master-list/"
# }
#
# get list of packages on this host:
pkg_args=""
PKGS=`/usr/sbin/pkg info -q`
for pkg in $PKGS
do
pkg_args="$pkg_args packages[]=$pkg"
done
#echo $pkg_args
# yeah, this repo stuff will break if you have multiple repos
/usr/local/bin/jo -p name=`hostname` os=`uname` version=`uname -r` repo=`pkg -vv | grep url | cut -f2 -d \"` $pkg_args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.