Gopher talkback written in Go for Linux
-------------------------------------------------
< I am a talking gopher, written in Go for Linux. >
< (See what I did there?) >
-------------------------------------------------
\ \
\\
\ (o)—————(o)
/ Q Q \
| o@o |
| W |
c| |ɔ
| |
| |
\_______/
C Ɔ
- Using a
.goscript as source for the local compiler - For alternate ways to build and compile the same
gophersaypackage, seegitrepos:- gophersay-tar (from local tarball)
- gophersay-git (from
gitrepository)
This is a guide to create an installer package for the gophersay command on:
- Arch (Manjaro, Black Arch, et al)
- Debian (Ubuntu, Kali, Mint, et al)
- RPM (OpenSUSE, RedHat/CentOS, Fedora, et al)
Working examples for each already resides in this repository
| Arch :$ (& Manjaro, Black Arch)
git clone https://github.com/JesseSteele/gophersay.git
cd gophersay/arch
makepkg -si| Debian :$ (& Ubuntu, Kali, Mint)
git clone https://github.com/JesseSteele/gophersay.git
sudo apt-get update
sudo apt-get install dpkg-dev debhelper golang-go
cd gophersay/deb/build
sudo dpkg-buildpackage -us -uc
cd debian
dpkg-deb --build gophersay
sudo dpkg -i gophersay.deb| RedHat/CentOS :$ (& Fedora)
git clone https://github.com/JesseSteele/gophersay.git
sudo dnf update
sudo dnf install rpm-build rpmdevtools go
cp -rf gophersay/rpm/rpmbuild ~/
rpmbuild -ba ~/rpmbuild/SPECS/gophersay.spec
ls ~/rpmbuild/RPMS/noarch/
sudo rpm -i ~/rpmbuild/RPMS/noarch/gophersay-1.0.0-1.noarch.rpm # Change filename if needed
rm -rf ~/rpmbuild| OpenSUSE :$ (& Tumbleweed)
git clone https://github.com/JesseSteele/gophersay.git
cd gophersay/rpm
sudo zypper update
sudo zypper install rpm-build rpmdevtools go
cp -r rpmbuild ~/
rpmbuild -ba ~/rpmbuild/SPECS/gophersay.spec
ls ~/rpmbuild/RPMS/noarch/
sudo rpm -i ~/rpmbuild/RPMS/noarch/gophersay-1.0.0-1.noarch.rpm # Change filename if needed
rm -rf ~/rpmbuildInstructions explain each in detail to create these packages from scratch...
- These instructions presume you can access gophersay.go
Arch package directory structure:
| arch/ :
arch/
├─ gophersay.go
└─ PKGBUILD
- Create directory:
arch - In
arch/create file:PKGBUILD
| arch/PKGBUILD :
# Maintainer: Jesse Steele <codes@jessesteele.com>
pkgname=gophersay
pkgver=1.0.0
pkgrel=1
pkgdesc="Gopher talkback written in Go for Linux"
url="https://github.com/JesseSteele/gophersay"
arch=('x86_64') # Go is newer and may not work on older systems, so not 'any'
license=('GPL')
depends=('go') # Depends on the 'go' package to build the binary
replaces=('gophersay-tar' 'gophersay-git')
source=("$pkgname.go")
sha256sums=('26ebde65cd84a50cbca4146ca8fe78e88da7cb0dc2520768de0c2a1066cc5b4d') # Hash for gophersay.go only
build() {
# Get into the root, where our to-be-compiled files are
cd "$srcdir"
# Compile the Go binary
go build -o "$pkgname" "$pkgname.go"
}
package() {
install -Dm755 "$srcdir/$pkgname" "$pkgdir/usr/bin/$pkgname"
}
- Place files
gophersay.go&go.modin the same directory asPKGBUILD - Build package:
- Navigate to directory
arch/ - Run this, then the package will be built, then installed with
pacman:
- Navigate to directory
| Build & install Arch package :$ (in one command)
makepkg -si- Use this to build and install in two steps:
| Build, then install Arch package :$ (first line produces the .pkg.tar.zst file for repos or manual install)
makepkg
sudo pacman -U gophersay-1.0.0-1-x86_64.pkg.tar.zst- Special notes about Arch:
- We don't need to resolve any dependencies, we can omit the
-sflag withmakepkg- This package only needs
bashas a dependency, which should already be installed merely to execute the scriptdepends=('bash')is redundant and only serves as an example inPKGBUILD
- This package only needs
- The name of the directory containing the package files does not matter
PKGBUILDis the instruction file, not a directory as might be expected with other package buildersmakepkgmust be run from the same directory containingPKGBUILD- The
.pkg.tar.zstfile will appear inside the containing directory
- We don't need to resolve any dependencies, we can omit the
| Remove Arch package :$ (optional)
sudo pacman -R gophersayDebian "maintainer" build directory structure:
| deb/ :
deb/
└─ build/
├─ debian/
│ ├─ compat
│ ├─ control
│ ├─ copyright
│ ├─ changelog
│ ├─ install
│ └─ rules
├─ go.mod
└─ gophersay.go
- Create directories:
deb/build/debian - In
debian/create file:control- Learn about the Debian source package template control file
| deb/build/debian/control :
Source: gophersay
Section: games
Priority: optional
Maintainer: Jesse Steele <codes@jessesteele.com>
Homepage: https://github.com/JesseSteele/gophersay
Build-Depends: debhelper (>= 10), golang-go
Standards-Version: 3.9.6
Package: gophersay
#Version: 1.0.0 # No! Inherited from `debian/changelog`
Architecture: all
Depends: bash (>= 4.0)
Description: Gopher talkback written in Go for Linux
- In
debian/create file:compat
| deb/build/debian/compat : (debhelper minimum version)
10
- In
debian/create file:changelog
| deb/build/debian/changelog : (optional, for listing changes)
gophersay (1.0.0-1) stable; urgency=low
* First release
-- Jesse Steele <codes@jessesteele.com> Thu, 1 Jan 1970 00:00:00 +0000
- In
debian/create file:copyright
| deb/build/debian/copyright : (optional, may be legally wise)
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: gophersay
Source: https://github.com/JesseSteele/gophersay
Files: *
Copyright: 2024, Jesse Steele <codes@jessesteele.com>
License: GPL-3+
- In
debian/create file:rules- Note that only tab characters are allowed for indented lines, not sequential spaces
- Make it executable with :$
chmod +x debian/rules
| deb/build/debian/rules : (build compiler)
#!/usr/bin/make -f
%:
dh $@
override_dh_auto_build:
go build -o gophersay gophersay.go
override_dh_auto_install:
install -D -m 0755 gophersay $(DESTDIR)/usr/bin/gophersay
- In
debian/create file:install
| deb/build/debian/install : (places files in the .deb directory structure)
gophersay /usr/bin
- Place files
gophersay.go&go.modindeb/build/
- Install the
dpkg-dev,debhelper&golang-gopackages
| Install Debian dpkg-dev package :$
sudo apt-get update
sudo apt-get install dpkg-dev debhelper golang-go- Prepare package builder:
- Navigate to directory
deb/build/ - Run this, then the package builder & repo packages will be created:
- Navigate to directory
| Prepare the Debian package builder :$
sudo dpkg-buildpackage -us -uc # Create the package builder- Note what just happened
- Everything just done to this point is called "maintainer" work in the Debian world
- Basic repo packages and also the package
DEBIAN/builder structure were greated - At this point, one could navigate up one directory to
deb/and runsudo dpkg -i gophersay_1.0.0-1_all.deband the package would be installed, but we won't do this - The command has also been created at
/usr/bin/gophersay- Once installed with
sudo dpkg -i(later) this can be removed the standard way withsudo apt-get remove gophersay
- Once installed with
- This is the new, just-created directory structure for the standard Debian package builder:
| deb/build/debian/ :
deb/build/debian/
└─ gophersay/
├─ DEBIAN/
│ ├─ control
│ └─ md5sums
└─ usr/
└─ bin/
└─ gophersay
- Build package:
- Navigate to directory
deb/build/debian/- :$
cd debian
- :$
- Run this, then the package will be built, then installed:
- Navigate to directory
| Build, then install Debian package :$
dpkg-deb --build gophersay # Create the .deb package
sudo dpkg -i gophersay.deb # Install the package- Special notes about Debian
- The
deb/build/directory can be anything, but we want it for housekeeping...dpkg-buildpackagewill create a laundry list of files as peers to this directory indeb/
- The
debian/controlfile buildsDEBIAN/control, but uses different fields- Fields after the empty line in this
debian/controlexample will not be recognized by thedpkg-buildpackagebuilder, but will supply information forDEBIAN/controlin the final.debpackage
- Fields after the empty line in this
- The
rulesscript will compilegophersayfromgophersay.go - The
installscript will place the compiledgophersaybinary atusr/bin/gophersayinside the package- This is why we don't need to place the binary at
usr/bin/gophersaymanually
- This is why we don't need to place the binary at
- Note
usr/local/bin/won't work for CLI command files because Debian packages expect binary commands to go in/usr/bin/- Debian can install directories—but cannot install any file—under
usr/local/ - Trying to install a file will return an error from the package manager since it expects directories, but only finds a file
- Debian can install directories—but cannot install any file—under
- The standard package build files (for
dpkg-deb --build) will appear atdeb/build/debian/gophersay/DEBIAN/- So from
deb/build/debian/one could rundpkg-deb --build gophersayto create the.debpackage atdeb/build/debian/gophersay.deb
- So from
- The standard package installer will appear at
deb/gophersay_1.0.0-1_all.deb
- The
| Remove Debian package :$ (optional)
sudo apt-get remove gophersayRPM package directory structure:
| rpm/ :
rpm/
└─ rpmbuild/
├─ SPECS/
│ └─ gophersay.spec
└─ SOURCES/
├─ go.mod
└─ gophersay.go
- Create directories:
rpm/rpmbuild/SPECS - In
SPECS/create file:gophersay.spec
| rpm/rpmbuild/SPECS/gophersay.spec :
Name: gophersay
Version: 1.0.0
Release: 1%{?dist}
Summary: The talking gopher
License: GPL
URL: https://github.com/JesseSteele/gophersay
Source0: gophersay-1.0.0.tar.xz
BuildArch: noarch
BuildRequires: go
Requires: bash
%description
Gopher talkback written in Go for Linux
%prep
%setup -q
%build
go build -o gophersay gophersay.go
%install
mkdir -p %{buildroot}/usr/bin
install -D -m 0755 gophersay %{buildroot}/usr/bin/gophersay
%files
/usr/bin/gophersay
%changelog
* Thu Jan 01 1970 Jesse Steele <codes@jessesteele.com> - 1.0.0-1
- Something started, probably with v1.0.0-1
- RPM package builders cannot compile from source without a tarball, so we need one
- Create the
gophersay-1.0.0/directory - Place gophersay.go & go.mod inside the
gophersay-1.0.0/directory - Roll up the
gophersay-1.0.0.tar.xztarball fromgophersay-1.0.0/- :$
tar Jcf gophersay-1.0.0.tar.xz gophersay-1.0.0
- :$
- Create the
| Create .xz tarball :$ (gophersay-1.0.0.tar.xz)
git clone https://github.com/JesseSteele/gophersay
mkdir -p gophersay-1.0.0
cp gophersay/gophersay.go gophersay-1.0.0/
cp gophersay/go.mod gophersay-1.0.0/
tar Jcf gophersay-1.0.0.tar.xz gophersay-1.0.0- Create directory:
rpm/rpmbuild/SOURCES/ - Place files
gophersay-1.0.0.tar.xzin directoryrpm/rpmbuild/SOURCES/ - Install the
rpm-build,rpmdevtools&gopackages
| RedHat/CentOS :$
sudo dnf update
sudo dnf install rpm-build rpmdevtools go| OpenSUSE :$
sudo zypper update
sudo zypper install rpm-build rpmdevtools go- Build package:
- Navigate to directory
rpm/ - Run the following commands:
- Navigate to directory
| Build, then install RPM package :$
cp -r rpmbuild ~/
rpmbuild -ba ~/rpmbuild/SPECS/gophersay.spec # Create the .rpm package
ls ~/rpmbuild/RPMS/noarch/ # Check the .rpm filename
sudo rpm -i ~/rpmbuild/RPMS/noarch/gophersay-1.0.0-1.noarch.rpm # Install the package (filename may be different)- Special notes about RPM:
- RPM requires the build be done from
~/rpmbuild/ - The resulting
.rpmfill will be at:~/rpmbuild/RPMS/noarch/gophersay-1.0.0-1.noarch.rpm- This file might actually have a different name, but should be in the same directory (
~/rpmbuild/RPMS/noarch/)
- This file might actually have a different name, but should be in the same directory (
noarchmeans it works on any architecture- This part of the filename was set in the
.specfile withBuildArch: noarch
- This part of the filename was set in the
- If you get
changelogorbad dateerror, then consider yourself normal
- RPM requires the build be done from
| Remove RedHat/CentOS package :$ (optional)
sudo dnf remove gophersay| Remove OpenSUSE package :$ (optional)
sudo zypper remove gophersay