1243553Seadler/*-
2243553Seadler * Copyright (c) 2012 Eitan Adler
3243553Seadler * All rights reserved.
4241830Seadler *
5241830Seadler * Redistribution and use in source and binary forms, with or without
6241830Seadler * modification, are permitted provided that the following conditions
7241830Seadler * are met:
8241830Seadler * 1. Redistributions of source code must retain the above copyright
9241830Seadler *    notice, this list of conditions and the following disclaimer.
10241830Seadler * 2. Redistributions in binary form must reproduce the above copyright
11241830Seadler *    notice, this list of conditions and the following disclaimer in the
12241830Seadler *    documentation and/or other materials provided with the distribution.
13241830Seadler *
14243553Seadler * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15243553Seadler * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16243553Seadler * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17243553Seadler * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18243553Seadler * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19243553Seadler * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20243553Seadler * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21243553Seadler * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22243553Seadler * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23243553Seadler * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24243553Seadler * SUCH DAMAGE.
25241830Seadler *
26243553Seadler * $FreeBSD$
27241830Seadler */
28241830Seadler
29241830Seadler#include <sys/cdefs.h>
30241830Seadler
31241830Seadler#include "lib.h"
32241830Seadler#include <err.h>
33241830Seadler
34243553Seadlerstatic const char message[] = "You appear to be using the newer pkg(1) tool on \
35243553Seadlerthis system for package management, rather than the legacy package \
36243553Seadlermanagement tools (pkg_*).  The legacy tools should no longer be used on \
37243553Seadlerthis system.";
38243553Seadler
39243553Seadlervoid warnpkgng(void)
40243553Seadler{
41245828Sbapt	char pkgngpath[MAXPATHLEN + 1];
42241830Seadler	char *pkgngdir;
43243554Seadler	char *dontwarn;
44245828Sbapt	int rc;
45241830Seadler
46243554Seadler	dontwarn = getenv("PKG_OLD_NOWARN");
47243554Seadler	if (dontwarn != NULL)
48243554Seadler		return;
49241830Seadler	pkgngdir = getenv("PKG_DBDIR");
50241830Seadler	if (pkgngdir == NULL)
51241830Seadler		pkgngdir = "/var/db/pkg";
52241830Seadler
53245837Sjasone	rc = snprintf(pkgngpath, sizeof(pkgngpath), "%s/local.sqlite", pkgngdir);
54245837Sjasone	if ((size_t)rc >= sizeof(pkgngpath)) {
55245828Sbapt		warnx("path too long: %s/local.sqlite", pkgngdir);
56245828Sbapt		return;
57245828Sbapt	}
58245828Sbapt
59241830Seadler	if (access(pkgngpath, F_OK) == 0)
60243553Seadler		warnx(message);
61241830Seadler}
62