Add systemd timer and configurator

This commit is contained in:
2026-03-19 00:21:35 +01:00
parent a7a9b55a6c
commit ed9672f0c9
10 changed files with 109 additions and 8 deletions
+1
View File
@@ -181,3 +181,4 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
/.idea/
+9
View File
@@ -0,0 +1,9 @@
MIT License
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+20
View File
@@ -0,0 +1,20 @@
# Set up hf-cli for automatic daily downloads
To enable daily runs, you first need to generate a config.json file defining what
to download and where to put it:
```bash
configure-zepp-timer
```
then you need to enable the timer for the user and enable lingering, so the timer
is executed even when the user is not logged in:
```bash
enable-zepp-timer
```
You can test the service by running it manually:
```bash
systemctl --user start huami-token.service
```
+2
View File
@@ -1,2 +1,4 @@
# huami-token-rpm
Packages the [huami-token](https://codeberg.org/argrento/huami-token) app including a user systemd timer and
service to automate the downloading of fresh aGPS packages on a schedule.
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
CONFIG=${XDG_CONFIG_HOME:-$HOME/.config}/huami-token.env
if [ -s "$CONFIG" ]; then
# shellcheck disable=SC1090
source "$CONFIG"
fi
readarray -t CREDS < <(dialog --output-fd 1 --defaultno --title "Provide Zepp login credentials" --visit-items --keep-tite --insecure --mixedform "Please enter your credentials:" 8 60 2 "Username/Email:" 1 1 "$ZEPP_USER" 1 18 38 0 2 "Password:" 2 1 "$ZEPP_PASS" 2 18 38 0 1)
if [ ${#CREDS[@]} -eq 0 ]; then
echo "Cancelled. $CONFIG was not changed."
exit 0;
fi
ZEPP_USER="${CREDS[0]//\\n|\\t|\\r/}"
ZEPP_PASS="${CREDS[1]//\\n|\\t|\\r/}"
if [ -z "$ZEPP_USER" ] || [ -z "$ZEPP_PASS" ]; then
echo "No username or password were provided. Not changing $CONFIG"
exit 1;
fi
term_width=$(tput cols)
text_width=$((term_width - 4))
( huami-token --method amazfit --email "$ZEPP_USER" --password "$ZEPP_PASS" | tail -c "$text_width" ) 2>&1 | dialog --keep-tite --title "Remote check" --programbox "Trying to log into Zepp" 8 "$term_width"
if [ "${PIPESTATUS[0]}" -ne 0 ]; then
echo Failed to login with the given user and password. Aborting.
exit 1
fi
TARGET_DIR=$(dialog --output-fd 1 --erase-on-exit --visit-items --keep-tite --clear --title "Choose an directory to put the downloaded files into" --dselect "${ZEPP_AGPS_TARGET_DIR:-~}" 3 60)
if [ "${PIPESTATUS[0]}" -ne 0 ]; then
echo "Cancelled. $CONFIG was not changed."
exit 0;
fi
echo -e "ZEPP_USER=$ZEPP_USER\nZEPP_PASS=$ZEPP_PASS\nZEPP_AGPS_TARGET_DIR=${TARGET_DIR//\\n|\\t|\\r/}" > "$CONFIG"
echo "The config at $CONFIG was updated"
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
systemctl --user enable huami-token.timer huami-token.service
loginctl enable-linger
echo The timer is now enabled
+10
View File
@@ -0,0 +1,10 @@
[Unit]
Description=Run huami-token from saved config
After=network.target
ConditionFileNotEmpty=%E/huami-token.env
[Service]
Type=oneshot
EnvironmentFile=%E/.config/huami-token.env
WorkingDirectory=${ZEPP_AGPS_TARGET_DIR}
ExecStart=/usr/bin/huami-token --method amazfit --gps --email ${ZEPP_USER} --password ${ZEPP_PASS}
+22 -8
View File
@@ -6,36 +6,50 @@ Version: 0.8.0
Release: %autorelease
Summary: This script retrieves the Bluetooth access token for the watch or band from Huami servers. Additionally, it downloads the AGPS data packs, cep_alm_pak.zip and cep_7days.zip.
# Check if the automatically generated License and its spelling is correct for Fedora
# https://docs.fedoraproject.org/en-US/packaging-guidelines/LicensingGuidelines/
License: MIT
URL: https://codeberg.org/argrento/huami-token
Source: %{pypi_source %{modname}}
Source0: %{pypi_source %{modname}}
Source1: huami-token.service
Source2: huami-token.timer
Source3: configure-zepp-timer
Source4: enable-zepp-timer
Source5: README-user-systemd.md
Source6: MIT.txt
Patch: 01-switch-to-pycrytodomex.patch
BuildSystem: pyproject
# Replace ... with top-level Python module names as arguments, you can use globs
BuildOption(install): -l %{modname}
BuildOption(generate_buildrequires): -x dev
BuildArch: noarch
BuildRequires: python3-devel
Requires: dialog
# Fill in the actual package description to submit package to Fedora
%global _description %{expand:
This script retrieves the Bluetooth access token for a watch or band from Huami servers.
Additionally, it downloads the AGPS data packs, cep_alm_pak.zip and cep_7days.zip.}
%description %_description
# For official Fedora packages, review which extras should be actually packaged
# See: https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/#Extras
%pyproject_extras_subpkg -n %{pkgname} dev
%install
%pyproject_install
%pyproject_save_files -L %{modname}
%{__install} -D -m 0644 -t %{buildroot}%{_userunitdir} %{SOURCE1}
%{__install} -D -m 0644 -t %{buildroot}%{_userunitdir} %{SOURCE2}
%{__install} -D -m 0755 -t %{buildroot}%{_bindir} %{SOURCE3}
%{__install} -D -m 0755 -t %{buildroot}%{_bindir} %{SOURCE4}
%{__install} -D -m 0755 -t %{buildroot}%{_docdir}/%{pkgname} %{SOURCE5}
%{__install} -D -m 0755 -t %{buildroot}%{_defaultlicensedir}/%{pkgname} %{SOURCE6}
%files -n %{pkgname} -f %{pyproject_files}
%{_bindir}/%{pkgname}
%doc README.md README-user-systemd.md
%license MIT.txt
%{_bindir}
%{_userunitdir}/*
%changelog
%autochangelog
+8
View File
@@ -0,0 +1,8 @@
[Unit]
Description=Download fresh gps roms for ZeppOS gadgets
[Timer]
OnCalendar=*-*-* 01:10:00
[Install]
WantedBy=timers.target
Binary file not shown.