Compare commits
35 Commits
f81bb53353
...
v0.2.3
| Author | SHA1 | Date | |
|---|---|---|---|
| e3caf0bba9 | |||
|
287cd741b4
|
|||
| 8b29105686 | |||
|
27c7367ef1
|
|||
| f9cef4b70d | |||
|
e3a3e61bce
|
|||
| bcec1f8f90 | |||
|
cf483de06b
|
|||
| d9c9eda823 | |||
|
4737dbb60d
|
|||
| f82249d10f | |||
|
d46ad2c2b4
|
|||
| 7911a7ed6f | |||
|
9853f854c9
|
|||
| a2c8ff0f84 | |||
|
0ca8ed94cc
|
|||
| 227a0426b5 | |||
|
20d143035e
|
|||
| 7b5b855774 | |||
|
6fc6207da8
|
|||
|
264b43c9a6
|
|||
|
118e4e5a86
|
|||
|
01898a3a8e
|
|||
| 1a1ad66ab6 | |||
|
bd71b8ee14
|
|||
| a76417ce1d | |||
|
a288dbc140
|
|||
| c3a6957a9e | |||
|
10060db8cb
|
|||
| 283a0d3905 | |||
|
1012ca5378
|
|||
|
6e00e89bb0
|
|||
|
403e047c0c
|
|||
|
56fb554f13
|
|||
| 8ed98cc998 |
28
.gitea/workflows/sync-github.yml
Normal file
28
.gitea/workflows/sync-github.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
name: Sync Release to GitHub
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: "Release tag to synchronize"
|
||||
required: false
|
||||
type: string
|
||||
release:
|
||||
types: [published, edited]
|
||||
|
||||
jobs:
|
||||
sync-github:
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
- name: Run Releases Sync Action
|
||||
uses: https://git.0xmax42.io/actions/releases-sync@main
|
||||
with:
|
||||
gitea_token: ${{ secrets.RELEASE_PUBLISH_TOKEN }}
|
||||
gitea_url: https://git.0xmax42.io
|
||||
gitea_owner: maxp
|
||||
gitea_repo: systemd-timer
|
||||
tag_name: ${{ inputs.tag || github.event.release.tag_name }}
|
||||
github_token: ${{ secrets.SYNC_GITHUB_TOKEN }}
|
||||
github_owner: 0xmax42
|
||||
github_repo: systemd-timer
|
||||
44
.gitea/workflows/upload-assets.yml
Normal file
44
.gitea/workflows/upload-assets.yml
Normal file
@@ -0,0 +1,44 @@
|
||||
name: Upload Assets
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
upload-assets:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- target: linux
|
||||
arch: amd64
|
||||
- target: linux
|
||||
arch: arm64
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.release.tag_name }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Get Release ID from tag
|
||||
run: .gitea/scripts/get-release-id.sh "${{ github.event.release.tag_name }}"
|
||||
|
||||
- uses: denoland/setup-deno@v2
|
||||
with:
|
||||
deno-version: v2.x
|
||||
|
||||
- name: Build ${{ matrix.target }}-${{ matrix.arch }}
|
||||
run: deno task build:${{ matrix.arch }}
|
||||
|
||||
- name: Generate SHA256 for ${{ matrix.target }}-${{ matrix.arch }}
|
||||
run: |
|
||||
FILE="./dist/systemd-timer-${{ matrix.target }}-${{ matrix.arch }}"
|
||||
sha256sum "$FILE" > "$FILE.sha256"
|
||||
|
||||
- name: Upload binary for ${{ matrix.target }}-${{ matrix.arch }}
|
||||
run: .gitea/scripts/upload-asset.sh ./dist/systemd-timer-${{ matrix.target }}-${{ matrix.arch }} systemd-timer-${{ matrix.target }}-${{ matrix.arch }}
|
||||
|
||||
- name: Upload SHA256 for ${{ matrix.target }}-${{ matrix.arch }}
|
||||
run: .gitea/scripts/upload-asset.sh ./dist/systemd-timer-${{ matrix.target }}-${{ matrix.arch }}.sha256 systemd-timer-${{ matrix.target }}-${{ matrix.arch }}.sha256
|
||||
50
CHANGELOG.md
50
CHANGELOG.md
@@ -2,10 +2,52 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [unreleased]
|
||||
## [0.2.3](https://git.0xmax42.io/maxp/systemd-timer/compare/v0.2.2..v0.2.3) - 2025-05-26
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
- *(workflows)* Add GitHub release synchronization workflow - ([27c7367](https://git.0xmax42.io/maxp/systemd-timer/commit/27c7367ef1799428cc5a491b25036f77b65758af))
|
||||
|
||||
### 📚 Documentation
|
||||
|
||||
- *(readme)* Update project time badge interval - ([e3a3e61](https://git.0xmax42.io/maxp/systemd-timer/commit/e3a3e61bce0e62c2397bbc5bde3eff81b915c94a))
|
||||
- Add Englisch README - ([cf483de](https://git.0xmax42.io/maxp/systemd-timer/commit/cf483de06b555599052b1d9f97ee98e9233e5a86))
|
||||
|
||||
## [0.2.2](https://git.0xmax42.io/maxp/systemd-timer/compare/v0.2.0..v0.2.2) - 2025-05-22
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
|
||||
- *(install)* Enhance checksum validation with detailed comparison - ([0ca8ed9](https://git.0xmax42.io/maxp/systemd-timer/commit/0ca8ed94ccc4b9fe4ccac331957f01f852999094))
|
||||
- *(install)* Ensure compatibility with non-bash shells - ([20d1430](https://git.0xmax42.io/maxp/systemd-timer/commit/20d143035ec6893f680b68dc4a2f6319ca7a5b81))
|
||||
|
||||
### 📚 Documentation
|
||||
|
||||
- *(readme)* Update installation instructions with script - ([9853f85](https://git.0xmax42.io/maxp/systemd-timer/commit/9853f854c991d87b12cd4fb5e19fce55e7246024))
|
||||
|
||||
## [0.2.0](https://git.0xmax42.io/maxp/systemd-timer/compare/v0.1.0..v0.2.0) - 2025-05-22
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
- *(scripts)* Add installation script for systemd-timer binary - ([264b43c](https://git.0xmax42.io/maxp/systemd-timer/commit/264b43c9a667d344e27cca4ac2f17d7a4a25bffc))
|
||||
- *(workflows)* Add matrix build and SHA256 generation for releases - ([118e4e5](https://git.0xmax42.io/maxp/systemd-timer/commit/118e4e5a867a42c0d79efcc3b2a4db188affedec))
|
||||
- *(tasks)* Add build tasks for amd64 and arm64 targets - ([01898a3](https://git.0xmax42.io/maxp/systemd-timer/commit/01898a3a8e094dfbbf981ab6f1cf38d52f60ef5d))
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
|
||||
- *(utils)* Handle file write failures with rollback - ([bd71b8e](https://git.0xmax42.io/maxp/systemd-timer/commit/bd71b8ee14a1856f1adaaaea198c8467b1a00d24))
|
||||
|
||||
### 📚 Documentation
|
||||
|
||||
- *(readme)* Add project time badge - ([a288dbc](https://git.0xmax42.io/maxp/systemd-timer/commit/a288dbc140fefbc46745f70cdcd71148802fdabf))
|
||||
|
||||
## [0.1.0] - 2025-05-21
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
- *(workflows)* Add release asset upload workflow - ([1012ca5](https://git.0xmax42.io/maxp/systemd-timer/commit/1012ca53781c36131a8b7aa43a9134f7b8565599))
|
||||
- *(cli)* Use dynamic version retrieval - ([403e047](https://git.0xmax42.io/maxp/systemd-timer/commit/403e047c0c376229244a5605d5c52eb1699acd4a))
|
||||
- *(utils)* Add version retrieval utility - ([56fb554](https://git.0xmax42.io/maxp/systemd-timer/commit/56fb554f132a53d74b2e9a1a02cc973c5420e73c))
|
||||
- *(generator)* Add systemctl usage instructions - ([f81bb53](https://git.0xmax42.io/maxp/systemd-timer/commit/f81bb533536810fc34656d572369b94ab669a181))
|
||||
- *(cli)* Add command to generate systemd unit files - ([97dc3fe](https://git.0xmax42.io/maxp/systemd-timer/commit/97dc3fe23acf2c35053aced7b34918bab7778c35))
|
||||
- *(utils)* Export utility functions for filesystem and naming - ([428e849](https://git.0xmax42.io/maxp/systemd-timer/commit/428e84927f8a9a379fa014ea763dd61115be34d6))
|
||||
- *(types)* Add TimerOptions interface for timer configuration - ([ba4b933](https://git.0xmax42.io/maxp/systemd-timer/commit/ba4b933f78c48a52b1c199fe28dc82d7ebabd7fe))
|
||||
@@ -16,6 +58,11 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
- *(utils)* Update import path for TimerOptions - ([316f3af](https://git.0xmax42.io/maxp/systemd-timer/commit/316f3af04ef7fe4c08963cfe3ad7780ed3bc262c))
|
||||
|
||||
### 📚 Documentation
|
||||
|
||||
- Add README for systemd-timer CLI tool - ([db1f56c](https://git.0xmax42.io/maxp/systemd-timer/commit/db1f56c539309b8a02adff114d765c725ac5ff8a))
|
||||
- Add MIT license file - ([e1cd5df](https://git.0xmax42.io/maxp/systemd-timer/commit/e1cd5dfd353c7cd7ca770daae5fc40405e461d1d))
|
||||
|
||||
### 🧪 Testing
|
||||
|
||||
- *(generate)* Add unit tests for service and timer generation - ([569b14d](https://git.0xmax42.io/maxp/systemd-timer/commit/569b14d57432589107a0f33e52881b605c5f79f9))
|
||||
@@ -23,6 +70,7 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
### ⚙️ Miscellaneous Tasks
|
||||
|
||||
- *(tasks)* Include version file in build process - ([6e00e89](https://git.0xmax42.io/maxp/systemd-timer/commit/6e00e89bb086672b9c3276ffeebcb1ded28c836f))
|
||||
- Add VSCode settings for color customizations and folder listener - ([6608f48](https://git.0xmax42.io/maxp/systemd-timer/commit/6608f488405adefc7993f47a137a824e5de62154))
|
||||
- *(config)* Add deno configuration and lockfile - ([0b72050](https://git.0xmax42.io/maxp/systemd-timer/commit/0b720500e0fe34db087b3277c38fa6bb07875e80))
|
||||
- Add automated release workflow and scripts for version management - ([a058e7b](https://git.0xmax42.io/maxp/systemd-timer/commit/a058e7b6838d41a98f3269db9a9d1e31f752121f))
|
||||
|
||||
103
README.DE.md
Normal file
103
README.DE.md
Normal file
@@ -0,0 +1,103 @@
|
||||
# systemd-timer
|
||||
|
||||

|
||||
|
||||
Ein einfaches CLI-Tool zum schnellen Erzeugen von systemd `.service` und `.timer` Units – als Ersatz oder moderne Ergänzung zu klassischen `cron`-Jobs.
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- Erzeugt `.service` und `.timer` Dateien per CLI
|
||||
- Unterstützt `--user` Timer (für `~/.config/systemd/user/`)
|
||||
- Optionales Logging (`StandardOutput/StandardError`)
|
||||
- Unterstützt:
|
||||
- `--calendar`
|
||||
- `--exec`
|
||||
- `--after`
|
||||
- `--environment`
|
||||
- `--output`
|
||||
- `--dry-run`
|
||||
- Getestet und typisiert mit Deno + Cliffy
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ Installation
|
||||
|
||||
|
||||
Du kannst `systemd-timer` direkt per Shell-Skript installieren:
|
||||
|
||||
```bash
|
||||
curl -fsSL https://git.0xmax42.io/maxp/systemd-timer/raw/branch/main/scripts/install.sh | sh
|
||||
```
|
||||
|
||||
Das Skript erkennt automatisch deine Plattform (Linux `amd64` oder `arm64`) und installiert die passende Binary nach `/usr/local/bin`, sofern dies erlaubt ist (ggf. mit `sudo`).
|
||||
|
||||
**Hinweis:**
|
||||
- Für die Installation ist eine funktionierende Internetverbindung notwendig.
|
||||
- Die Integrität der Binary wird mittels SHA256-Prüfsumme verifiziert.
|
||||
- Du kannst das Skript vor der Ausführung auch manuell inspizieren:
|
||||
|
||||
```bash
|
||||
curl -fsSL https://git.0xmax42.io/maxp/systemd-timer/raw/branch/main/scripts/install.sh -o install.sh
|
||||
less install.sh
|
||||
```
|
||||
|
||||
Weitere Optionen und manuelle Installationswege findest du unter [`scripts/install.sh`](scripts/install.sh).
|
||||
|
||||
---
|
||||
|
||||
## 📦 Beispiel
|
||||
|
||||
```bash
|
||||
./systemd-timer create \
|
||||
--exec "/usr/local/bin/backup.sh" \
|
||||
--calendar "Mon..Fri 02:00" \
|
||||
--description "Backup Job" \
|
||||
--user \
|
||||
--logfile "/var/log/backup.log"
|
||||
```
|
||||
|
||||
Erzeugt:
|
||||
- `~/.config/systemd/user/backup.service`
|
||||
- `~/.config/systemd/user/backup.timer`
|
||||
|
||||
Anschließend aktivieren:
|
||||
|
||||
```bash
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable --now backup.timer
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🧪 Tests ausführen
|
||||
|
||||
```bash
|
||||
deno task test
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🧰 Entwickeln
|
||||
|
||||
```bash
|
||||
deno task start create --exec "/bin/true" --calendar "daily" --dry-run
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔒 Rechte / Flags
|
||||
|
||||
Das Tool benötigt beim Ausführen bzw. Kompilieren:
|
||||
|
||||
- `--allow-env` (für `$HOME`)
|
||||
- `--allow-write` (zum Schreiben von `.service`/`.timer`)
|
||||
|
||||
Beim Entwickeln wird meist `-A` (allow all) verwendet.
|
||||
|
||||
---
|
||||
|
||||
## 📝 Lizenz
|
||||
|
||||
[MIT License](LICENSE)
|
||||
79
README.md
79
README.md
@@ -1,39 +1,55 @@
|
||||
# systemd-timer
|
||||
|
||||
Ein einfaches CLI-Tool zum schnellen Erzeugen von systemd `.service` und `.timer` Units – als Ersatz oder moderne Ergänzung zu klassischen `cron`-Jobs.
|
||||
- 
|
||||
- [Deutsche Version dieser Readme](README.DE.md)
|
||||
|
||||
A simple CLI tool for quickly generating systemd `.service` and `.timer` units — as a replacement or modern supplement to classic `cron` jobs.
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- Erzeugt `.service` und `.timer` Dateien per CLI
|
||||
- Unterstützt `--user` Timer (für `~/.config/systemd/user/`)
|
||||
- Optionales Logging (`StandardOutput/StandardError`)
|
||||
- Unterstützt:
|
||||
- `--calendar`
|
||||
- `--exec`
|
||||
- `--after`
|
||||
- `--environment`
|
||||
- `--output`
|
||||
- `--dry-run`
|
||||
- Getestet und typisiert mit Deno + Cliffy
|
||||
* Generates `.service` and `.timer` files via CLI
|
||||
* Supports `--user` timers (for `~/.config/systemd/user/`)
|
||||
* Optional logging (`StandardOutput/StandardError`)
|
||||
* Supports:
|
||||
|
||||
* `--calendar`
|
||||
* `--exec`
|
||||
* `--after`
|
||||
* `--environment`
|
||||
* `--output`
|
||||
* `--dry-run`
|
||||
* Tested and typed with Deno + Cliffy
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ Installation
|
||||
|
||||
```bash
|
||||
git clone https://git.0xmax42.io/maxp/systemd-timer.git
|
||||
cd systemd-timer
|
||||
deno task build
|
||||
You can install `systemd-timer` directly via shell script:
|
||||
|
||||
# Binary liegt nun unter ./systemd-timer
|
||||
./systemd-timer --help
|
||||
```bash
|
||||
curl -fsSL https://git.0xmax42.io/maxp/systemd-timer/raw/branch/main/scripts/install.sh | sh
|
||||
```
|
||||
|
||||
The script automatically detects your platform (Linux `amd64` or `arm64`) and installs the appropriate binary to `/usr/local/bin`, if permitted (possibly using `sudo`).
|
||||
|
||||
**Note:**
|
||||
|
||||
* A working internet connection is required for installation.
|
||||
* The integrity of the binary is verified using a SHA256 checksum.
|
||||
* You can manually inspect the script before execution:
|
||||
|
||||
```bash
|
||||
curl -fsSL https://git.0xmax42.io/maxp/systemd-timer/raw/branch/main/scripts/install.sh -o install.sh
|
||||
less install.sh
|
||||
```
|
||||
|
||||
Additional options and manual installation methods are available under [`scripts/install.sh`](scripts/install.sh).
|
||||
|
||||
---
|
||||
|
||||
## 📦 Beispiel
|
||||
## 📦 Example
|
||||
|
||||
```bash
|
||||
./systemd-timer create \
|
||||
@@ -44,11 +60,12 @@ deno task build
|
||||
--logfile "/var/log/backup.log"
|
||||
```
|
||||
|
||||
Erzeugt:
|
||||
- `~/.config/systemd/user/backup.service`
|
||||
- `~/.config/systemd/user/backup.timer`
|
||||
This creates:
|
||||
|
||||
Anschließend aktivieren:
|
||||
* `~/.config/systemd/user/backup.service`
|
||||
* `~/.config/systemd/user/backup.timer`
|
||||
|
||||
Activate afterwards:
|
||||
|
||||
```bash
|
||||
systemctl --user daemon-reload
|
||||
@@ -57,7 +74,7 @@ systemctl --user enable --now backup.timer
|
||||
|
||||
---
|
||||
|
||||
## 🧪 Tests ausführen
|
||||
## 🧪 Running Tests
|
||||
|
||||
```bash
|
||||
deno task test
|
||||
@@ -65,7 +82,7 @@ deno task test
|
||||
|
||||
---
|
||||
|
||||
## 🧰 Entwickeln
|
||||
## 🧰 Development
|
||||
|
||||
```bash
|
||||
deno task start create --exec "/bin/true" --calendar "daily" --dry-run
|
||||
@@ -73,17 +90,17 @@ deno task start create --exec "/bin/true" --calendar "daily" --dry-run
|
||||
|
||||
---
|
||||
|
||||
## 🔒 Rechte / Flags
|
||||
## 🔒 Permissions / Flags
|
||||
|
||||
Das Tool benötigt beim Ausführen bzw. Kompilieren:
|
||||
The tool requires the following permissions when running or compiling:
|
||||
|
||||
- `--allow-env` (für `$HOME`)
|
||||
- `--allow-write` (zum Schreiben von `.service`/`.timer`)
|
||||
* `--allow-env` (for `$HOME`)
|
||||
* `--allow-write` (to write `.service`/`.timer` files)
|
||||
|
||||
Beim Entwickeln wird meist `-A` (allow all) verwendet.
|
||||
During development, usually `-A` (allow all) is used.
|
||||
|
||||
---
|
||||
|
||||
## 📝 Lizenz
|
||||
## 📝 License
|
||||
|
||||
[MIT License](LICENSE)
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
"tasks": {
|
||||
"start": "deno run -A src/mod.ts",
|
||||
"test": "deno test -A --coverage **/__tests__/*.test.ts",
|
||||
"build": "deno compile --allow-env --allow-write --output dist/systemd-timer src/mod.ts"
|
||||
"build:amd64": "deno compile --target x86_64-unknown-linux-gnu --include=VERSION --allow-env --allow-write --output dist/systemd-timer-linux-amd64 src/mod.ts",
|
||||
"build:arm64": "deno compile --target aarch64-unknown-linux-gnu --include=VERSION --allow-env --allow-write --output dist/systemd-timer-linux-arm64 src/mod.ts"
|
||||
},
|
||||
"compilerOptions": {},
|
||||
"fmt": {
|
||||
|
||||
63
scripts/install.sh
Normal file
63
scripts/install.sh
Normal file
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Fail-safe bash mode (only if bash is used)
|
||||
if [ -n "$BASH_VERSION" ]; then
|
||||
set -euo pipefail
|
||||
else
|
||||
set -eu
|
||||
fi
|
||||
|
||||
# === Konfiguration ===
|
||||
REPO_URL="https://git.0xmax42.io/maxp/systemd-timer/releases/download/latest"
|
||||
BINARY_NAME="systemd-timer"
|
||||
INSTALL_PATH="/usr/local/bin"
|
||||
|
||||
# === Systemarchitektur erkennen ===
|
||||
ARCH=$(uname -m)
|
||||
case "$ARCH" in
|
||||
x86_64) ARCH="amd64" ;;
|
||||
aarch64 | arm64) ARCH="arm64" ;;
|
||||
*) echo "Unsupported architecture: $ARCH" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
OS=$(uname -s)
|
||||
case "$OS" in
|
||||
Linux) OS="linux" ;;
|
||||
*) echo "Unsupported OS: $OS" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
# === Download-URL zusammensetzen ===
|
||||
BINARY_FILE="${BINARY_NAME}-${OS}-${ARCH}"
|
||||
DOWNLOAD_URL="${REPO_URL}/${BINARY_FILE}"
|
||||
|
||||
echo "📦 Installing ${BINARY_NAME} for ${OS}/${ARCH}..."
|
||||
echo "🌐 Downloading from: ${DOWNLOAD_URL}"
|
||||
|
||||
# === Binary herunterladen ===
|
||||
TMP_FILE=$(mktemp)
|
||||
curl -fsSL "${DOWNLOAD_URL}" -o "${TMP_FILE}"
|
||||
chmod +x "${TMP_FILE}"
|
||||
|
||||
# === SHA256-Check ===
|
||||
TMP_HASH=$(mktemp)
|
||||
curl -fsSL "${DOWNLOAD_URL}.sha256" -o "$TMP_HASH"
|
||||
EXPECTED_HASH=$(cut -d ' ' -f1 "$TMP_HASH")
|
||||
ACTUAL_HASH=$(openssl dgst -sha256 "$TMP_FILE" | awk '{print $2}')
|
||||
|
||||
if [ "$EXPECTED_HASH" != "$ACTUAL_HASH" ]; then
|
||||
echo "⚠️ Checksum mismatch!"
|
||||
echo "Expected: $EXPECTED_HASH"
|
||||
echo "Actual: $ACTUAL_HASH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# === Installation ===
|
||||
echo "🚀 Installing to ${INSTALL_PATH}/${BINARY_NAME}"
|
||||
if [ -w "$INSTALL_PATH" ]; then
|
||||
install -m 755 "${TMP_FILE}" "${INSTALL_PATH}/${BINARY_NAME}"
|
||||
else
|
||||
sudo install -m 755 "${TMP_FILE}" "${INSTALL_PATH}/${BINARY_NAME}"
|
||||
fi
|
||||
|
||||
echo "✅ Installation complete: $(command -v ${BINARY_NAME})"
|
||||
"${BINARY_NAME}" --version || true
|
||||
@@ -1,9 +1,10 @@
|
||||
import { Command } from '@cliffy/command';
|
||||
import { createCommand } from './create.ts';
|
||||
import { getVersion } from '../utils/mod.ts';
|
||||
|
||||
await new Command()
|
||||
.name('systemd-timer')
|
||||
.version('0.1.0')
|
||||
.version(await getVersion())
|
||||
.description('CLI Tool zum Erzeugen von systemd .timer und .service Units')
|
||||
.command('create', createCommand)
|
||||
.parse(Deno.args);
|
||||
|
||||
@@ -12,14 +12,20 @@ export async function generateUnitFiles(options: TimerOptions): Promise<void> {
|
||||
console.log(`\n===== ${name}.timer =====`);
|
||||
console.log(timerUnit);
|
||||
} else {
|
||||
const { servicePath, timerPath } = await writeUnitFiles(
|
||||
const result = await writeUnitFiles(
|
||||
name,
|
||||
serviceUnit,
|
||||
timerUnit,
|
||||
options,
|
||||
);
|
||||
console.log(`Service unit written to: ${servicePath}`);
|
||||
console.log(`Timer unit written to: ${timerPath}`);
|
||||
|
||||
if (result) {
|
||||
const { servicePath, timerPath } = result;
|
||||
console.log(`Service Unit geschrieben in: ${servicePath}`);
|
||||
console.log(`Timer Unit geschrieben in: ${timerPath}`);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`\nℹ️ Hinweis:`);
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ Deno.test('writeUnitFiles schreibt .service und .timer korrekt', async () => {
|
||||
serviceContent,
|
||||
timerContent,
|
||||
options as TimerOptions,
|
||||
);
|
||||
) as { servicePath: string; timerPath: string };
|
||||
|
||||
// Überprüfe Pfade
|
||||
assertEquals(servicePath, join(tmp, 'test-backup.service'));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ensureDir } from 'https://deno.land/std@0.224.0/fs/mod.ts';
|
||||
import { ensureDir, exists } from 'https://deno.land/std@0.224.0/fs/mod.ts';
|
||||
import { join } from 'https://deno.land/std@0.224.0/path/mod.ts';
|
||||
import { TimerOptions } from '../types/mod.ts';
|
||||
|
||||
@@ -7,7 +7,7 @@ export async function writeUnitFiles(
|
||||
serviceContent: string,
|
||||
timerContent: string,
|
||||
options: TimerOptions,
|
||||
): Promise<{ servicePath: string; timerPath: string }> {
|
||||
): Promise<{ servicePath: string; timerPath: string } | undefined> {
|
||||
const basePath = resolveUnitTargetPath(options);
|
||||
|
||||
await ensureDir(basePath);
|
||||
@@ -15,8 +15,24 @@ export async function writeUnitFiles(
|
||||
const servicePath = join(basePath, `${name}.service`);
|
||||
const timerPath = join(basePath, `${name}.timer`);
|
||||
|
||||
try {
|
||||
await Deno.writeTextFile(servicePath, serviceContent);
|
||||
await Deno.writeTextFile(timerPath, timerContent);
|
||||
} catch (error) {
|
||||
// Rollback: Remove any files that were written
|
||||
try {
|
||||
if (await exists(servicePath)) {
|
||||
await Deno.remove(servicePath);
|
||||
}
|
||||
if (await exists(timerPath)) {
|
||||
await Deno.remove(timerPath);
|
||||
}
|
||||
} catch (rollbackError) {
|
||||
console.error('Rollback fehlgeschlagen:', rollbackError);
|
||||
}
|
||||
console.error('Fehler beim Schreiben der Units:', error);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return { servicePath, timerPath };
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
export { resolveUnitTargetPath, writeUnitFiles } from './fs.ts';
|
||||
export { deriveNameFromExec } from './misc.ts';
|
||||
export { getVersion } from './version.ts';
|
||||
|
||||
12
src/utils/version.ts
Normal file
12
src/utils/version.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export async function getVersion(): Promise<string> {
|
||||
try {
|
||||
const versionUrl = new URL('../../VERSION', import.meta.url);
|
||||
const version = await Deno.readTextFile(versionUrl);
|
||||
return version.trim();
|
||||
} catch (err) {
|
||||
if (err instanceof Deno.errors.NotFound) {
|
||||
return 'dev';
|
||||
}
|
||||
return 'unknown';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user