added pkg build for project

This commit is contained in:
Lukas Forsberg 2025-05-30 12:28:38 +02:00
parent 1e9a377c2a
commit 3d3264d8d6
8 changed files with 59 additions and 24 deletions

View File

@ -32,7 +32,7 @@ endforeach()
# Use Crow from system include (installed via yay -S crow + asio)
include_directories(/usr/include)
add_executable(app src/main.cpp
add_executable(lf-server-admin-panel src/main.cpp
src/htmx/HtmxTable.cpp
src/htmx/HtmxTable.h
src/systemd.cpp
@ -48,7 +48,7 @@ add_executable(app src/main.cpp
src/json_settings.h
src/json.hpp)
target_link_libraries(app pthread)
target_link_libraries(lf-server-admin-panel pthread)
# Optional: Print build type at configuration time
message(STATUS "Configuring build type: ${CMAKE_BUILD_TYPE}")

26
PKGBUILD Normal file
View File

@ -0,0 +1,26 @@
# Maintainer: Lukas Forsberg lukas96.forsberg@gmail.com
pkgname=lf-server-admin-panel
pkgver=0.1.0
pkgrel=1
arch=('x86_64')
depends=('crow' 'asio')
pkgdesc="A Linux C++ Crow/HTMX web service to list the status of user specified systemd services"
license=('MIT')
makedepends=('cmake' 'gcc')
source=(
${pkgname}-${pkgver}.tar.gz
)
md5sums=('SKIP') # SKIP if local files
build() {
cd "$srcdir"
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
make
}
package() {
install -Dm755 "$srcdir/${pkgname}" "$pkgdir/usr/bin/${pkgname}"
install -Dm644 "$srcdir/templates/index.html" "$pkgdir/usr/share/${pkgname}/templates/index.html"
install -Dm644 "$srcdir/static/htmx.min.js" "$pkgdir/usr/share/${pkgname}/static/htmx.min.js"
install -Dm644 "$srcdir/static/settings.json" "$pkgdir/usr/share/${pkgname}/static/settings.json"
install -Dm644 "$srcdir/lf-server-admin-panel.service" "$pkgdir/usr/lib/systemd/system/lf-server-admin-panel.service"
}

View File

@ -7,4 +7,17 @@ pacman -S crow asio gdb gcc cmake make
### vscode
build : Ctrl+Shift+P → "CMake: Configure"
run : F5 or Run → Start Debugging
run : F5 or Run → Start Debugging
## Make Package
1. tar the source files to make it cleaner
```
tar czf lf-server-admin-panel-0.1.0.tar.gz src/ static/ templates/ lf-server-admin-panel.service CMakeLists.txt
```
2. create the package
```
makepkg -fL
```

View File

@ -0,0 +1,13 @@
[Unit]
Description=lf-server-admin-panel Service
After=network.target
[Service]
Type=simple
WorkingDirectory=/usr/share/lf-server-admin-panel
ExecStart=/usr/bin/lf-server-admin-panel
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target

View File

@ -1,18 +0,0 @@
pkgname=service-viewer
pkgver=1.0.0
pkgrel=1
arch=('x86_64')
depends=('crow') # add any libraries you need
pkgdesc="A C++ Crow/HTMX web service"
license=('MIT')
source=('src/')
md5sums=('SKIP') # SKIP if local files
build() {
# No build needed if already compiled
return 0
}
package() {
install -Dm755 "$srcdir/src/yourapp" "$pkgdir/usr/bin/yourapp"
install -Dm644 "$srcdir/src/assets/index.html" "$pkgdir/usr/share/yourapp/index.html"
install -Dm644 "$srcdir/src/assets/style.css" "$pkgdir/usr/share/yourapp/style.css"
}

View File

@ -44,7 +44,7 @@ expected<AppSettings, string> AppSettings::loadAppSettings() {
return settings;
}
optional<const std::string&> AppSettings::getId(string_view name){
optional<std::string> AppSettings::getId(string_view name){
for (auto& service : services) {
if(service.name == name) {
return service.service;

View File

@ -14,7 +14,7 @@ struct Service {
struct AppSettings {
static std::expected<AppSettings, std::string> loadAppSettings();
std::optional<const std::string&> getId(std::string_view name);
std::optional<std::string> getId(std::string_view name);
std::vector<Service> services;
};

View File

@ -21,6 +21,7 @@ namespace systemd {
void toggle_service(string_view serviceName){
string_view toggle = is_service_active(serviceName) ? "stop" : "start";
const string cmd = format("systemctl {} {}", toggle, serviceName);
system(cmd.c_str());
// TODO: add error handling
(void)system(cmd.c_str());
}
}