Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
neolynx committed Jun 12, 2024
1 parent aa83fba commit 8369306
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 96 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ debian/aptly.substvars
debian/aptly/
debian/debhelper-build-stamp
debian/files

.go/
obj-x86_64-linux-gnu/
12 changes: 0 additions & 12 deletions aptly-api.service

This file was deleted.

12 changes: 0 additions & 12 deletions aptly.service

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/api_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func aptlyAPIServe(cmd *commander.Command, args []string) error {
// anything else must fail.
// E.g.: Running the service under a different user may lead to a rootDir
// that exists but is not usable due to access permissions.
err = utils.DirIsAccessible(context.Config().RootDir)
err = utils.DirIsAccessible(context.Config().GetRootDir())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func aptlyServe(cmd *commander.Command, args []string) error {
// anything else must fail.
// E.g.: Running the service under a different user may lead to a rootDir
// that exists but is not usable due to access permissions.
err = utils.DirIsAccessible(context.Config().RootDir)
err = utils.DirIsAccessible(context.Config().GetRootDir())
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (context *AptlyContext) DBPath() string {

// DBPath builds path to database
func (context *AptlyContext) dbPath() string {
return filepath.Join(context.config().RootDir, "db")
return filepath.Join(context.config().GetRootDir(), "db")
}

// Database opens and returns current instance of database
Expand Down Expand Up @@ -361,7 +361,7 @@ func (context *AptlyContext) PackagePool() aptly.PackagePool {
defer context.Unlock()

if context.packagePool == nil {
context.packagePool = files.NewPackagePool(context.config().RootDir, !context.config().SkipLegacyPool)
context.packagePool = files.NewPackagePool(context.config().GetRootDir(), !context.config().SkipLegacyPool)
}

return context.packagePool
Expand All @@ -375,7 +375,7 @@ func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedSto
publishedStorage, ok := context.publishedStorages[name]
if !ok {
if name == "" {
publishedStorage = files.NewPublishedStorage(filepath.Join(context.config().RootDir, "public"), "hardlink", "")
publishedStorage = files.NewPublishedStorage(filepath.Join(context.config().GetRootDir(), "public"), "hardlink", "")
} else if strings.HasPrefix(name, "filesystem:") {
params, ok := context.config().FileSystemPublishRoots[name[11:]]
if !ok {
Expand Down Expand Up @@ -433,7 +433,7 @@ func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedSto

// UploadPath builds path to upload storage
func (context *AptlyContext) UploadPath() string {
return filepath.Join(context.Config().RootDir, "upload")
return filepath.Join(context.Config().GetRootDir(), "upload")
}

func (context *AptlyContext) pgpProvider() string {
Expand Down
3 changes: 0 additions & 3 deletions debian/aptly-api.conf

This file was deleted.

1 change: 0 additions & 1 deletion debian/aptly-api.install

This file was deleted.

16 changes: 0 additions & 16 deletions debian/aptly-api.service

This file was deleted.

33 changes: 33 additions & 0 deletions debian/aptly.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"rootDir": "~/.aptly",
"downloadConcurrency": 4,
"downloadSpeedLimit": 0,
"downloadRetries": 0,
"downloader": "default",
"databaseOpenAttempts": -1,
"architectures": [],
"dependencyFollowSuggests": false,
"dependencyFollowRecommends": false,
"dependencyFollowAllVariants": false,
"dependencyFollowSource": false,
"dependencyVerboseResolve": false,
"gpgDisableSign": false,
"gpgDisableVerify": false,
"gpgProvider": "gpg",
"downloadSourcePackages": false,
"skipLegacyPool": true,
"ppaDistributorID": "ubuntu",
"ppaCodename": "",
"skipContentsPublishing": false,
"skipBz2Publishing": false,
"FileSystemPublishEndpoints": {},
"S3PublishEndpoints": {},
"SwiftPublishEndpoints": {},
"AzurePublishEndpoints": {},
"AsyncAPI": false,
"enableMetricsEndpoint": false,
"logLevel": "info",
"logFormat": "default",
"serveInAPIMode": false,
"enableSwaggerEndpoint": false
}
2 changes: 1 addition & 1 deletion debian/aptly-api.default → debian/aptly.default
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Default settings for aptly-api
LISTEN_ADDRESS='localhost:8080'
LISTEN_ADDRESS='localhost:3142'
1 change: 1 addition & 0 deletions debian/aptly.install
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build/aptly usr/bin/
README.rst usr/share/aptly/
LICENSE usr/share/aptly/
AUTHORS usr/share/aptly/
debian/aptly.conf etc/
37 changes: 26 additions & 11 deletions debian/aptly.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,35 @@ set -e
# source debconf library
. /usr/share/debconf/confmodule

USER=aptly
HOME_DIR=/var/lib/aptly

# ---------------------------------------------------------------------------------------------------------------
# User Setup
# ---------------------------------------------------------------------------------------------------------------
setup_user()
{
id -u $USER >/dev/null 2>&1 || adduser --system --home $HOME_DIR --shell /bin/bash $USER
}

case "$1" in
configure)
setup_user
# create an aptly group and user
if ! getent passwd aptly > /dev/null; then
useradd --system --user-group --shell /bin/bash --create-home --home-dir /var/lib/aptly aptly
fi

if [ -d /var/lib/aptly-api/ ]; then
# FIXME: handle if mountpoint
# FIXME: only when rootDir configured to /var/lib/aptly-api/
mkdir -p /var/lib/aptly/.aptly/
cp -ar /var/lib/aptly-api/* /var/lib/aptly/.aptly/
chown -R aptly:aptly /var/lib/aptly/.aptly/

getent passwd aptly-api > /dev/null && userdel aptly-api
getent group aptly-api > /dev/null && groupdel aptly-api
mv /var/lib/aptly-api /var/lib/aptly-api.old
fi

if [ -f /etc/default/aptly-api ]; then
cp /etc/default/aptly-api /etc/default/aptly
mv /etc/default/aptly-api /etc/default/aptly-api.old
fi

# set config file permissions
# it may contain secrets so it is not world readable
chown root:aptly /etc/aptly.conf
chmod 640 /etc/aptly.conf
;;

abort-upgrade|abort-remove|abort-deconfigure)
Expand Down
39 changes: 39 additions & 0 deletions debian/aptly.preinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
# * <new-preinst> `install'
# * <new-preinst> `install' <old-version>
# * <new-preinst> `upgrade' <old-version>
# * <old-preinst> `abort-upgrade' <new-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
install|upgrade)
if [ -f /etc/aptly-api.conf ]; then
cp /etc/aptly-api.conf /etc/aptly.conf
mv /etc/aptly-api.conf /etc/aptly-api.conf.old
sed -i 's_/var/lib/aptly-api_~/.aptly_' /etc/aptly.conf
fi
;;

abort-upgrade)
;;

*)
echo "preinst called with unknown argument \`$1'" >&2
exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
12 changes: 8 additions & 4 deletions debian/aptly.service
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
[Unit]
Description=Aptly REST API service
Description=Aptly REST API
After=network.target
Documentation=man:aptly(1)

[Service]
Environment=TERM=dumb
User=aptly
WorkingDirectory=/var/lib/aptly
ExecStart=/usr/bin/aptly api serve -listen localhost:3142
Group=aptly
Environment=TERM=dumb
WorkingDirectory=~
EnvironmentFile=/etc/default/aptly
ExecStart=/usr/bin/aptly api serve -config=/etc/aptly.conf -listen=${LISTEN_ADDRESS}

[Install]
WantedBy=multi-user.target
27 changes: 5 additions & 22 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,8 @@ Testsuite: autopkgtest-pkg-go

Package: aptly
Architecture: any
Depends: ${misc:Depends}, bzip2, xz-utils
Description: aptly - Debian repository management tool
Aptly is a swiss army knife for Debian repository management.

Package: aptly-api
Architecture: any
Depends: ${misc:Depends}, aptly, adduser
Built-Using: ${misc:Built-Using}
Description: Swiss army knife for Debian repository management - API
It offers several features making it easy to manage Debian package
repositories:
.
- make mirrors of remote Debian/Ubuntu repositories, limiting by
components/architectures
- take snapshots of mirrors at any point in time, fixing state of
repository at some moment of time
- publish snapshot as Debian repository, ready to be consumed by apt
- controlled update of one or more packages in snapshot from upstream
mirror, tracking dependencies
- merge two or more snapshots into one
.
This package contains the aptly-api service.
Provides: aptly-api
Conflicts: aptly-api
Depends: ${misc:Depends}, ${shlibs:Depends}, bzip2, xz-utils, adduser
Description: Debian repository management tool
aptly is a Swiss army knife for Debian repository management.
14 changes: 7 additions & 7 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

include /usr/share/dpkg/pkg-info.mk

export GOPATH=$(PWD)/.go
export GOPATH=$(shell pwd)/.go
export DEB_BUILD_OPTIONS=crossbuildcanrunhostbinaries

export GOARCH := $(shell if [ $(DEB_TARGET_ARCH) = "i386" ]; then echo "386"; elif [ $(DEB_TARGET_ARCH) = "armhf" ]; then echo "arm"; else echo $(DEB_TARGET_ARCH); fi )
export GOARCH := $(shell if [ $(DEB_TARGET_ARCH) = "i386" ]; then echo "386"; elif [ $(DEB_TARGET_ARCH) = "armhf" ]; then echo "arm"; else echo $(DEB_TARGET_ARCH); fi)

override_dh_auto_install:
dh_auto_install -- --no-source
mkdir -p debian/aptly/usr/share/man/man1/ debian/aptly/usr/share/bash-completion/completion/
mkdir -p debian/aptly/usr/share/man/man1/ debian/aptly/usr/share/bash-completion/completions/
cp man/aptly.1 debian/aptly/usr/share/man/man1
cp completion.d/aptly debian/aptly/usr/share/bash-completion/completion/
cp completion.d/aptly debian/aptly/usr/share/bash-completion/completions/
gzip debian/aptly/usr/share/man/man1/aptly.1

%:
dh $@ --buildsystem=golang --with=golang

override_dh_auto_build:
mkdir -p obj-$(DEB_TARGET_GNU_TYPE)/src/github.com/aptly-dev/aptly
echo $(DEB_VERSION) > obj-$(DEB_TARGET_GNU_TYPE)/src/github.com/aptly-dev/aptly/VERSION
# mkdir -p obj-$(DEB_TARGET_GNU_TYPE)/src/github.com/aptly-dev/aptly
echo $(DEB_VERSION) > VERSION
go build -o build/aptly

override_dh_auto_test:

# not needed with golang, fail with cross compiling
override_dh_strip:
#override_dh_strip:
override_dh_makeshlibs:
override_dh_golang:
7 changes: 7 additions & 0 deletions utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"os"
"path/filepath"
"strings"
)

// ConfigStructure is structure of main configuration
Expand Down Expand Up @@ -148,3 +149,9 @@ func SaveConfig(filename string, config *ConfigStructure) error {
_, err = f.Write(encoded)
return err
}

// GetRootDir returns the RootDir with expanded ~ as home directory
func (conf *ConfigStructure) GetRootDir() string {
return strings.Replace(conf.RootDir, "~", os.Getenv("HOME"), 1)
}

Check failure on line 157 in utils/config.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)

0 comments on commit 8369306

Please sign in to comment.