From 3f3220cdce5c96181fef40985a373af69ae73852 Mon Sep 17 00:00:00 2001 From: poslop Date: Tue, 19 May 2026 12:04:00 -0500 Subject: [PATCH] script and new cron method --- install.sh | 26 ++++++++++++++++++++++++++ pc-script.cron | 8 ++++++++ readme.md | 30 +++++++++++------------------- 3 files changed, 45 insertions(+), 19 deletions(-) create mode 100755 install.sh create mode 100644 pc-script.cron diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..7137d1f --- /dev/null +++ b/install.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -e + +RED='\e[31m' +GREEN='\e[32m' +YELLOW='\e[33m' +RESET='\e[0m' + +# root check +if [[ $EUID -ne 0 ]]; then + echo -e "${RED}You must be root to do this." 1>&2 + exit 100 +fi + +git pull + +cp ./pc-script.cron /etc/cron.d/pc-script +chmod 644 /etc/cron.d/pc-script + +touch /var/log/directory.log /var/log/sidecar.log +chown asterisk:asterisk /var/log/directory.log /var/log/sidecar.log + +mkdir /var/lib/asterisk/PC-Contact-Sync +cp ./sidecar.php ./directory.php ./example-config.json /var/lib/asterisk/PC-Contact-Sync + +chown asterisk:asterisk /var/lib/asterisk/PC-Contact-Sync -R diff --git a/pc-script.cron b/pc-script.cron new file mode 100644 index 0000000..9a29d83 --- /dev/null +++ b/pc-script.cron @@ -0,0 +1,8 @@ +DIR=/var/lib/asterisk/PC-Contact-Sync + +# Run Polycom directory sync every 4 hours at :00 +0 */4 * * * asterisk cd $DIR && /usr/bin/php /var/lib/asterisk/PC-Contact-Sync/directory.php --notify >> /var/log/directory.log 2>&1 + +# Run PC sidecar sync every 4 hours at :05 (5 mins after) +5 */4 * * * asterisk $DIR && /usr/bin/php /var/lib/asterisk/PC-Contact-Sync/sidecar.php >> /var/log/sidecar.log 2>&1 + diff --git a/readme.md b/readme.md index 45a315f..76a4c73 100644 --- a/readme.md +++ b/readme.md @@ -1,11 +1,21 @@ ## Gen PC Sidecar Script -The files are stored typically inside of `/var/lib/asterisk/PC-Contact-Sync` and the scripts should be run every 6 hours by a cron job. +The files are stored typically inside of `/var/lib/asterisk/PC-Contact-Sync` and the scripts should be run every 6 hours or so by a cron job. Make sure that all files are owned by asterisk user including the output files and the cronjob.
## Quickstart +#### Install +Download this repo +``` +git clone https://git.archfox.org/poslop/PC-Contact-Sync +``` +Run the install script as Root +``` +./install.sh +``` + #### Config Fields `config.json` has several fields. The config file needs to be next to the script in order to be read. @@ -34,24 +44,6 @@ prepend_extensions 5. Add extra contacts you want added to the phones in `prepend_extensions`.
-#### Cronjob Example -Create the cronjob as asterisk user. - -``` -EDITOR=vim crontab -e -u asterisk -``` - -Append this to the crontab - -``` -# Run Polycom directory sync every 4 hours at :00 -0 */4 * * * /usr/bin/php /var/lib/asterisk/PC-Contact-Sync/directory.php --notify >> /var/log/directory.log 2>&1 - -# Run PC sidecar sync every 4 hours at :05 (5 mins after) -5 */4 * * * /usr/bin/php /var/lib/asterisk/PC-Contact-Sync/sidecar.php >> /var/log/sidecar.log 2>&1 -``` -
- ## Process Walkthrough #### 1. Pull Contact List