Compare commits
No commits in common. "main" and "1.0" have entirely different histories.
5 changed files with 52 additions and 493 deletions
|
@ -1,243 +0,0 @@
|
||||||
name: Build for Releases
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
ensure-release-exists:
|
|
||||||
runs-on: any_archLinux
|
|
||||||
steps:
|
|
||||||
- name: Check release and create if it doesn't exist
|
|
||||||
run: |
|
|
||||||
THE_ACTION_WORKING_DIRECTORY="$(pwd)"
|
|
||||||
curl -X GET "https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases/tags/$GITHUB_REF_NAME" \
|
|
||||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
|
||||||
-H 'accept: application/json' -o "${THE_ACTION_WORKING_DIRECTORY}/release_${GITHUB_REF_NAME}_check.json" \
|
|
||||||
-w '%{http_code}' 2>/dev/null > release_${GITHUB_REF_NAME}_check_code
|
|
||||||
if [[ "404" == "$(cat release_${GITHUB_REF_NAME}_check_code)" ]]; then
|
|
||||||
curl --fail-with-body -X POST \
|
|
||||||
"https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases" \
|
|
||||||
-H 'accept: application/json' \
|
|
||||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
|
||||||
-H 'Content-Type: application/json' \
|
|
||||||
-d "{
|
|
||||||
\"body\": \" SHA256SUMS\",
|
|
||||||
\"name\": \"break_interval version ${GITHUB_REF_NAME}\",
|
|
||||||
\"tag_name\": \"${GITHUB_REF_NAME}\" }" 2>/dev/null > "${THE_ACTION_WORKING_DIRECTORY}/release_${GITHUB_REF_NAME}_create.json"
|
|
||||||
fi
|
|
||||||
|
|
||||||
push-build-x86_64:
|
|
||||||
needs: ensure-release-exists
|
|
||||||
concurrency:
|
|
||||||
group: push-build-group
|
|
||||||
runs-on: x86_64_archLinux
|
|
||||||
steps:
|
|
||||||
- name: Check release assets and build for x86_64
|
|
||||||
run: |
|
|
||||||
THE_ACTION_WORKING_DIRECTORY="$(pwd)"
|
|
||||||
BUILD_ASSET_NAME="break_interval_x86_64_${GITHUB_REF_NAME}.zst"
|
|
||||||
curl -X GET \
|
|
||||||
"https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases/tags/${GITHUB_REF_NAME}" \
|
|
||||||
-H 'accept: application/json' -o "${THE_ACTION_WORKING_DIRECTORY}/release_info.json" 2>/dev/null
|
|
||||||
BUILD_ASSET_EXISTS=0
|
|
||||||
for asset in $(jq '.assets.[].name' < "${THE_ACTION_WORKING_DIRECTORY}/release_info.json" | tr -d '"'); do
|
|
||||||
if [[ "$asset" == "$BUILD_ASSET_NAME" ]]; then
|
|
||||||
BUILD_ASSET_EXISTS=1
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
if ! (( BUILD_ASSET_EXISTS )); then
|
|
||||||
if ! [[ -d "break_interval_clone" ]]; then
|
|
||||||
git clone --depth=1 --no-single-branch https://git.seodisparate.com/stephenseo/break_interval.git break_interval_clone
|
|
||||||
fi
|
|
||||||
pushd break_interval_clone >&/dev/null
|
|
||||||
git clean -xfd && git restore . && git checkout "${GITHUB_REF_NAME}"
|
|
||||||
cmake -S . -B buildRelease -DCMAKE_BUILD_TYPE=Release
|
|
||||||
make -C buildRelease
|
|
||||||
strip --strip-unneeded buildRelease/break_interval
|
|
||||||
zstd --ultra -20 buildRelease/break_interval -o "${THE_ACTION_WORKING_DIRECTORY}/${BUILD_ASSET_NAME}"
|
|
||||||
curl --fail-with-body -X GET \
|
|
||||||
"https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases/$(jq .id < "${THE_ACTION_WORKING_DIRECTORY}/release_info.json")" \
|
|
||||||
-H 'accept: application/json' -o "${THE_ACTION_WORKING_DIRECTORY}/current_release_info.json" 2>/dev/null
|
|
||||||
curl --fail-with-body -X PATCH \
|
|
||||||
"https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases/$(jq .id < "${THE_ACTION_WORKING_DIRECTORY}/release_info.json")" \
|
|
||||||
-H 'accept: application/json' \
|
|
||||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
|
||||||
-H 'Content-Type: application/json' \
|
|
||||||
-d "{
|
|
||||||
\"body\": \"$(jq .body < "${THE_ACTION_WORKING_DIRECTORY}/current_release_info.json" | sed -e 's/^"//' -e 's/"$//')
|
|
||||||
$(find "${THE_ACTION_WORKING_DIRECTORY}" -maxdepth 1 -name "*${BUILD_ASSET_NAME}" -execdir sha256sum '{}' ';')\"
|
|
||||||
}" >&/dev/null
|
|
||||||
curl --fail-with-body -X POST \
|
|
||||||
"https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases/$(jq .id < "${THE_ACTION_WORKING_DIRECTORY}/release_info.json")/assets" \
|
|
||||||
-H 'accept: application/json' \
|
|
||||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
|
||||||
-H 'Content-Type: multipart/form-data' \
|
|
||||||
-F "attachment=@${THE_ACTION_WORKING_DIRECTORY}/${BUILD_ASSET_NAME};type=application/zstd" > "${THE_ACTION_WORKING_DIRECTORY}/attach_${GITHUB_REF_NAME}.json" 2>/dev/null
|
|
||||||
popd >&/dev/null
|
|
||||||
fi
|
|
||||||
|
|
||||||
push-build-aarch64:
|
|
||||||
if: ${{ always() }}
|
|
||||||
needs: push-build-x86_64
|
|
||||||
concurrency:
|
|
||||||
group: push-build-group
|
|
||||||
runs-on: aarch64_archLinux
|
|
||||||
steps:
|
|
||||||
- name: Check release assets and build for aarch64
|
|
||||||
run: |
|
|
||||||
THE_ACTION_WORKING_DIRECTORY="$(pwd)"
|
|
||||||
BUILD_ASSET_NAME="break_interval_aarch64_${GITHUB_REF_NAME}.zst"
|
|
||||||
curl -X GET \
|
|
||||||
"https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases/tags/${GITHUB_REF_NAME}" \
|
|
||||||
-H 'accept: application/json' -o "${THE_ACTION_WORKING_DIRECTORY}/release_info.json" 2>/dev/null
|
|
||||||
BUILD_ASSET_EXISTS=0
|
|
||||||
for asset in $(jq '.assets.[].name' < "${THE_ACTION_WORKING_DIRECTORY}/release_info.json" | tr -d '"'); do
|
|
||||||
if [[ "$asset" == "$BUILD_ASSET_NAME" ]]; then
|
|
||||||
BUILD_ASSET_EXISTS=1
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
if ! (( BUILD_ASSET_EXISTS )); then
|
|
||||||
if ! [[ -d "break_interval_clone" ]]; then
|
|
||||||
git clone --depth=1 --no-single-branch https://git.seodisparate.com/stephenseo/break_interval.git break_interval_clone
|
|
||||||
fi
|
|
||||||
pushd break_interval_clone >&/dev/null
|
|
||||||
git clean -xfd && git restore . && git checkout "${GITHUB_REF_NAME}"
|
|
||||||
cmake -S . -B buildRelease -DCMAKE_BUILD_TYPE=Release
|
|
||||||
make -C buildRelease
|
|
||||||
strip --strip-unneeded buildRelease/break_interval
|
|
||||||
zstd --ultra -20 buildRelease/break_interval -o "${THE_ACTION_WORKING_DIRECTORY}/${BUILD_ASSET_NAME}"
|
|
||||||
curl --fail-with-body -X GET \
|
|
||||||
"https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases/$(jq .id < "${THE_ACTION_WORKING_DIRECTORY}/release_info.json")" \
|
|
||||||
-H 'accept: application/json' -o "${THE_ACTION_WORKING_DIRECTORY}/current_release_info.json" 2>/dev/null
|
|
||||||
curl --fail-with-body -X PATCH \
|
|
||||||
"https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases/$(jq .id < "${THE_ACTION_WORKING_DIRECTORY}/release_info.json")" \
|
|
||||||
-H 'accept: application/json' \
|
|
||||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
|
||||||
-H 'Content-Type: application/json' \
|
|
||||||
-d "{
|
|
||||||
\"body\": \"$(jq .body < "${THE_ACTION_WORKING_DIRECTORY}/current_release_info.json" | sed -e 's/^"//' -e 's/"$//')
|
|
||||||
$(find "${THE_ACTION_WORKING_DIRECTORY}" -maxdepth 1 -name "*${BUILD_ASSET_NAME}" -execdir sha256sum '{}' ';')\"
|
|
||||||
}" >&/dev/null
|
|
||||||
curl --fail-with-body -X POST \
|
|
||||||
"https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases/$(jq .id < "${THE_ACTION_WORKING_DIRECTORY}/release_info.json")/assets" \
|
|
||||||
-H 'accept: application/json' \
|
|
||||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
|
||||||
-H 'Content-Type: multipart/form-data' \
|
|
||||||
-F "attachment=@${THE_ACTION_WORKING_DIRECTORY}/${BUILD_ASSET_NAME};type=application/zstd" > "${THE_ACTION_WORKING_DIRECTORY}/attach_${GITHUB_REF_NAME}.json" 2>/dev/null
|
|
||||||
popd >&/dev/null
|
|
||||||
fi
|
|
||||||
push-build-x86_64_debian:
|
|
||||||
if: ${{ always() }}
|
|
||||||
needs: push-build-aarch64
|
|
||||||
concurrency:
|
|
||||||
group: push-build-group
|
|
||||||
runs-on: docker_debian_bookworm
|
|
||||||
env:
|
|
||||||
BUILD_ASSET_NAME: "break_interval_x86_64_debian_${{ github.ref_name }}.zst"
|
|
||||||
steps:
|
|
||||||
- name: Update and upgrade with apt
|
|
||||||
run: apt-get --yes update && apt-get --yes upgrade
|
|
||||||
- name: Get necessary packages
|
|
||||||
run: apt-get --yes install gcc g++ jq curl cmake make zstd sed git
|
|
||||||
- name: Get release info
|
|
||||||
run: |
|
|
||||||
curl -X GET \
|
|
||||||
"https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases/tags/${GITHUB_REF_NAME}" \
|
|
||||||
-H 'accept: application/json' -o release_info.json
|
|
||||||
- name: Check if asset exists
|
|
||||||
run: |
|
|
||||||
for asset in $(jq '.assets[].name' < release_info.json | tr -d '"'); do
|
|
||||||
if [[ "$asset" == "$BUILD_ASSET_NAME" ]]; then
|
|
||||||
touch asset_exists
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
- name: Build and publish if asset does not exist
|
|
||||||
run: |
|
|
||||||
if ! [[ -e ./asset_exists ]]; then
|
|
||||||
git clone --depth=1 --no-single-branch https://git.seodisparate.com/stephenseo/break_interval.git break_interval_clone
|
|
||||||
pushd break_interval_clone >&/dev/null
|
|
||||||
|
|
||||||
git checkout "${GITHUB_REF_NAME}"
|
|
||||||
cmake -S . -B buildRelease -DCMAKE_BUILD_TYPE=Release
|
|
||||||
make -C buildRelease
|
|
||||||
|
|
||||||
popd >&/dev/null
|
|
||||||
zstd --ultra -20 break_interval_clone/buildRelease/break_interval -o "${BUILD_ASSET_NAME}"
|
|
||||||
|
|
||||||
curl --fail-with-body -X PATCH \
|
|
||||||
"https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases/$(jq .id < release_info.json)" \
|
|
||||||
-H 'accept: application/json' \
|
|
||||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
|
||||||
-H 'Content-Type: application/json' \
|
|
||||||
-d "{
|
|
||||||
\"body\": \"$(jq .body < release_info.json | sed -e 's/^"//' -e 's/"$//')
|
|
||||||
$(sha256sum "${BUILD_ASSET_NAME}")\"
|
|
||||||
}" >&/dev/null
|
|
||||||
|
|
||||||
curl --fail-with-body -X POST \
|
|
||||||
"https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases/$(jq .id < release_info.json)/assets" \
|
|
||||||
-H 'accept: application/json' \
|
|
||||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
|
||||||
-H 'Content-Type: multipart/form-data' \
|
|
||||||
-F "attachment=@${BUILD_ASSET_NAME};type=application/zstd" > attach.json 2>/dev/null
|
|
||||||
fi
|
|
||||||
push-build-aarch64_debian:
|
|
||||||
if: ${{ always() }}
|
|
||||||
needs: push-build-x86_64_debian
|
|
||||||
concurrency:
|
|
||||||
group: push-build-group
|
|
||||||
runs-on: aarch64_docker_debian_bookworm
|
|
||||||
env:
|
|
||||||
BUILD_ASSET_NAME: "break_interval_aarch64_debian_${{ github.ref_name }}.zst"
|
|
||||||
steps:
|
|
||||||
- name: Update and upgrade with apt
|
|
||||||
run: apt-get --yes update && apt-get --yes upgrade
|
|
||||||
- name: Get necessary packages
|
|
||||||
run: apt-get --yes install gcc g++ jq curl cmake make zstd sed git
|
|
||||||
- name: Get release info
|
|
||||||
run: |
|
|
||||||
curl -X GET \
|
|
||||||
"https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases/tags/${GITHUB_REF_NAME}" \
|
|
||||||
-H 'accept: application/json' -o release_info.json
|
|
||||||
- name: Check if asset exists
|
|
||||||
run: |
|
|
||||||
for asset in $(jq '.assets[].name' < release_info.json | tr -d '"'); do
|
|
||||||
if [[ "$asset" == "$BUILD_ASSET_NAME" ]]; then
|
|
||||||
touch asset_exists
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
- name: Build and publish if asset does not exist
|
|
||||||
run: |
|
|
||||||
if ! [[ -e ./asset_exists ]]; then
|
|
||||||
git clone --depth=1 --no-single-branch https://git.seodisparate.com/stephenseo/break_interval.git break_interval_clone
|
|
||||||
pushd break_interval_clone >&/dev/null
|
|
||||||
|
|
||||||
git checkout "${GITHUB_REF_NAME}"
|
|
||||||
cmake -S . -B buildRelease -DCMAKE_BUILD_TYPE=Release
|
|
||||||
make -C buildRelease
|
|
||||||
|
|
||||||
popd >&/dev/null
|
|
||||||
zstd --ultra -20 break_interval_clone/buildRelease/break_interval -o "${BUILD_ASSET_NAME}"
|
|
||||||
|
|
||||||
curl --fail-with-body -X PATCH \
|
|
||||||
"https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases/$(jq .id < release_info.json)" \
|
|
||||||
-H 'accept: application/json' \
|
|
||||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
|
||||||
-H 'Content-Type: application/json' \
|
|
||||||
-d "{
|
|
||||||
\"body\": \"$(jq .body < release_info.json | sed -e 's/^"//' -e 's/"$//')
|
|
||||||
$(sha256sum "${BUILD_ASSET_NAME}")\"
|
|
||||||
}" >&/dev/null
|
|
||||||
|
|
||||||
curl --fail-with-body -X POST \
|
|
||||||
"https://git.seodisparate.com/api/v1/repos/stephenseo/break_interval/releases/$(jq .id < release_info.json)/assets" \
|
|
||||||
-H 'accept: application/json' \
|
|
||||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
|
||||||
-H 'Content-Type: multipart/form-data' \
|
|
||||||
-F "attachment=@${BUILD_ASSET_NAME};type=application/zstd" > attach.json 2>/dev/null
|
|
||||||
fi
|
|
36
Changelog.md
36
Changelog.md
|
@ -1,41 +1,5 @@
|
||||||
# Changelog for break\_interval
|
# Changelog for break\_interval
|
||||||
|
|
||||||
## Upcoming Changes
|
|
||||||
|
|
||||||
## Version 1.3.2
|
|
||||||
|
|
||||||
Updated action/workflow to build for Debian aarch64.
|
|
||||||
|
|
||||||
Minor fixes to action/workflow.
|
|
||||||
|
|
||||||
## Version 1.3.1
|
|
||||||
|
|
||||||
Updated action/workflow to build for Debian x86_64.
|
|
||||||
|
|
||||||
Minor fixes to action/workflow.
|
|
||||||
|
|
||||||
## Version 1.3
|
|
||||||
|
|
||||||
More tweaks to README.
|
|
||||||
|
|
||||||
Allow playing internal file even if custom player command is specified.
|
|
||||||
Do this by specifying "INTERNAL_FILE" as the filename parameter.
|
|
||||||
|
|
||||||
## Version 1.2
|
|
||||||
|
|
||||||
Minor tweaks to help text, README.
|
|
||||||
|
|
||||||
Add workflow to build break\_interval for x86_64 and aarch64.
|
|
||||||
|
|
||||||
## Version 1.1
|
|
||||||
|
|
||||||
Change usage of internal audio to use a Unix pipe instead of reading from
|
|
||||||
temporary file.
|
|
||||||
|
|
||||||
Implement way to run different audio-player with support for custom args.
|
|
||||||
|
|
||||||
Some refactorings.
|
|
||||||
|
|
||||||
## Version 1.0
|
## Version 1.0
|
||||||
|
|
||||||
Initial version with working program.
|
Initial version with working program.
|
||||||
|
|
29
README.md
29
README.md
|
@ -5,34 +5,7 @@ meant to be used as a way to notify the user to take a break when the interval
|
||||||
jingle plays.
|
jingle plays.
|
||||||
|
|
||||||
# For usage:
|
# For usage:
|
||||||
> ./break_interval --help
|
./break_interval --help
|
||||||
./program [minutes] [file_to_play_on_interval] [player_program] [player_args...]
|
|
||||||
minutes defaults to 5, file defaults to internal file, program defaults to "/usr/bin/mpv".
|
|
||||||
Note that this program uses execl/execv, so if a program is specified, it must be the full path to the program.
|
|
||||||
|
|
||||||
Running the program with no args will default to playing a jingle every 5
|
Running the program with no args will default to playing a jingle every 5
|
||||||
minutes.
|
minutes.
|
||||||
|
|
||||||
If `[player_program]` is specified (with full path) like with
|
|
||||||
`/usr/bin/ffplay`, then the command executed will look like:
|
|
||||||
|
|
||||||
/usr/bin/ffplay <file_to_play>
|
|
||||||
|
|
||||||
If `[player_args...]` is specified like with `--flag` and `--another-flag`, then
|
|
||||||
the command executed will look like:
|
|
||||||
|
|
||||||
/usr/bin/ffplay --flag --another-flag <file_to_play>
|
|
||||||
|
|
||||||
It may be recommended to use a command like:
|
|
||||||
|
|
||||||
./break_interval 5 /my/music/file.mp3 /usr/bin/ffplay -nodisp
|
|
||||||
|
|
||||||
Which will execute (every 5 minutes):
|
|
||||||
|
|
||||||
/usr/bin/ffplay -nodisp /my/music/file.mp3
|
|
||||||
|
|
||||||
To play the internal file instead of a specified one, use the parameter
|
|
||||||
"INTERNAL_FILE" for the filename and break\_interval will play the internal
|
|
||||||
file.
|
|
||||||
|
|
||||||
./break_interval 5 INTERNAL_FILE /usr/bin/ffplay -nodisp
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
#ifndef SEODISPARATE_COM_BREAK_INTERVAL_INTERVAL_NOTIFICATION_JINGLE_H
|
|
||||||
#define SEODISPARATE_COM_BREAK_INTERVAL_INTERVAL_NOTIFICATION_JINGLE_H
|
|
||||||
|
|
||||||
unsigned char interval_notification_mp3[] = {
|
unsigned char interval_notification_mp3[] = {
|
||||||
0x49, 0x44, 0x33, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x54, 0x53,
|
0x49, 0x44, 0x33, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x54, 0x53,
|
||||||
0x53, 0x45, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x03, 0x4c, 0x61, 0x76,
|
0x53, 0x45, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x03, 0x4c, 0x61, 0x76,
|
||||||
|
@ -11502,5 +11499,3 @@ unsigned char interval_notification_mp3[] = {
|
||||||
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
|
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
|
||||||
};
|
};
|
||||||
unsigned int interval_notification_mp3_len = 137970;
|
unsigned int interval_notification_mp3_len = 137970;
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
232
src/main.c
232
src/main.c
|
@ -6,8 +6,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
// Local includes.
|
// Local includes.
|
||||||
#include "interval_notification.h"
|
#include "interval_notification.h"
|
||||||
|
@ -23,164 +21,14 @@ void interval_notification_handle_signal(int sig) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int play_jingle_from_file(char *player,
|
|
||||||
char **player_args,
|
|
||||||
unsigned int args_count,
|
|
||||||
char *jingle_filename,
|
|
||||||
int use_internal_file_specified) {
|
|
||||||
int pipe_filedes[2];
|
|
||||||
if (use_internal_file_specified == 0) {
|
|
||||||
int jingle_fd = open(jingle_filename, O_RDONLY);
|
|
||||||
if (jingle_fd == -1) {
|
|
||||||
puts("ERROR: Failed to play jingle: Failed to open file!");
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
close(jingle_fd);
|
|
||||||
} else {
|
|
||||||
if (pipe(pipe_filedes) != 0) {
|
|
||||||
puts("ERROR: Failed to play jingle: Failed to create pipe!");
|
|
||||||
return 7;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(fork()) {
|
|
||||||
case -1:
|
|
||||||
puts("ERROR: Failed to play jingle: Failed to fork!");
|
|
||||||
return 3;
|
|
||||||
case 0:
|
|
||||||
// Pipe output to /dev/null.
|
|
||||||
int null_fd = open("/dev/null", O_WRONLY);
|
|
||||||
if (null_fd == -1) {
|
|
||||||
puts("ERROR: Failed to redirect play-jingle-output to /dev/null!");
|
|
||||||
exit(4);
|
|
||||||
}
|
|
||||||
dup2(null_fd, 1);
|
|
||||||
dup2(null_fd, 2);
|
|
||||||
|
|
||||||
if (use_internal_file_specified != 0) {
|
|
||||||
// Handle pipe into stdin.
|
|
||||||
close(pipe_filedes[1]);
|
|
||||||
dup2(pipe_filedes[0], 0);
|
|
||||||
jingle_filename = "/dev/stdin";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exec.
|
|
||||||
if (args_count == 0 && strcmp(player, "/usr/bin/mpv") == 0) {
|
|
||||||
if (execl(player,
|
|
||||||
player,
|
|
||||||
"--vid=no",
|
|
||||||
jingle_filename,
|
|
||||||
(char*)NULL)
|
|
||||||
== -1) {
|
|
||||||
printf("ERROR: Failed to play with player \"%s\" and jingle \"%s\"!\n",
|
|
||||||
player, jingle_filename);
|
|
||||||
close(null_fd);
|
|
||||||
exit(5);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Every pointer has the same size, but for sanity use sizeof(char*).
|
|
||||||
char **argvs = malloc(sizeof(char*) * (args_count + 3));
|
|
||||||
memset(argvs, 0, sizeof(char*) * (args_count + 3));
|
|
||||||
argvs[0] = player;
|
|
||||||
printf("<%s> ", player);
|
|
||||||
for (unsigned int i = 0; i < args_count; ++i) {
|
|
||||||
argvs[1 + i] = player_args[i];
|
|
||||||
printf("%s ", player_args[i]);
|
|
||||||
}
|
|
||||||
argvs[1 + args_count] = jingle_filename;
|
|
||||||
printf("%s NULL\n", jingle_filename);
|
|
||||||
if (execv(player, argvs) == -1) {
|
|
||||||
printf("ERROR: Failed to play with player \"%s\"!\n", player);
|
|
||||||
free(argvs);
|
|
||||||
close(null_fd);
|
|
||||||
exit(6);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This shouldn't run due to exec, but handle it anyway.
|
|
||||||
close(null_fd);
|
|
||||||
exit(0);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (use_internal_file_specified != 0) {
|
|
||||||
close(pipe_filedes[0]);
|
|
||||||
write(pipe_filedes[1],
|
|
||||||
interval_notification_mp3,
|
|
||||||
interval_notification_mp3_len);
|
|
||||||
close(pipe_filedes[1]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Only supports playing with /usr/bin/mpv .
|
|
||||||
int play_jingle_from_memory(void) {
|
|
||||||
int pipe_filedes[2];
|
|
||||||
if (pipe(pipe_filedes) != 0) {
|
|
||||||
puts("ERROR: Failed to play jingle: Failed to create pipe!");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(fork()) {
|
|
||||||
case -1:
|
|
||||||
puts("ERROR: Failed to play jingle: Failed to fork!");
|
|
||||||
return 2;
|
|
||||||
case 0:
|
|
||||||
// Handle pipe into stdin.
|
|
||||||
close(pipe_filedes[1]);
|
|
||||||
dup2(pipe_filedes[0], 0);
|
|
||||||
|
|
||||||
// Pipe output to /dev/null.
|
|
||||||
int null_fd = open("/dev/null", O_WRONLY);
|
|
||||||
if (null_fd == -1) {
|
|
||||||
puts("ERROR: Failed to redirect play-jingle-output to /dev/null!");
|
|
||||||
close(pipe_filedes[0]);
|
|
||||||
exit(3);
|
|
||||||
}
|
|
||||||
dup2(null_fd, 1);
|
|
||||||
dup2(null_fd, 2);
|
|
||||||
|
|
||||||
// Exec.
|
|
||||||
if (execl("/usr/bin/mpv",
|
|
||||||
"/usr/bin/mpv",
|
|
||||||
"--vid=no",
|
|
||||||
"-",
|
|
||||||
(char*)NULL)
|
|
||||||
== -1) {
|
|
||||||
printf("ERROR: Failed to play!\n");
|
|
||||||
close(pipe_filedes[0]);
|
|
||||||
close(null_fd);
|
|
||||||
exit(4);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This shouldn't run due to exec, but handle it anyway.
|
|
||||||
close(pipe_filedes[0]);
|
|
||||||
close(null_fd);
|
|
||||||
exit(0);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
close(pipe_filedes[0]);
|
|
||||||
write(pipe_filedes[1],
|
|
||||||
interval_notification_mp3,
|
|
||||||
interval_notification_mp3_len);
|
|
||||||
close(pipe_filedes[1]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_help(void) {
|
void print_help(void) {
|
||||||
puts("./program [minutes] [file_to_play_on_interval] [player_program] [player_args...]");
|
puts("./program [minutes] [file_to_play_on_interval] [player_program]");
|
||||||
puts(" minutes defaults to 5, file defaults to internal file, program defaults to \"/usr/bin/mpv\".");
|
puts(" minutes defaults to 5, file defaults to internal file, program defaults to \"/usr/bin/mpv\".");
|
||||||
puts("Note that this program uses execl/execv, so if a program is specified, it must be the full path to the program.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
if (argc > 1 && (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "-h") == 0
|
if (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "-h") == 0
|
||||||
|| strcmp(argv[1], "--help") == 0)) {
|
|| strcmp(argv[1], "--help") == 0) {
|
||||||
print_help();
|
print_help();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -188,9 +36,6 @@ int main(int argc, char **argv) {
|
||||||
unsigned int minutes = 5;
|
unsigned int minutes = 5;
|
||||||
char *file_name = NULL;
|
char *file_name = NULL;
|
||||||
char *player_name = NULL;
|
char *player_name = NULL;
|
||||||
char **player_args = NULL;
|
|
||||||
unsigned int args_count = 0;
|
|
||||||
int use_internal_file_specified = 0;
|
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
// Intentionally left blank.
|
// Intentionally left blank.
|
||||||
|
@ -208,12 +53,6 @@ int main(int argc, char **argv) {
|
||||||
minutes = atoi(argv[1]);
|
minutes = atoi(argv[1]);
|
||||||
file_name = argv[2];
|
file_name = argv[2];
|
||||||
player_name = argv[3];
|
player_name = argv[3];
|
||||||
} else if (argc > 4) {
|
|
||||||
minutes = atoi(argv[1]);
|
|
||||||
file_name = argv[2];
|
|
||||||
player_name = argv[3];
|
|
||||||
player_args = argv + 4;
|
|
||||||
args_count = argc - 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minutes == 0) {
|
if (minutes == 0) {
|
||||||
|
@ -227,13 +66,44 @@ int main(int argc, char **argv) {
|
||||||
printf("Using player \"%s\"...\n", player_name);
|
printf("Using player \"%s\"...\n", player_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *play_audio_command;
|
||||||
|
char *temp_filename = NULL;
|
||||||
|
|
||||||
if (file_name) {
|
if (file_name) {
|
||||||
if (strcmp(file_name, "INTERNAL_FILE") == 0) {
|
int len = strlen(file_name) + 1 + 1;
|
||||||
puts("Using internal file...");
|
if (player_name) {
|
||||||
use_internal_file_specified = 1;
|
len += strlen(player_name) + 10;
|
||||||
} else {
|
} else {
|
||||||
printf("Using file \"%s\"...\n", file_name);
|
len += 14;
|
||||||
}
|
}
|
||||||
|
play_audio_command = malloc(len);
|
||||||
|
snprintf(play_audio_command, len, "%s %s",
|
||||||
|
player_name ? player_name : DEFAULT_FILE_PLAYER_PROGRAM, file_name);
|
||||||
|
} else {
|
||||||
|
int len = 5 + 1 + strlen(getenv("USER")) + 7 + 1 + 25 + 10;
|
||||||
|
temp_filename = malloc(len);
|
||||||
|
snprintf(temp_filename, len, "/tmp/%s%07lu_interval_audio_file.mp3",
|
||||||
|
getenv("USER"),
|
||||||
|
random() % 10000000);
|
||||||
|
FILE *fd = fopen(temp_filename, "wb");
|
||||||
|
if (fwrite(interval_notification_mp3, 1, interval_notification_mp3_len, fd)
|
||||||
|
!= interval_notification_mp3_len) {
|
||||||
|
free(temp_filename);
|
||||||
|
fclose(fd);
|
||||||
|
puts("ERROR: Failed to save temporary interval audio file to /tmp/!");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fclose(fd);
|
||||||
|
|
||||||
|
len = strlen(temp_filename) + 1 + 10;
|
||||||
|
if (player_name) {
|
||||||
|
len += strlen(player_name) + 10;
|
||||||
|
} else {
|
||||||
|
len += 14;
|
||||||
|
}
|
||||||
|
play_audio_command = malloc(len);
|
||||||
|
snprintf(play_audio_command, len, "%s %s",
|
||||||
|
player_name ? player_name : DEFAULT_FILE_PLAYER_PROGRAM, temp_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup for loop
|
// Setup for loop
|
||||||
|
@ -243,7 +113,12 @@ int main(int argc, char **argv) {
|
||||||
memset(&action, 0, sizeof(struct sigaction));
|
memset(&action, 0, sizeof(struct sigaction));
|
||||||
action.sa_handler = interval_notification_handle_signal;
|
action.sa_handler = interval_notification_handle_signal;
|
||||||
if(sigaction(SIGINT, &action, NULL) != 0) {
|
if(sigaction(SIGINT, &action, NULL) != 0) {
|
||||||
|
free(play_audio_command);
|
||||||
puts("ERROR: Failed to set handling of SIGINT!");
|
puts("ERROR: Failed to set handling of SIGINT!");
|
||||||
|
if (temp_filename) {
|
||||||
|
unlink(temp_filename);
|
||||||
|
free(temp_filename);
|
||||||
|
}
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,27 +127,22 @@ int main(int argc, char **argv) {
|
||||||
puts("Begin main loop...");
|
puts("Begin main loop...");
|
||||||
while(is_running) {
|
while(is_running) {
|
||||||
sleep(minutes * 60);
|
sleep(minutes * 60);
|
||||||
/* sleep(10);*/
|
/* sleep(4);*/
|
||||||
if (!is_running) {
|
if (!is_running) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (file_name) {
|
ret = system(play_audio_command);
|
||||||
ret = play_jingle_from_file(player_name ?
|
|
||||||
player_name : DEFAULT_FILE_PLAYER_PROGRAM,
|
|
||||||
player_args,
|
|
||||||
args_count,
|
|
||||||
file_name,
|
|
||||||
use_internal_file_specified);
|
|
||||||
} else {
|
|
||||||
ret = play_jingle_from_memory();
|
|
||||||
}
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
printf("ERROR: Failed to play jingle! (returned \"%i\")\n", ret);
|
printf("ERROR: Executing \"%s\" failed! (returned \"%i\")\n", play_audio_command, ret);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf(".");
|
printf(".");
|
||||||
fflush(stdout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(play_audio_command);
|
||||||
|
if (temp_filename) {
|
||||||
|
unlink(temp_filename);
|
||||||
|
free(temp_filename);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue