Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Create layout for plugins, install plugins in ${PREFIX}/lib/pkg
Baptiste Daroussin committed 13 years ago
commit fd6e54ba123f7cf89e978ba7a94833357b7e21c1
parent b07e4b2
11 files changed +241 -240
added plugins/Makefile
@@ -0,0 +1,3 @@
+
SUBDIR+=	command-mystats
+

+
.include <bsd.subdir.mk>
added plugins/command-mystats/Makefile
@@ -0,0 +1,16 @@
+
.include <bsd.own.mk>
+

+
PREFIX?=	/usr/local
+
LIBDIR=		${PREFIX}/lib/pkg/command
+
SHLIB_DIR?=	${LIBDIR}/
+
SHLIB_NAME?=	${PLUGIN_NAME}.so
+

+
PLUGIN_NAME=	command-mystats
+
SRCS=		mystats.c
+

+
CFLAGS+=	-I${.CURDIR}/../../libpkg
+

+
beforeinstall:
+
	${INSTALL} -d ${LIBDIR}
+

+
.include <bsd.lib.mk>
added plugins/command-mystats/README.md
@@ -0,0 +1,43 @@
+
## General Information
+

+
The *pkg-plugin-mystats* plugin is used for displaying package statistics.
+

+
It is meant to serve for demonstration purposes on how to write pkgng plugins which
+
provides commands to be executed by running `pkg <plugin-command>`
+

+
The command uses the code from `pkg stats` for displaying package stats.
+

+
## How to build the plugin?
+

+
In order to build the plugin enter into the plugin's directory and run make(1), e.g.:
+

+
	$ cd /path/to/pkg-plugins-mystats
+
	$ make
+
	
+
Once the plugin is built you can install it using the following command:
+

+
	$ make install 
+
	
+
The plugin will be installed as a shared library in ${PREFIX}/lib/libpkg-plugin-mystats.so
+

+
## Configuring the plugin
+

+
In order to configure the plugin simply copy the *mystats.conf* file to the pkgng plugins directory,
+
which by default is set to */usr/local/etc/pkg/plugins*, unless you've specified it elsewhere by 
+
using the *PKG\_PLUGINS\_DIR* option.
+

+
	$ cp /path/to/pkg-plugins-mystats/mystats.conf /usr/local/etc/pkg/plugins/
+
	
+
## Testing the plugin
+

+
To test the plugin, first check that it is recongnized and
+
loaded by pkgng by executing the `pkg plugins` command:
+

+
	$ pkg plugins
+
	NAME       DESC                                VERSION    LOADED  
+
	mystats    Plugin command for displaying stats 1.0        YES       
+

+
If the plugin shows up correctly then you are good to go!
+

+
Now go ahead and execute `pkg mystats` and see the plugin in action! :)
+

added plugins/command-mystats/mystats.c
@@ -0,0 +1,136 @@
+
/*
+
 * Copyright (c) 2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
+
 * All rights reserved.
+
 * 
+
 * Redistribution and use in source and binary forms, with or without
+
 * modification, are permitted provided that the following conditions
+
 * are met:
+
 * 1. Redistributions of source code must retain the above copyright
+
 *    notice, this list of conditions and the following disclaimer
+
 *    in this position and unchanged.
+
 * 2. Redistributions in binary form must reproduce the above copyright
+
 *    notice, this list of conditions and the following disclaimer in the
+
 *    documentation and/or other materials provided with the distribution.
+
 * 
+
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
 */
+

+
#include <assert.h>
+
#include <stdio.h>
+
#include <sysexits.h>
+
#include <unistd.h>
+
#include <inttypes.h>
+
#include <libutil.h>
+

+
#include <pkg.h>
+

+
#include "mystats.h"
+

+
#define PLUGIN_NAME 		"mystats"
+
#define PLUGIN_STATS_LOCAL 	(1<<0)
+
#define PLUGIN_STATS_REMOTE 	(1<<1)
+

+
static char myname[] = "mystats";
+
static char mydesc[] = "A plugin for displaying package statistics";
+

+
static int plugin_mystats_usage(void);
+

+
int
+
pkg_plugins_init_mystats(void)
+
{
+
	return (EPKG_OK);
+
}
+

+
int
+
pkg_plugins_shutdown_mystats(void)
+
{
+
	/* nothing to be done here */
+

+
	return (EPKG_OK);
+
}
+

+
static int
+
plugin_mystats_usage(void)
+
{
+
	fprintf(stderr, "usage: pkg mystats [-lr]\n\n");
+
	fprintf(stderr, "A plugin for displaying package statistics\n");
+
	return (EPKG_OK);
+
}
+

+
static int
+
plugin_mystats_callback(int argc, char **argv)
+
{
+
	struct pkgdb *db = NULL;
+
        int64_t flatsize = 0;
+
        char size[7];
+
        unsigned int opt = 0;
+
        int ch;
+

+
        while ((ch = getopt(argc, argv, "lr")) != -1) {
+
                switch (ch) {
+
                case 'l':
+
                        opt |= PLUGIN_STATS_LOCAL;
+
                        break;
+
                case 'r':
+
                        opt |= PLUGIN_STATS_REMOTE;
+
                        break;
+
                default:
+
                        plugin_mystats_usage();
+
                        return (EX_USAGE);
+
                }
+
        }
+
        argc -= optind;
+
        argv += optind;
+

+
        /* default is to show everything we have */
+
        if (opt == 0)
+
                opt |= (PLUGIN_STATS_LOCAL | PLUGIN_STATS_REMOTE);
+

+
        if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) {
+
                return (EX_IOERR);
+
        }
+

+
        if (opt & PLUGIN_STATS_LOCAL) {
+
                printf("Local package database:\n");
+
                printf("\tInstalled packages: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_LOCAL_COUNT));
+

+
                flatsize = pkgdb_stats(db, PKG_STATS_LOCAL_SIZE);
+
                humanize_number(size, sizeof(flatsize), flatsize, "B", HN_AUTOSCALE, 0);
+
                printf("\tDisk space occupied: %s\n\n", size);
+
        }
+

+
        if (opt & PLUGIN_STATS_REMOTE) {
+
                printf("Remote package database(s):\n");
+
                printf("\tNumber of repositories: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_REMOTE_REPOS));
+
                printf("\tPackages available: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_REMOTE_COUNT));
+
                printf("\tUnique packages: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_REMOTE_UNIQUE));
+

+
                flatsize = pkgdb_stats(db, PKG_STATS_REMOTE_SIZE);
+
                humanize_number(size, sizeof(flatsize), flatsize, "B", HN_AUTOSCALE, 0);
+
                printf("\tTotal size of packages: %s\n", size);
+
        }
+

+
	pkgdb_close(db);
+

+
	return (EPKG_OK);
+
}
+

+
int
+
pkg_register_cmd(const char **name, const char **desc, int (**exec)(int argc, char **argv))
+
{
+
	*name = myname;
+
	*desc = mydesc;
+
	*exec = plugin_mystats_callback;
+

+
	return (EPKG_OK);
+
}
+

added plugins/command-mystats/mystats.conf
@@ -0,0 +1,6 @@
+
# Configuration file for pkg-plugin-mystats
+
enabled=YES
+
name=mystats
+
description=Plugin command for displaying stats
+
version=1.0
+
plugin=/usr/local/lib/libpkg-plugin-mystats.so
added plugins/command-mystats/mystats.h
@@ -0,0 +1,37 @@
+
/*
+
 * Copyright (c) 2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
+
 * All rights reserved.
+
 * 
+
 * Redistribution and use in source and binary forms, with or without
+
 * modification, are permitted provided that the following conditions
+
 * are met:
+
 * 1. Redistributions of source code must retain the above copyright
+
 *    notice, this list of conditions and the following disclaimer
+
 *    in this position and unchanged.
+
 * 2. Redistributions in binary form must reproduce the above copyright
+
 *    notice, this list of conditions and the following disclaimer in the
+
 *    documentation and/or other materials provided with the distribution.
+
 * 
+
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
 */
+

+
#ifndef _PKG_PLUGINS_MYSTATS_H
+
#define _PKG_PLUGINS_MYSTATS_H
+

+
/* callback functions */
+
int pkg_register_cmd(const char **name, const char **desc, int (**exec)(int argc, char **argv));
+

+
/* plugin init and shutdown functions */
+
int pkg_plugins_init_mystats(void);
+
int pkg_plugins_shutdown_mystats(void);
+

+
#endif /* !_PKG_PLUGINS_MYSTATS_H */
deleted plugins/pkg-plugin-mystats-command/Makefile
@@ -1,18 +0,0 @@
-
.include <bsd.own.mk>
-

-
LIB=		pkg-plugin-mystats
-
INCS=		mystats.h
-
#WARNS=		6
-
PREFIX?=	/usr/local
-
LIBDIR=		${PREFIX}/lib
-
INCLUDEDIR=	${PREFIX}/include
-
SHLIB_MAJOR=	0
-

-
SRCS=		mystats.c
-

-
CFLAGS+=	-std=c99 -fPIC -shared
-
CFLAGS+=	-I${INCLUDEDIR}
-

-
DEBUG_FLAGS+=  -g -O0
-

-
.include <bsd.lib.mk>
deleted plugins/pkg-plugin-mystats-command/README.md
@@ -1,43 +0,0 @@
-
## General Information
-

-
The *pkg-plugin-mystats* plugin is used for displaying package statistics.
-

-
It is meant to serve for demonstration purposes on how to write pkgng plugins which
-
provides commands to be executed by running `pkg <plugin-command>`
-

-
The command uses the code from `pkg stats` for displaying package stats.
-

-
## How to build the plugin?
-

-
In order to build the plugin enter into the plugin's directory and run make(1), e.g.:
-

-
	$ cd /path/to/pkg-plugins-mystats
-
	$ make
-
	
-
Once the plugin is built you can install it using the following command:
-

-
	$ make install 
-
	
-
The plugin will be installed as a shared library in ${PREFIX}/lib/libpkg-plugin-mystats.so
-

-
## Configuring the plugin
-

-
In order to configure the plugin simply copy the *mystats.conf* file to the pkgng plugins directory,
-
which by default is set to */usr/local/etc/pkg/plugins*, unless you've specified it elsewhere by 
-
using the *PKG\_PLUGINS\_DIR* option.
-

-
	$ cp /path/to/pkg-plugins-mystats/mystats.conf /usr/local/etc/pkg/plugins/
-
	
-
## Testing the plugin
-

-
To test the plugin, first check that it is recongnized and
-
loaded by pkgng by executing the `pkg plugins` command:
-

-
	$ pkg plugins
-
	NAME       DESC                                VERSION    LOADED  
-
	mystats    Plugin command for displaying stats 1.0        YES       
-

-
If the plugin shows up correctly then you are good to go!
-

-
Now go ahead and execute `pkg mystats` and see the plugin in action! :)
-

deleted plugins/pkg-plugin-mystats-command/mystats.c
@@ -1,136 +0,0 @@
-
/*
-
 * Copyright (c) 2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
-
 * All rights reserved.
-
 * 
-
 * Redistribution and use in source and binary forms, with or without
-
 * modification, are permitted provided that the following conditions
-
 * are met:
-
 * 1. Redistributions of source code must retain the above copyright
-
 *    notice, this list of conditions and the following disclaimer
-
 *    in this position and unchanged.
-
 * 2. Redistributions in binary form must reproduce the above copyright
-
 *    notice, this list of conditions and the following disclaimer in the
-
 *    documentation and/or other materials provided with the distribution.
-
 * 
-
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
-
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
-
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 */
-

-
#include <assert.h>
-
#include <stdio.h>
-
#include <sysexits.h>
-
#include <unistd.h>
-
#include <inttypes.h>
-
#include <libutil.h>
-

-
#include <pkg.h>
-

-
#include "mystats.h"
-

-
#define PLUGIN_NAME 		"mystats"
-
#define PLUGIN_STATS_LOCAL 	(1<<0)
-
#define PLUGIN_STATS_REMOTE 	(1<<1)
-

-
static char myname[] = "mystats";
-
static char mydesc[] = "A plugin for displaying package statistics";
-

-
static int plugin_mystats_usage(void);
-

-
int
-
pkg_plugins_init_mystats(void)
-
{
-
	return (EPKG_OK);
-
}
-

-
int
-
pkg_plugins_shutdown_mystats(void)
-
{
-
	/* nothing to be done here */
-

-
	return (EPKG_OK);
-
}
-

-
static int
-
plugin_mystats_usage(void)
-
{
-
	fprintf(stderr, "usage: pkg mystats [-lr]\n\n");
-
	fprintf(stderr, "A plugin for displaying package statistics\n");
-
	return (EPKG_OK);
-
}
-

-
static int
-
plugin_mystats_callback(int argc, char **argv)
-
{
-
	struct pkgdb *db = NULL;
-
        int64_t flatsize = 0;
-
        char size[7];
-
        unsigned int opt = 0;
-
        int ch;
-

-
        while ((ch = getopt(argc, argv, "lr")) != -1) {
-
                switch (ch) {
-
                case 'l':
-
                        opt |= PLUGIN_STATS_LOCAL;
-
                        break;
-
                case 'r':
-
                        opt |= PLUGIN_STATS_REMOTE;
-
                        break;
-
                default:
-
                        plugin_mystats_usage();
-
                        return (EX_USAGE);
-
                }
-
        }
-
        argc -= optind;
-
        argv += optind;
-

-
        /* default is to show everything we have */
-
        if (opt == 0)
-
                opt |= (PLUGIN_STATS_LOCAL | PLUGIN_STATS_REMOTE);
-

-
        if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) {
-
                return (EX_IOERR);
-
        }
-

-
        if (opt & PLUGIN_STATS_LOCAL) {
-
                printf("Local package database:\n");
-
                printf("\tInstalled packages: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_LOCAL_COUNT));
-

-
                flatsize = pkgdb_stats(db, PKG_STATS_LOCAL_SIZE);
-
                humanize_number(size, sizeof(flatsize), flatsize, "B", HN_AUTOSCALE, 0);
-
                printf("\tDisk space occupied: %s\n\n", size);
-
        }
-

-
        if (opt & PLUGIN_STATS_REMOTE) {
-
                printf("Remote package database(s):\n");
-
                printf("\tNumber of repositories: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_REMOTE_REPOS));
-
                printf("\tPackages available: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_REMOTE_COUNT));
-
                printf("\tUnique packages: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_REMOTE_UNIQUE));
-

-
                flatsize = pkgdb_stats(db, PKG_STATS_REMOTE_SIZE);
-
                humanize_number(size, sizeof(flatsize), flatsize, "B", HN_AUTOSCALE, 0);
-
                printf("\tTotal size of packages: %s\n", size);
-
        }
-

-
	pkgdb_close(db);
-

-
	return (EPKG_OK);
-
}
-

-
int
-
pkg_register_cmd(const char **name, const char **desc, int (**exec)(int argc, char **argv))
-
{
-
	*name = myname;
-
	*desc = mydesc;
-
	*exec = plugin_mystats_callback;
-

-
	return (EPKG_OK);
-
}
-

deleted plugins/pkg-plugin-mystats-command/mystats.conf
@@ -1,6 +0,0 @@
-
# Configuration file for pkg-plugin-mystats
-
enabled=YES
-
name=mystats
-
description=Plugin command for displaying stats
-
version=1.0
-
plugin=/usr/local/lib/libpkg-plugin-mystats.so
deleted plugins/pkg-plugin-mystats-command/mystats.h
@@ -1,37 +0,0 @@
-
/*
-
 * Copyright (c) 2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
-
 * All rights reserved.
-
 * 
-
 * Redistribution and use in source and binary forms, with or without
-
 * modification, are permitted provided that the following conditions
-
 * are met:
-
 * 1. Redistributions of source code must retain the above copyright
-
 *    notice, this list of conditions and the following disclaimer
-
 *    in this position and unchanged.
-
 * 2. Redistributions in binary form must reproduce the above copyright
-
 *    notice, this list of conditions and the following disclaimer in the
-
 *    documentation and/or other materials provided with the distribution.
-
 * 
-
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
-
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
-
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 */
-

-
#ifndef _PKG_PLUGINS_MYSTATS_H
-
#define _PKG_PLUGINS_MYSTATS_H
-

-
/* callback functions */
-
int pkg_register_cmd(const char **name, const char **desc, int (**exec)(int argc, char **argv));
-

-
/* plugin init and shutdown functions */
-
int pkg_plugins_init_mystats(void);
-
int pkg_plugins_shutdown_mystats(void);
-

-
#endif /* !_PKG_PLUGINS_MYSTATS_H */