generated from pavel.muhortov/template-bash
simple code refactoring
This commit is contained in:
parent
a241aa5977
commit
d470736839
64
README.md
64
README.md
|
@ -1,18 +1,26 @@
|
||||||
# cctv-scheduler
|
# cctv-scheduler
|
||||||
|
|
||||||
PTZ IP-Camera management
|
PTZ IP-Camera management
|
||||||
|
|
||||||
![cctv-scheduler](info/images/cctv-scheduler-0.1.png)
|
![cctv-scheduler](info/images/cctv-scheduler-0.1.png)
|
||||||
|
|
||||||
## `Installation`
|
## `Installation`
|
||||||
|
|
||||||
### `Requirements`
|
### `Requirements`
|
||||||
|
|
||||||
Cameras settings:
|
Cameras settings:
|
||||||
|
>
|
||||||
> - Configuration -> System -> Security -> Authentication -> RTSP Authentication: digest/basic
|
> - Configuration -> System -> Security -> Authentication -> RTSP Authentication: digest/basic
|
||||||
> - Configuration -> System -> Security -> Authentication -> WEB Authentication: digest/basic
|
> - Configuration -> System -> Security -> Authentication -> WEB Authentication: digest/basic
|
||||||
> - Configuration -> Network -> Advanced Settings -> Integration Protocol -> Enable Hikvision-CGI: Enabled
|
> - Configuration -> Network -> Advanced Settings -> Integration Protocol -> Enable Hikvision-CGI: Enabled
|
||||||
> - Configuration -> Network -> Advanced Settings -> Integration Protocol -> Hikvision-CGI Authentication: digest/basic
|
> - Configuration -> Network -> Advanced Settings -> Integration Protocol -> Hikvision-CGI Authentication: digest/basic
|
||||||
|
|
||||||
Look at the description of dependencies and install the necessary.
|
Look at the description of dependencies and install the necessary.
|
||||||
|
|
||||||
### `Downloading`
|
### `Downloading`
|
||||||
|
|
||||||
Download scripts and configs.
|
Download scripts and configs.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/sequences.sh -O /home/user/cctv-scheduler/sequences.sh
|
wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/sequences.sh -O /home/user/cctv-scheduler/sequences.sh
|
||||||
wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/sequences.conf -O /home/user/cctv-scheduler/sequences.conf
|
wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/sequences.conf -O /home/user/cctv-scheduler/sequences.conf
|
||||||
|
@ -23,66 +31,84 @@ wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/publi
|
||||||
wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/publisher-template-page-1007.xml -O /home/user/cctv-scheduler/publisher-template-page-1007.xml
|
wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/publisher-template-page-1007.xml -O /home/user/cctv-scheduler/publisher-template-page-1007.xml
|
||||||
wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/streaming.py -O /home/user/cctv-scheduler/streaming.py
|
wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/streaming.py -O /home/user/cctv-scheduler/streaming.py
|
||||||
```
|
```
|
||||||
|
|
||||||
### `Configuration`
|
### `Configuration`
|
||||||
|
|
||||||
Edit configs.
|
Edit configs.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
nano /home/user/cctv-scheduler/sequences.conf
|
nano /home/user/cctv-scheduler/sequences.conf
|
||||||
nano /home/user/cctv-scheduler/converter.conf
|
nano /home/user/cctv-scheduler/converter.conf
|
||||||
nano /home/user/cctv-scheduler/publisher.conf
|
nano /home/user/cctv-scheduler/publisher.conf
|
||||||
```
|
```
|
||||||
|
|
||||||
### `Scheduler`
|
### `Scheduler`
|
||||||
|
|
||||||
Look at examples and edit scheduler tasks:
|
Look at examples and edit scheduler tasks:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
crontab -e
|
crontab -e
|
||||||
```
|
```
|
||||||
____
|
|
||||||
* [`sequences.sh`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#sequences-sh)
|
|
||||||
* [`converter.sh`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#converter-sh)
|
|
||||||
* [`publisher.sh`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#publisher-sh)
|
|
||||||
* [`streaming.py`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#streaming-py)
|
|
||||||
|
|
||||||
____
|
____
|
||||||
|
|
||||||
|
- [`sequences.sh`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#sequences-sh)
|
||||||
|
- [`converter.sh`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#converter-sh)
|
||||||
|
- [`publisher.sh`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#publisher-sh)
|
||||||
|
- [`streaming.py`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#streaming-py)
|
||||||
|
|
||||||
|
____
|
||||||
|
|
||||||
## `sequences`.sh
|
## `sequences`.sh
|
||||||
|
|
||||||
**Description:**
|
**Description:**
|
||||||
> [Hikvision](https://git.hmp.today/pavel.muhortov/cctv-scheduler/src/branch/master/info/hikvision/manual/isapi.pdf) PTZ-camera sequences.
|
> [Hikvision](https://git.hmp.today/pavel.muhortov/cctv-scheduler/src/branch/master/info/hikvision/manual/isapi.pdf) PTZ-camera sequences.
|
||||||
> Additionally:
|
> Additionally:
|
||||||
|
>
|
||||||
> - getting temperature from DS18B20 over SSH,
|
> - getting temperature from DS18B20 over SSH,
|
||||||
> - saving pictures to FTP.
|
> - saving pictures to FTP.
|
||||||
>
|
>
|
||||||
> This is only a local "proof of conept" for testing and debugging.
|
> This is only a local "proof of conept" for testing and debugging.
|
||||||
|
|
||||||
**Dependencies:**
|
**Dependencies:**
|
||||||
|
>
|
||||||
> - [bash](https://www.gnu.org/software/bash/) (tested version 5.1.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
> - [bash](https://www.gnu.org/software/bash/) (tested version 5.1.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
||||||
> - [curl](https://curl.se/download.html) (tested version 7.74 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
> - [curl](https://curl.se/download.html) (tested version 7.74 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
||||||
> - [sshpass](https://www.cyberciti.biz/faq/noninteractive-shell-script-ssh-password-provider/) (tested version 1.09 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
> - [sshpass](https://www.cyberciti.biz/faq/noninteractive-shell-script-ssh-password-provider/) (tested version 1.09 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
||||||
|
|
||||||
|
|
||||||
| POSITION | PARAMETERS | DESCRIPTION | DEFAULT |
|
| POSITION | PARAMETERS | DESCRIPTION | DEFAULT |
|
||||||
|-----------|--------------|------------------------|---------------|
|
|-----------|--------------|------------------------|---------------|
|
||||||
| 1 | **[qn]** |execution without pauses||
|
| 1 | **[qn]** |execution without pauses||
|
||||||
| 2 | **[/path/to/conf]** |path to config| ./sequences.conf |
|
| 2 | **[/path/to/conf]** |path to config| ./sequences.conf |
|
||||||
|
|
||||||
|
|
||||||
Example usage in terminal with bash:
|
Example usage in terminal with bash:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bash ./sequences.sh - ./sequences.conf
|
bash ./sequences.sh - ./sequences.conf
|
||||||
```
|
```
|
||||||
|
|
||||||
Example usage with cron:
|
Example usage with cron:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# crontab -e
|
# crontab -e
|
||||||
0 * * * * bash /home/user/cctv-scheduler/sequences.sh qn
|
0 * * * * bash /home/user/cctv-scheduler/sequences.sh qn
|
||||||
```
|
```
|
||||||
|
|
||||||
____
|
____
|
||||||
|
|
||||||
## `converter`.sh
|
## `converter`.sh
|
||||||
|
|
||||||
**Description:**
|
**Description:**
|
||||||
> JPEG to MP4 converter.
|
> JPEG to MP4 converter.
|
||||||
>
|
>
|
||||||
> This is only a local "proof of conept" for testing and debugging.
|
> This is only a local "proof of conept" for testing and debugging.
|
||||||
|
|
||||||
**Dependencies:**
|
**Dependencies:**
|
||||||
|
>
|
||||||
> - [bash](https://www.gnu.org/software/bash/) (tested version 5.1.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
> - [bash](https://www.gnu.org/software/bash/) (tested version 5.1.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
||||||
> - [ffmpeg](https://ffmpeg.org/download.html) (tested version 4.3.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
> - [ffmpeg](https://ffmpeg.org/download.html) (tested version 4.3.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
||||||
> - filesystem organization:
|
> - filesystem organization:
|
||||||
|
>
|
||||||
>```bash
|
>```bash
|
||||||
> # filesystem organisation example
|
> # filesystem organisation example
|
||||||
>/root/
|
>/root/
|
||||||
|
@ -109,12 +135,14 @@ ____
|
||||||
| 2 | **[/path/to/conf]** |path to config| ./converter.conf |
|
| 2 | **[/path/to/conf]** |path to config| ./converter.conf |
|
||||||
| 3 | **[-d\|-w\|-m\|-y]** |periods: '' - today \| '-d' - yesterday \| '-w' - last week \| '-m' - last month \| '-y' - last year||
|
| 3 | **[-d\|-w\|-m\|-y]** |periods: '' - today \| '-d' - yesterday \| '-w' - last week \| '-m' - last month \| '-y' - last year||
|
||||||
|
|
||||||
|
|
||||||
Example usage in terminal with bash for today's MP4 making:
|
Example usage in terminal with bash for today's MP4 making:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bash ./converter.sh - ./converter.conf
|
bash ./converter.sh - ./converter.conf
|
||||||
```
|
```
|
||||||
|
|
||||||
Example usage with cron:
|
Example usage with cron:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# crontab -e
|
# crontab -e
|
||||||
1 0 * * * bash /home/user/cctv-scheduler/converter.sh qn - -d
|
1 0 * * * bash /home/user/cctv-scheduler/converter.sh qn - -d
|
||||||
|
@ -122,17 +150,22 @@ Example usage with cron:
|
||||||
30 0 1 * * bash /home/user/cctv-scheduler/converter.sh qn - -m
|
30 0 1 * * bash /home/user/cctv-scheduler/converter.sh qn - -m
|
||||||
36 0 1 1 * bash /home/user/cctv-scheduler/converter.sh qn - -y
|
36 0 1 1 * bash /home/user/cctv-scheduler/converter.sh qn - -y
|
||||||
```
|
```
|
||||||
|
|
||||||
____
|
____
|
||||||
|
|
||||||
## `publisher`.sh
|
## `publisher`.sh
|
||||||
|
|
||||||
**Description:**
|
**Description:**
|
||||||
> Uploading MP4 to [Wordpress](https://wordpress.com/) and [Telegram](https://web.telegram.org/).
|
> Uploading MP4 to [Wordpress](https://wordpress.com/) and [Telegram](https://web.telegram.org/).
|
||||||
> Additionally:
|
> Additionally:
|
||||||
|
>
|
||||||
> - editing [Wordpress](https://codex.wordpress.org/XML-RPC_WordPress_API) page from template
|
> - editing [Wordpress](https://codex.wordpress.org/XML-RPC_WordPress_API) page from template
|
||||||
> - recompressing video if size [over 50MB](https://core.telegram.org/bots/api#sendvideo)
|
> - recompressing video if size [over 50MB](https://core.telegram.org/bots/api#sendvideo)
|
||||||
>
|
>
|
||||||
> This is only a local "proof of conept" for testing and debugging.
|
> This is only a local "proof of conept" for testing and debugging.
|
||||||
|
|
||||||
**Dependencies:**
|
**Dependencies:**
|
||||||
|
>
|
||||||
> - [bash](https://www.gnu.org/software/bash/) (tested version 5.1.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
> - [bash](https://www.gnu.org/software/bash/) (tested version 5.1.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
||||||
> - [curl](https://curl.se/download.html) (tested version 7.74 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
> - [curl](https://curl.se/download.html) (tested version 7.74 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
||||||
> - [ffmpeg](https://ffmpeg.org/download.html) (tested version 4.3.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
> - [ffmpeg](https://ffmpeg.org/download.html) (tested version 4.3.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
||||||
|
@ -148,12 +181,14 @@ ____
|
||||||
| 4 | **[1\|2\|3..XXX]** |multiplier for period: '' - 1 day\|week\|month\|year|1|
|
| 4 | **[1\|2\|3..XXX]** |multiplier for period: '' - 1 day\|week\|month\|year|1|
|
||||||
| 5 | **[--onlytg\|--onlywp]** |'--onlytg' - only publish to Telegram \|'--onlywp' - only publish to Wordpress||
|
| 5 | **[--onlytg\|--onlywp]** |'--onlytg' - only publish to Telegram \|'--onlywp' - only publish to Wordpress||
|
||||||
|
|
||||||
|
Example usage in terminal with bash for publish to Telegram today's MP4:
|
||||||
|
|
||||||
Example usage in terminal with bash for publish today's MP4 maked:
|
|
||||||
```bash
|
```bash
|
||||||
bash ./publisher.sh - ./publisher.conf - --onlytg
|
bash ./publisher.sh - ./publisher.conf - - - - --onlytg
|
||||||
```
|
```
|
||||||
|
|
||||||
Example usage with cron:
|
Example usage with cron:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# crontab -e
|
# crontab -e
|
||||||
1 1 * * * bash /home/user/cctv-scheduler/publisher.sh qn - -d
|
1 1 * * * bash /home/user/cctv-scheduler/publisher.sh qn - -d
|
||||||
|
@ -161,12 +196,16 @@ Example usage with cron:
|
||||||
30 1 1 * * bash /home/user/cctv-scheduler/publisher.sh qn - -m
|
30 1 1 * * bash /home/user/cctv-scheduler/publisher.sh qn - -m
|
||||||
36 1 1 1 * bash /home/user/cctv-scheduler/publisher.sh qn - -y
|
36 1 1 1 * bash /home/user/cctv-scheduler/publisher.sh qn - -y
|
||||||
```
|
```
|
||||||
|
|
||||||
____
|
____
|
||||||
|
|
||||||
## `streaming`.py
|
## `streaming`.py
|
||||||
|
|
||||||
**Description:**
|
**Description:**
|
||||||
> FFmpeg management from Python
|
> FFmpeg management from Python
|
||||||
|
|
||||||
**Dependencies:**
|
**Dependencies:**
|
||||||
|
>
|
||||||
> - [Python 3](https://www.python.org/downloads/) (tested version 3.9.5 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
> - [Python 3](https://www.python.org/downloads/) (tested version 3.9.5 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
||||||
> - [ffmpeg](https://ffmpeg.org/download.html) (tested version 4.3.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
> - [ffmpeg](https://ffmpeg.org/download.html) (tested version 4.3.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
||||||
|
|
||||||
|
@ -183,17 +222,22 @@ ____
|
||||||
|**[--mono]**|detect ffmpeg running copy and terminate||
|
|**[--mono]**|detect ffmpeg running copy and terminate||
|
||||||
|
|
||||||
Example usage in terminal with make the script executable:
|
Example usage in terminal with make the script executable:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
chmod u+x ./streaming.py
|
chmod u+x ./streaming.py
|
||||||
./streaming.py -s rtsp://user:pass@host:554/Streaming/Channels/101 --dst rtp://239.0.0.1:5554
|
./streaming.py -s rtsp://user:pass@host:554/Streaming/Channels/101 --dst rtp://239.0.0.1:5554
|
||||||
```
|
```
|
||||||
|
|
||||||
Example usage with cron:
|
Example usage with cron:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# crontab -e
|
# crontab -e
|
||||||
* * * * * /usr/bin/python3 /home/user/cctv-scheduler/streaming.py -s rtsp://user:pass@host:554/Streaming/Channels/video,http://Streaming/Channels/audio --dst rtmp://a.rtmp.youtube.com/live2/YOUKEY --mono --watchdog --sec 30 >> /dev/null 2>&1
|
* * * * * /usr/bin/python3 /home/user/cctv-scheduler/streaming.py -s rtsp://user:pass@host:554/Streaming/Channels/video,http://Streaming/Channels/audio --dst rtmp://a.rtmp.youtube.com/live2/YOUKEY --mono --watchdog --sec 30 >> /dev/null 2>&1
|
||||||
* * * * * /usr/bin/python3 /home/user/cctv-scheduler/streaming.py -s ~/media.mp4 --dst rtmp://b.rtmp.youtube.com/live2?backup=1/YOUKEY --mono >> /dev/null 2>&1
|
* * * * * /usr/bin/python3 /home/user/cctv-scheduler/streaming.py -s ~/media.mp4 --dst rtmp://b.rtmp.youtube.com/live2?backup=1/YOUKEY --mono >> /dev/null 2>&1
|
||||||
```
|
```
|
||||||
|
|
||||||
Example usage in Python:
|
Example usage in Python:
|
||||||
|
|
||||||
```Python
|
```Python
|
||||||
from streaming import FFmpeg
|
from streaming import FFmpeg
|
||||||
|
|
||||||
|
|
181
converter.sh
181
converter.sh
|
@ -1,69 +1,113 @@
|
||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
#
|
# DESCRIPTION:
|
||||||
## DESCRIPTION:
|
# Converting JPEG collection to MP4.
|
||||||
# JPEG to MP4 converter.
|
|
||||||
# This is only a local "proof of conept" for testing and debugging.
|
# This is only a local "proof of conept" for testing and debugging.
|
||||||
#
|
#
|
||||||
|
# DEPENDENCIES:
|
||||||
|
# - ffmpeg
|
||||||
#
|
#
|
||||||
## DEPENDENCIES: sudo apt|yum install -y ffmpeg
|
# PARAMETERS:
|
||||||
#
|
# 1: "qn" - execution without pauses
|
||||||
|
# 2: custom configuration file path
|
||||||
#
|
# 3: periods: '' - today | '-d' - yesterday | '-w' - last week | '-m' - last month | '-y' - last year
|
||||||
## FUNCTIONS
|
#
|
||||||
|
# FUNCTIONS:
|
||||||
#
|
#
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Print message and add to log.
|
||||||
|
# Globals:
|
||||||
|
# logs
|
||||||
|
# Arguments:
|
||||||
|
# 1: message to print and logging
|
||||||
|
#######################################
|
||||||
addtologs() {
|
addtologs() {
|
||||||
echo "$(date +'%Y.%m.%d-%H:%M:%S') $1" | tee -a $logs
|
echo "$(date +'%Y.%m.%d-%H:%M:%S') $1" | tee -a "${logs}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Waiting for press [ENTER].
|
||||||
|
# Globals:
|
||||||
|
# None
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
execpause() {
|
execpause() {
|
||||||
read -p "Press [ENTER] to continue... "
|
read -r -p "Press [ENTER] to continue... "
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Exit procedure.
|
||||||
|
# Globals:
|
||||||
|
# show
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
execquite() {
|
execquite() {
|
||||||
addtologs "execution time is $(($(date +%s)-$time)) seconds, exit"
|
addtologs "execution time is $(($(date +%s)-time)) seconds, exit"
|
||||||
if [ "${show}" != "qn" ];then
|
if [ "${show}" != "qn" ]; then
|
||||||
execpause
|
execpause
|
||||||
fi
|
fi
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Error exit procedure with Telegram notification.
|
||||||
|
# Globals:
|
||||||
|
# telegramapiurl
|
||||||
|
# telegramchatid
|
||||||
|
# Arguments:
|
||||||
|
# 1: message to print and logging
|
||||||
|
#######################################
|
||||||
execerror() {
|
execerror() {
|
||||||
addtologs "error: $1"
|
addtologs "error: $1"
|
||||||
curl -s -X POST $telegramapiurl/sendMessage -d chat_id=$telegramchatid -d text="$(basename -s .sh $0) error: $1" >> /dev/null 2>&1
|
curl -s -X POST "${telegramapiurl}/sendMessage" \
|
||||||
|
-d "chat_id=${telegramchatid}" \
|
||||||
|
-d "text=$(basename -s .sh "$0") error: $1" \
|
||||||
|
>> /dev/null 2>&1
|
||||||
execquite
|
execquite
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Parsing config file and creating global vars.
|
||||||
|
# Globals:
|
||||||
|
# None
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
getconfig() {
|
getconfig() {
|
||||||
logs=$(cat $conf | grep "logs=" | cut -d= -f2)
|
logs=$(grep "logs=" "${conf}" | cut -d= -f2)
|
||||||
list=$(cat $conf | grep "list=" | cut -d= -f2)
|
list=$(grep "list=" "${conf}" | cut -d= -f2)
|
||||||
imgroot=$(cat $conf | grep "imgroot=" | cut -d= -f2)
|
imgroot=$(grep "imgroot=" "${conf}" | cut -d= -f2)
|
||||||
imgnames=($(cat $conf | grep "imgnames=" | cut -d= -f2))
|
IFS=" " read -r -a imgnames <<< "$(grep "imgnames=" "${conf}" | cut -d= -f2)"
|
||||||
xscale=$(cat $conf | grep "xscale=" | cut -d= -f2)
|
xscale=$(grep "xscale=" "${conf}" | cut -d= -f2)
|
||||||
yscale=$(cat $conf | grep "yscale=" | cut -d= -f2)
|
yscale=$(grep "yscale=" "${conf}" | cut -d= -f2)
|
||||||
mp4fps=$(cat $conf | grep "mp4fps=" | cut -d= -f2)
|
mp4fps=$(grep "mp4fps=" "${conf}" | cut -d= -f2)
|
||||||
telegramapiurl=$(cat $conf | grep "telegramapiurl=" | cut -d= -f2)
|
telegramapiurl=$(grep "telegramapiurl=" "${conf}" | cut -d= -f2)
|
||||||
telegramchatid=$(cat $conf | grep "telegramchatid=" | cut -d= -f2)
|
telegramchatid=$(grep "telegramchatid=" "${conf}" | cut -d= -f2)
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
## PARAMETERS
|
## VARIABLES:
|
||||||
#
|
#
|
||||||
|
|
||||||
show=${1}
|
show=$1
|
||||||
conf=${2}
|
conf=$2
|
||||||
if [ -z "${conf}" ] || [ "${conf}" == "-" ];then
|
if [ -z "${conf}" ] || [ "${conf}" == "-" ]; then
|
||||||
conf="$(dirname $(realpath "$0"))/$(basename -s .sh $0).conf"
|
conf="$(dirname "$(realpath "$0")")/$(basename -s .sh "$0").conf"
|
||||||
fi
|
fi
|
||||||
when=${3}
|
when=$3
|
||||||
if [ -z "$when" ]; then
|
if [ -z "${when}" ]; then
|
||||||
d=$(date +"%d")
|
d=$(date +"%d")
|
||||||
w=$(date +"%V")
|
w=$(date +"%V")
|
||||||
m=$(date +"%m")
|
m=$(date +"%m")
|
||||||
y=$(date +"%Y")
|
y=$(date +"%Y")
|
||||||
duration=1
|
duration=1
|
||||||
imgpath=$y/$m/$w/$d
|
imgpath="${y}/${m}/${w}/${d}"
|
||||||
imgname=$y.$m.$d
|
imgname="${y}.${m}.${d}"
|
||||||
fi
|
fi
|
||||||
if [ "$when" == "-d" ]; then
|
if [ "${when}" == "-d" ]; then
|
||||||
d=$(date -d "-1 day" +"%d")
|
d=$(date -d "-1 day" +"%d")
|
||||||
m=$(date +"%m")
|
m=$(date +"%m")
|
||||||
if [ "$(date -d '-1 day' +'%m')" != "$(date +'%m')" ]; then
|
if [ "$(date -d '-1 day' +'%m')" != "$(date +'%m')" ]; then
|
||||||
|
@ -78,10 +122,10 @@ if [ "$when" == "-d" ]; then
|
||||||
w=$(date -d "-1 week" +"%V")
|
w=$(date -d "-1 week" +"%V")
|
||||||
fi
|
fi
|
||||||
duration=1
|
duration=1
|
||||||
imgpath=$y/$m/$w/$d
|
imgpath="${y}/${m}/${w}/${d}"
|
||||||
imgname=$y.$m.$d
|
imgname="${y}.${m}.${d}"
|
||||||
fi
|
fi
|
||||||
if [ "$when" == "-w" ]; then
|
if [ "${when}" == "-w" ]; then
|
||||||
w=$(date -d "-1 week" +"%V")
|
w=$(date -d "-1 week" +"%V")
|
||||||
m=$(date +"%m")
|
m=$(date +"%m")
|
||||||
if [ "$(date -d '-1 week' +'%m')" != "$(date +'%m')" ]; then
|
if [ "$(date -d '-1 week' +'%m')" != "$(date +'%m')" ]; then
|
||||||
|
@ -92,74 +136,73 @@ if [ "$when" == "-w" ]; then
|
||||||
y=$(date -d '-1 week' +'%Y')
|
y=$(date -d '-1 week' +'%Y')
|
||||||
fi
|
fi
|
||||||
duration=7
|
duration=7
|
||||||
imgpath=$y/*/$w
|
imgpath="${y}/*/${w}"
|
||||||
imgname=$y-w$w
|
imgname="${y}-w${w}"
|
||||||
fi
|
fi
|
||||||
if [ "$when" == "-m" ]; then
|
if [ "${when}" == "-m" ]; then
|
||||||
m=$(date -d "-1 month" +"%m")
|
m=$(date -d "-1 month" +"%m")
|
||||||
y=$(date +"%Y")
|
y=$(date +"%Y")
|
||||||
if [ "$(date -d '-1 month' +'%Y')" != "$(date +'%Y')" ]; then
|
if [ "$(date -d '-1 month' +'%Y')" != "$(date +'%Y')" ]; then
|
||||||
y=$(date -d '-1 month' +'%Y')
|
y=$(date -d '-1 month' +'%Y')
|
||||||
fi
|
fi
|
||||||
duration=30
|
duration=30
|
||||||
imgpath=$y/$m
|
imgpath="${y}/${m}"
|
||||||
imgname=$y.$m
|
imgname="${y}.${m}"
|
||||||
fi
|
fi
|
||||||
if [ "$when" == "-y" ]; then
|
if [ "${when}" == "-y" ]; then
|
||||||
y=$(date -d "-1 year" +"%Y")
|
y=$(date -d "-1 year" +"%Y")
|
||||||
duration=360
|
duration=360
|
||||||
imgpath=$y
|
imgpath="${y}"
|
||||||
imgname=$y
|
imgname="${y}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
|
||||||
## VARIABLES
|
|
||||||
#
|
|
||||||
|
|
||||||
time=$(date +%s)
|
time=$(date +%s)
|
||||||
cd "$(dirname "$(realpath "$0")")"
|
cd "$(dirname "$(realpath "$0")")" || execerror
|
||||||
if [ ! -e ${conf} ];then
|
if [ ! -e "${conf}" ]; then
|
||||||
execerror "Not found config file: ${conf}"
|
execerror "Not found config file: ${conf}"
|
||||||
else
|
else
|
||||||
getconfig
|
getconfig
|
||||||
fi
|
fi
|
||||||
if [ -z "${logs}" ];then
|
if [ -z "${logs}" ];then
|
||||||
logs=/dev/null
|
logs=/dev/null
|
||||||
elif [ ! -e ${logs} ];then
|
elif [ ! -e "${logs}" ];then
|
||||||
touch ${logs}
|
touch "${logs}"
|
||||||
fi
|
fi
|
||||||
if [ -z "${list}" ];then
|
if [ -z "${list}" ];then
|
||||||
list="$(dirname $(realpath "$0"))/$(basename -s .sh $0).list"
|
list="$(dirname "$(realpath "$0")")/$(basename -s .sh "$0").list"
|
||||||
fi
|
fi
|
||||||
if [ ! -e ${list} ];then
|
if [ ! -e "${list}" ];then
|
||||||
touch ${list}
|
touch "${list}"
|
||||||
fi
|
fi
|
||||||
if ! command -v ffmpeg &> /dev/null; then
|
if ! command -v ffmpeg &> /dev/null; then
|
||||||
execerror "Not found dependencies"
|
execerror "Not found dependencies"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
## RUN
|
# MAIN:
|
||||||
#
|
#
|
||||||
|
|
||||||
for name in ${imgnames[*]}; do
|
for name in "${imgnames[@]}"; do
|
||||||
imgmatch="*$name*.jpeg"
|
imgmatch="*${name}*.jpeg"
|
||||||
imgarray=()
|
imgarray=()
|
||||||
while read FILE; do
|
while read -r FILE; do
|
||||||
imgarray+=("${FILE}")
|
imgarray+=("${FILE}")
|
||||||
done < <(find $imgroot/$imgpath -name "$imgmatch" | sort)
|
done < <(find "${imgroot}/${imgpath}" -name "${imgmatch}" | sort)
|
||||||
imgcount=${#imgarray[*]}
|
imgcount=${#imgarray[*]}
|
||||||
|
|
||||||
echo '' > $list
|
echo '' > "${list}"
|
||||||
for item in ${imgarray[*]}; do
|
for item in "${imgarray[@]}"; do
|
||||||
echo file \'$item\' >> $list
|
echo file \'"${item}"\' >> "${list}"
|
||||||
done
|
done
|
||||||
|
|
||||||
imgdest=$imgroot/$name\_$imgname.mp4
|
imgdest="${imgroot}/${name}_${imgname}.mp4"
|
||||||
echo $imgdest
|
echo "${imgdest}"
|
||||||
#ffmpeg -r $imgcount/$duration -f concat -safe 0 -i $list -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -t $duration -c:v libx264 -vf "scale=$xscale:$yscale,fps=$mp4fps,format=yuv420p" -c:a aac $imgdest -y
|
if ffmpeg -r "${imgcount}/${duration}" -f concat -safe 0 -i "${list}" \
|
||||||
ffmpeg -r $imgcount/$duration -f concat -safe 0 -i $list -c:v libx264 -vf "scale=$xscale:$yscale,fps=$mp4fps,format=yuv420p" $imgdest -y \
|
-c:v libx264 -vf "scale=${xscale}:${yscale},fps=${mp4fps},format=yuv420p" \
|
||||||
&& addtologs "converted $imgcount images to $imgdest with duration $duration" \
|
"${imgdest}" -y; then
|
||||||
|| execerror "converted $imgcount images to $imgdest with duration $duration"
|
addtologs "converted ${imgcount} images to ${imgdest} with duration ${duration}"
|
||||||
|
else
|
||||||
|
execerror "converted ${imgcount} images to ${imgdest} with duration ${duration}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
execquite
|
execquite
|
||||||
|
|
638
publisher.sh
638
publisher.sh
|
@ -1,375 +1,431 @@
|
||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
#
|
# DESCRIPTION:
|
||||||
## DESCRIPTION:
|
|
||||||
# Uploading MP4 to Wordpress and Telegram.
|
# Uploading MP4 to Wordpress and Telegram.
|
||||||
# Additionally:
|
# Additionally:
|
||||||
# - editing Wordpress page from template
|
# - editing Wordpress page from template
|
||||||
# - recompressing video if size over 50MB
|
# - recompressing video if size over 50MB
|
||||||
# This is only a local "proof of conept" for testing and debugging.
|
# This is only a local "proof of conept" for testing and debugging.
|
||||||
#
|
#
|
||||||
|
# DEPENDENCIES:
|
||||||
|
# - curl
|
||||||
|
# - ffmpeg
|
||||||
|
# - libxml2-utils
|
||||||
|
# - jq
|
||||||
#
|
#
|
||||||
## DEPENDENCIES: sudo apt|yum install -y curl ffmpeg libxml2-utils jq
|
# PARAMETERS:
|
||||||
#
|
# 1: "qn" - execution without pauses
|
||||||
|
# 2: custom configuration file path
|
||||||
#
|
# 3: periods: '' - today | '-d' - yesterday | '-w' - last week | '-m' - last month | '-y' - last year
|
||||||
## FUNCTIONS
|
# 4: period multiplier: '' - 1 day|week|month|year
|
||||||
|
# 5: publishing '--onlytg' - only to Telegram | '--onlywp' - only to Wordpress
|
||||||
|
#
|
||||||
|
# FUNCTIONS:
|
||||||
#
|
#
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Print message and add to log.
|
||||||
|
# Globals:
|
||||||
|
# logs
|
||||||
|
# Arguments:
|
||||||
|
# 1: message to print and logging
|
||||||
|
#######################################
|
||||||
addtologs() {
|
addtologs() {
|
||||||
echo "$(date +'%Y.%m.%d-%H:%M:%S') $1" | tee -a $logs
|
echo "$(date +'%Y.%m.%d-%H:%M:%S') $1" | tee -a "${logs}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Waiting for press [ENTER].
|
||||||
|
# Globals:
|
||||||
|
# None
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
execpause() {
|
execpause() {
|
||||||
read -p "Press [ENTER] to continue... "
|
read -r -p "Press [ENTER] to continue... "
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Exit procedure.
|
||||||
|
# Globals:
|
||||||
|
# show
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
execquite() {
|
execquite() {
|
||||||
addtologs "execution time is $(($(date +%s)-$time)) seconds, exit"
|
addtologs "execution time is $(($(date +%s)-time)) seconds, exit"
|
||||||
if [ "${show}" != "qn" ];then
|
if [ "${show}" != "qn" ]; then
|
||||||
execpause
|
execpause
|
||||||
fi
|
fi
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Error exit procedure with Telegram notification.
|
||||||
|
# Globals:
|
||||||
|
# telegramapiurl
|
||||||
|
# telegramchatid
|
||||||
|
# Arguments:
|
||||||
|
# 1: message to print and logging
|
||||||
|
#######################################
|
||||||
execerror() {
|
execerror() {
|
||||||
addtologs "error: $1"
|
addtologs "error: $1"
|
||||||
curl -s -X POST $telegramapiurl/sendMessage -d chat_id=$telegramchatid -d text="$(basename -s .sh $0) error: $1" >> /dev/null 2>&1
|
curl -s -X POST "${telegramapiurl}/sendMessage" \
|
||||||
|
-d "chat_id=${telegramchatid}" \
|
||||||
|
-d "text=$(basename -s .sh "$0") error: $1" \
|
||||||
|
>> /dev/null 2>&1
|
||||||
execquite
|
execquite
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Parsing config file and creating global vars.
|
||||||
|
# Globals:
|
||||||
|
# None
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
getconfig() {
|
getconfig() {
|
||||||
logs=$(cat $conf | grep "logs=" | cut -d= -f2)
|
logs=$(grep "logs=" "${conf}" | cut -d= -f2)
|
||||||
pathroot=$(cat $conf | grep "pathroot=" | cut -d= -f2)
|
pathroot=$(grep "pathroot=" "${conf}" | cut -d= -f2)
|
||||||
vidnamesarray=($(cat $conf | grep "vidnamesarray=" | cut -d= -f2))
|
IFS=" " read -r -a vidnamesarray <<< "$(grep "vidnamesarray=" "${conf}" | cut -d= -f2)"
|
||||||
telegramapiurl=$(cat $conf | grep "telegramapiurl=" | cut -d= -f2)
|
telegramapiurl=$(grep "telegramapiurl=" "${conf}" | cut -d= -f2)
|
||||||
telegramchatid=$(cat $conf | grep "telegramchatid=" | cut -d= -f2)
|
telegramchatid=$(grep "telegramchatid=" "${conf}" | cut -d= -f2)
|
||||||
tgpreviewlink=$(cat $conf | grep "tgpreviewlink=" | cut -d= -f2)
|
tgpreviewlink=$(grep "tgpreviewlink=" "${conf}" | cut -d= -f2)
|
||||||
tgpreviewtext=$(cat $conf | grep "tgpreviewtext=" | cut -d= -f2)
|
tgpreviewtext=$(grep "tgpreviewtext=" "${conf}" | cut -d= -f2)
|
||||||
wpxmlrpclink=$(cat $conf | grep "wpxmlrpclink=" | cut -d= -f2)
|
wpxmlrpclink=$(grep "wpxmlrpclink=" "${conf}" | cut -d= -f2)
|
||||||
wpxmlrpcuser=$(cat $conf | grep "wpxmlrpcuser=" | cut -d= -f2)
|
wpxmlrpcuser=$(grep "wpxmlrpcuser=" "${conf}" | cut -d= -f2)
|
||||||
wpxmlrpcpass=$(cat $conf | grep "wpxmlrpcpass=" | cut -d= -f2)
|
wpxmlrpcpass=$(grep "wpxmlrpcpass=" "${conf}" | cut -d= -f2)
|
||||||
wppageauthor=$(cat $conf | grep "wppageauthor=" | cut -d= -f2)
|
wppageauthor=$(grep "wppageauthor=" "${conf}" | cut -d= -f2)
|
||||||
wppagelinkis=$(cat $conf | grep "wppagelinkis=" | cut -d= -f2)
|
wppagelinkis=$(grep "wppagelinkis=" "${conf}" | cut -d= -f2)
|
||||||
wpeditpageid=$(cat $conf | grep "wpeditpageid=" | cut -d= -f2)
|
wpeditpageid=$(grep "wpeditpageid=" "${conf}" | cut -d= -f2)
|
||||||
wpedituserid=$(cat $conf | grep "wpedituserid=" | cut -d= -f2)
|
wpedituserid=$(grep "wpedituserid=" "${conf}" | cut -d= -f2)
|
||||||
wpeditdateis=$(cat $conf | grep "wpeditdateis=" | cut -d= -f2)
|
wpeditdateis=$(grep "wpeditdateis=" "${conf}" | cut -d= -f2)
|
||||||
wptemplateis=$(cat $conf | grep "wptemplateis=" | cut -d= -f2)
|
wptemplateis=$(grep "wptemplateis=" "${conf}" | cut -d= -f2)
|
||||||
youtubelink=$(cat $conf | grep "youtubelink=" | cut -d= -f2)
|
youtubelink=$(grep "youtubelink=" "${conf}" | cut -d= -f2)
|
||||||
|
|
||||||
defaultdp01=($(cat $conf | grep "defaultdp01=" | cut -d= -f2))
|
IFS=" " read -r -a defaultdp01 <<< "$(grep "defaultdp01=" "${conf}" | cut -d= -f2)"
|
||||||
defaultwp01=($(cat $conf | grep "defaultwp01=" | cut -d= -f2))
|
IFS=" " read -r -a defaultwp01 <<< "$(grep "defaultwp01=" "${conf}" | cut -d= -f2)"
|
||||||
defaultmp01=($(cat $conf | grep "defaultmp01=" | cut -d= -f2))
|
IFS=" " read -r -a defaultmp01 <<< "$(grep "defaultmp01=" "${conf}" | cut -d= -f2)"
|
||||||
defaultyp01=($(cat $conf | grep "defaultyp01=" | cut -d= -f2))
|
IFS=" " read -r -a defaultyp01 <<< "$(grep "defaultyp01=" "${conf}" | cut -d= -f2)"
|
||||||
|
|
||||||
defaultdp02=($(cat $conf | grep "defaultdp02=" | cut -d= -f2))
|
IFS=" " read -r -a defaultdp02 <<< "$(grep "defaultdp02=" "${conf}" | cut -d= -f2)"
|
||||||
defaultwp02=($(cat $conf | grep "defaultwp02=" | cut -d= -f2))
|
IFS=" " read -r -a defaultwp02 <<< "$(grep "defaultwp02=" "${conf}" | cut -d= -f2)"
|
||||||
defaultmp02=($(cat $conf | grep "defaultmp02=" | cut -d= -f2))
|
IFS=" " read -r -a defaultmp02 <<< "$(grep "defaultmp02=" "${conf}" | cut -d= -f2)"
|
||||||
defaultyp02=($(cat $conf | grep "defaultyp02=" | cut -d= -f2))
|
IFS=" " read -r -a defaultyp02 <<< "$(grep "defaultyp02=" "${conf}" | cut -d= -f2)"
|
||||||
|
|
||||||
defaultdp04=($(cat $conf | grep "defaultdp04=" | cut -d= -f2))
|
IFS=" " read -r -a defaultdp04 <<< "$(grep "defaultdp04=" "${conf}" | cut -d= -f2)"
|
||||||
defaultwp04=($(cat $conf | grep "defaultwp04=" | cut -d= -f2))
|
IFS=" " read -r -a defaultwp04 <<< "$(grep "defaultwp04=" "${conf}" | cut -d= -f2)"
|
||||||
defaultmp04=($(cat $conf | grep "defaultmp04=" | cut -d= -f2))
|
IFS=" " read -r -a defaultmp04 <<< "$(grep "defaultmp04=" "${conf}" | cut -d= -f2)"
|
||||||
defaultyp04=($(cat $conf | grep "defaultyp04=" | cut -d= -f2))
|
IFS=" " read -r -a defaultyp04 <<< "$(grep "defaultyp04=" "${conf}" | cut -d= -f2)"
|
||||||
|
|
||||||
defaultdp05=($(cat $conf | grep "defaultdp05=" | cut -d= -f2))
|
IFS=" " read -r -a defaultdp05 <<< "$(grep "defaultdp05=" "${conf}" | cut -d= -f2)"
|
||||||
defaultwp05=($(cat $conf | grep "defaultwp05=" | cut -d= -f2))
|
IFS=" " read -r -a defaultwp05 <<< "$(grep "defaultwp05=" "${conf}" | cut -d= -f2)"
|
||||||
defaultmp05=($(cat $conf | grep "defaultmp05=" | cut -d= -f2))
|
IFS=" " read -r -a defaultmp05 <<< "$(grep "defaultmp05=" "${conf}" | cut -d= -f2)"
|
||||||
defaultyp05=($(cat $conf | grep "defaultyp05=" | cut -d= -f2))
|
IFS=" " read -r -a defaultyp05 <<< "$(grep "defaultyp05=" "${conf}" | cut -d= -f2)"
|
||||||
|
|
||||||
defaultdp11=($(cat $conf | grep "defaultdp11=" | cut -d= -f2))
|
IFS=" " read -r -a defaultdp11 <<< "$(grep "defaultdp11=" "${conf}" | cut -d= -f2)"
|
||||||
defaultwp11=($(cat $conf | grep "defaultwp11=" | cut -d= -f2))
|
IFS=" " read -r -a defaultwp11 <<< "$(grep "defaultwp11=" "${conf}" | cut -d= -f2)"
|
||||||
defaultmp11=($(cat $conf | grep "defaultmp11=" | cut -d= -f2))
|
IFS=" " read -r -a defaultmp11 <<< "$(grep "defaultmp11=" "${conf}" | cut -d= -f2)"
|
||||||
defaultyp11=($(cat $conf | grep "defaultyp11=" | cut -d= -f2))
|
IFS=" " read -r -a defaultyp11 <<< "$(grep "defaultyp11=" "${conf}" | cut -d= -f2)"
|
||||||
|
|
||||||
defaultdp12=($(cat $conf | grep "defaultdp12=" | cut -d= -f2))
|
IFS=" " read -r -a defaultdp12 <<< "$(grep "defaultdp12=" "${conf}" | cut -d= -f2)"
|
||||||
defaultwp12=($(cat $conf | grep "defaultwp12=" | cut -d= -f2))
|
IFS=" " read -r -a defaultwp12 <<< "$(grep "defaultwp12=" "${conf}" | cut -d= -f2)"
|
||||||
defaultmp12=($(cat $conf | grep "defaultmp12=" | cut -d= -f2))
|
IFS=" " read -r -a defaultmp12 <<< "$(grep "defaultmp12=" "${conf}" | cut -d= -f2)"
|
||||||
defaultyp12=($(cat $conf | grep "defaultyp12=" | cut -d= -f2))
|
IFS=" " read -r -a defaultyp12 <<< "$(grep "defaultyp12=" "${conf}" | cut -d= -f2)"
|
||||||
|
|
||||||
|
IFS=" " read -r -a currentdp01 <<< "$(grep "currentdp01=" "${conf}" | cut -d= -f2)"
|
||||||
currentdp01=($(cat $conf | grep "currentdp01=" | cut -d= -f2))
|
if [ -z "${currentdp01[1]}" ]; then
|
||||||
if [ -z "$currentdp01" ];then
|
currentdp01=${defaultdp01[*]}
|
||||||
currentdp01=(${defaultdp01[*]})
|
|
||||||
fi
|
fi
|
||||||
currentwp01=($(cat $conf | grep "currentwp01=" | cut -d= -f2))
|
IFS=" " read -r -a currentwp01 <<< "$(grep "currentwp01=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentwp01" ];then
|
if [ -z "${currentwp01[1]}" ]; then
|
||||||
currentwp01=(${defaultwp01[*]})
|
currentwp01=${defaultwp01[*]}
|
||||||
fi
|
fi
|
||||||
currentmp01=($(cat $conf | grep "currentmp01=" | cut -d= -f2))
|
IFS=" " read -r -a currentmp01 <<< "$(grep "currentmp01=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentmp01" ];then
|
if [ -z "${currentmp01[1]}" ]; then
|
||||||
currentmp01=(${defaultmp01[*]})
|
currentmp01=${defaultmp01[*]}
|
||||||
fi
|
fi
|
||||||
currentyp01=($(cat $conf | grep "currentyp01=" | cut -d= -f2))
|
IFS=" " read -r -a currentyp01 <<< "$(grep "currentyp01=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentyp01" ];then
|
if [ -z "${currentyp01[1]}" ]; then
|
||||||
currentyp01=(${defaultyp01[*]})
|
currentyp01=${defaultyp01[*]}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
currentdp02=($(cat $conf | grep "currentdp02=" | cut -d= -f2))
|
IFS=" " read -r -a currentdp02 <<< "$(grep "currentdp02=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentdp02" ];then
|
if [ -z "${currentdp02[1]}" ]; then
|
||||||
currentdp02=(${defaultdp02[*]})
|
currentdp02=${defaultdp02[*]}
|
||||||
fi
|
fi
|
||||||
currentwp02=($(cat $conf | grep "currentwp02=" | cut -d= -f2))
|
IFS=" " read -r -a currentwp02 <<< "$(grep "currentwp02=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentwp02" ];then
|
if [ -z "${currentwp02[1]}" ]; then
|
||||||
currentwp02=(${defaultwp02[*]})
|
currentwp02=${defaultwp02[*]}
|
||||||
fi
|
fi
|
||||||
currentmp02=($(cat $conf | grep "currentmp02=" | cut -d= -f2))
|
IFS=" " read -r -a currentmp02 <<< "$(grep "currentmp02=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentmp02" ];then
|
if [ -z "${currentmp02[1]}" ]; then
|
||||||
currentmp02=(${defaultmp02[*]})
|
currentmp02=${defaultmp02[*]}
|
||||||
fi
|
fi
|
||||||
currentyp02=($(cat $conf | grep "currentyp02=" | cut -d= -f2))
|
IFS=" " read -r -a currentyp02 <<< "$(grep "currentyp02=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentyp02" ];then
|
if [ -z "${currentyp02[1]}" ]; then
|
||||||
currentyp02=(${defaultyp02[*]})
|
currentyp02=${defaultyp02[*]}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
currentdp04=($(cat $conf | grep "currentdp04=" | cut -d= -f2))
|
IFS=" " read -r -a currentdp04 <<< "$(grep "currentdp04=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentdp04" ];then
|
if [ -z "${currentdp04[1]}" ]; then
|
||||||
currentdp04=(${defaultdp04[*]})
|
currentdp04=${defaultdp04[*]}
|
||||||
fi
|
fi
|
||||||
currentwp04=($(cat $conf | grep "currentwp04=" | cut -d= -f2))
|
IFS=" " read -r -a currentwp04 <<< "$(grep "currentwp04=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentwp04" ];then
|
if [ -z "${currentwp04[1]}" ]; then
|
||||||
currentwp04=(${defaultwp04[*]})
|
currentwp04=${defaultwp04[*]}
|
||||||
fi
|
fi
|
||||||
currentmp04=($(cat $conf | grep "currentmp04=" | cut -d= -f2))
|
IFS=" " read -r -a currentmp04 <<< "$(grep "currentmp04=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentmp04" ];then
|
if [ -z "${currentmp04[1]}" ]; then
|
||||||
currentmp04=(${defaultmp04[*]})
|
currentmp04=${defaultmp04[*]}
|
||||||
fi
|
fi
|
||||||
currentyp04=($(cat $conf | grep "currentyp04=" | cut -d= -f2))
|
IFS=" " read -r -a currentyp04 <<< "$(grep "currentyp04=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentyp04" ];then
|
if [ -z "${currentyp04[1]}" ]; then
|
||||||
currentyp04=(${defaultyp04[*]})
|
currentyp04=${defaultyp04[*]}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
currentdp05=($(cat $conf | grep "currentdp05=" | cut -d= -f2))
|
IFS=" " read -r -a currentdp05 <<< "$(grep "currentdp05=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentdp05" ];then
|
if [ -z "${currentdp05[1]}" ]; then
|
||||||
currentdp05=(${defaultdp05[*]})
|
currentdp05=${defaultdp05[*]}
|
||||||
fi
|
fi
|
||||||
currentwp05=($(cat $conf | grep "currentwp05=" | cut -d= -f2))
|
IFS=" " read -r -a currentwp05 <<< "$(grep "currentwp05=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentwp05" ];then
|
if [ -z "${currentwp05[1]}" ]; then
|
||||||
currentwp05=(${defaultwp05[*]})
|
currentwp05=${defaultwp05[*]}
|
||||||
fi
|
fi
|
||||||
currentmp05=($(cat $conf | grep "currentmp05=" | cut -d= -f2))
|
IFS=" " read -r -a currentmp05 <<< "$(grep "currentmp05=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentmp05" ];then
|
if [ -z "${currentmp05[1]}" ]; then
|
||||||
currentmp05=(${defaultmp05[*]})
|
currentmp05=${defaultmp05[*]}
|
||||||
fi
|
fi
|
||||||
currentyp05=($(cat $conf | grep "currentyp05=" | cut -d= -f2))
|
IFS=" " read -r -a currentyp05 <<< "$(grep "currentyp05=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentyp05" ];then
|
if [ -z "${currentyp05[1]}" ]; then
|
||||||
currentyp05=(${defaultyp05[*]})
|
currentyp05=${defaultyp05[*]}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
currentdp11=($(cat $conf | grep "currentdp11=" | cut -d= -f2))
|
IFS=" " read -r -a currentdp11 <<< "$(grep "currentdp11=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentdp11" ];then
|
if [ -z "${currentdp11[1]}" ]; then
|
||||||
currentdp11=(${defaultdp11[*]})
|
currentdp11=${defaultdp11[*]}
|
||||||
fi
|
fi
|
||||||
currentwp11=($(cat $conf | grep "currentwp11=" | cut -d= -f2))
|
IFS=" " read -r -a currentwp11 <<< "$(grep "currentwp11=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentwp11" ];then
|
if [ -z "${currentwp11[1]}" ]; then
|
||||||
currentwp11=(${defaultwp11[*]})
|
currentwp11=${defaultwp11[*]}
|
||||||
fi
|
fi
|
||||||
currentmp11=($(cat $conf | grep "currentmp11=" | cut -d= -f2))
|
IFS=" " read -r -a currentmp11 <<< "$(grep "currentmp11=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentmp11" ];then
|
if [ -z "${currentmp11[1]}" ]; then
|
||||||
currentmp11=(${defaultmp11[*]})
|
currentmp11=${defaultmp11[*]}
|
||||||
fi
|
fi
|
||||||
currentyp11=($(cat $conf | grep "currentyp11=" | cut -d= -f2))
|
IFS=" " read -r -a currentyp11 <<< "$(grep "currentyp11=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentyp11" ];then
|
if [ -z "${currentyp11[1]}" ]; then
|
||||||
currentyp11=(${defaultyp11[*]})
|
currentyp11=${defaultyp11[*]}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
currentdp12=($(cat $conf | grep "currentdp12=" | cut -d= -f2))
|
IFS=" " read -r -a currentdp12 <<< "$(grep "currentdp12=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentdp12" ];then
|
if [ -z "${currentdp12[1]}" ]; then
|
||||||
currentdp12=(${defaultdp12[*]})
|
currentdp12=${defaultdp12[*]}
|
||||||
fi
|
fi
|
||||||
currentwp12=($(cat $conf | grep "currentwp12=" | cut -d= -f2))
|
IFS=" " read -r -a currentwp12 <<< "$(grep "currentwp12=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentwp12" ];then
|
if [ -z "${currentwp12[1]}" ]; then
|
||||||
currentwp12=(${defaultwp12[*]})
|
currentwp12=${defaultwp12[*]}
|
||||||
fi
|
fi
|
||||||
currentmp12=($(cat $conf | grep "currentmp12=" | cut -d= -f2))
|
IFS=" " read -r -a currentmp12 <<< "$(grep "currentmp12=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentmp12" ];then
|
if [ -z "${currentmp12[1]}" ]; then
|
||||||
currentmp12=(${defaultmp12[*]})
|
currentmp12=${defaultmp12[*]}
|
||||||
fi
|
fi
|
||||||
currentyp12=($(cat $conf | grep "currentyp12=" | cut -d= -f2))
|
IFS=" " read -r -a currentyp12 <<< "$(grep "currentyp12=" "${conf}" | cut -d= -f2)"
|
||||||
if [ -z "$currentyp12" ];then
|
if [ -z "${currentyp12[1]}" ]; then
|
||||||
currentyp12=(${defaultyp12[*]})
|
currentyp12=${defaultyp12[*]}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Writing changes to configuration file.
|
||||||
|
# Globals:
|
||||||
|
# conf
|
||||||
|
# when
|
||||||
|
# vidnamesarray
|
||||||
|
# vidlinksarray
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
setconfig() {
|
setconfig() {
|
||||||
if [ -z "$target" ] || [ "$target" == "-d" ];then
|
if [ -z "${when}" ] || [ "${when}" == "-d" ]; then
|
||||||
if [ ! -z "${vidnamesarray[0]}" ] && [ ! -z "${vidlinksarray[0]}" ];then
|
if [ -n "${vidnamesarray[0]}" ] && [ -n "${vidlinksarray[0]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentdp01=')#currentdp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" $conf
|
sed -i "s#$(grep 'currentdp01=' "${conf}")#currentdp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[1]}" ] && [ ! -z "${vidlinksarray[1]}" ];then
|
if [ -n "${vidnamesarray[1]}" ] && [ -n "${vidlinksarray[1]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentdp02=')#currentdp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" $conf
|
sed -i "s#$(grep 'currentdp02=' "${conf}")#currentdp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[2]}" ] && [ ! -z "${vidlinksarray[2]}" ];then
|
if [ -n "${vidnamesarray[2]}" ] && [ -n "${vidlinksarray[2]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentdp04=')#currentdp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" $conf
|
sed -i "s#$(grep 'currentdp04=' "${conf}")#currentdp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[3]}" ] && [ ! -z "${vidlinksarray[3]}" ];then
|
if [ -n "${vidnamesarray[3]}" ] && [ -n "${vidlinksarray[3]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentdp05=')#currentdp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" $conf
|
sed -i "s#$(grep 'currentdp05=' "${conf}")#currentdp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[4]}" ] && [ ! -z "${vidlinksarray[4]}" ];then
|
if [ -n "${vidnamesarray[4]}" ] && [ -n "${vidlinksarray[4]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentdp11=')#currentdp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" $conf
|
sed -i "s#$(grep 'currentdp11=' "${conf}")#currentdp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[5]}" ] && [ ! -z "${vidlinksarray[5]}" ];then
|
if [ -n "${vidnamesarray[5]}" ] && [ -n "${vidlinksarray[5]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentdp12=')#currentdp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" $conf
|
sed -i "s#$(grep 'currentdp12=' "${conf}")#currentdp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ "$target" == "-w" ];then
|
if [ "${when}" == "-w" ]; then
|
||||||
if [ ! -z "${vidnamesarray[0]}" ] && [ ! -z "${vidlinksarray[0]}" ];then
|
if [ -n "${vidnamesarray[0]}" ] && [ -n "${vidlinksarray[0]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentwp01=')#currentwp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" $conf
|
sed -i "s#$(grep 'currentwp01=' "${conf}")#currentwp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[1]}" ] && [ ! -z "${vidlinksarray[1]}" ];then
|
if [ -n "${vidnamesarray[1]}" ] && [ -n "${vidlinksarray[1]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentwp02=')#currentwp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" $conf
|
sed -i "s#$(grep 'currentwp02=' "${conf}")#currentwp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[2]}" ] && [ ! -z "${vidlinksarray[2]}" ];then
|
if [ -n "${vidnamesarray[2]}" ] && [ -n "${vidlinksarray[2]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentwp04=')#currentwp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" $conf
|
sed -i "s#$(grep 'currentwp04=' "${conf}")#currentwp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[3]}" ] && [ ! -z "${vidlinksarray[3]}" ];then
|
if [ -n "${vidnamesarray[3]}" ] && [ -n "${vidlinksarray[3]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentwp05=')#currentwp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" $conf
|
sed -i "s#$(grep 'currentwp05=' "${conf}")#currentwp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[4]}" ] && [ ! -z "${vidlinksarray[4]}" ];then
|
if [ -n "${vidnamesarray[4]}" ] && [ -n "${vidlinksarray[4]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentwp11=')#currentwp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" $conf
|
sed -i "s#$(grep 'currentwp11=' "${conf}")#currentwp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[5]}" ] && [ ! -z "${vidlinksarray[5]}" ];then
|
if [ -n "${vidnamesarray[5]}" ] && [ -n "${vidlinksarray[5]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentwp12=')#currentwp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" $conf
|
sed -i "s#$(grep 'currentwp12=' "${conf}")#currentwp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ "$target" == "-m" ];then
|
if [ "${when}" == "-m" ]; then
|
||||||
if [ ! -z "${vidnamesarray[0]}" ] && [ ! -z "${vidlinksarray[0]}" ];then
|
if [ -n "${vidnamesarray[0]}" ] && [ -n "${vidlinksarray[0]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentmp01=')#currentmp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" $conf
|
sed -i "s#$(grep 'currentmp01=' "${conf}")#currentmp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[1]}" ] && [ ! -z "${vidlinksarray[1]}" ];then
|
if [ -n "${vidnamesarray[1]}" ] && [ -n "${vidlinksarray[1]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentmp02=')#currentmp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" $conf
|
sed -i "s#$(grep 'currentmp02=' "${conf}")#currentmp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[2]}" ] && [ ! -z "${vidlinksarray[2]}" ];then
|
if [ -n "${vidnamesarray[2]}" ] && [ -n "${vidlinksarray[2]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentmp04=')#currentmp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" $conf
|
sed -i "s#$(grep 'currentmp04=' "${conf}")#currentmp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[3]}" ] && [ ! -z "${vidlinksarray[3]}" ];then
|
if [ -n "${vidnamesarray[3]}" ] && [ -n "${vidlinksarray[3]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentmp05=')#currentmp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" $conf
|
sed -i "s#$(grep 'currentmp05=' "${conf}")#currentmp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[4]}" ] && [ ! -z "${vidlinksarray[4]}" ];then
|
if [ -n "${vidnamesarray[4]}" ] && [ -n "${vidlinksarray[4]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentmp11=')#currentmp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" $conf
|
sed -i "s#$(grep 'currentmp11=' "${conf}")#currentmp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[5]}" ] && [ ! -z "${vidlinksarray[5]}" ];then
|
if [ -n "${vidnamesarray[5]}" ] && [ -n "${vidlinksarray[5]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentmp12=')#currentmp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" $conf
|
sed -i "s#$(grep 'currentmp12=' "${conf}")#currentmp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ "$target" == "-y" ];then
|
if [ "${when}" == "-y" ]; then
|
||||||
if [ ! -z "${vidnamesarray[0]}" ] && [ ! -z "${vidlinksarray[0]}" ];then
|
if [ -n "${vidnamesarray[0]}" ] && [ -n "${vidlinksarray[0]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentyp01=')#currentyp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" $conf
|
sed -i "s#$(grep 'currentyp01=' "${conf}")#currentyp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[1]}" ] && [ ! -z "${vidlinksarray[1]}" ];then
|
if [ -n "${vidnamesarray[1]}" ] && [ -n "${vidlinksarray[1]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentyp02=')#currentyp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" $conf
|
sed -i "s#$(grep 'currentyp02=' "${conf}")#currentyp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[2]}" ] && [ ! -z "${vidlinksarray[2]}" ];then
|
if [ -n "${vidnamesarray[2]}" ] && [ -n "${vidlinksarray[2]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentyp04=')#currentyp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" $conf
|
sed -i "s#$(grep 'currentyp04=' "${conf}")#currentyp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[3]}" ] && [ ! -z "${vidlinksarray[3]}" ];then
|
if [ -n "${vidnamesarray[3]}" ] && [ -n "${vidlinksarray[3]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentyp05=')#currentyp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" $conf
|
sed -i "s#$(grep 'currentyp05=' "${conf}")#currentyp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[4]}" ] && [ ! -z "${vidlinksarray[4]}" ];then
|
if [ -n "${vidnamesarray[4]}" ] && [ -n "${vidlinksarray[4]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentyp11=')#currentyp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" $conf
|
sed -i "s#$(grep 'currentyp11=' "${conf}")#currentyp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "${vidnamesarray[5]}" ] && [ ! -z "${vidlinksarray[5]}" ];then
|
if [ -n "${vidnamesarray[5]}" ] && [ -n "${vidlinksarray[5]}" ]; then
|
||||||
sed -i "s#$(cat $conf | grep 'currentyp12=')#currentyp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" $conf
|
sed -i "s#$(grep 'currentyp12=' "${conf}")#currentyp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" "${conf}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
## PARAMETERS
|
## VARIABLES:
|
||||||
#
|
#
|
||||||
|
|
||||||
show=${1}
|
show=$1
|
||||||
conf=${2}
|
conf=$2
|
||||||
if [ -z "${conf}" ] || [ "${conf}" == "-" ];then
|
if [ -z "${conf}" ] || [ "${conf}" == "-" ]; then
|
||||||
conf="$(dirname $(realpath "$0"))/$(basename -s .sh $0).conf"
|
conf="$(dirname "$(realpath "$0")")/$(basename -s .sh "$0").conf"
|
||||||
fi
|
fi
|
||||||
ever=${4}
|
ever=$4
|
||||||
if [ -z "$ever" ] || [ "$ever" == "-" ];then
|
if [ -z "${ever}" ] || [ "${ever}" == "-" ]; then
|
||||||
ever=1
|
ever=1
|
||||||
fi
|
fi
|
||||||
if [ ! -z $(echo "$ever" | grep -o "^[0-9][0-9]*$") ];then
|
if grep -q -o "^[0-9][0-9]*$" <<< "${ever}"; then
|
||||||
:
|
:
|
||||||
else
|
else
|
||||||
execerror "$ever - wrong argument"
|
execerror "${ever} - wrong argument"
|
||||||
fi
|
fi
|
||||||
when=${3}
|
when=$3
|
||||||
if [ -z "$when" ];then
|
if [ -z "${when}" ]; then
|
||||||
viddate=$(date +"%Y").$(date +"%m").$(date +"%d")
|
viddate=$(date +"%Y").$(date +"%m").$(date +"%d")
|
||||||
fi
|
fi
|
||||||
if [ "$when" == "-d" ];then
|
if [ "${when}" == "-d" ]; then
|
||||||
d=$(date -d "-${ever} day" +"%d")
|
d=$(date -d "-${ever} day" +"%d")
|
||||||
m=$(date +"%m")
|
m=$(date +"%m")
|
||||||
if [ "$(date -d "-${ever} day" +'%m')" != "$(date +'%m')" ];then
|
if [ "$(date -d "-${ever} day" +'%m')" != "$(date +'%m')" ]; then
|
||||||
m=$(date -d "-${ever} day" +'%m')
|
m=$(date -d "-${ever} day" +'%m')
|
||||||
fi
|
fi
|
||||||
y=$(date +"%Y")
|
y=$(date +"%Y")
|
||||||
if [ "$(date -d "-${ever} day" +'%Y')" != "$(date +'%Y')" ];then
|
if [ "$(date -d "-${ever} day" +'%Y')" != "$(date +'%Y')" ]; then
|
||||||
y=$(date -d "-${ever} day" +'%Y')
|
y=$(date -d "-${ever} day" +'%Y')
|
||||||
fi
|
fi
|
||||||
viddate=${y}.${m}.${d}
|
viddate="${y}.${m}.${d}"
|
||||||
fi
|
fi
|
||||||
if [ "$when" == "-w" ];then
|
if [ "${when}" == "-w" ]; then
|
||||||
w=$(date -d "-${ever} week" +"%V")
|
w=$(date -d "-${ever} week" +"%V")
|
||||||
y=$(date +"%Y")
|
y=$(date +"%Y")
|
||||||
if [ "$(date -d "-${ever} week" +'%Y')" != "$(date +'%Y')" ];then
|
if [ "$(date -d "-${ever} week" +'%Y')" != "$(date +'%Y')" ]; then
|
||||||
y=$(date -d "-${ever} week" +'%Y')
|
y=$(date -d "-${ever} week" +'%Y')
|
||||||
fi
|
fi
|
||||||
viddate=${y}-w${w}
|
viddate="${y}-w${w}"
|
||||||
fi
|
fi
|
||||||
if [ "$when" == "-m" ];then
|
if [ "${when}" == "-m" ]; then
|
||||||
m=$(date -d "-${ever} month" +"%m")
|
m=$(date -d "-${ever} month" +"%m")
|
||||||
y=$(date +"%Y")
|
y=$(date +"%Y")
|
||||||
if [ "$(date -d "-${ever} month" +'%Y')" != "$(date +'%Y')" ];then
|
if [ "$(date -d "-${ever} month" +'%Y')" != "$(date +'%Y')" ]; then
|
||||||
y=$(date -d "-${ever} month" +'%Y')
|
y=$(date -d "-${ever} month" +'%Y')
|
||||||
fi
|
fi
|
||||||
viddate=${y}.${m}
|
viddate="${y}.${m}"
|
||||||
fi
|
fi
|
||||||
if [ "$when" == "-y" ];then
|
if [ "${when}" == "-y" ]; then
|
||||||
y=$(date -d "-${ever} year" +"%Y")
|
y=$(date -d "-${ever} year" +"%Y")
|
||||||
viddate=${y}
|
viddate="${y}"
|
||||||
fi
|
fi
|
||||||
vidname=${viddate}.mp4
|
vidname="${viddate}.mp4"
|
||||||
only=${5}
|
only=$5
|
||||||
|
|
||||||
#
|
|
||||||
## VARIABLES
|
|
||||||
#
|
|
||||||
|
|
||||||
time=$(date +%s)
|
time=$(date +%s)
|
||||||
cd "$(dirname "$(realpath "$0")")"
|
cd "$(dirname "$(realpath "$0")")" || execerror
|
||||||
if [ ! -e ${conf} ];then
|
if [ ! -e "${conf}" ]; then
|
||||||
execerror "Not found config file: ${conf}"
|
execerror "Not found config file: ${conf}"
|
||||||
else
|
else
|
||||||
getconfig
|
getconfig
|
||||||
fi
|
fi
|
||||||
if [ -z "${logs}" ];then
|
if [ -z "${logs}" ]; then
|
||||||
logs=/dev/null
|
logs=/dev/null
|
||||||
elif [ ! -e ${logs} ];then
|
elif [ ! -e "${logs}" ]; then
|
||||||
touch ${logs}
|
touch "${logs}"
|
||||||
fi
|
fi
|
||||||
if ! command -v curl &> /dev/null || ! command -v ffmpeg &> /dev/null || ! command -v xmllint &> /dev/null || ! command -v jq &> /dev/null; then
|
if ! command -v curl &> /dev/null || \
|
||||||
|
! command -v ffmpeg &> /dev/null || \
|
||||||
|
! command -v xmllint &> /dev/null || \
|
||||||
|
! command -v jq &> /dev/null; then
|
||||||
execerror "Not found dependencies"
|
execerror "Not found dependencies"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
## RUN
|
# MAIN:
|
||||||
#
|
#
|
||||||
|
|
||||||
vidpathsarray=()
|
vidpathsarray=()
|
||||||
vidlinksarray=()
|
vidlinksarray=()
|
||||||
vidtgidsarray=()
|
vidtgidsarray=()
|
||||||
vidtgcpsarray=()
|
vidtgcpsarray=()
|
||||||
for name in ${vidnamesarray[*]}
|
for name in "${vidnamesarray[@]}"; do
|
||||||
do
|
vidmatch="${name}_${vidname}"
|
||||||
vidmatch=$name\_$vidname
|
while read -r FILE; do
|
||||||
while read FILE; do
|
|
||||||
vidpathsarray+=("${FILE}")
|
vidpathsarray+=("${FILE}")
|
||||||
done < <(find $pathroot -name "*$vidmatch" | sort)
|
done < <(find "${pathroot}" -name "*${vidmatch}" | sort)
|
||||||
done
|
done
|
||||||
for item in "${!vidpathsarray[@]}"
|
for item in "${!vidpathsarray[@]}"; do
|
||||||
do
|
# WORDPRESS UPLOAD VIDEO
|
||||||
### WORDPRESS UPLOAD VIDEO
|
if [ ! "$only" == "--onlytg" ]; then
|
||||||
if [ ! "$only" == "--onlytg" ];then
|
|
||||||
# This realisation isn't optimal, but it fixes a few issues with large files:
|
# This realisation isn't optimal, but it fixes a few issues with large files:
|
||||||
# variable=$(base64 $file) -> "xrealloc: cannot allocate"
|
# variable=$(base64 $file) -> "xrealloc: cannot allocate"
|
||||||
# response=$(curl -X POST -d @${file}.xml $url) -> "curl: option -d: out of memory"
|
# response=$(curl -X POST -d @${file}.xml $url) -> "curl: option -d: out of memory"
|
||||||
filetype=video/mp4
|
filetype="video/mp4"
|
||||||
echo '<?xml version="1.0"?>
|
echo '<?xml version="1.0"?>
|
||||||
<methodCall><methodName>wp.uploadFile</methodName>
|
<methodCall><methodName>wp.uploadFile</methodName>
|
||||||
<params>
|
<params>
|
||||||
|
@ -377,79 +433,97 @@ do
|
||||||
<param><value>'"${wpxmlrpcuser}"'</value></param>
|
<param><value>'"${wpxmlrpcuser}"'</value></param>
|
||||||
<param><value>'"${wpxmlrpcpass}"'</value></param>
|
<param><value>'"${wpxmlrpcpass}"'</value></param>
|
||||||
<param><value><struct>
|
<param><value><struct>
|
||||||
<member><name>name</name><value><string>'"$(basename ${vidpathsarray[$item]})"'</string></value></member>
|
<member><name>name</name><value><string>'"$(basename "${vidpathsarray[$item]}")"'</string></value></member>
|
||||||
<member><name>type</name><value><string>'"${filetype}"'</string></value></member>
|
<member><name>type</name><value><string>'"${filetype}"'</string></value></member>
|
||||||
<member><name>bits</name><value><base64>' > ${vidpathsarray[$item]}.xml
|
<member><name>bits</name><value><base64>' > "${vidpathsarray[$item]}.xml"
|
||||||
base64 --wrap=0 ${vidpathsarray[$item]} >> ${vidpathsarray[$item]}.xml
|
base64 --wrap=0 "${vidpathsarray[$item]}" >> "${vidpathsarray[$item]}.xml"
|
||||||
echo '</base64></value></member>
|
echo '</base64></value></member>
|
||||||
</struct></value></param>
|
</struct></value></param>
|
||||||
</params>
|
</params>
|
||||||
</methodCall>' >> ${vidpathsarray[$item]}.xml
|
</methodCall>' >> "${vidpathsarray[$item]}.xml"
|
||||||
curl -X POST -T ${vidpathsarray[$item]}.xml $wpxmlrpclink > ${vidpathsarray[$item]}-response.xml \
|
response="${vidpathsarray[$item]}-response.xml"
|
||||||
&& vidlinksarray+=("$(xmllint --xpath '//member[contains(name,"link")]/value/string/text()' ${vidpathsarray[$item]}-response.xml)") \
|
if curl -X POST -T "${vidpathsarray[$item]}.xml" "${wpxmlrpclink}" > "${response}"; then
|
||||||
&& vidlinkcodeis=$(curl --output /dev/null --silent --write-out "%{http_code}" ${vidlinksarray[$item]}) \
|
vidlinksarray+=("$(xmllint --xpath '//member[contains(name,"link")]/value/string/text()' "${response}")")
|
||||||
|| execerror "${vidpathsarray[$item]}-response.xml"
|
vidlinkcodeis=$(curl --output /dev/null --silent --write-out "%{http_code}" "${vidlinksarray[$item]}")
|
||||||
if [[ ${vidlinkcodeis} -eq 200 ]];then
|
else
|
||||||
rm ${vidpathsarray[$item]}.xml
|
execerror "${response}"
|
||||||
rm ${vidpathsarray[$item]}-response.xml
|
fi
|
||||||
echo "$(date +'%Y.%m.%d-%H:%M:%S') sent ${vidpathsarray[$item]} to ${vidlinksarray[$item]}" | tee -a $logs
|
if [[ ${vidlinkcodeis} -eq 200 ]]; then
|
||||||
|
rm "${vidpathsarray[$item]}.xml"
|
||||||
|
rm "${response}"
|
||||||
|
echo "$(date +'%Y.%m.%d-%H:%M:%S') sent ${vidpathsarray[$item]} to ${vidlinksarray[$item]}" | tee -a "${logs}"
|
||||||
echo -e "WORDPRESS UPLOAD VIDEO RESULT:"
|
echo -e "WORDPRESS UPLOAD VIDEO RESULT:"
|
||||||
echo -e "item: $item"
|
echo -e "item: ${item}"
|
||||||
echo -e "type: $filetype"
|
echo -e "type: ${filetype}"
|
||||||
echo -e "name: ${vidnamesarray[$item]}"
|
echo -e "name: ${vidnamesarray[$item]}"
|
||||||
echo -e "base: $(basename ${vidpathsarray[$item]})"
|
echo -e "base: $(basename "${vidpathsarray[$item]}")"
|
||||||
echo -e "path: ${vidpathsarray[$item]}"
|
echo -e "path: ${vidpathsarray[$item]}"
|
||||||
echo -e "link: ${vidlinksarray[$item]}"
|
echo -e "link: ${vidlinksarray[$item]}"
|
||||||
echo -e "code: $vidlinkcodeis"
|
echo -e "code: ${vidlinkcodeis}"
|
||||||
else
|
else
|
||||||
vidlinksarray[$item]=''
|
vidlinksarray[item]=''
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
### TELEGRAM SEND/UPLOAD VIDEO
|
|
||||||
if [ ! "$only" == "--onlywp" ];then
|
# TELEGRAM SEND/UPLOAD VIDEO
|
||||||
|
if [ ! "${only}" == "--onlywp" ]; then
|
||||||
videofullpath=${vidpathsarray[$item]}
|
videofullpath=${vidpathsarray[$item]}
|
||||||
vidcompressed=$(echo ${vidpathsarray[$item]} | sed -e 's/.mp4/-compressed.mp4/g')
|
vidcompressed=${videofullpath//".mp4"/"-compressed.mp4"}
|
||||||
if [ -n "$(find "$videofullpath" -prune -size +51380224c)" ];then
|
if [ -n "$(find "${videofullpath}" -prune -size +51380224c)" ]; then
|
||||||
duration=$(ffprobe -i "$videofullpath" -show_entries format=duration -v quiet -of csv="p=0" | cut -d'.' -f 1) \
|
duration=$(ffprobe -i "${videofullpath}" \
|
||||||
&& ffmpeg -i "$videofullpath" -c:v libx264 -b:v $((49*8*1000/$duration))k -vf "scale=960:540,fps=25,format=yuv420p" -preset veryslow "$vidcompressed" -y -loglevel quiet -stats \
|
-show_entries format=duration -v quiet -of csv="p=0" | cut -d'.' -f 1)
|
||||||
&& videofullpath=$vidcompressed \
|
if ffmpeg -i "${videofullpath}" \
|
||||||
|| execerror "ffmpeg convert ${videofullpath} to ${vidcompressed}"
|
-c:v libx264 -b:v "$((49*8*1000/duration))k" \
|
||||||
|
-vf "scale=960:540,fps=25,format=yuv420p" \
|
||||||
|
-preset veryslow "${vidcompressed}" -y -loglevel quiet -stats; then
|
||||||
|
videofullpath=${vidcompressed}
|
||||||
|
else
|
||||||
|
execerror "ffmpeg convert ${videofullpath} to ${vidcompressed}"
|
||||||
fi
|
fi
|
||||||
response=$(curl -s -F chat_id=$telegramchatid \
|
fi
|
||||||
-F video=@${videofullpath} \
|
videobasename=$(basename "${videofullpath}")
|
||||||
-F caption="$(echo $(basename ${videofullpath}) | sed -e 's/.mp4//g')" \
|
videobasename=${videobasename//".mp4"/""}
|
||||||
$telegramapiurl/sendVideo) \
|
response=$(curl -s \
|
||||||
&& curl -s -F chat_id=$telegramchatid \
|
-F "chat_id=${telegramchatid}" \
|
||||||
-F message_id=$(echo $response | jq -r '.result.message_id') \
|
-F "video=@${videofullpath}" \
|
||||||
$telegramapiurl/deleteMessage \
|
-F "caption=${videobasename}" \
|
||||||
&& vidtgidsarray+=("$(echo $response | jq -r '.result.video.file_id')") \
|
"${telegramapiurl}/sendVideo")
|
||||||
&& vidtgcpsarray+=("$(echo $response | jq -r '.result.caption')") \
|
if curl -s -F "chat_id=${telegramchatid}" \
|
||||||
&& echo "$(date +'%Y.%m.%d-%H:%M:%S') sent ${videofullpath} to ${vidtgidsarray[$item]} Telegram file ID" | tee -a $logs \
|
-F "message_id=$(echo "${response}" | jq -r '.result.message_id')" \
|
||||||
|| execerror "sent ${videofullpath} to $telegramchatid Telegram Chat ID"
|
"${telegramapiurl}/deleteMessage"; then
|
||||||
if [ -e $vidcompressed ];then
|
vidtgidsarray+=("$(echo "${response}" | jq -r '.result.video.file_id')")
|
||||||
rm $vidcompressed
|
vidtgcpsarray+=("$(echo "${response}" | jq -r '.result.caption')")
|
||||||
|
addtologs "sent ${videofullpath} to ${vidtgidsarray[$item]} Telegram file ID"
|
||||||
|
else
|
||||||
|
execerror "sent ${videofullpath} to ${telegramchatid} Telegram Chat ID"
|
||||||
|
fi
|
||||||
|
if [ -e "${vidcompressed}" ]; then
|
||||||
|
rm "${vidcompressed}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
### TELEGRAM SEND MEDIAGROUP
|
|
||||||
if [ ! "$only" == "--onlywp" ];then
|
# TELEGRAM SEND MEDIAGROUP
|
||||||
response=$(curl -s -F chat_id=$telegramchatid \
|
if [ ! "${only}" == "--onlywp" ]; then
|
||||||
|
response=$(curl -s -F "chat_id=${telegramchatid}" \
|
||||||
-F media='[
|
-F media='[
|
||||||
{"type":"photo","media":"'${tgpreviewlink}'","caption":"period: '${viddate}'\nsource: '${tgpreviewtext}'\nstream: '${youtubelink}'"},
|
{"type":"photo","media":"'"${tgpreviewlink}"'",
|
||||||
{"type":"video","media":"'${vidtgidsarray[0]}'"},
|
"caption":"period: '"${viddate}"'\nsource: '"${tgpreviewtext}"'\nstream: '"${youtubelink}"'"},
|
||||||
{"type":"video","media":"'${vidtgidsarray[1]}'"},
|
{"type":"video","media":"'"${vidtgidsarray[0]}"'"},
|
||||||
{"type":"video","media":"'${vidtgidsarray[2]}'"},
|
{"type":"video","media":"'"${vidtgidsarray[1]}"'"},
|
||||||
{"type":"video","media":"'${vidtgidsarray[3]}'"},
|
{"type":"video","media":"'"${vidtgidsarray[2]}"'"},
|
||||||
{"type":"video","media":"'${vidtgidsarray[4]}'"},
|
{"type":"video","media":"'"${vidtgidsarray[3]}"'"},
|
||||||
{"type":"video","media":"'${vidtgidsarray[5]}'"}]' \
|
{"type":"video","media":"'"${vidtgidsarray[4]}"'"},
|
||||||
|
{"type":"video","media":"'"${vidtgidsarray[5]}"'"}]' \
|
||||||
-H "Content-Type:multipart/form-data" \
|
-H "Content-Type:multipart/form-data" \
|
||||||
$telegramapiurl/sendMediaGroup)
|
"${telegramapiurl}/sendMediaGroup")
|
||||||
fi
|
fi
|
||||||
### WORDPRESS UPDATE PAGE
|
|
||||||
if [ ! "$only" == "--onlytg" ];then
|
# WORDPRESS UPDATE PAGE
|
||||||
|
if [ ! "${only}" == "--onlytg" ]; then
|
||||||
setconfig
|
setconfig
|
||||||
getconfig
|
getconfig
|
||||||
xml=$(cat ./${wptemplateis})
|
xml=$(cat "./${wptemplateis}")
|
||||||
|
|
||||||
xml=${xml//wpeditpageid/${wpeditpageid}}
|
xml=${xml//wpeditpageid/${wpeditpageid}}
|
||||||
xml=${xml//wpxmlrpcuser/${wpxmlrpcuser}}
|
xml=${xml//wpxmlrpcuser/${wpxmlrpcuser}}
|
||||||
|
@ -514,12 +588,12 @@ if [ ! "$only" == "--onlytg" ];then
|
||||||
xml=${xml//wppagelinkis/${wppagelinkis}}
|
xml=${xml//wppagelinkis/${wppagelinkis}}
|
||||||
xml=${xml//wpeditdateis/${wpeditdateis}}
|
xml=${xml//wpeditdateis/${wpeditdateis}}
|
||||||
|
|
||||||
response=$(curl -d "$xml" $wpxmlrpclink)
|
response=$(curl -d "${xml}" "${wpxmlrpclink}")
|
||||||
if echo "$response" | grep -q '<boolean>1</boolean>';then
|
if echo "${response}" | grep -q '<boolean>1</boolean>'; then
|
||||||
addtologs "update $(echo "$xml" | grep 'Link' | cut -d'>' -f 6 | cut -d'<' -f 1))"
|
addtologs "update $(grep 'Link' "${xml}" | cut -d'>' -f 6 | cut -d'<' -f 1))"
|
||||||
else
|
else
|
||||||
echo $response | xmllint --format - > $pathroot/wp-page${wpeditpageid}-response.xml 2>/dev/null
|
echo "${response}" | xmllint --format - > "${pathroot}/wp-page${wpeditpageid}-response.xml" 2>/dev/null
|
||||||
execerror "$pathroot/wp-page${wpeditpageid}-response.xml"
|
execerror "${pathroot}/wp-page${wpeditpageid}-response.xml"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
execquite
|
execquite
|
|
@ -9,6 +9,7 @@ ftpuser=user
|
||||||
ftppass=pass
|
ftppass=pass
|
||||||
ftpaddr=192.168.254.254
|
ftpaddr=192.168.254.254
|
||||||
ftpport=21
|
ftpport=21
|
||||||
|
ftppath=Records/cam.test.local
|
||||||
|
|
||||||
tmpuser=user
|
tmpuser=user
|
||||||
tmppass=pass
|
tmppass=pass
|
||||||
|
|
295
sequences.sh
295
sequences.sh
|
@ -1,137 +1,291 @@
|
||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
#
|
# DESCRIPTION:
|
||||||
## DESCRIPTION:
|
# Handling Hikvision PTZ-cameras sequences.
|
||||||
# Hikvision PTZ-camera sequences.
|
|
||||||
# Additionally:
|
# Additionally:
|
||||||
# - getting temperature from ds-18b20 over SSH,
|
# - get ds18b20 sensor value over SSH,
|
||||||
# - saving pictures to FTP.
|
# - saving pictures to FTP.
|
||||||
# This is only a local "proof of conept" for testing and debugging.
|
# This is only a local "proof of conept" for testing and debugging.
|
||||||
#
|
#
|
||||||
|
# DEPENDENCIES:
|
||||||
|
# - curl
|
||||||
|
# - sshpass
|
||||||
#
|
#
|
||||||
## DEPENDENCIES: sudo apt|yum install -y curl sshpass
|
# PARAMETERS:
|
||||||
#
|
# 1: "qn" - execution without pauses
|
||||||
|
# 2: custom configuration file path
|
||||||
#
|
#
|
||||||
## FUNCTIONS
|
# FUNCTIONS:
|
||||||
#
|
#
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Print message and add to log.
|
||||||
|
# Globals:
|
||||||
|
# logs
|
||||||
|
# Arguments:
|
||||||
|
# 1: message to print and logging
|
||||||
|
#######################################
|
||||||
addtologs() {
|
addtologs() {
|
||||||
echo "$(date +'%Y.%m.%d-%H:%M:%S') $1" | tee -a $logs
|
echo "$(date +'%Y.%m.%d-%H:%M:%S') $1" | tee -a "${logs}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Waiting for press [ENTER].
|
||||||
|
# Globals:
|
||||||
|
# None
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
execpause() {
|
execpause() {
|
||||||
read -p "Press [ENTER] to continue... "
|
read -r -p "Press [ENTER] to continue... "
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Exit procedure.
|
||||||
|
# Globals:
|
||||||
|
# show
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
execquite() {
|
execquite() {
|
||||||
addtologs "execution time is $(($(date +%s)-$time)) seconds, exit"
|
addtologs "execution time is $(($(date +%s)-time)) seconds, exit"
|
||||||
if [ "${show}" != "qn" ];then
|
if [ "${show}" != "qn" ]; then
|
||||||
execpause
|
execpause
|
||||||
fi
|
fi
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Error exit procedure with Telegram notification.
|
||||||
|
# Globals:
|
||||||
|
# telegramapiurl
|
||||||
|
# telegramchatid
|
||||||
|
# Arguments:
|
||||||
|
# 1: message to print and logging
|
||||||
|
#######################################
|
||||||
execerror() {
|
execerror() {
|
||||||
addtologs "error: $1"
|
addtologs "error: $1"
|
||||||
curl -s -X POST $telegramapiurl/sendMessage -d chat_id=$telegramchatid -d text="$(basename -s .sh $0) error: $1" >> /dev/null 2>&1
|
curl -s -X POST "${telegramapiurl}/sendMessage" \
|
||||||
|
-d "chat_id=${telegramchatid}" \
|
||||||
|
-d "text=$(basename -s .sh "$0") error: $1" \
|
||||||
|
>> /dev/null 2>&1
|
||||||
execquite
|
execquite
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Parsing config file and creating global vars.
|
||||||
|
# Globals:
|
||||||
|
# None
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
getconfig() {
|
getconfig() {
|
||||||
logs=$(cat $conf | grep "logs=" | cut -d= -f2)
|
logs=$(grep "logs=" "${conf}" | cut -d= -f2)
|
||||||
camuser=$(cat $conf | grep "camuser=" | cut -d= -f2)
|
camuser=$(grep "camuser=" "${conf}" | cut -d= -f2)
|
||||||
campass=$(cat $conf | grep "campass=" | cut -d= -f2)
|
campass=$(grep "campass=" "${conf}" | cut -d= -f2)
|
||||||
camaddr=$(cat $conf | grep "camaddr=" | cut -d= -f2)
|
camaddr=$(grep "camaddr=" "${conf}" | cut -d= -f2)
|
||||||
camport=$(cat $conf | grep "camport=" | cut -d= -f2)
|
camport=$(grep "camport=" "${conf}" | cut -d= -f2)
|
||||||
ftpuser=$(cat $conf | grep "ftpuser=" | cut -d= -f2)
|
ftpuser=$(grep "ftpuser=" "${conf}" | cut -d= -f2)
|
||||||
ftppass=$(cat $conf | grep "ftppass=" | cut -d= -f2)
|
ftppass=$(grep "ftppass=" "${conf}" | cut -d= -f2)
|
||||||
ftpaddr=$(cat $conf | grep "ftpaddr=" | cut -d= -f2)
|
ftpaddr=$(grep "ftpaddr=" "${conf}" | cut -d= -f2)
|
||||||
ftpport=$(cat $conf | grep "ftpport=" | cut -d= -f2)
|
ftpport=$(grep "ftpport=" "${conf}" | cut -d= -f2)
|
||||||
tmpuser=$(cat $conf | grep "tmpuser=" | cut -d= -f2)
|
ftppath=$(grep "ftppath=" "${conf}" | cut -d= -f2)
|
||||||
tmppass=$(cat $conf | grep "tmppass=" | cut -d= -f2)
|
tmpuser=$(grep "tmpuser=" "${conf}" | cut -d= -f2)
|
||||||
tmpaddr=$(cat $conf | grep "tmpaddr=" | cut -d= -f2)
|
tmppass=$(grep "tmppass=" "${conf}" | cut -d= -f2)
|
||||||
tmpport=$(cat $conf | grep "tmpport=" | cut -d= -f2)
|
tmpaddr=$(grep "tmpaddr=" "${conf}" | cut -d= -f2)
|
||||||
tmpnode=$(cat $conf | grep "tmpnode=" | cut -d= -f2)
|
tmpport=$(grep "tmpport=" "${conf}" | cut -d= -f2)
|
||||||
telegramapiurl=$(cat $conf | grep "telegramapiurl=" | cut -d= -f2)
|
tmpnode=$(grep "tmpnode=" "${conf}" | cut -d= -f2)
|
||||||
telegramchatid=$(cat $conf | grep "telegramchatid=" | cut -d= -f2)
|
telegramapiurl=$(grep "telegramapiurl=" "${conf}" | cut -d= -f2)
|
||||||
|
telegramchatid=$(grep "telegramchatid=" "${conf}" | cut -d= -f2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Get ds18b20 sensor value over SSH.
|
||||||
|
# Globals:
|
||||||
|
# tmpaddr
|
||||||
|
# tmpport
|
||||||
|
# tmpuser
|
||||||
|
# tmppass
|
||||||
|
# tmpnode
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
# return:
|
||||||
|
# temperature in Celsius
|
||||||
|
#######################################
|
||||||
getairtmp() {
|
getairtmp() {
|
||||||
local temp=$( \
|
temp=$(sshpass -p "${tmppass}" \
|
||||||
sshpass -p $tmppass ssh $tmpuser@$tmpaddr -p $tmpport -o StrictHostKeyChecking=no -o ConnectTimeout=10 \
|
ssh "${tmpuser}@${tmpaddr}" -p "${tmpport}" \
|
||||||
"cat /sys/bus/w1/devices/$tmpnode/temperature" \
|
-o StrictHostKeyChecking=no -o ConnectTimeout=10 \
|
||||||
) && temp=$(($temp / 1000))
|
"cat /sys/bus/w1/devices/${tmpnode}/temperature" \
|
||||||
if [ ! -z "${temp}" ]; then
|
) && temp=$((temp / 1000))
|
||||||
addtologs "air temperature now is $temp'C" > /dev/null
|
if [ -n "${temp}" ]; then
|
||||||
echo $temp
|
addtologs "getairtmp: air temperature now is ${temp}'C" > /dev/null
|
||||||
|
echo "${temp}"
|
||||||
else
|
else
|
||||||
execerror "air temperature now is $temp'C"
|
execerror "getairtmp: air temperature now is ${temp}'C"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Get static picture from camera and upload to FTP.
|
||||||
|
# Globals:
|
||||||
|
# camaddr
|
||||||
|
# camport
|
||||||
|
# camuser
|
||||||
|
# campass
|
||||||
|
# ftpaddr
|
||||||
|
# ftpport
|
||||||
|
# ftppath
|
||||||
|
# ftpuser
|
||||||
|
# ftppass
|
||||||
|
# Arguments:
|
||||||
|
# 1: filename prefix
|
||||||
|
#######################################
|
||||||
getcamimg() {
|
getcamimg() {
|
||||||
local name=$1
|
local name
|
||||||
local file="$ftpaddr:$ftpport/Records/cam-street.home.local/$(date +"%Y")/$(date +"%m")/$(date +"%V")/$(date +"%d")/${name}_$(date +"%Y.%m.%d_%H-%M-%S").jpeg"
|
name=$1
|
||||||
url='/Streaming/channels/101/picture?snapShotImageType=JPEG&videoResolutionWidth=1920&videoResolutionHeight=1080'
|
path="${ftppath}/$(date +"%Y")/$(date +"%m")/$(date +"%V")/$(date +"%d")"
|
||||||
curl -vs "http://$camuser:$campass@$camaddr:$camport/$url" -o tmp \
|
file="${ftpaddr}:${ftpport}/${path}/${name}_$(date +"%Y.%m.%d_%H-%M-%S").jpeg"
|
||||||
&& curl -T tmp "ftp://$ftpuser:$ftppass@$file" --ftp-create-dirs \
|
url='Streaming/channels/101/picture?snapShotImageType=JPEG&videoResolutionWidth=1920&videoResolutionHeight=1080'
|
||||||
&& rm tmp && addtologs "save photo to ftp://$file" || execerror "save photo to ftp://$file"
|
if curl -vs "http://$camuser:$campass@$camaddr:$camport/$url" -o tmp \
|
||||||
|
&& curl -T tmp "ftp://$ftpuser:$ftppass@$file" --ftp-create-dirs; then
|
||||||
|
addtologs "getcamimg: save photo to ftp://${file}"
|
||||||
|
rm tmp
|
||||||
|
else
|
||||||
|
execerror "getcamimg: save photo to ftp://${file}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Set message as video overlay text.
|
||||||
|
# Globals:
|
||||||
|
# camaddr
|
||||||
|
# camport
|
||||||
|
# camuser
|
||||||
|
# campass
|
||||||
|
# Arguments:
|
||||||
|
# 1: overlay text content
|
||||||
|
#######################################
|
||||||
setcamtxt() {
|
setcamtxt() {
|
||||||
local message=$1
|
local message=$1
|
||||||
url='/Video/inputs/channels/101/overlays/text'
|
url='ISAPI/System/Video/inputs/channels/101/overlays/text'
|
||||||
xml='<TextOverlayList><TextOverlay><id>1</id><enabled>true</enabled><posX>0</posX><posY>0</posY><message>'"${message}"'</message></TextOverlay></TextOverlayList>'
|
xml='<TextOverlayList>
|
||||||
curl -d "$xml" -X PUT "http://$camuser:$campass@$camaddr:$camport/$url" && addtologs "text on video is $message" && sleep 5 || execerror "text on video is $message"
|
<TextOverlay>
|
||||||
|
<id>1</id>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
<posX>0</posX><posY>0</posY>
|
||||||
|
<displayText>'"${message}"'</displayText>
|
||||||
|
</TextOverlay>
|
||||||
|
</TextOverlayList>'
|
||||||
|
if curl -d "${xml}" -X PUT "http://$camuser:$campass@$camaddr:$camport/$url" \
|
||||||
|
| grep -q '<statusString>OK</statusString>'; then
|
||||||
|
addtologs "setcamtxt: ${message}"
|
||||||
|
sleep 5
|
||||||
|
else
|
||||||
|
execerror "setcamtxt: ${message}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Set camera moving to absolute position.
|
||||||
|
# Globals:
|
||||||
|
# camaddr
|
||||||
|
# camport
|
||||||
|
# camuser
|
||||||
|
# campass
|
||||||
|
# Arguments:
|
||||||
|
# 1: horisontal camera position from 0 to 3600
|
||||||
|
# 2: vertical camera position from -900 to 2700
|
||||||
|
# 3: zoom camera position from 0 to 1000
|
||||||
|
# 4: time to wait
|
||||||
|
# 5: message to print and logging
|
||||||
|
#######################################
|
||||||
setcampos() {
|
setcampos() {
|
||||||
local x=$1
|
local x=$1
|
||||||
local y=$2
|
local y=$2
|
||||||
local z=$3
|
local z=$3
|
||||||
local t=$4
|
local t=$4
|
||||||
local message=$5
|
local message=$5
|
||||||
url='/ISAPI/PTZCtrl/channels/101/absolute'
|
url='ISAPI/PTZCtrl/channels/101/absolute'
|
||||||
xml='<PTZData><AbsoluteHigh><elevation>'"${y}"'</elevation><azimuth>'"${x}"'</azimuth><absoluteZoom>'"${z}"'</absoluteZoom></AbsoluteHigh></PTZData>'
|
xml='<PTZData>
|
||||||
curl -d "$xml" -X PUT "http://$camuser:$campass@$camaddr:$camport/$url" && addtologs "$message" && sleep $t || execerror "$message"
|
<AbsoluteHigh>
|
||||||
|
<elevation>'"${y}"'</elevation>
|
||||||
|
<azimuth>'"${x}"'</azimuth>
|
||||||
|
<absoluteZoom>'"${z}"'</absoluteZoom>
|
||||||
|
</AbsoluteHigh>
|
||||||
|
</PTZData>'
|
||||||
|
if curl -d "${xml}" -X PUT "http://$camuser:$campass@$camaddr:$camport/$url" \
|
||||||
|
| grep -q '<statusString>OK</statusString>'; then
|
||||||
|
addtologs "setcampos: ${message}"
|
||||||
|
sleep "${t}"
|
||||||
|
else
|
||||||
|
execerror "setcampos: ${message}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Set camera moving to direction.
|
||||||
|
# Globals:
|
||||||
|
# camaddr
|
||||||
|
# camport
|
||||||
|
# camuser
|
||||||
|
# campass
|
||||||
|
# Arguments:
|
||||||
|
# 1: acceleration of horizontal camera movement from -100 to 100
|
||||||
|
# 2: acceleration of vertical camera movement from -100 to 100
|
||||||
|
# 3: acceleration of zoom camera movement from -100 to 100
|
||||||
|
# 4: time to wait
|
||||||
|
# 5: message to print and logging
|
||||||
|
#######################################
|
||||||
setcammov() {
|
setcammov() {
|
||||||
local x=$1
|
local x=$1
|
||||||
local y=$2
|
local y=$2
|
||||||
local z=$3
|
local z=$3
|
||||||
local t=$4
|
local t=$4
|
||||||
local message=$5
|
local message=$5
|
||||||
url='/ISAPI/PTZCtrl/channels/101/continuous'
|
url='ISAPI/PTZCtrl/channels/101/continuous'
|
||||||
xml='<PTZData><pan>'"${x}"'</pan><tilt>'"${y}"'</tilt><zoom>'"${z}"'</zoom></PTZData>'
|
xml='<PTZData>
|
||||||
curl -d "$xml" -X PUT "http://$camuser:$campass@$camaddr:$camport/$url" && addtologs "$message" && sleep $t || execerror "$message"
|
<pan>'"${x}"'</pan>
|
||||||
|
<tilt>'"${y}"'</tilt>
|
||||||
|
<zoom>'"${z}"'</zoom>
|
||||||
|
</PTZData>'
|
||||||
|
if curl -d "${xml}" -X PUT "http://$camuser:$campass@$camaddr:$camport/$url" \
|
||||||
|
| grep -q '<statusString>OK</statusString>'; then
|
||||||
|
addtologs "setcammov: ${message}"
|
||||||
|
sleep "${t}"
|
||||||
|
else
|
||||||
|
execerror "setcammov: ${message}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
## PARAMETERS
|
## VARIABLES:
|
||||||
#
|
#
|
||||||
|
|
||||||
show=${1}
|
show=$1
|
||||||
conf=${2}
|
conf=$2
|
||||||
if [ -z "${conf}" ] || [ "${conf}" == "-" ];then
|
if [ -z "${conf}" ] || [ "${conf}" == "-" ]; then
|
||||||
conf="$(dirname $(realpath "$0"))/$(basename -s .sh $0).conf"
|
conf="$(dirname "$(realpath "$0")")/$(basename -s .sh "$0").conf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
|
||||||
## VARIABLES
|
|
||||||
#
|
|
||||||
|
|
||||||
time=$(date +%s)
|
time=$(date +%s)
|
||||||
cd "$(dirname "$(realpath "$0")")"
|
cd "$(dirname "$(realpath "$0")")" || execerror
|
||||||
if [ ! -e ${conf} ];then
|
if [ ! -e "${conf}" ]; then
|
||||||
execerror "Not found config file: ${conf}"
|
execerror "Not found config file: ${conf}"
|
||||||
else
|
else
|
||||||
getconfig
|
getconfig
|
||||||
fi
|
fi
|
||||||
if [ -z "${logs}" ];then
|
if [ -z "${logs}" ];then
|
||||||
logs=/dev/null
|
logs=/dev/null
|
||||||
elif [ ! -e ${logs} ];then
|
elif [ ! -e "${logs}" ];then
|
||||||
touch ${logs}
|
touch "${logs}"
|
||||||
fi
|
fi
|
||||||
if ! command -v curl &> /dev/null || ! command -v sshpass &> /dev/null; then
|
if ! command -v curl &> /dev/null || ! command -v sshpass &> /dev/null; then
|
||||||
execerror "Not found dependencies"
|
execerror "Not found dependencies"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
## RUN
|
# MAIN:
|
||||||
#
|
#
|
||||||
|
|
||||||
setcamtxt "$(getairtmp)'C"
|
setcamtxt "$(getairtmp)'C"
|
||||||
|
@ -162,12 +316,13 @@ sleep 4m
|
||||||
setcammov 0 -44 33 1.50s '08 >> 09 Точка - Стадион 8x'
|
setcammov 0 -44 33 1.50s '08 >> 09 Точка - Стадион 8x'
|
||||||
setcampos 2860 -170 80 5.00s '08 >| 09 Точка - Стадион 8x'
|
setcampos 2860 -170 80 5.00s '08 >| 09 Точка - Стадион 8x'
|
||||||
sleep 1m
|
sleep 1m
|
||||||
|
setcammov 0 -99 0 7.50s '09 >> 10 Точка - Въезд во двор 8x'
|
||||||
setcampos 2805 200 80 5.00s '09 >| 10 Точка - Въезд во двор 8x'
|
setcampos 2805 200 80 5.00s '09 >| 10 Точка - Въезд во двор 8x'
|
||||||
sleep 5m
|
sleep 5m
|
||||||
setcammov -88 99 0 5.00s '10 >> 11 Точка - Бассейн 8x'
|
setcammov -88 99 0 5.00s '10 >> 11 Точка - Бассейн 8x'
|
||||||
setcammov -99 88 0 2.00s '10 >> 11 Точка - Бассейн 8x'
|
setcammov -99 88 0 2.00s '10 >> 11 Точка - Бассейн 8x'
|
||||||
setcammov -44 99 0 4.25s '10 >> 11 Точка - Бассейн 8x'
|
setcammov -44 99 0 4.25s '10 >> 11 Точка - Бассейн 8x'
|
||||||
setcampos 2510 -100 80 5.00s '10 >| 11 Точка - Бассейн 8x'
|
setcampos 2510 -20 80 5.00s '10 >| 11 Точка - Бассейн 8x'
|
||||||
sleep 1m
|
sleep 1m
|
||||||
setcammov -88 99 33 2.50s '11 >> 12 Точка - Общежитие дальнее 16x'
|
setcammov -88 99 33 2.50s '11 >> 12 Точка - Общежитие дальнее 16x'
|
||||||
setcampos 2415 -200 160 5.00s '11 >| 12 Точка - Общежитие дальнее 16x'
|
setcampos 2415 -200 160 5.00s '11 >| 12 Точка - Общежитие дальнее 16x'
|
||||||
|
@ -176,7 +331,7 @@ setcammov 66 0 0 22.5s '12 >> 13 Точка - Общ
|
||||||
setcampos 2640 -200 160 5.00s '12 >| 13 Точка - Общежите ближнее 16x'
|
setcampos 2640 -200 160 5.00s '12 >| 13 Точка - Общежите ближнее 16x'
|
||||||
sleep 1m
|
sleep 1m
|
||||||
setcammov 66 0 0 90.5s '13 >> 14 Точка - Крыша магазина 4x'
|
setcammov 66 0 0 90.5s '13 >> 14 Точка - Крыша магазина 4x'
|
||||||
setcammov 99 0 -33 3.25s '13 >> 14 Точка - Крыша магазина 4x'
|
setcammov 99 0 -44 3.25s '13 >> 14 Точка - Крыша магазина 4x'
|
||||||
setcampos 335 -200 40 5.00s '13 >| 14 Точка - Крыша магазина 4x'
|
setcampos 335 -200 40 5.00s '13 >| 14 Точка - Крыша магазина 4x'
|
||||||
sleep 1m
|
sleep 1m
|
||||||
setcamtxt '' && getcamimg 'point-11' && setcamtxt "$(getairtmp)'C"
|
setcamtxt '' && getcamimg 'point-11' && setcamtxt "$(getairtmp)'C"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user