Skip to content

Commit

Permalink
fix: do not encourage using /usr/local/bin (#596)
Browse files Browse the repository at this point in the history
* fix: do not encourage using /usr/local/bin

Examples, tests and docs often refer to /usr/local/bin, which should
only be used for things compiled locally, which is not the case of
installed packages.

Changed that to /usr/bin, and also some usages of things like
/usr/something to /usr/share/something.

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: complex test

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Dec 30, 2022
1 parent 0c2ef6b commit dedee6d
Show file tree
Hide file tree
Showing 29 changed files with 103 additions and 96 deletions.
8 changes: 4 additions & 4 deletions apk/apk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func exampleInfo() *nfpm.Info {
Contents: []*files.Content{
{
Source: "../testdata/fake",
Destination: "/usr/local/bin/fake",
Destination: "/usr/bin/fake",
},
{
Source: "../testdata/whatever.conf",
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestCreateBuilderData(t *testing.T) {

require.NoError(t, builderData(tw))

require.Equal(t, 13832, buf.Len())
require.Equal(t, 13320, buf.Len())
}

func TestCombineToApk(t *testing.T) {
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestPathsToCreate(t *testing.T) {
func TestDefaultWithArch(t *testing.T) {
expectedChecksums := map[string]string{
"usr/share/doc/fake/fake.txt": "96c335dc28122b5f09a4cef74b156cd24c23784c",
"usr/local/bin/fake": "f46cece3eeb7d9ed5cb244d902775427be71492d",
"usr/bin/fake": "f46cece3eeb7d9ed5cb244d902775427be71492d",
"etc/fake/fake.conf": "96c335dc28122b5f09a4cef74b156cd24c23784c",
"etc/fake/fake2.conf": "96c335dc28122b5f09a4cef74b156cd24c23784c",
}
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestFileDoesNotExist(t *testing.T) {
Contents: []*files.Content{
{
Source: "../testdata/fake",
Destination: "/usr/local/bin/fake",
Destination: "/usr/bin/fake",
},
{
Source: "../testdata/whatever.confzzz",
Expand Down
2 changes: 1 addition & 1 deletion arch/arch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func exampleInfo() *nfpm.Info {
Contents: []*files.Content{
{
Source: "../testdata/fake",
Destination: "/usr/local/bin/fake",
Destination: "/usr/share/bin/fake",
},
{
Source: "../testdata/whatever.conf",
Expand Down
4 changes: 2 additions & 2 deletions deb/deb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func exampleInfo() *nfpm.Info {
Contents: []*files.Content{
{
Source: "../testdata/fake",
Destination: "/usr/local/bin/fake",
Destination: "/usr/bin/fake",
},
{
Source: "../testdata/whatever.conf",
Expand Down Expand Up @@ -325,7 +325,7 @@ func TestDebFileDoesNotExist(t *testing.T) {
Contents: []*files.Content{
{
Source: "../testdata/fake",
Destination: "/usr/local/bin/fake",
Destination: "/usr/bin/fake",
},
{
Source: "../testdata/whatever.confzzz",
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ license: "MIT"
changelog: "changelog.yaml"
contents:
- src: ./foo
dst: /usr/local/bin/foo
dst: /usr/bin/foo
- src: ./bar
dst: /usr/local/bin/bar
dst: /usr/bin/bar
- src: ./foobar.conf
dst: /etc/foobar.conf
type: config
- src: /usr/local/bin/foo
- src: /usr/bin/foo
dst: /sbin/foo
type: symlink
overrides:
Expand Down
12 changes: 6 additions & 6 deletions internal/rpmpack/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestFileOwner(t *testing.T) {
user := "testUser"

r.AddFile(RPMFile{
Name: "/usr/local/hello",
Name: "/usr/hello",
Body: []byte("content of the file"),
Group: group,
Owner: user,
Expand All @@ -46,7 +46,7 @@ func Test100644(t *testing.T) {
t.Fatalf("NewRPM returned error %v", err)
}
r.AddFile(RPMFile{
Name: "/usr/local/hello",
Name: "/usr/share/hello",
Body: []byte("content of the file"),
Mode: 0o100644,
})
Expand Down Expand Up @@ -162,20 +162,20 @@ func TestAllowListDirs(t *testing.T) {
}

r.AddFile(RPMFile{
Name: "/usr/local/dir1",
Name: "/usr/share/dir1",
Mode: 0o40000,
})
r.AddFile(RPMFile{
Name: "/usr/local/dir2",
Name: "/usr/share/dir2",
Mode: 0o40000,
})

r.AllowListDirs(map[string]bool{"/usr/local/dir1": true})
r.AllowListDirs(map[string]bool{"/usr/share/dir1": true})

if err := r.Write(io.Discard); err != nil {
t.Errorf("NewRPM returned error %v", err)
}
expected := map[string]RPMFile{"/usr/local/dir1": {Name: "/usr/local/dir1", Mode: 0o40000}}
expected := map[string]RPMFile{"/usr/share/dir1": {Name: "/usr/share/dir1", Mode: 0o40000}}
if d := cmp.Diff(expected, r.files); d != "" {
t.Errorf("Expected dirs differs (want->got):\n%v", d)
}
Expand Down
4 changes: 2 additions & 2 deletions rpm/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func exampleInfo() *nfpm.Info {
Contents: []*files.Content{
{
Source: "../testdata/fake",
Destination: "/usr/local/bin/fake",
Destination: "/usr/bin/fake",
},
{
Source: "../testdata/whatever.conf",
Expand Down Expand Up @@ -466,7 +466,7 @@ func TestRPMFileDoesNotExist(t *testing.T) {
info.Contents = []*files.Content{
{
Source: "../testdata/fake",
Destination: "/usr/local/bin/fake",
Destination: "/usr/bin/fake",
},
{
Source: "../testdata/whatever.confzzz",
Expand Down
16 changes: 8 additions & 8 deletions testdata/acceptance/apk.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ RUN ls -l /path/to/symlink | grep "/path/to/symlink -> /etc/foo/whatever.conf"

# ---- simple test ----
FROM min AS simple
RUN test -e /usr/local/bin/fake
RUN test -e /usr/bin/fake
RUN test -f /etc/foo/whatever.conf
RUN echo wat >> /etc/foo/whatever.conf
RUN apk del foo
RUN test -f /etc/foo/whatever.conf
RUN test ! -f /usr/local/bin/fake
RUN test ! -f /usr/bin/fake


# ---- no-glob test ----
Expand All @@ -36,7 +36,7 @@ RUN test -f /usr/share/whatever/folder2/file2

# ---- complex test ----
FROM min AS complex
RUN test -e /usr/local/bin/fake
RUN test -e /usr/bin/fake
RUN test -f /etc/foo/whatever.conf
RUN test -d /usr/share/whatever/
RUN test -d /usr/share/whatever/folder
Expand All @@ -53,16 +53,16 @@ RUN test -f /etc/something/a
RUN test -f /etc/something/b
RUN test -d /etc/something/c
RUN test -f /etc/something/c/d
RUN test $(stat -c %a /usr/sbin/fake) -eq 4755
RUN test $(stat -c %a /usr/bin/fake2) -eq 4755
RUN test -f /tmp/preinstall-proof
RUN test -f /tmp/postinstall-proof
RUN test ! -f /tmp/preremove-proof
RUN test ! -f /tmp/postremove-proof
RUN echo wat >> /etc/foo/whatever.conf
RUN apk del foo
RUN test -f /etc/foo/whatever.conf
RUN test ! -f /usr/local/bin/fake
RUN test ! -f /usr/sbin/fake
RUN test ! -f /usr/bin/fake
RUN test ! -f /usr/bin/fake2
RUN test -f /tmp/preremove-proof
RUN test -f /tmp/postremove-proof
RUN test ! -d /var/log/whatever
Expand All @@ -79,7 +79,7 @@ RUN apk add /tmp/foo.apk

# ---- overrides test ----
FROM min AS overrides
RUN test -e /usr/local/bin/fake
RUN test -e /usr/bin/fake
RUN test -f /etc/foo/whatever.conf
RUN test ! -f /tmp/preinstall-proof
RUN test -f /tmp/postinstall-proof
Expand All @@ -88,7 +88,7 @@ RUN test ! -f /tmp/postremove-proof
RUN echo wat >> /etc/foo/whatever.conf
RUN apk del foo
RUN test -f /etc/foo/whatever.conf
RUN test ! -f /usr/local/bin/fake
RUN test ! -f /usr/bin/fake
RUN test -f /tmp/preremove-proof
RUN test ! -f /tmp/postremove-proof

Expand Down
16 changes: 8 additions & 8 deletions testdata/acceptance/archlinux.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ RUN ls -l /path/to/symlink | grep "/path/to/symlink -> /etc/foo/whatever.conf"

# ---- simple test ----
FROM min AS simple
RUN test -e /usr/local/bin/fake
RUN test -e /usr/bin/fake
RUN test -f /etc/foo/whatever.conf
RUN echo wat >> /etc/foo/whatever.conf
RUN pacman --noconfirm -R foo
RUN test -f /etc/foo/whatever.conf.pacsave
RUN test ! -f /usr/local/bin/fake
RUN test ! -f /usr/bin/fake


# ---- no-glob test ----
Expand All @@ -39,7 +39,7 @@ FROM min AS complex
RUN pacman -Qi foo | grep "Depends On\\s*: bash"
RUN pacman -Qi foo | grep "Replaces\\s*: foo"
RUN pacman -Qi foo | grep "Provides\\s*: fake"
RUN test -e /usr/local/bin/fake
RUN test -e /usr/bin/fake
RUN test -f /etc/foo/whatever.conf
RUN test -d /usr/share/whatever/
RUN test -d /usr/share/whatever/folder
Expand All @@ -56,16 +56,16 @@ RUN test -f /etc/something/a
RUN test -f /etc/something/b
RUN test -d /etc/something/c
RUN test -f /etc/something/c/d
RUN test $(stat -c %a /usr/bin/fake) -eq 4755
RUN test $(stat -c %a /usr/bin/fake2) -eq 4755
RUN test -f /tmp/preinstall-proof
RUN test -f /tmp/postinstall-proof
RUN test ! -f /tmp/preremove-proof
RUN test ! -f /tmp/postremove-proof
RUN echo wat >> /etc/foo/whatever.conf
RUN pacman --noconfirm -R foo
RUN test -f /etc/foo/whatever.conf.pacsave
RUN test ! -f /usr/local/bin/fake
RUN test ! -f /usr/bin/fake
RUN test ! -f /usr/bin/fake2
RUN test -f /tmp/preremove-proof
RUN test -f /tmp/postremove-proof
RUN test ! -d /var/log/whatever
Expand All @@ -80,7 +80,7 @@ RUN echo "Arch Linux has no signature support"

# ---- overrides test ----
FROM min AS overrides
RUN test -e /usr/local/bin/fake
RUN test -e /usr/bin/fake
RUN test -f /etc/foo/whatever.conf
RUN test ! -f /tmp/preinstall-proof
RUN test -f /tmp/postinstall-proof
Expand All @@ -89,7 +89,7 @@ RUN test ! -f /tmp/postremove-proof
RUN echo wat >> /etc/foo/whatever.conf
RUN pacman --noconfirm -R foo
RUN test -f /etc/foo/whatever.conf.pacsave
RUN test ! -f /usr/local/bin/fake
RUN test ! -f /usr/bin/fake
RUN test -f /tmp/preremove-proof
RUN test ! -f /tmp/postremove-proof

Expand Down Expand Up @@ -133,4 +133,4 @@ RUN test -f /tmp/postupgrade-proof
RUN test -f /etc/regular.conf
RUN test -f /etc/regular.conf.pacnew
RUN test -f /etc/noreplace.conf
RUN test -f /etc/noreplace.conf.pacnew
RUN test -f /etc/noreplace.conf.pacnew
45 changes: 26 additions & 19 deletions testdata/acceptance/core.complex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,47 @@ homepage: "https://foobar.org"
license: "MIT"
contents:
- src: ./testdata/fake
dst: /usr/local/bin/fake
dst: /usr/bin/fake
- src: ./testdata/acceptance/folder/*
dst: /usr/share/whatever/folder
- src: ./testdata/whatever.conf
dst: /etc/foo/whatever.conf
type: config
- src: ./testdata/something
dst: /etc/something
- src: ./testdata/fake
dst: /usr/sbin/fake
packager: deb
- dst: /usr/foo/bar/something
type: dir
- dst: /var/log/whatever
type: dir
- dst: /usr/share/foo
type: dir

# Packager specifics:

- packager: deb
src: ./testdata/fake
dst: /usr/bin/fake2
file_info:
mode: 04755
- src: ./testdata/fake
dst: /usr/sbin/fake
packager: rpm

- packager: rpm
src: ./testdata/fake
dst: /usr/bin/fake2
file_info:
mode: 04755
- src: ./testdata/fake
dst: /usr/sbin/fake
packager: apk

- packager: apk
src: ./testdata/fake
dst: /usr/bin/fake2
file_info:
mode: 04755
- src: ./testdata/fake
dst: /usr/bin/fake

- packager: archlinux
src: ./testdata/fake
dst: /usr/bin/fake2
file_info:
mode: 04755
packager: archlinux
- dst: /usr/foo/bar/something
type: dir
- dst: /var/log/whatever
type: dir
- dst: /usr/share/foo
type: dir

scripts:
preinstall: ./testdata/acceptance/scripts/preinstall.sh
postinstall: ./testdata/acceptance/scripts/postinstall.sh
Expand Down
2 changes: 1 addition & 1 deletion testdata/acceptance/core.env-var-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ homepage: "https://foobar.org"
license: "MIT"
contents:
- src: ./testdata/fake
dst: /usr/local/bin/fake
dst: /usr/bin/fake
- src: ./testdata/acceptance/folder/**/*
dst: /usr/share/whatever/folder/
- src: ./testdata/whatever.conf
Expand Down
2 changes: 1 addition & 1 deletion testdata/acceptance/core.min.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ license: MIT
maintainer: "Foo Bar"
contents:
- src: ./testdata/fake
dst: /usr/local/bin/fake
dst: /usr/bin/fake
2 changes: 1 addition & 1 deletion testdata/acceptance/core.overrides.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ homepage: "https://foobar.org"
license: "MIT"
contents:
- src: ./testdata/fake
dst: /usr/local/bin/fake
dst: /usr/bin/fake
- src: ./testdata/acceptance/folder/*
dst: /usr/share/whatever/folder
- src: ./testdata/whatever.conf
Expand Down
2 changes: 1 addition & 1 deletion testdata/acceptance/core.signed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ vendor: "FooBarCorp"
homepage: "http://example.com"
contents:
- src: ./testdata/fake
dst: /usr/local/bin/fake
dst: /usr/bin/fake
deb:
signature:
key_file: ./internal/sign/testdata/privkey_unprotected.asc
Expand Down
2 changes: 1 addition & 1 deletion testdata/acceptance/core.simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ homepage: "https://foobar.org"
license: "MIT"
contents:
- src: ./testdata/fake
dst: /usr/local/bin/fake
dst: /usr/bin/fake
- src: ./testdata/whatever.conf
dst: /etc/foo/whatever.conf
type: config
2 changes: 1 addition & 1 deletion testdata/acceptance/core.withchangelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ homepage: "https://foobar.org"
license: "MIT"
contents:
- src: ./testdata/fake
dst: /usr/local/bin/fake
dst: /usr/bin/fake
- src: ./testdata/whatever.conf
dst: /etc/foo/whatever.conf
type: config
2 changes: 1 addition & 1 deletion testdata/acceptance/deb.debsign.sign.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ vendor: "FooBarCorp"
homepage: "http://example.com"
contents:
- src: ./testdata/fake
dst: /usr/local/bin/fake
dst: /usr/bin/fake
deb:
signature:
method: debsign
Expand Down
Loading

0 comments on commit dedee6d

Please sign in to comment.