Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debian package #212

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: actions/checkout@v3
with: # fetch tags for git describe
fetch-depth: 0
- run: git fetch --tags
- name: Install Dependencies
run: |
sudo apt-get update
Expand All @@ -113,6 +115,22 @@ jobs:
cmake DCMAKE_BUILD_TYPE=Release ..
make

- name: Install Debian build Dependencies
run: |
sudo apt-get update
sudo apt-get -y install devscripts equivs dpkg-dev
sudo mk-build-deps -i

- name: Test debian build
shell: bash
run: |
gcc --version
rm -f debian/changelog.dch
debchange -Mv $(git describe --tags HEAD | cut -f2- -dv) 'CI/CD build'
dpkg-buildpackage -us -uc
mkdir -p out
mv ../*.*deb out/

- name: Test Scripts
shell: bash
run: |
Expand All @@ -131,3 +149,9 @@ jobs:
fi
exit 0

- name: Upload ryzenadj Debian
uses: actions/upload-artifact@v3
with:
name: ryzenadj-ubuntu-focal-amd64
path: |
./out/*.*deb
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,9 @@ ASALocalRun/
healthchecksdb

# End of https://www.gitignore.io/api/visualstudio

# Debian package build
obj-*/

# Cmake generated version file
lib/ryzenadj_version.h
22 changes: 20 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)

#define project name
PROJECT(ryzenadj)
PROJECT(ryzenadj VERSION 0.11.1)
joka90 marked this conversation as resolved.
Show resolved Hide resolved

set(CMAKE_CXX_STANDARD 11)

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

configure_file (
"${PROJECT_SOURCE_DIR}/lib/ryzenadj_version.h.in"
"${PROJECT_SOURCE_DIR}/lib/ryzenadj_version.h"
)

INCLUDE_DIRECTORIES(${INC_DIR})

AUX_SOURCE_DIRECTORY(./ SRC_DIR)
Expand Down Expand Up @@ -37,4 +42,17 @@ target_link_libraries(${PROJECT_NAME} ${OS_LINK_LIBRARY})
ADD_LIBRARY (libryzenadj SHARED ${OS_SOURCE} ${COMMON_SOURCES})
set_target_properties(libryzenadj PROPERTIES PREFIX "")
target_link_libraries(libryzenadj ${OS_LINK_LIBRARY})
#SET_TARGET_PROPERTIES(libryzenadj PROPERTIES LINKER_LANGUAGE C)
set_target_properties(libryzenadj PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})
set_target_properties(libryzenadj PROPERTIES PUBLIC_HEADER "lib/ryzenadj.h;lib/ryzenadj_version.h;lib/nb_smu_ops.h;lib/ryzenadj_priv.h")

if (UNIX)
include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME} libryzenadj
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif (UNIX)
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,38 @@ The simplest way to build it:
cmake -DCMAKE_BUILD_TYPE=Release ..
make

modify permissions for executing as root when started from Ryzen controller
and user belongs to the ryzenadj group

setcap 'cap_sys_rawio=ep cap_dac_override=ep cap_sys_admin=ep' ./ryzenadj

or via the suid bit

sudo chow root:root ./ryzenadj
sudo chmod u+s ./ryzenadj

add system group for RyzenAdj authentication

getent group ryzenadj || sudo addgroup --quiet --system ryzenadj

add allowed users to ryzenadj group

sudo usermod -aG ryzenadj $USER

### Package build

On Debian/Ubuntu:

sudo apt-get update
sudo apt-get -y install devscripts equivs dpkg-dev
sudo mk-build-deps -i
dpkg-buildpackage -us -uc
sudo dpkg -i ../ryzenadj_*.deb ../libryzenadj0_*.deb

add allowed users to ryzenadj group

sudo usermod -aG ryzenadj $USER

### Windows

It can be built by Visual Studio + MSVC automaticaly, or Clang + Nmake in command line.
Expand Down
8 changes: 8 additions & 0 deletions debian/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.debhelper/
debhelper-build-stamp
files
*.substvars
ryzenadj/
libryzenadj-dev/
libryzenadj0/
tmp/
53 changes: 53 additions & 0 deletions debian/apparmor/usr.bin.ryzenadj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
abi <abi/3.0>,

include <tunables/global>

/usr/bin/ryzenadj flags=(enforce) {
include <abstractions/base>
include <abstractions/consoles>
include <abstractions/nameservice>
include if exists <local/usr.bin.ryzenadj>

capability sys_admin,
capability sys_rawio,
capability dac_override,

# Needed for some files in /proc see
# https://gitlab.com/apparmor/apparmor/-/wikis/TechnicalDoc_Proc_and_ptrace#apparmor-3-with-ptrace-rules
# from man proc 5 :
# /proc/[pid]/exe :
# Permission to dereference or read (readlink(2)) this symbolic link is governed by a ptrace access mode
# PTRACE_MODE_READ_FSCREDS check; see ptrace(2).
capability sys_ptrace,
ptrace read peer=unconfined,

/etc/ld.so.cache r,
/lib/@{multiarch}/ld-*.so* mr,
/lib/@{multiarch}/libc-*.so* mr,
/lib/@{multiarch}/libgcc_s.so* mr,
/lib/@{multiarch}/libld-*.so* mr,
/lib/libgcc_s.so* mr,
/lib{,32,64}/ld-*.so* mr,
/lib{,32,64}/libc-*.so* mr,
/lib{,32,64}/libld-*.so* mr,
/usr/bin/ryzenadj mr,
/usr/lib/@{multiarch}/libpci.so* mr,
/usr/lib/@{multiarch}/libudev.so* mr,
/usr/lib/@{multiarch}/libz.so* mr,
/usr/lib/libpci.so* mr,
/usr/lib/libudev.so* mr,
/usr/lib/libz.so* mr,
@{PROC}/ r,
@{PROC}/[0-9]*/ r,
@{PROC}/[0-9]*/exe r,

@{sys}/kernel/ryzen_smu_drv/pm_table r,
/dev/mem r,

@{sys}/devices/pci0000:00/0000:00:00.0/class r,
@{sys}/devices/pci0000:00/0000:00:00.0/config rw,
@{sys}/devices/pci0000:00/0000:00:00.0/device r,
@{sys}/devices/pci0000:00/0000:00:00.0/resource r,
@{sys}/devices/pci0000:00/0000:00:00.0/vendor r,

}
11 changes: 11 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ryzenadj (0.11.1-1) unstable; urgency=medium

New revision

-- Johan Källström <[email protected]> Sat, 27 Aug 2022 14:02:53 +0200

ryzenadj (0.11.0-1) unstable; urgency=medium

initial debian package release

-- Johan Källström <[email protected]> Sat, 27 Mar 2022 08:18:45 +0100
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11
47 changes: 47 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Source: ryzenadj
Section: admin
Priority: optional
Maintainer: Johan Källström <[email protected]>
Uploaders: Johan Källström <[email protected]>,
Build-Depends: cmake (>= 3.0~),
dh-apparmor,
libpci-dev,
debhelper
Standards-Version: 4.6.0
Homepage: https://github.com/FlyGoat/RyzenAdj/
Vcs-Browser: https://github.com/FlyGoat/RyzenAdj/
Vcs-Git: https://github.com/FlyGoat/RyzenAdj.git
Rules-Requires-Root: no


Package: ryzenadj
Architecture: any
Depends: ${misc:Depends},
${shlibs:Depends},
libryzenadj0 (= ${binary:Version}),
Pre-Depends: adduser (>= 3.11),
libcap2-bin,
Description: Adjust power management settings for Ryzen Mobile Processors.
This is a commandline tool that allows you to adjust power management
settings for Ryzen Mobile Processors.

Package: libryzenadj0
Architecture: any
Depends: ${misc:Depends},
${shlibs:Depends},
Suggests: ryzen-smu-dkms
Description: power management library for Ryzen Mobile Processors.
This library provides APIs to Adjust power management settings for
Ryzen Mobile Processors.

Package: libryzenadj-dev
Architecture: any
Depends: ${misc:Depends},
libryzenadj0 (= ${binary:Version})
Description: power management library - development files
for Ryzen Mobile Processors.
This library provides APIs to Adjust power management settings for
Ryzen Mobile Processors.
.
This package contains the files needed for developing applications that
use libryzenadj.
8 changes: 8 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Contact: [email protected]
Upstream-Name: ryzenadj
Source: https://github.com/FlyGoat/RyzenAdj/

Files: *
Copyright: 2019-2022, Jiaxun Yang <[email protected]>
License: LGPL-3
3 changes: 3 additions & 0 deletions debian/libryzenadj-dev.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
usr/include/*
usr/lib/*/libryzenadj.so

2 changes: 2 additions & 0 deletions debian/libryzenadj0.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
usr/lib/*/libryzenadj.so.*

19 changes: 19 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/make -f

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

export DEB_BUILD_MAINT_OPTIONS=hardening=+all
export DH_VERBOSE = 1

%:
dh $@

override_dh_auto_configure:
dh_auto_configure -- \
-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) \
-DCMAKE_BUILD_TYPE=RelWithDebInfo


override_dh_install:
dh_install
dh_apparmor -p ryzenadj --profile-name=usr.bin.ryzenadj
2 changes: 2 additions & 0 deletions debian/ryzenadj.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
usr/bin/ryzenadj
debian/apparmor/usr.bin.ryzenadj etc/apparmor.d
19 changes: 19 additions & 0 deletions debian/ryzenadj.postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
# postinst script for #PACKAGE#

BINARY=/usr/bin/ryzenadj
case "$1" in
configure)
if which setcap > /dev/null && setcap 'cap_sys_rawio=ep cap_dac_override=ep cap_sys_admin=ep' "$BINARY" ; then
echo "Set setcap on $BINARY successfull"
else
echo "Set setuid root on $BINARY"
chmod u+s "$BINARY" || ( echo "Error: failed to setuid root on $BINARY" >&2 )
fi
;;

*)
;;
esac

#DEBHELPER#
18 changes: 18 additions & 0 deletions debian/ryzenadj.preinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
# preinst script for #PACKAGE#
set -e
RYZENADJ_GROUP=ryzenadj

case "$1" in
install|upgrade)
# create group for authenticating users.
if ! getent group $RYZENADJ_GROUP 2>&1 >/dev/null ; then
echo "Adding group $RYZENADJ_GROUP.."
addgroup --quiet --system $RYZENADJ_GROUP
fi
;;
*)
;;
esac

#DEBHELPER#
7 changes: 3 additions & 4 deletions lib/ryzenadj.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

#ifndef RYZENADJ_H
#define RYZENADJ_H

#include "ryzenadj_version.h"

#ifdef __cplusplus
extern "C" {
#endif

#define RYZENADJ_REVISION_VER 0
#define RYZENADJ_MAJOR_VER 11
#define RYZENADJ_MINIOR_VER 1

enum ryzen_family {
FAM_UNKNOWN = -1,
FAM_RAVEN = 0,
Expand Down
18 changes: 18 additions & 0 deletions lib/ryzenadj_version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* SPDX-License-Identifier: LGPL */
/* Copyright (C) 2019 Jiaxun Yang <[email protected]> */
/* RyzenAdj API Version */

#ifndef RYZENADJ_VERSION_H
#define RYZENADJ_VERSION_H
#ifdef __cplusplus
extern "C" {
#endif

#define RYZENADJ_REVISION_VER @PROJECT_VERSION_MAJOR@
#define RYZENADJ_MAJOR_VER @PROJECT_VERSION_MINOR@
#define RYZENADJ_MINIOR_VER @PROJECT_VERSION_PATCH@

#ifdef __cplusplus
}
#endif
#endif
Loading