Compare commits
295 Commits
v1.3-beta3
...
master
Author | SHA1 | Date |
---|---|---|
|
f02cbfdc92 | |
|
6c6b2e5b12 | |
|
7a6cb155cc | |
|
266fa0d97f | |
|
a566549875 | |
|
bc1878bf7f | |
|
59d99823e4 | |
|
c5ef7a916e | |
|
f0d9cfcf35 | |
|
548f3c5730 | |
|
f094fb0481 | |
|
b1e08fe947 | |
|
3a9accaea0 | |
|
6a717859b8 | |
|
6d13e3976a | |
|
0d00fa8ab9 | |
|
05e594e101 | |
|
639055bf00 | |
|
35afd1af8a | |
|
09225de945 | |
|
99d01b2ed0 | |
|
e34ebfd4cd | |
|
7aeb2e3b69 | |
|
51e79cb56a | |
|
2ce2561f99 | |
|
88e1f3f4f6 | |
|
b1a0510a0e | |
|
b3d723ad07 | |
|
ed2e8438d2 | |
|
f2ff318f46 | |
|
f889eb99e8 | |
|
737008d662 | |
|
19dbdeb28a | |
|
f39fb6613e | |
|
f6fd288cfa | |
|
63cbe3786e | |
|
98a4d6bb0c | |
|
e47c1d7f58 | |
|
cef25b646f | |
|
4054f3ca75 | |
|
ea1b3b379e | |
|
988009a438 | |
|
b2f221cb86 | |
|
c4349bc945 | |
|
99f107fcb0 | |
|
776c07386d | |
|
edfc292486 | |
|
9ade468ed8 | |
|
d9e22b06e5 | |
|
d0af0804a0 | |
|
9b9c1105eb | |
|
9b862ae49d | |
|
57ef919364 | |
|
833c16ca43 | |
|
83a0f5c328 | |
|
5a7455173c | |
|
edd35d42aa | |
|
50f975d2df | |
|
43e1aaaaa1 | |
|
b15e8e8f88 | |
|
91950446f0 | |
|
0ef4af40dc | |
|
6b6f723094 | |
|
d100841bd9 | |
|
52a42bc1d7 | |
|
30d66003ef | |
|
b95e75aa0b | |
|
8ef2262421 | |
|
fa7f6d1088 | |
|
5f4e7af910 | |
|
a9da549e4f | |
|
4bf065f94e | |
|
912906ef8c | |
|
77cbcd97d9 | |
|
5beb9220d1 | |
|
53193aceb6 | |
|
4d08791d04 | |
|
01769189b7 | |
|
9dd69349ad | |
|
ef0cd58d49 | |
|
d8915512ea | |
|
9fa4c45b6c | |
|
22e269902b | |
|
edaeb9a400 | |
|
f646fffc79 | |
|
ce4b435eb2 | |
|
e395e8ca65 | |
|
60ceccfff1 | |
|
cf78875ab5 | |
|
059f95d4a8 | |
|
9edeb39d45 | |
|
55c4cffcf0 | |
|
59bd176e48 | |
|
7da01328b2 | |
|
36db883ab0 | |
|
632db7d9a2 | |
|
999aeed303 | |
|
a83f76c639 | |
|
663b5be3be | |
|
898fcbb8c1 | |
|
ecc4c1d396 | |
|
89f8533c27 | |
|
7168aa9d02 | |
|
9245030a9d | |
|
a1f8773953 | |
|
35a71ad517 | |
|
e01d8c410b | |
|
4e44020619 | |
|
f2761d6a42 | |
|
f48ff41072 | |
|
08759b895c | |
|
508cd4bf50 | |
|
87dd5d07ea | |
|
134acff3a9 | |
|
c091996231 | |
|
a7e1b4505b | |
|
803d25ac8b | |
|
a36fd05069 | |
|
96c26e2791 | |
|
f74108ed4a | |
|
27866f1db5 | |
|
904105904e | |
|
c2efdb2063 | |
|
edcfe337c3 | |
|
56c8fa868a | |
|
3c1eb0989e | |
|
2bc8e899d7 | |
|
9a8b028c96 | |
|
e5922f04a5 | |
|
11e19108f5 | |
|
4076423d98 | |
|
536f8ce6f0 | |
|
88c74dda70 | |
|
2ebd22c441 | |
|
ca822566d4 | |
|
009a4aabe0 | |
|
cc21cc6acc | |
|
81437b5824 | |
|
45304c608c | |
|
8451024ae2 | |
|
5ea103b36b | |
|
f2be25f83d | |
|
5852d76cd3 | |
|
67dc58f3b5 | |
|
b589c32ce7 | |
|
8e4e745420 | |
|
f9694d6478 | |
|
ea0ca4e4c2 | |
|
3c0f0b542d | |
|
179bf6281e | |
|
f5403bd13a | |
|
5870003c73 | |
|
7ed547786f | |
|
747e9c710e | |
|
7a7653957e | |
|
ad7d022dcf | |
|
e6088c88de | |
|
347f9a9ae8 | |
|
7577f220dc | |
|
acf388bc7b | |
|
5881c71212 | |
|
60f2005209 | |
|
7688317bd1 | |
|
e997493fb5 | |
|
be3fc2e848 | |
|
844e08f92f | |
|
38190c6139 | |
|
45a8a7a589 | |
|
3a9d00ff4f | |
|
7bc80b9574 | |
|
a912a7d7c3 | |
|
1c7d21c485 | |
|
51a4c8bcce | |
|
fbce80bc0a | |
|
6edce242b0 | |
|
8788582f63 | |
|
cc4ce385ee | |
|
98c1b97fb0 | |
|
17e2bf6dce | |
|
c2fef97c84 | |
|
eaeb218508 | |
|
a9cb30ffb4 | |
|
08ab938477 | |
|
5e71ed0854 | |
|
f5356ea702 | |
|
10adfe6128 | |
|
572a055901 | |
|
45915611f6 | |
|
e4970830ac | |
|
b6181e15d9 | |
|
b8cfce2eb8 | |
|
d8bdf2d721 | |
|
e4d52aec2f | |
|
a4b03b12e2 | |
|
bf86cc5f6f | |
|
39a8a309f5 | |
|
97fb53f6de | |
|
314505eb4a | |
|
fb57fb9d74 | |
|
689928eac1 | |
|
42c7493ef0 | |
|
6139fa002b | |
|
a48f4a85e6 | |
|
cbff578ec5 | |
|
dc901282dc | |
|
08372e74ba | |
|
7d8978dc88 | |
|
925adbd488 | |
|
e0b2f0435e | |
|
cb7dbbe2af | |
|
3d94544337 | |
|
8197ea3ddb | |
|
78323cc06a | |
|
ba830fe7d0 | |
|
87dd470344 | |
|
2c45d58659 | |
|
4d4728b90c | |
|
22538907b3 | |
|
f3365ed5ff | |
|
145814f231 | |
|
21bd1657ec | |
|
6be95a3cff | |
|
a7526c8a87 | |
|
8b757bf083 | |
|
be1281ffa3 | |
|
bdc9e42046 | |
|
d66ea211d5 | |
|
da5140d3f0 | |
|
d37872c730 | |
|
997a7904ed | |
|
712c3179ee | |
|
0d28d0c482 | |
|
f22cff5a49 | |
|
7fb8eb7004 | |
|
afdc5334f4 | |
|
c02a7af424 | |
|
17a97d129b | |
|
183ca45b63 | |
|
31986d0d19 | |
|
bf3b846026 | |
|
7d137ed0c5 | |
|
723501526c | |
|
2f4384d911 | |
|
8f2b22a117 | |
|
5f6f7482dd | |
|
f0ea6df5ea | |
|
4df4c594b7 | |
|
08910b3895 | |
|
21c59cfd27 | |
|
151cfb8d39 | |
|
3b545648ac | |
|
0ae3a0c629 | |
|
9c7ef090f1 | |
|
b124f7dfaf | |
|
f87b529195 | |
|
3cddb9b97e | |
|
80f3b2f0bc | |
|
31b8ce4c52 | |
|
f81291c0eb | |
|
59ec9e42c1 | |
|
9cfa13c59a | |
|
ca78d76bb2 | |
|
b0b91a4db0 | |
|
8d9e95c6cd | |
|
154318be0f | |
|
ddb820d2fa | |
|
dce4092085 | |
|
219067be26 | |
|
8f85d20a68 | |
|
492064f8e2 | |
|
32ee9f8071 | |
|
33971c359c | |
|
d9d5aaf1e8 | |
|
bd25ef4b72 | |
|
2b17326630 | |
|
228a4d1f51 | |
|
679b4bc29e | |
|
f1b558d646 | |
|
c8bb8c214f | |
|
c801d6b418 | |
|
0b539e6153 | |
|
8256bbef88 | |
|
b3a7572c0e | |
|
9976b3a6e5 | |
|
bcd79e06aa | |
|
6459a9dd4c | |
|
9b481467f6 | |
|
72f2e43071 | |
|
a6e4c4a0ee | |
|
b4892b9fdc | |
|
63f6194305 | |
|
3dae261b9b | |
|
c6876924c7 | |
|
0c343662f4 | |
|
f4130119ef |
|
@ -9,18 +9,22 @@ A clear and concise description of what the bug is.
|
||||||
|
|
||||||
**To Reproduce**
|
**To Reproduce**
|
||||||
Steps to reproduce the behavior:
|
Steps to reproduce the behavior:
|
||||||
1. Setup osync with the following config file / the following parameters
|
1. Setup osync with the following config file / the following parameters (please provide either anonymized)
|
||||||
2. Run osync with following parameters
|
2. Run osync with following parameters
|
||||||
3. Result
|
3. Result
|
||||||
|
|
||||||
**Expected behavior**
|
**Expected behavior**
|
||||||
A clear and concise description of what you expected to happen.
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
** Deviated behavior**
|
||||||
|
How does the actual result deviate from the expected behavior.
|
||||||
|
|
||||||
**Logs**
|
**Logs**
|
||||||
Please send logs of what happens.
|
Please send logs of what happens.
|
||||||
Also, you might run osync with _DEBUG=yes environement variable to have more verbose debug logs.
|
Also, you might run osync with _DEBUG=yes environement variable to have more verbose debug logs.
|
||||||
|
|
||||||
**Desktop (please complete the following information):**
|
**Environment (please complete the following information):**
|
||||||
|
- Full osync version (including build)
|
||||||
- OS: [e.g. iOS]
|
- OS: [e.g. iOS]
|
||||||
- Bitness [e.g. x64 or x86]
|
- Bitness [e.g. x64 or x86]
|
||||||
- Shell (busybox or else)
|
- Shell (busybox or else)
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
# Codespell configuration is within .codespellrc
|
||||||
|
---
|
||||||
|
name: Codespell
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
codespell:
|
||||||
|
name: Check for spelling errors
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Annotate locations with typos
|
||||||
|
uses: codespell-project/codespell-problem-matcher@v1
|
||||||
|
- name: Codespell
|
||||||
|
uses: codespell-project/actions-codespell@v2
|
|
@ -0,0 +1,25 @@
|
||||||
|
name: linux-tests
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get install inotify-tools acl
|
||||||
|
- name: Execute tests and generate coverage report
|
||||||
|
run: |
|
||||||
|
export RUNNING_ON_GITHUB_ACTIONS=true
|
||||||
|
export SSH_PORT=22
|
||||||
|
echo "Running on github actions: ${RUNNING_ON_GITHUB_ACTIONS}"
|
||||||
|
echo "Running on ssh port ${SSH_PORT}"
|
||||||
|
sudo -E bash ./dev/tests/run_tests.sh
|
||||||
|
- name: Upload Coverage to Codecov
|
||||||
|
uses: codecov/codecov-action@v1
|
|
@ -0,0 +1,28 @@
|
||||||
|
name: macosx-tests
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [macos-latest]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Install Bash 4
|
||||||
|
run: |
|
||||||
|
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||||
|
brew update
|
||||||
|
|
||||||
|
brew install bash
|
||||||
|
brew install fswatch
|
||||||
|
echo "/usr/local/bin" >> $GITHUB_PATH
|
||||||
|
- name: Execute tests and generate coverage report
|
||||||
|
run: |
|
||||||
|
export RUNNING_ON_GITHUB_ACTIONS=true
|
||||||
|
export SSH_PORT=22
|
||||||
|
sudo -E bash ./dev/tests/run_tests.sh
|
||||||
|
- name: Upload Coverage to Codecov
|
||||||
|
uses: codecov/codecov-action@v1
|
|
@ -0,0 +1,29 @@
|
||||||
|
name: windows-tests
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [windows-latest]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: Vampire/setup-wsl@v1
|
||||||
|
with:
|
||||||
|
additional-packages:
|
||||||
|
dos2unix
|
||||||
|
rsync
|
||||||
|
openssh-server
|
||||||
|
- name: Execute tests and generate coverage report
|
||||||
|
shell: wsl-bash {0}
|
||||||
|
run: |
|
||||||
|
export RUNNING_ON_GITHUB_ACTIONS=true
|
||||||
|
export SSH_PORT=22
|
||||||
|
find ./ -type f ! -path "./.git/*" -print0 | xargs -0 -n 1 -P 4 dos2unix
|
||||||
|
service ssh start
|
||||||
|
./dev/tests/run_tests.sh
|
||||||
|
- name: Upload Coverage to Codecov
|
||||||
|
uses: codecov/codecov-action@v1
|
|
@ -1,17 +1,42 @@
|
||||||
RECENT CHANGES
|
## RECENT CHANGES
|
||||||
--------------
|
|
||||||
|
|
||||||
dd Mmm YYYY: dev
|
### Current master
|
||||||
- --log-conflicts
|
|
||||||
|
|
||||||
dd Mmm YYYY: osync v1.3 release (for full changelog since v1.2 branch see all v1.3-beta/RC entries)
|
- Make --log-conflicts non experimental (randomly fails)
|
||||||
|
|
||||||
dd Mmm YYYY: osync v1.3-RC1 release
|
|
||||||
- ! new option FORCE_CONFLICT_PREVALANCE which will always use Initiator or Target, regardless of best time
|
- ! new option FORCE_CONFLICT_PREVALANCE which will always use Initiator or Target, regardless of best time
|
||||||
- ! target-helper: destination mails etc on target, also, no cmd after on configs
|
- ! target-helper: destination mails etc on target, also, no cmd after on configs
|
||||||
|
|
||||||
|
### 16 June 2023: osync v1.3 release (for full changelog since v1.2 branch see all v1.3-beta/RC entries)
|
||||||
|
|
||||||
20 May 2019: osync v1.3-beta2 release
|
- Fix for new RSYNC protocol
|
||||||
|
- New options ALWAYS_SEND_MAILS to allow sending logs regardless of execution states
|
||||||
|
|
||||||
|
### 29 June 2020: osync v1.3-RC1 release
|
||||||
|
|
||||||
|
- New option to use SSH_CONTROLMASTER in order to speed up remote sync tasks and preserve a single ssh channel
|
||||||
|
- New option SSH_OPTIONAL_ARGS
|
||||||
|
- Fixed a problem with macos mv not preserving ownership of files from /tmp
|
||||||
|
- Fixed very long outstanding issue with special characters in remote target handling
|
||||||
|
- Fixed an issue where STOP_ON_ERROR_CMD did not work anymore
|
||||||
|
- Fixed a remote file lock problem (thanks to https://github.com/zhangzhishan)
|
||||||
|
- Fixed various cosmetic issues with code and logs
|
||||||
|
- Improved upgrade script
|
||||||
|
- Fixed a possible bash buffer overflow when synchronizing large filesets (tested with 2M files)
|
||||||
|
- This fix actually truncats every string sent to Logger not being more than 16KB
|
||||||
|
- Fixed osync leaving temporary log files behind in RUN_DIR (/tmp by default)
|
||||||
|
- Updated target helper service configuration file
|
||||||
|
- Improved codacy results
|
||||||
|
- Added more debugging
|
||||||
|
- Fixed service logs being junked by spinner
|
||||||
|
- Fixed MINIMUM_SPACE=0 didn't stop the disk space check anymore (Thanks to Val)
|
||||||
|
- Fixed conflict file logs to be less verbose when no conflicts happen
|
||||||
|
|
||||||
|
### 22 May 2019: osync v1.3-beta3 release
|
||||||
|
|
||||||
|
- Config file update script fixes
|
||||||
|
- Removed old Win10 1607 bash fixes to make Win10 1809 work (breaks Win10 1607 beta bash version...Yeah, nothing I can do about that)
|
||||||
|
|
||||||
|
### 20 May 2019: osync v1.3-beta2 release
|
||||||
|
|
||||||
- More --summary statistics
|
- More --summary statistics
|
||||||
- Config file syntax now uses booleans instead of yes / no (but still accepts old syntax)
|
- Config file syntax now uses booleans instead of yes / no (but still accepts old syntax)
|
||||||
|
@ -32,7 +57,7 @@ dd Mmm YYYY: osync v1.3-RC1 release
|
||||||
- Multiple installer fixes
|
- Multiple installer fixes
|
||||||
- Multiple batch fixes
|
- Multiple batch fixes
|
||||||
|
|
||||||
08 Aug 2018: osync v1.3-beta1 release
|
### 08 Aug 2018: osync v1.3-beta1 release
|
||||||
|
|
||||||
- Added an option to log conflictual files
|
- Added an option to log conflictual files
|
||||||
- Presence of conflictual files can trigger a special mail
|
- Presence of conflictual files can trigger a special mail
|
||||||
|
@ -63,20 +88,20 @@ dd Mmm YYYY: osync v1.3-RC1 release
|
||||||
- Upgraded shunit2 test framework to v2.1.8pre (git commit 07bb329)
|
- Upgraded shunit2 test framework to v2.1.8pre (git commit 07bb329)
|
||||||
- Multiple smaller fixes and improvements
|
- Multiple smaller fixes and improvements
|
||||||
|
|
||||||
25 Mar 2017: osync v1.2 release (for full changelog of v1.2 branch see all v1.2-beta/RC entries)
|
### 25 Mar 2017: osync v1.2 release (for full changelog of v1.2 branch see all v1.2-beta/RC entries)
|
||||||
|
|
||||||
- Check for initiator directory before launching monitor mode
|
- Check for initiator directory before launching monitor mode
|
||||||
- Updated RPM spec file (Thanks to https://github.com/liger1978)
|
- Updated RPM spec file (Thanks to https://github.com/liger1978)
|
||||||
- Fixed remote commands can be run on local runs and obviously fail
|
- Fixed remote commands can be run on local runs and obviously fail
|
||||||
- Minor fixes in installer logic
|
- Minor fixes in installer logic
|
||||||
|
|
||||||
10 Feb 2017: osync v1.2-RC3 release
|
### 10 Feb 2017: osync v1.2-RC3 release
|
||||||
|
|
||||||
- Uninstaller skips ssh_filter if needed by other program (osync/obackup)
|
- Uninstaller skips ssh_filter if needed by other program (osync/obackup)
|
||||||
- Logger now automatically obfuscates _REMOTE_TOKEN
|
- Logger now automatically obfuscates _REMOTE_TOKEN
|
||||||
- Logger doesn't show failed commands in stdout, only logs them
|
- Logger doesn't show failed commands in stdout, only logs them
|
||||||
|
|
||||||
08 Feb 2017: osync v1.2-RC2 release
|
### 08 Feb 2017: osync v1.2-RC2 release
|
||||||
|
|
||||||
- Tests have run on CentOS 5,7 and 7, Debian 8, Linux Mint 18, Fedora 25, FreeBSD 10.3/pfSense, FreeBSD 11, MacOSX Sierra, Win10 1607 (14393.479) bash, Cygwin x64 and MSYS2 current
|
- Tests have run on CentOS 5,7 and 7, Debian 8, Linux Mint 18, Fedora 25, FreeBSD 10.3/pfSense, FreeBSD 11, MacOSX Sierra, Win10 1607 (14393.479) bash, Cygwin x64 and MSYS2 current
|
||||||
- Hugely improved ssh_filter
|
- Hugely improved ssh_filter
|
||||||
|
@ -87,7 +112,7 @@ dd Mmm YYYY: osync v1.3-RC1 release
|
||||||
- Fixed installer statistics don't report OS
|
- Fixed installer statistics don't report OS
|
||||||
- Minor tweaks and fixes in ofunctions
|
- Minor tweaks and fixes in ofunctions
|
||||||
|
|
||||||
13 Dec 2016: osync v1.2-RC1 release
|
### 13 Dec 2016: osync v1.2-RC1 release
|
||||||
|
|
||||||
- Unit tests have run on CentOS 5,6 and 7, Debian 8, Linux Mint 18, FreeBSD 10.3/pfSense, FreeBSD 11, MacOSX Sierra, Win10 1607 (14393.479) bash, Cygwin x64 and MSYS2 current
|
- Unit tests have run on CentOS 5,6 and 7, Debian 8, Linux Mint 18, FreeBSD 10.3/pfSense, FreeBSD 11, MacOSX Sierra, Win10 1607 (14393.479) bash, Cygwin x64 and MSYS2 current
|
||||||
- Added optional rsync arguments configuration value
|
- Added optional rsync arguments configuration value
|
||||||
|
@ -136,7 +161,7 @@ dd Mmm YYYY: osync v1.3-RC1 release
|
||||||
- More code compliance
|
- More code compliance
|
||||||
- Lots of minor fixes
|
- Lots of minor fixes
|
||||||
|
|
||||||
19 Nov 2016: osync v1.2-beta3 re-release
|
### 19 Nov 2016: osync v1.2-beta3 re-release
|
||||||
|
|
||||||
- Fixed blocker bug where local tests tried GetRemoteOS Anyway
|
- Fixed blocker bug where local tests tried GetRemoteOS Anyway
|
||||||
- Fixed CentOS 5 compatibility bug for checking disk space introduced in beta3
|
- Fixed CentOS 5 compatibility bug for checking disk space introduced in beta3
|
||||||
|
@ -144,7 +169,7 @@ dd Mmm YYYY: osync v1.3-RC1 release
|
||||||
- Made unit tests clean authorized_keys file after usage
|
- Made unit tests clean authorized_keys file after usage
|
||||||
- Added local unit test where remote OS connection would fail
|
- Added local unit test where remote OS connection would fail
|
||||||
|
|
||||||
18 Nov 2016: osync v1.2-beta3 released
|
### 18 Nov 2016: osync v1.2-beta3 released
|
||||||
|
|
||||||
- Improved locking / unlocking replicas
|
- Improved locking / unlocking replicas
|
||||||
- Fixed killing local pid that has lock bug introduced in v1.2 rewrite
|
- Fixed killing local pid that has lock bug introduced in v1.2 rewrite
|
||||||
|
@ -174,14 +199,16 @@ dd Mmm YYYY: osync v1.3-RC1 release
|
||||||
- Simplified logger
|
- Simplified logger
|
||||||
- All fixes from v1.1.5
|
- All fixes from v1.1.5
|
||||||
|
|
||||||
17 Oct 2016: osync v1.2-beta2 released
|
### 17 Oct 2016: osync v1.2-beta2 released
|
||||||
|
|
||||||
- osync now propagates symlink deletions and moves symlinks without referrents to deletion dir
|
- osync now propagates symlink deletions and moves symlinks without referrents to deletion dir
|
||||||
- Upgrade script now has the ability to add any missing value
|
- Upgrade script now has the ability to add any missing value
|
||||||
- Improved unit tests
|
- Improved unit tests
|
||||||
- Added upgrade script test
|
- Added upgrade script test
|
||||||
- Added deletion propagation tests
|
- Added deletion propagation tests
|
||||||
|
|
||||||
30 Aug 2016: osync v1.2-beta released
|
### 30 Aug 2016: osync v1.2-beta released
|
||||||
|
|
||||||
- Rendered more recent code compatible with bash 3.2+
|
- Rendered more recent code compatible with bash 3.2+
|
||||||
- Added a PKGBUILD file for ArchLinux thanks to Shadowigor (https://github.com/shaodwigor). Builds available at https://aur.archlinux.org/packages/osync/
|
- Added a PKGBUILD file for ArchLinux thanks to Shadowigor (https://github.com/shaodwigor). Builds available at https://aur.archlinux.org/packages/osync/
|
||||||
- Some more code compliance & more paranoia checks
|
- Some more code compliance & more paranoia checks
|
||||||
|
@ -208,7 +235,8 @@ dd Mmm YYYY: osync v1.3-RC1 release
|
||||||
- Added KillAllChilds function to accept multiple pids
|
- Added KillAllChilds function to accept multiple pids
|
||||||
- Improved logging
|
- Improved logging
|
||||||
|
|
||||||
17 Nov 2016: osync v1.1.5 released
|
### 17 Nov 2016: osync v1.1.5 released
|
||||||
|
|
||||||
- Backported unit tests from v1.2-beta allowing to fix the following
|
- Backported unit tests from v1.2-beta allowing to fix the following
|
||||||
- Allow quicksync mode to specify rsync include / exclude patterns as environment variables
|
- Allow quicksync mode to specify rsync include / exclude patterns as environment variables
|
||||||
- Added default path separator char in quicksync mode for multiple includes / exclusions
|
- Added default path separator char in quicksync mode for multiple includes / exclusions
|
||||||
|
@ -217,25 +245,30 @@ dd Mmm YYYY: osync v1.3-RC1 release
|
||||||
- Fixed error alerts cannot be triggered from subprocesses
|
- Fixed error alerts cannot be triggered from subprocesses
|
||||||
- Fixed remote locked targets are unlocked in any case
|
- Fixed remote locked targets are unlocked in any case
|
||||||
|
|
||||||
10 Nov 2016: osync v1.1.4 released
|
### 10 Nov 2016: osync v1.1.4 released
|
||||||
|
|
||||||
- Fixed a corner case with sending alerts with logfile attachments when osync is used by multiple users
|
- Fixed a corner case with sending alerts with logfile attachments when osync is used by multiple users
|
||||||
|
|
||||||
02 Sep 2016: osync v1.1.3 released
|
### 02 Sep 2016: osync v1.1.3 released
|
||||||
|
|
||||||
- Fixed installer for CYGWIN / MSYS environment
|
- Fixed installer for CYGWIN / MSYS environment
|
||||||
|
|
||||||
28 Aug 2016: osync v1.1.2 released
|
### 28 Aug 2016: osync v1.1.2 released
|
||||||
|
|
||||||
- Renamed sync.conf to sync.conf.example (thanks to https://github.com/hortimech)
|
- Renamed sync.conf to sync.conf.example (thanks to https://github.com/hortimech)
|
||||||
- Fixed RunAfterHook may be executed twice
|
- Fixed RunAfterHook may be executed twice
|
||||||
- Fixed soft deletion when SUDO_EXEC is enabled
|
- Fixed soft deletion when SUDO_EXEC is enabled
|
||||||
|
|
||||||
06 Aug 2016: osync v1.1.1 released
|
### 06 Aug 2016: osync v1.1.1 released
|
||||||
|
|
||||||
- Fixed bogus rsync pattern file adding
|
- Fixed bogus rsync pattern file adding
|
||||||
- Fixed soft deletion always enabled on target
|
- Fixed soft deletion always enabled on target
|
||||||
- Fixed problem with attributes file list function
|
- Fixed problem with attributes file list function
|
||||||
- Fixed deletion propagation code
|
- Fixed deletion propagation code
|
||||||
- Fixed missing deletion / backup diretories message in verbose mode
|
- Fixed missing deletion / backup diretories message in verbose mode
|
||||||
|
|
||||||
27 Jul 2016: osync v1.1 released
|
### 27 Jul 2016: osync v1.1 released
|
||||||
|
|
||||||
- More msys and cygwin compatibility
|
- More msys and cygwin compatibility
|
||||||
- Logging begins now before any remote checks
|
- Logging begins now before any remote checks
|
||||||
- Improved process killing and process time control
|
- Improved process killing and process time control
|
||||||
|
@ -271,10 +304,10 @@ dd Mmm YYYY: osync v1.3-RC1 release
|
||||||
- Uploaded coding style manifest
|
- Uploaded coding style manifest
|
||||||
- Added LSB info to init script for Debian based distros
|
- Added LSB info to init script for Debian based distros
|
||||||
|
|
||||||
v0-v1.0x - Jun 2013 - Sep 2015
|
## v0-v1.0x - Jun 2013 - Sep 2015
|
||||||
------------------------------
|
|
||||||
|
### 22 Jul. 2015: Osync v1.00a released
|
||||||
|
|
||||||
22 Jul. 2015: Osync v1.00a released
|
|
||||||
- Small improvements in osync-batch.sh time management
|
- Small improvements in osync-batch.sh time management
|
||||||
- Improved various logging on error
|
- Improved various logging on error
|
||||||
- Work in progress: Unit tests (intial tests written by onovy, Thanks again!)
|
- Work in progress: Unit tests (intial tests written by onovy, Thanks again!)
|
||||||
|
@ -290,7 +323,8 @@ v0-v1.0x - Jun 2013 - Sep 2015
|
||||||
- Removed legacy lockfile code from init script
|
- Removed legacy lockfile code from init script
|
||||||
- Removed hardcoded program name from init script
|
- Removed hardcoded program name from init script
|
||||||
|
|
||||||
01 Avr. 2015: Osync v1.00pre
|
### 01 Avr. 2015: Osync v1.00pre
|
||||||
|
|
||||||
- Improved and refactored the soft deletion routine by merging conflict backup and soft deletion
|
- Improved and refactored the soft deletion routine by merging conflict backup and soft deletion
|
||||||
- Reworked soft deletion code to handle a case where a top level directory gets deleted even if the files contained in it are not old enough (this obviously shouldn't happen on most FS)
|
- Reworked soft deletion code to handle a case where a top level directory gets deleted even if the files contained in it are not old enough (this obviously shouldn't happen on most FS)
|
||||||
- Added more logging
|
- Added more logging
|
||||||
|
@ -324,7 +358,8 @@ v0-v1.0x - Jun 2013 - Sep 2015
|
||||||
- Added a routine that reinjects failed deletions for next run in order to prevent bringing back when deletion failed with permission issues
|
- Added a routine that reinjects failed deletions for next run in order to prevent bringing back when deletion failed with permission issues
|
||||||
- Added treat dir symlink as dir parameter
|
- Added treat dir symlink as dir parameter
|
||||||
|
|
||||||
27 May 2014: Osync 0.99 RC3
|
### 27 May 2014: Osync 0.99 RC3
|
||||||
|
|
||||||
- Additionnal delete fix for *BSD and MSYS (deleted file list not created right)
|
- Additionnal delete fix for *BSD and MSYS (deleted file list not created right)
|
||||||
- Fixed dry mode to use non dry after run treelists to create delete lists
|
- Fixed dry mode to use non dry after run treelists to create delete lists
|
||||||
- Added follow symlink parameter
|
- Added follow symlink parameter
|
||||||
|
@ -371,7 +406,8 @@ v0-v1.0x - Jun 2013 - Sep 2015
|
||||||
- Added possibility to quick sync two local directories without any prior configuration
|
- Added possibility to quick sync two local directories without any prior configuration
|
||||||
- Added time control on OS detection
|
- Added time control on OS detection
|
||||||
|
|
||||||
02 Nov. 2013: Osync 0.99 RC2
|
### 02 Nov. 2013: Osync 0.99 RC2
|
||||||
|
|
||||||
- Minor improvement on operating system detection
|
- Minor improvement on operating system detection
|
||||||
- Improved RunLocalCommand execution hook
|
- Improved RunLocalCommand execution hook
|
||||||
- Minor improvements on permission checks
|
- Minor improvements on permission checks
|
||||||
|
@ -396,7 +432,8 @@ v0-v1.0x - Jun 2013 - Sep 2015
|
||||||
- Fixed various typos
|
- Fixed various typos
|
||||||
- Enforced CheckConnectivityRemoteHost and CheckConnectivity3rdPartyHosts checks (if one of these fails, osync is stopped)
|
- Enforced CheckConnectivityRemoteHost and CheckConnectivity3rdPartyHosts checks (if one of these fails, osync is stopped)
|
||||||
|
|
||||||
18 Aug. 2013: Osync 0.99 RC1
|
### 18 Aug. 2013: Osync 0.99 RC1
|
||||||
|
|
||||||
- Added possibility to change default logfile
|
- Added possibility to change default logfile
|
||||||
- Fixed a possible error upon master replica lock check
|
- Fixed a possible error upon master replica lock check
|
||||||
- Fixed exclude directorires with spaces in names generate errros on master replica tree functions
|
- Fixed exclude directorires with spaces in names generate errros on master replica tree functions
|
||||||
|
@ -407,7 +444,8 @@ v0-v1.0x - Jun 2013 - Sep 2015
|
||||||
- Fixed LoadConfigFile function will not warn on wrong config file
|
- Fixed LoadConfigFile function will not warn on wrong config file
|
||||||
- Added --no-maxtime parameter for sync big changes without enforcing execution time checks
|
- Added --no-maxtime parameter for sync big changes without enforcing execution time checks
|
||||||
|
|
||||||
03 Aug. 2013: beta 3 milestone
|
### 03 Aug. 2013: beta 3 milestone
|
||||||
|
|
||||||
- Softdelete functions do now honor --dry switch
|
- Softdelete functions do now honor --dry switch
|
||||||
- Simplified sync delete functions
|
- Simplified sync delete functions
|
||||||
- Enhanced compatibility with different charsets in filenames
|
- Enhanced compatibility with different charsets in filenames
|
||||||
|
@ -415,12 +453,14 @@ v0-v1.0x - Jun 2013 - Sep 2015
|
||||||
- Tree functions now honor supplementary rsync arguments
|
- Tree functions now honor supplementary rsync arguments
|
||||||
- Tree functions now honor exclusion lists
|
- Tree functions now honor exclusion lists
|
||||||
|
|
||||||
01 Aug. 2013: beta 2 milestone
|
### 01 Aug. 2013: beta 2 milestone
|
||||||
|
|
||||||
- Fixed an issue with spaces in directory trees
|
- Fixed an issue with spaces in directory trees
|
||||||
- Fixed an issue with recursive directory trees
|
- Fixed an issue with recursive directory trees
|
||||||
- Revamped a bit code to add bash 3.2 compatibility
|
- Revamped a bit code to add bash 3.2 compatibility
|
||||||
|
|
||||||
24 Jul. 2013: beta milestone
|
### 24 Jul. 2013: beta milestone
|
||||||
|
|
||||||
- Fixed some bad error handling in CheckMasterSlaveDirs and LockDirectories
|
- Fixed some bad error handling in CheckMasterSlaveDirs and LockDirectories
|
||||||
- Added support for spaces in sync dirs and exclude lists
|
- Added support for spaces in sync dirs and exclude lists
|
||||||
- Fixed false exit code if no remote slave lock present
|
- Fixed false exit code if no remote slave lock present
|
||||||
|
@ -450,5 +490,4 @@ v0-v1.0x - Jun 2013 - Sep 2015
|
||||||
- Added soft-deleted items
|
- Added soft-deleted items
|
||||||
- Added backup items in case of conflict
|
- Added backup items in case of conflict
|
||||||
|
|
||||||
19 Jun. 2013: Project begin as Obackup fork
|
### 19 Jun. 2013: Project begin as Obackup fork
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
KNOWN ISSUES
|
## KNOWN ISSUES
|
||||||
------------
|
|
||||||
|
|
||||||
- Cannot finish sync if one replica contains a directory and the other replica contains a file named the same way (Unix doesn't allow this)
|
- Cannot finish sync if one replica contains a directory and the other replica contains a file named the same way (Unix doesn't allow this)
|
||||||
- Daemon mode monitors changes in the whole replica directories, without honoring exclusion lists
|
- Daemon mode monitors changes in the whole replica directories, without honoring exclusion lists
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
Copyright (c) 2013-2016, Orsiris de Jong. ozy@netpower.fr
|
Copyright (c) 2013-2023, Orsiris de Jong. ozy@netpower.fr
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
232
README.md
232
README.md
|
@ -1,24 +1,29 @@
|
||||||
# osync [](https://travis-ci.org/deajan/osync) [](https://opensource.org/licenses/BSD-3-Clause) [](https://github.com/deajan/osync/releases/latest) [](http://isitmaintained.com/project/deajan/osync "Percentage of issues still open")
|
# osync
|
||||||
|
[](https://opensource.org/licenses/BSD-3-Clause)
|
||||||
|
[](https://github.com/deajan/osync/releases/latest)
|
||||||
|
[](http://isitmaintained.com/project/deajan/osync "Percentage of issues still open")
|
||||||
|
[](https://www.codacy.com/app/ozy/osync?utm_source=github.com&utm_medium=referral&utm_content=deajan/osync&utm_campaign=Badge_Grade)
|
||||||
|
[](https://github.com/deajan/osync/actions/workflows/linux.yml/badge.svg)
|
||||||
|
[](https://github.com/deajan/osync/actions/workflows/windows.yml/badge.svg)
|
||||||
|
[](https://github.com/deajan/osync/actions/workflows/macos.yml/badge.svg)
|
||||||
|
|
||||||
A two way filesync script running on bash Linux, BSD, Android, MacOSX, Cygwin, MSYS2, Win10 bash and virtually any system supporting bash).
|
|
||||||
File synchronization is bidirectional, and can be run manually, as scheduled task, or triggered on file changes in daemon mode.
|
A two way filesync script running on bash Linux, BSD, Android, MacOSX, Cygwin, MSYS2, Win10 bash and virtually any system supporting bash.
|
||||||
|
File synchronization is bidirectional, and can be run manually, as scheduled task, or triggered on file changes in monitor mode.
|
||||||
It is a command line tool rsync wrapper with a lot of additional features baked in.
|
It is a command line tool rsync wrapper with a lot of additional features baked in.
|
||||||
|
|
||||||
This is a quickstart guide, you can find the full documentation on the author's site.
|
This is a quickstart guide, you can find the full documentation on the [author's site](http://www.netpower.fr/osync).
|
||||||
|
|
||||||
**22 May 2019: I am happy to announce that osync 1.3-beta2 passed it's tests on all target platforms.
|
## About
|
||||||
In order to speed up a osync 1.3 final release, please consider testing this beta.**
|
|
||||||
|
|
||||||
About
|
osync provides the following capabilities:
|
||||||
-----
|
|
||||||
osync provides the following capabilities
|
|
||||||
|
|
||||||
- Local-Local and Local-Remote sync
|
- Local-Local and Local-Remote sync
|
||||||
- Fault tolerance with resume scenarios
|
- Fault tolerance with resume scenarios
|
||||||
- POSIX ACL and extended attributes synchronization
|
- POSIX ACL and extended attributes synchronization
|
||||||
- Full script Time control
|
- Full script Time control
|
||||||
- Soft deletions and multiple backups handling
|
- Soft deletions and multiple backups handling
|
||||||
- Before / after run command execution
|
- Before/after run command execution
|
||||||
- Email alerts
|
- Email alerts
|
||||||
- Logging facility
|
- Logging facility
|
||||||
- Directory monitoring
|
- Directory monitoring
|
||||||
|
@ -28,28 +33,39 @@ osync provides the following capabilities
|
||||||
osync is a stateful synchronizer. This means it's agentless and doesn't have to monitor files for changes. Instead, it compares replica file lists between two runs.
|
osync is a stateful synchronizer. This means it's agentless and doesn't have to monitor files for changes. Instead, it compares replica file lists between two runs.
|
||||||
A full run takes about 2 seconds on a local-local replication and about 7 seconds on a local-remote replication.
|
A full run takes about 2 seconds on a local-local replication and about 7 seconds on a local-remote replication.
|
||||||
Disabling some features file like attributes preservation and disk space checks may speed up execution.
|
Disabling some features file like attributes preservation and disk space checks may speed up execution.
|
||||||
osync uses a initiator / target sync schema. It can sync local to local or local to remote directories. By definition, initiator replica is always a local directory on the system osync runs on.
|
osync uses a initiator/target sync schema. It can sync local to local or local to remote directories. By definition, initiator replica is always a local directory on the system osync runs on.
|
||||||
osync uses pidlocks to prevent multiple concurrent sync processes on/to the same initiator / target replica.
|
osync uses pidlocks to prevent multiple concurrent sync processes on/to the same initiator/target replica.
|
||||||
You may launch concurrent sync processes on the same system but as long as the replicas to synchronize are different.
|
You may launch concurrent sync processes on the same system but as long as the replicas to synchronize are different.
|
||||||
Multiple osync tasks may be launched sequentially by osync osync-batch tool.
|
Multiple osync tasks may be launched sequentially by osync osync-batch tool.
|
||||||
|
|
||||||
Currently, it has been tested on CentOS 5.x, 6.x, 7.x, Fedora 22-25, Debian 6-8, Linux Mint 14-18, Ubuntu 12.04-12.10, FreeBSD 8.3-11, Mac OS X and pfSense 2.3.x.
|
## Tested platforms
|
||||||
Microsoft Windows is supported via MSYS or Cygwin and now via Windows 10 bash.
|
|
||||||
Android support works via Termux.
|
| Operating system | Version |
|
||||||
Some users also have successfully used osync on Gentoo and created an openRC init scriptt for it.
|
|------------------|------------------------|
|
||||||
|
| AlmaLinux | 9 |
|
||||||
|
| Android\* | Not known |
|
||||||
|
| CentOS | 5.x, 6.x, 7.x |
|
||||||
|
| Fedora | 22-25 |
|
||||||
|
| FreeBSD | 8.3-11 |
|
||||||
|
| Debian | 6-11 |
|
||||||
|
| Linux Mint | 14-18 |
|
||||||
|
| macOS | Not known |
|
||||||
|
| pfSense | 2.3.x |
|
||||||
|
| QTS (x86) | 4.5.1 |
|
||||||
|
| Ubuntu | 12.04-22.04 |
|
||||||
|
| Windows\*\* | 10 |
|
||||||
|
|
||||||
|
\* via Termux.
|
||||||
|
\*\* via MSYS, Cygwin and WSL.
|
||||||
|
|
||||||
|
Some users also have successfully used osync on Gentoo and created an OpenRC init script for it.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
Installation
|
|
||||||
------------
|
|
||||||
osync has been designed to not delete any data, but rather make backups of conflictual files or soft deletes.
|
osync has been designed to not delete any data, but rather make backups of conflictual files or soft deletes.
|
||||||
Nevertheless, you should always have a neat backup of your data before trying a new sync tool.
|
Nevertheless, you should always have a neat backup of your data before trying a new sync tool.
|
||||||
|
|
||||||
You may get osync on the author's site (stable version) or on github (stable or latest dev snapshot)
|
Getting osync via GitHub (remove the -b "stable" if you want latest dev snapshot)
|
||||||
Getting osync via author's site on **http://www.netpower.fr/osync**
|
|
||||||
|
|
||||||
$ wget http://www.netpower.fr/projects/osync/osync.v1.2.tar.gz
|
|
||||||
$ tar xvf osync.v1.2.tar.gz
|
|
||||||
|
|
||||||
Getting osync via github (remove the -b "stable" if you want latest dev snapshot)
|
|
||||||
|
|
||||||
$ git clone -b "stable" https://github.com/deajan/osync
|
$ git clone -b "stable" https://github.com/deajan/osync
|
||||||
$ cd osync
|
$ cd osync
|
||||||
|
@ -57,10 +73,10 @@ Getting osync via github (remove the -b "stable" if you want latest dev snapshot
|
||||||
|
|
||||||
Installer script accepts some parameters for automation. Launch install.sh --help for options.
|
Installer script accepts some parameters for automation. Launch install.sh --help for options.
|
||||||
|
|
||||||
There is also a RPM file that should fit RHEL/CentOS/Fedora and basically any RPM based distro, see the github release.
|
There is also an RPM file that should fit RHEL/CentOS/Fedora and basically any RPM based distro, see the GitHub release.
|
||||||
Please note that RPM files will install osync to /usr/bin instead of /usr/local/bin in order to enforce good practices.
|
Please note that RPM files will install osync to `/usr/bin` instead of `/usr/local/bin` in order to enforce good practices.
|
||||||
|
|
||||||
osync will install itself to /usr/local/bin and an example configuration file will be installed to /etc/osync
|
osync will install itself to `/usr/local/bin` and an example configuration file will be installed to `/etc/osync`.
|
||||||
|
|
||||||
osync needs to run with bash shell. Using any other shell will most probably result in errors.
|
osync needs to run with bash shell. Using any other shell will most probably result in errors.
|
||||||
If bash is not your default shell, you may invoke it using
|
If bash is not your default shell, you may invoke it using
|
||||||
|
@ -71,78 +87,90 @@ On *BSD and BusyBox, be sure to have bash installed.
|
||||||
|
|
||||||
If you can't install osync, you may just copy osync.sh where you needed and run it from there.
|
If you can't install osync, you may just copy osync.sh where you needed and run it from there.
|
||||||
|
|
||||||
Archlinux packages are available at https://aur.archlinux.org/packages/osync/ (thanks to Shadowigor, https://github.com/shadowigor)
|
Arch Linux packages are available at <https://aur.archlinux.org/packages/osync/> (thanks to Shadowigor, <https://github.com/shadowigor>).
|
||||||
|
|
||||||
## Upgrade from previous configuration files
|
## Upgrade from previous configuration files
|
||||||
|
|
||||||
Since osync v1.1 the config file format has changed in semantics and adds new config options.
|
Since osync v1.1 the config file format has changed in semantics and adds new config options.
|
||||||
Also, master is now called initiator and slave is now called target.
|
Also, master is now called initiator and slave is now called target.
|
||||||
osync v1.2 also added multiple new configuration options.
|
osync v1.3 also added multiple new configuration options.
|
||||||
|
|
||||||
You can upgrade all v1.0x-v1.2-dev config files by running the upgrade script
|
You can upgrade all v1.0x-v1.3-dev config files by running the upgrade script
|
||||||
|
|
||||||
$ ./upgrade-v1.0x-v1.2x.sh /etc/osync/your-config-file.conf
|
$ ./upgrade-v1.0x-v1.3x.sh /etc/osync/your-config-file.conf
|
||||||
|
|
||||||
The script will backup your config file, update it's content and try to connect to initiator and target replicas to update the state dir.
|
The script will backup your config file, update it's content and try to connect to initiator and target replicas to update the state dir.
|
||||||
|
|
||||||
Usage
|
## Usage
|
||||||
-----
|
|
||||||
Osync can work with in three flavors: Quick sync mode, configuration file mode, and daemon mode.
|
Osync can work in 3 modes:
|
||||||
While quick sync mode is convenient to do fast syncs between some directories, a configuration file gives much more functionnality.
|
1. [:rocket: Quick sync mode](#quick-sync-mode)
|
||||||
Please use double quotes as path delimiters. Do not use escaped characters in path names.
|
2. [:gear: Configuration file mode](#configuration-file-mode)
|
||||||
|
3. [:mag_right: Monitor mode](#monitor-mode)
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> Please use double quotes as path delimiters. Do not use escaped characters in path names.
|
||||||
|
|
||||||
|
### <a id="quick-sync-mode"></a>:rocket: Quick sync mode
|
||||||
|
|
||||||
|
Quick sync mode is convenient to do fast syncs between some directories. However, the [configuration file mode](#configuration-file-mode) gives much more functionality.
|
||||||
|
|
||||||
QuickSync example
|
|
||||||
-----------------
|
|
||||||
# osync.sh --initiator="/path/to/dir1" --target="/path/to/remote dir2"
|
# osync.sh --initiator="/path/to/dir1" --target="/path/to/remote dir2"
|
||||||
# osync.sh --initiator="/path/to/another dir" --target="ssh://user@host.com:22//path/to/dir2" --rsakey=/home/user/.ssh/id_rsa_private_key_example.com
|
# osync.sh --initiator="/path/to/another dir" --target="ssh://user@host.com:22//path/to/dir2" --rsakey=/home/user/.ssh/id_rsa_private_key_example.com
|
||||||
|
|
||||||
Summary mode
|
#### Quick sync with minimal options
|
||||||
------------
|
|
||||||
osync may output only file changes and errors with the following
|
|
||||||
|
|
||||||
# osync.sh --initiator="/path/to/dir1" --target="/path/to/dir" --summary --errors-only --no-prefix
|
|
||||||
|
|
||||||
This also works in configuration file mode.
|
|
||||||
|
|
||||||
QuickSync with minimal options
|
|
||||||
------------------------------
|
|
||||||
In order to run osync the quickest (without transferring file attributes, without softdeletion, without prior space checks and without remote connectivity checks, you may use the following:
|
In order to run osync the quickest (without transferring file attributes, without softdeletion, without prior space checks and without remote connectivity checks, you may use the following:
|
||||||
|
|
||||||
# MINIMUM_SPACE=0 PRESERVE_ACL=no PRESERVE_XATTR=no SOFT_DELETE_DAYS=0 CONFLICT_BACKUP_DAYS=0 REMOTE_HOST_PING=no osync.sh --initiator="/path/to/another dir" --target="ssh://user@host.com:22//path/to/dir2" --rsakey=/home/user/.ssh/id_rsa_private_key_example.com
|
# MINIMUM_SPACE=0 PRESERVE_ACL=no PRESERVE_XATTR=no SOFT_DELETE_DAYS=0 CONFLICT_BACKUP_DAYS=0 REMOTE_HOST_PING=no osync.sh --initiator="/path/to/another dir" --target="ssh://user@host.com:22//path/to/dir2" --rsakey=/home/user/.ssh/id_rsa_private_key_example.com
|
||||||
|
|
||||||
All the settings described here may also be configured in the conf file.
|
All the settings described here may also be configured in the conf file.
|
||||||
|
|
||||||
Running osync with a Configuration file
|
### Summary mode
|
||||||
---------------------------------------
|
|
||||||
You'll have to customize the sync.conf file according to your needs.
|
osync will output only file changes and errors with the following:
|
||||||
If you intend to sync a remote directory, osync will need a pair of private / public RSA keys to perform remote SSH connections.
|
|
||||||
Also, running sync as superuser requires to configure /etc/sudoers file.
|
# osync.sh --initiator="/path/to/dir1" --target="/path/to/dir" --summary --errors-only --no-prefix
|
||||||
Please read the documentation about remote sync setups.
|
|
||||||
Once you've customized a sync.conf file, you may run osync with the following test run:
|
This also works in configuration file mode.
|
||||||
|
|
||||||
|
### <a id="configuration-file-mode"></a>:gear: Configuration file mode
|
||||||
|
|
||||||
|
You'll have to customize the `sync.conf` file according to your needs.
|
||||||
|
|
||||||
|
If you intend to sync a remote directory, osync will need a pair of private/public RSA keys to perform remote SSH connections. Also, running sync as superuser requires to configure the `/etc/sudoers` file.
|
||||||
|
|
||||||
|
> [!TIP]
|
||||||
|
> Read the [example configuration file](https://github.com/deajan/osync/blob/master/sync.conf.example) for documentation about remote sync setups.
|
||||||
|
|
||||||
|
Once you've customized a `sync.conf` file, you may run osync with the following test run:
|
||||||
|
|
||||||
# osync.sh /path/to/your.conf --dry
|
# osync.sh /path/to/your.conf --dry
|
||||||
|
|
||||||
If everything went well, you may run the actual configuration with one of the following:
|
If everything went well, you may run the actual configuration with:
|
||||||
|
|
||||||
# osync.sh /path/to/your.conf
|
# osync.sh /path/to/your.conf
|
||||||
|
|
||||||
|
To display which files and attrs are actually synchronized and which files are to be soft deleted / are in conflict, use `--verbose` (you may mix it with `--silent` to output verbose input only in the log files):
|
||||||
|
|
||||||
# osync.sh /path/to/your.conf --verbose
|
# osync.sh /path/to/your.conf --verbose
|
||||||
|
|
||||||
|
Use `--no-maxtime` to disable execution time checks, which is usefull for big initial sync tasks that might take long time. Next runs should then only propagate changes and take much less time:
|
||||||
|
|
||||||
# osync.sh /path/to/your.conf --no-maxtime
|
# osync.sh /path/to/your.conf --no-maxtime
|
||||||
|
|
||||||
Verbose option will display which files and attrs are actually synchronized and which files are to be soft deleted / are in conflict.
|
Once you're confident about your first runs, you may add osync as a cron task like the following in `/etc/crontab` which would run osync every 30 minutes:
|
||||||
You may mix "--silent" and "--verbose" parameters to output verbose input only in the log files.
|
|
||||||
No-Maxtime option will disable execution time checks, which is usefull for big initial sync tasks that might take long time. Next runs should then only propagate changes and take much less time.
|
|
||||||
|
|
||||||
Once you're confident about your first runs, you may add osync as a cron task like the following in /etc/crontab which would run osync every 30 minutes:
|
|
||||||
|
|
||||||
*/30 * * * * root /usr/local/bin/osync.sh /etc/osync/my_sync.conf --silent
|
*/30 * * * * root /usr/local/bin/osync.sh /etc/osync/my_sync.conf --silent
|
||||||
|
|
||||||
Please note that this syntax works for RedHat / CentOS. On Debian you might want to remove the username (ie root) in order to make the crontab entry work.
|
Please note that this syntax works for RedHat/CentOS. On Debian you might want to remove the username (i.e. root) in order to make the crontab entry work.
|
||||||
|
|
||||||
Batch mode
|
### Batch mode
|
||||||
----------
|
|
||||||
You may want to sequentially run multiple sync sets between the same servers. In that case, osync-batch.sh is a nice tool that will run every osync conf file, and, if a task fails,
|
You may want to sequentially run multiple sync sets between the same servers. In that case, `osync-batch.sh` is a nice tool that will run every osync conf file, and, if a task fails,
|
||||||
run it again if there's still some time left.
|
run it again if there's still some time left.
|
||||||
The following example will run all .conf files found in /etc/osync, and retry 3 times every configuration that fails, if the whole sequential run took less than 2 hours.
|
|
||||||
|
To run all `.conf` files found in `/etc/osync`, and retry 3 times every configuration that fails if the whole sequential run took less than 2 hours, use:
|
||||||
|
|
||||||
# osync-batch.sh --path=/etc/osync --max-retries=3 --max-exec-time=7200
|
# osync-batch.sh --path=/etc/osync --max-retries=3 --max-exec-time=7200
|
||||||
|
|
||||||
|
@ -150,71 +178,75 @@ Having multiple conf files can then be run in a single cron command like
|
||||||
|
|
||||||
00 00 * * * root /usr/local/bin/osync-batch.sh --path=/etc/osync --silent
|
00 00 * * * root /usr/local/bin/osync-batch.sh --path=/etc/osync --silent
|
||||||
|
|
||||||
Daemon mode
|
### <a id="monitor-mode"></a>:mag_right: Monitor mode
|
||||||
-----------
|
|
||||||
Additionaly, you may run osync in monitor mode, which means it will perform a sync upon file operations on initiator replica.
|
> [!NOTE]
|
||||||
This can be a drawback on functionnality versus scheduled mode because this mode only launches a sync task if there are file modifications on the initiator replica, without being able to monitor the target replica.
|
> Monitoring changes requires inotifywait command (`inotify-tools` package for most Linux distributions). BSD, macOS and Windows are not yet supported for this operation mode, unless you find an `inotify-tool` package on these OSes.
|
||||||
Target replica changes are only synced when initiator replica changes occur, or when a given amount of time (default 600 seconds) passed without any changes on initiator replica.
|
|
||||||
File monitor mode can also be launched as a daemon with an init script. Please read the documentation for more info.
|
Monitor mode will perform a sync upon file operations on initiator replica. This can be a drawback on functionality versus scheduled mode because this mode only launches a sync task if there are file modifications on the initiator replica, without being able to monitor the target replica. Target replica changes are only synced when initiator replica changes occur, or when a given amount of time (600 seconds by default) passed without any changes on initiator replica.
|
||||||
Note that monitoring changes requires inotifywait command (inotify-tools package for most Linux distributions).
|
|
||||||
BSD, MacOS X and Windows are not yet supported for this operation mode, unless you find a inotify-tools package on these OSes.
|
This mode can also be launched as a daemon with an init script. Please read the documentation for more info.
|
||||||
|
|
||||||
|
To use this mode, use `--on-changes`:
|
||||||
|
|
||||||
# osync.sh /etc/osync/my_sync.conf --on-changes
|
# osync.sh /etc/osync/my_sync.conf --on-changes
|
||||||
|
|
||||||
Osync file monitor mode may be run as system service with the osync-srv script.
|
To run this mode as a system service with the `osync-srv` script, you can run the `install.sh` script (which should work in most cases) or copy the files by hand:
|
||||||
You may run the install.sh script which should work in most cases or copy the files by hand (osync.sh to /usr/bin/local, sync.conf to /etc/osync, osync-srv to /etc/init.d for initV, osync-srv@.service to /usr/lib/systemd/system for systemd, osync-srv-openrc to /etc/init.d/osync-srv-openrc for OpenRC).
|
- `osync.sh` to `/usr/bin/local`
|
||||||
|
- `sync.conf` to `/etc/osync`
|
||||||
|
- For InitV, `osync-srv` to `/etc/init.d`
|
||||||
|
- For systemd, `osync-srv@.service` to `/usr/lib/systemd/system`
|
||||||
|
- For OpenRC, `osync-srv-openrc` to `/etc/init.d/osync-srv-openrc`
|
||||||
|
|
||||||
InitV specific instructions:
|
For InitV (any configuration file found in `/etc/osync` will create an osync daemon instance when service is launched on initV):
|
||||||
|
|
||||||
Any configuration file found in /etc/osync will create a osync daemon instance when service is launched on initV with:
|
|
||||||
|
|
||||||
$ service osync-srv start
|
$ service osync-srv start
|
||||||
$ chkconfig osync-srv on
|
$ chkconfig osync-srv on
|
||||||
|
|
||||||
Systemd specific (one service per config file)
|
For systemd, launch service (one service per config file to launch) with:
|
||||||
|
|
||||||
Launch service (one service per config file to launch) with:
|
|
||||||
$ systemctl start osync-srv@configfile.conf
|
$ systemctl start osync-srv@configfile.conf
|
||||||
$ systemctl enable osync-srv@configfile.conf
|
$ systemctl enable osync-srv@configfile.conf
|
||||||
|
|
||||||
OpenRC specific instructions (user contrib)
|
For OpenRC (user contrib), launch service (one service per config file to launch) with:
|
||||||
|
|
||||||
Launch service (one service per config file to launch) with:
|
|
||||||
$ rc-update add osync-srv.configfile default
|
$ rc-update add osync-srv.configfile default
|
||||||
|
|
||||||
Security enhancements
|
## Security enhancements
|
||||||
---------------------
|
|
||||||
Remote SSH connection security can be improved by limiting what hostnames may connect, disabling some SSH options and using ssh filter.
|
Remote SSH connection security can be improved by limiting what hostnames may connect, disabling some SSH options and using ssh filter.
|
||||||
Please read full documentation in order to configure ssh filter.
|
Please read full documentation in order to configure ssh filter.
|
||||||
|
|
||||||
Contributions
|
## Contributions
|
||||||
-------------
|
|
||||||
All kind of contribs are welcome.
|
All kind of contribs are welcome.
|
||||||
|
|
||||||
When submitting a PR, please be sure to modify files in dev directory (dev/n_osync.sh, dev/ofunctions.sh, dev/common_install.sh etc) as most of the main files are generated via merge.sh.
|
When submitting a PR, please be sure to modify files in dev directory (`dev/n_osync.sh`, `dev/ofunctions.sh`, `dev/common_install.sh etc`) as most of the main files are generated via merge.sh.
|
||||||
When testing your contribs, generate files via merge.sh or use bootstrap.sh which generates a temporary version of n_osync.sh with all includes.
|
When testing your contribs, generate files via merge.sh or use bootstrap.sh which generates a temporary version of n_osync.sh with all includes.
|
||||||
|
|
||||||
Unit tests are run by travis on every PR, but you may also run them manually which adds some tests that travis can't do, via dev/tests/run_tests.sh
|
Unit tests are run by travis on every PR, but you may also run them manually which adds some tests that travis can't do, via `dev/tests/run_tests.sh`.
|
||||||
SSH port can be changed on the fly via environment variable SSH_PORT, eg: SSH_PORT=2222 dev/tests/run_tests.sh
|
SSH port can be changed on the fly via environment variable SSH_PORT, e.g.:
|
||||||
|
|
||||||
|
# SSH_PORT=2222 dev/tests/run_tests.sh
|
||||||
|
|
||||||
Consider reading CODING_CONVENTIONS.TXT before submitting a patch.
|
Consider reading CODING_CONVENTIONS.TXT before submitting a patch.
|
||||||
|
|
||||||
Troubleshooting
|
## Troubleshooting
|
||||||
---------------
|
|
||||||
You may find osync's logs in /var/log/osync.[INSTANCE_ID].log (or current directory if /var/log is not writable).
|
You may find osync's logs in `/var/log/osync.[INSTANCE_ID].log` (or current directory if `/var/log` is not writable).
|
||||||
Additionnaly, you can use the --verbose flag see to what actions are going on.
|
Additionnaly, you can use the --verbose flag see to what actions are going on.
|
||||||
|
|
||||||
When opening an issue, please post the corresponding log files. Also, you may run osync with _DEBUG option in order to have more precise logs, eg:
|
When opening an issue, please post the corresponding log files. Also, you may run osync with _DEBUG option in order to have more precise logs, e.g.:
|
||||||
_DEBUG=yes ./osync.sh /path/to/conf
|
|
||||||
|
|
||||||
|
# _DEBUG=yes ./osync.sh /path/to/conf
|
||||||
|
|
||||||
|
## Uninstalling
|
||||||
|
|
||||||
Uninstalling
|
|
||||||
------------
|
|
||||||
The installer script also has an uninstall mode that will keep configuration files. Use it with
|
The installer script also has an uninstall mode that will keep configuration files. Use it with
|
||||||
|
|
||||||
$ ./install.sh --remove
|
$ ./install.sh --remove
|
||||||
|
|
||||||
Author
|
## Author
|
||||||
------
|
|
||||||
Feel free to open an issue on github or mail me for support in my spare time :)
|
Feel free to open an issue on GitHub or mail me for support in my spare time :)
|
||||||
Orsiris de Jong | ozy@netpower.fr
|
Orsiris de Jong | ozy@netpower.fr
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
SUBPROGRAM=[prgname]
|
SUBPROGRAM=[prgname]
|
||||||
PROGRAM="$SUBPROGRAM-batch" # Batch program to run osync / obackup instances sequentially and rerun failed ones
|
PROGRAM="$SUBPROGRAM-batch" # Batch program to run osync / obackup instances sequentially and rerun failed ones
|
||||||
AUTHOR="(L) 2013-2018 by Orsiris de Jong"
|
AUTHOR="(L) 2013-2020 by Orsiris de Jong"
|
||||||
CONTACT="http://www.netpower.fr - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr - ozy@netpower.fr"
|
||||||
PROGRAM_BUILD=2018100201
|
PROGRAM_BUILD=2020031502
|
||||||
|
|
||||||
## Runs an osync /obackup instance for every conf file found
|
## Runs an osync /obackup instance for every conf file found
|
||||||
## If an instance fails, run it again if time permits
|
## If an instance fails, run it again if time permits
|
||||||
|
@ -34,12 +34,11 @@ elif [ -w /var/tmp ]; then
|
||||||
else
|
else
|
||||||
RUN_DIR=.
|
RUN_DIR=.
|
||||||
fi
|
fi
|
||||||
|
|
||||||
trap TrapQuit TERM EXIT HUP QUIT
|
|
||||||
|
|
||||||
# No need to edit under this line ##############################################################
|
# No need to edit under this line ##############################################################
|
||||||
|
|
||||||
include #### Logger SUBSET ####
|
include #### Logger SUBSET ####
|
||||||
|
include #### CleanUp SUBSET ####
|
||||||
|
include #### GenericTrapQuit SUBSET ####
|
||||||
|
|
||||||
function CheckEnvironment {
|
function CheckEnvironment {
|
||||||
## osync / obackup executable full path can be set here if it cannot be found on the system
|
## osync / obackup executable full path can be set here if it cannot be found on the system
|
||||||
|
@ -129,6 +128,8 @@ function Usage {
|
||||||
exit 128
|
exit 128
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trap GenericTrapQuit TERM EXIT HUP QUIT
|
||||||
|
|
||||||
opts=""
|
opts=""
|
||||||
for i in "$@"
|
for i in "$@"
|
||||||
do
|
do
|
||||||
|
|
|
@ -10,7 +10,7 @@ PROGRAM_BINARY=$PROGRAM".sh"
|
||||||
PROGRAM_BATCH=$PROGRAM"-batch.sh"
|
PROGRAM_BATCH=$PROGRAM"-batch.sh"
|
||||||
SSH_FILTER="ssh_filter.sh"
|
SSH_FILTER="ssh_filter.sh"
|
||||||
|
|
||||||
SCRIPT_BUILD=2019052001
|
SCRIPT_BUILD=2025012001
|
||||||
INSTANCE_ID="installer-$SCRIPT_BUILD"
|
INSTANCE_ID="installer-$SCRIPT_BUILD"
|
||||||
|
|
||||||
## osync / obackup / pmocr / zsnap install script
|
## osync / obackup / pmocr / zsnap install script
|
||||||
|
@ -27,62 +27,6 @@ _STATS=1
|
||||||
ACTION="install"
|
ACTION="install"
|
||||||
FAKEROOT=""
|
FAKEROOT=""
|
||||||
|
|
||||||
function GetCommandlineArguments {
|
|
||||||
for i in "$@"; do
|
|
||||||
case $i in
|
|
||||||
--prefix=*)
|
|
||||||
FAKEROOT="${i##*=}"
|
|
||||||
;;
|
|
||||||
--silent)
|
|
||||||
_LOGGER_SILENT=true
|
|
||||||
;;
|
|
||||||
--no-stats)
|
|
||||||
_STATS=0
|
|
||||||
;;
|
|
||||||
--remove)
|
|
||||||
ACTION="uninstall"
|
|
||||||
;;
|
|
||||||
--help|-h|-?)
|
|
||||||
Usage
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
Logger "Unknown option '$i'" "ERROR"
|
|
||||||
Usage
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
GetCommandlineArguments "$@"
|
|
||||||
|
|
||||||
CONF_DIR=$FAKEROOT/etc/$PROGRAM
|
|
||||||
BIN_DIR="$FAKEROOT/usr/local/bin"
|
|
||||||
SERVICE_DIR_INIT=$FAKEROOT/etc/init.d
|
|
||||||
# Should be /usr/lib/systemd/system, but /lib/systemd/system exists on debian & rhel / fedora
|
|
||||||
SERVICE_DIR_SYSTEMD_SYSTEM=$FAKEROOT/lib/systemd/system
|
|
||||||
SERVICE_DIR_SYSTEMD_USER=$FAKEROOT/etc/systemd/user
|
|
||||||
SERVICE_DIR_OPENRC=$FAKEROOT/etc/init.d
|
|
||||||
|
|
||||||
if [ "$PROGRAM" == "osync" ]; then
|
|
||||||
SERVICE_NAME="osync-srv"
|
|
||||||
TARGET_HELPER_SERVICE_NAME="osync-target-helper-srv"
|
|
||||||
|
|
||||||
TARGET_HELPER_SERVICE_FILE_INIT="$TARGET_HELPER_SERVICE_NAME"
|
|
||||||
TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM="$TARGET_HELPER_SERVICE_NAME@.service"
|
|
||||||
TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER="$TARGET_HELPER_SERVICE_NAME@.service.user"
|
|
||||||
TARGET_HELPER_SERVICE_FILE_OPENRC="$TARGET_HELPER_SERVICE_NAME-openrc"
|
|
||||||
elif [ "$PROGRAM" == "pmocr" ]; then
|
|
||||||
SERVICE_NAME="pmocr-srv"
|
|
||||||
fi
|
|
||||||
|
|
||||||
SERVICE_FILE_INIT="$SERVICE_NAME"
|
|
||||||
SERVICE_FILE_SYSTEMD_SYSTEM="$SERVICE_NAME@.service"
|
|
||||||
SERVICE_FILE_SYSTEMD_USER="$SERVICE_NAME@.service.user"
|
|
||||||
SERVICE_FILE_OPENRC="$SERVICE_NAME-openrc"
|
|
||||||
|
|
||||||
## Generic code
|
|
||||||
|
|
||||||
## Default log file
|
## Default log file
|
||||||
if [ -w "$FAKEROOT/var/log" ]; then
|
if [ -w "$FAKEROOT/var/log" ]; then
|
||||||
LOG_FILE="$FAKEROOT/var/log/$PROGRAM-install.log"
|
LOG_FILE="$FAKEROOT/var/log/$PROGRAM-install.log"
|
||||||
|
@ -95,9 +39,12 @@ fi
|
||||||
include #### UrlEncode SUBSET ####
|
include #### UrlEncode SUBSET ####
|
||||||
include #### GetLocalOS SUBSET ####
|
include #### GetLocalOS SUBSET ####
|
||||||
include #### GetConfFileValue SUBSET ####
|
include #### GetConfFileValue SUBSET ####
|
||||||
|
include #### CleanUp SUBSET ####
|
||||||
|
include #### GenericTrapQuit SUBSET ####
|
||||||
|
|
||||||
function SetLocalOSSettings {
|
function SetLocalOSSettings {
|
||||||
USER=root
|
USER=root
|
||||||
|
DO_INIT=true
|
||||||
|
|
||||||
# LOCAL_OS and LOCAL_OS_FULL are global variables set at GetLocalOS
|
# LOCAL_OS and LOCAL_OS_FULL are global variables set at GetLocalOS
|
||||||
|
|
||||||
|
@ -107,10 +54,12 @@ function SetLocalOSSettings {
|
||||||
;;
|
;;
|
||||||
*"MacOSX"*)
|
*"MacOSX"*)
|
||||||
GROUP=admin
|
GROUP=admin
|
||||||
|
DO_INIT=false
|
||||||
;;
|
;;
|
||||||
*"msys"*|*"Cygwin"*)
|
*"Cygwin"*|*"Android"*|*"msys"*|*"BusyBox"*)
|
||||||
USER=""
|
USER=""
|
||||||
GROUP=""
|
GROUP=""
|
||||||
|
DO_INIT=false
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
GROUP=root
|
GROUP=root
|
||||||
|
@ -131,15 +80,26 @@ function SetLocalOSSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetInit {
|
function GetInit {
|
||||||
|
init="none"
|
||||||
if [ -f /sbin/openrc-run ]; then
|
if [ -f /sbin/openrc-run ]; then
|
||||||
init="openrc"
|
init="openrc"
|
||||||
Logger "Detected openrc." "NOTICE"
|
Logger "Detected openrc." "NOTICE"
|
||||||
|
elif [ -f /usr/lib/systemd/systemd ]; then
|
||||||
|
init="systemd"
|
||||||
|
Logger "Detected systemd." "NOTICE"
|
||||||
elif [ -f /sbin/init ]; then
|
elif [ -f /sbin/init ]; then
|
||||||
|
if type -p file > /dev/null 2>&1; then
|
||||||
if file /sbin/init | grep systemd > /dev/null; then
|
if file /sbin/init | grep systemd > /dev/null; then
|
||||||
init="systemd"
|
init="systemd"
|
||||||
Logger "Detected systemd." "NOTICE"
|
Logger "Detected systemd." "NOTICE"
|
||||||
else
|
else
|
||||||
init="initV"
|
init="initV"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
init="initV"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $init == "initV" ]; then
|
||||||
Logger "Detected initV." "NOTICE"
|
Logger "Detected initV." "NOTICE"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
@ -195,15 +155,14 @@ function CopyFile {
|
||||||
local overwrite="${8:-false}"
|
local overwrite="${8:-false}"
|
||||||
|
|
||||||
local userGroup=""
|
local userGroup=""
|
||||||
local oldFileName
|
|
||||||
|
|
||||||
if [ "$destFileName" == "" ]; then
|
if [ "$destFileName" == "" ]; then
|
||||||
destFileName="$sourceFileName"
|
destFileName="$sourceFileName"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$destPath/$destFileName" ] && [ $overwrite == false ]; then
|
if [ -f "$destPath/$destFileName" ] && [ $overwrite == false ]; then
|
||||||
destfileName="$sourceFileName.new"
|
destFileName="$sourceFileName.new"
|
||||||
Logger "Copying [$sourceFileName] to [$destPath/$destFilename]." "NOTICE"
|
Logger "Copying [$sourceFileName] to [$destPath/$destFileName]." "NOTICE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cp "$sourcePath/$sourceFileName" "$destPath/$destFileName"
|
cp "$sourcePath/$sourceFileName" "$destPath/$destFileName"
|
||||||
|
@ -291,11 +250,11 @@ function CopyServiceFiles {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$SCRIPT_PATH/$TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM" ]; then
|
if [ -f "$SCRIPT_PATH/$TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM" ]; then
|
||||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_SYSTEMD_SYSTEM" "$TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM" "$SERVICE_FILE_SYSTEMD_SYSTEM" "" "" "" true
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_SYSTEMD_SYSTEM" "$TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM" "$TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM" "" "" "" true
|
||||||
Logger "Created optional service [$TARGET_HELPER_SERVICE_NAME] with same specifications as below." "NOTICE"
|
Logger "Created optional service [$TARGET_HELPER_SERVICE_NAME] with same specifications as below." "NOTICE"
|
||||||
fi
|
fi
|
||||||
if [ -f "$SCRIPT_PATH/$TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER" ]; then
|
if [ -f "$SCRIPT_PATH/$TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER" ]; then
|
||||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_SYSTEMD_USER" "$TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER" "$SERVICE_FILE_SYSTEMD_USER" "" "" "" true
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_SYSTEMD_USER" "$TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER" "$TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER" "" "" "" true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
@ -307,7 +266,7 @@ function CopyServiceFiles {
|
||||||
#CreateDir "$SERVICE_DIR_INIT"
|
#CreateDir "$SERVICE_DIR_INIT"
|
||||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_INIT" "$SERVICE_FILE_INIT" "$SERVICE_FILE_INIT" "755" "" "" true
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_INIT" "$SERVICE_FILE_INIT" "$SERVICE_FILE_INIT" "755" "" "" true
|
||||||
if [ -f "$SCRIPT_PATH/$TARGET_HELPER_SERVICE_FILE_INIT" ]; then
|
if [ -f "$SCRIPT_PATH/$TARGET_HELPER_SERVICE_FILE_INIT" ]; then
|
||||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_INIT" "$TARGET_HELPER_SERVICE_FILE_INIT" "$SERVICE_FILE_INIT" "755" "" "" true
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_INIT" "$TARGET_HELPER_SERVICE_FILE_INIT" "$TARGET_HELPER_SERVICE_FILE_INIT" "755" "" "" true
|
||||||
Logger "Created optional service [$TARGET_HELPER_SERVICE_NAME] with same specifications as below." "NOTICE"
|
Logger "Created optional service [$TARGET_HELPER_SERVICE_NAME] with same specifications as below." "NOTICE"
|
||||||
fi
|
fi
|
||||||
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_INIT]." "NOTICE"
|
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_INIT]." "NOTICE"
|
||||||
|
@ -317,7 +276,7 @@ function CopyServiceFiles {
|
||||||
# Rename service to usual service file
|
# Rename service to usual service file
|
||||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_OPENRC" "$SERVICE_FILE_OPENRC" "$SERVICE_FILE_INIT" "755" "" "" true
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_OPENRC" "$SERVICE_FILE_OPENRC" "$SERVICE_FILE_INIT" "755" "" "" true
|
||||||
if [ -f "$SCRPT_PATH/$TARGET_HELPER_SERVICE_FILE_OPENRC" ]; then
|
if [ -f "$SCRPT_PATH/$TARGET_HELPER_SERVICE_FILE_OPENRC" ]; then
|
||||||
CopyFile "$SCRIPT_PATH" "$TARGET_HELPER_SERVICE_DIR_OPENRC" "$SERVICE_FILE_OPENRC" "$SERVICE_FILE_INIT" "755" "" "" true
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_OPENRC" "$TARGET_HELPER_SERVICE_FILE_OPENRC" "$TARGET_HELPER_SERVICE_FILE_OPENRC" "755" "" "" true
|
||||||
Logger "Created optional service [$TARGET_HELPER_SERVICE_NAME] with same specifications as below." "NOTICE"
|
Logger "Created optional service [$TARGET_HELPER_SERVICE_NAME] with same specifications as below." "NOTICE"
|
||||||
fi
|
fi
|
||||||
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_OPENRC]." "NOTICE"
|
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_OPENRC]." "NOTICE"
|
||||||
|
@ -328,14 +287,14 @@ function CopyServiceFiles {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Statistics {
|
function Statistics {
|
||||||
if type wget > /dev/null; then
|
if type wget > /dev/null 2>&1; then
|
||||||
wget -qO- "$STATS_LINK" > /dev/null 2>&1
|
wget -qO- "$STATS_LINK" > /dev/null 2>&1
|
||||||
if [ $? == 0 ]; then
|
if [ $? == 0 ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if type curl > /dev/null; then
|
if type curl > /dev/null 2>&1; then
|
||||||
curl "$STATS_LINK" -o /dev/null > /dev/null 2>&1
|
curl "$STATS_LINK" -o /dev/null > /dev/null 2>&1
|
||||||
if [ $? == 0 ]; then
|
if [ $? == 0 ]; then
|
||||||
return 0
|
return 0
|
||||||
|
@ -373,10 +332,22 @@ function RemoveAll {
|
||||||
else
|
else
|
||||||
Logger "Skipping removal of [$BIN_DIR/$SSH_FILTER] because other programs present that need it." "NOTICE"
|
Logger "Skipping removal of [$BIN_DIR/$SSH_FILTER] because other programs present that need it." "NOTICE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Try to uninstall every possible service file
|
||||||
|
if [ $init == "systemd" ]; then
|
||||||
RemoveFile "$SERVICE_DIR_SYSTEMD_SYSTEM/$SERVICE_FILE_SYSTEMD_SYSTEM"
|
RemoveFile "$SERVICE_DIR_SYSTEMD_SYSTEM/$SERVICE_FILE_SYSTEMD_SYSTEM"
|
||||||
RemoveFile "$SERVICE_DIR_SYSTEMD_USER/$SERVICE_FILE_SYSTEMD_USER"
|
RemoveFile "$SERVICE_DIR_SYSTEMD_USER/$SERVICE_FILE_SYSTEMD_USER"
|
||||||
|
RemoveFile "$SERVICE_DIR_SYSTEMD_SYSTEM/$TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM"
|
||||||
|
RemoveFile "$SERVICE_DIR_SYSTEMD_USER/$TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER"
|
||||||
|
elif [ $init == "initV" ]; then
|
||||||
RemoveFile "$SERVICE_DIR_INIT/$SERVICE_FILE_INIT"
|
RemoveFile "$SERVICE_DIR_INIT/$SERVICE_FILE_INIT"
|
||||||
|
RemoveFile "$SERVICE_DIR_INIT/$TARGET_HELPER_SERVICE_FILE_INIT"
|
||||||
|
elif [ $init == "openrc" ]; then
|
||||||
|
RemoveFile "$SERVICE_DIR_OPENRC/$SERVICE_FILE_OPENRC"
|
||||||
|
RemoveFile "$SERVICE_DIR_OPENRC/$TARGET_HELPER_SERVICE_FILE_OPENRC"
|
||||||
|
else
|
||||||
|
Logger "Can uninstall only from initV, systemd or openRC." "WARN"
|
||||||
|
fi
|
||||||
Logger "Skipping configuration files in [$CONF_DIR]. You may remove this directory manually." "NOTICE"
|
Logger "Skipping configuration files in [$CONF_DIR]. You may remove this directory manually." "NOTICE"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,26 +361,65 @@ function Usage {
|
||||||
exit 127
|
exit 127
|
||||||
}
|
}
|
||||||
|
|
||||||
function TrapQuit {
|
|
||||||
local exitcode=0
|
|
||||||
|
|
||||||
# Get ERROR / WARN alert flags from subprocesses that call Logger
|
|
||||||
if [ -f "$RUN_DIR/$PROGRAM.Logger.warn.$SCRIPT_PID.$TSTAMP" ]; then
|
|
||||||
WARN_ALERT=true
|
|
||||||
exitcode=2
|
|
||||||
fi
|
|
||||||
if [ -f "$RUN_DIR/$PROGRAM.Logger.error.$SCRIPT_PID.$TSTAMP" ]; then
|
|
||||||
ERROR_ALERT=true
|
|
||||||
exitcode=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
CleanUp
|
|
||||||
exit $exitcode
|
|
||||||
}
|
|
||||||
|
|
||||||
############################## Script entry point
|
############################## Script entry point
|
||||||
|
|
||||||
trap TrapQuit TERM EXIT HUP QUIT
|
function GetCommandlineArguments {
|
||||||
|
for i in "$@"; do
|
||||||
|
case $i in
|
||||||
|
--prefix=*)
|
||||||
|
FAKEROOT="${i##*=}"
|
||||||
|
;;
|
||||||
|
--silent)
|
||||||
|
_LOGGER_SILENT=true
|
||||||
|
;;
|
||||||
|
--no-stats)
|
||||||
|
_STATS=0
|
||||||
|
;;
|
||||||
|
--remove)
|
||||||
|
ACTION="uninstall"
|
||||||
|
;;
|
||||||
|
--help|-h|-?)
|
||||||
|
Usage
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
Logger "Unknown option '$i'" "ERROR"
|
||||||
|
Usage
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
GetCommandlineArguments "$@"
|
||||||
|
|
||||||
|
CONF_DIR=$FAKEROOT/etc/$PROGRAM
|
||||||
|
BIN_DIR="$FAKEROOT/usr/local/bin"
|
||||||
|
SERVICE_DIR_INIT=$FAKEROOT/etc/init.d
|
||||||
|
# Should be /usr/lib/systemd/system, but /lib/systemd/system exists on debian & rhel / fedora
|
||||||
|
SERVICE_DIR_SYSTEMD_SYSTEM=$FAKEROOT/lib/systemd/system
|
||||||
|
SERVICE_DIR_SYSTEMD_USER=$FAKEROOT/etc/systemd/user
|
||||||
|
SERVICE_DIR_OPENRC=$FAKEROOT/etc/init.d
|
||||||
|
|
||||||
|
if [ "$PROGRAM" == "osync" ]; then
|
||||||
|
SERVICE_NAME="osync-srv"
|
||||||
|
TARGET_HELPER_SERVICE_NAME="osync-target-helper-srv"
|
||||||
|
|
||||||
|
TARGET_HELPER_SERVICE_FILE_INIT="$TARGET_HELPER_SERVICE_NAME"
|
||||||
|
TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM="$TARGET_HELPER_SERVICE_NAME@.service"
|
||||||
|
TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER="$TARGET_HELPER_SERVICE_NAME@.service.user"
|
||||||
|
TARGET_HELPER_SERVICE_FILE_OPENRC="$TARGET_HELPER_SERVICE_NAME-openrc"
|
||||||
|
elif [ "$PROGRAM" == "pmocr" ]; then
|
||||||
|
SERVICE_NAME="pmocr-srv"
|
||||||
|
fi
|
||||||
|
|
||||||
|
SERVICE_FILE_INIT="$SERVICE_NAME"
|
||||||
|
SERVICE_FILE_SYSTEMD_SYSTEM="$SERVICE_NAME@.service"
|
||||||
|
SERVICE_FILE_SYSTEMD_USER="$SERVICE_NAME@.service.user"
|
||||||
|
SERVICE_FILE_OPENRC="$SERVICE_NAME-openrc"
|
||||||
|
|
||||||
|
## Generic code
|
||||||
|
|
||||||
|
trap GenericTrapQuit TERM EXIT HUP QUIT
|
||||||
|
|
||||||
if [ ! -w "$(dirname $LOG_FILE)" ]; then
|
if [ ! -w "$(dirname $LOG_FILE)" ]; then
|
||||||
echo "Cannot write to log [$(dirname $LOG_FILE)]."
|
echo "Cannot write to log [$(dirname $LOG_FILE)]."
|
||||||
|
@ -422,7 +432,11 @@ umask 0022
|
||||||
|
|
||||||
GetLocalOS
|
GetLocalOS
|
||||||
SetLocalOSSettings
|
SetLocalOSSettings
|
||||||
GetInit
|
# On Mac OS this always produces a warning which causes the installer to fail with exit code 2
|
||||||
|
# Since we know it won't work anyway, and that's fine, just skip this step
|
||||||
|
if $DO_INIT; then
|
||||||
|
GetInit
|
||||||
|
fi
|
||||||
|
|
||||||
STATS_LINK="http://instcount.netpower.fr?program=$PROGRAM&version=$PROGRAM_VERSION&os=$OS&action=$ACTION"
|
STATS_LINK="http://instcount.netpower.fr?program=$PROGRAM&version=$PROGRAM_VERSION&os=$OS&action=$ACTION"
|
||||||
|
|
||||||
|
|
1238
dev/debug_osync.sh
1238
dev/debug_osync.sh
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
## MERGE 2019022601
|
## MERGE 2020031501
|
||||||
|
|
||||||
## Merges ofunctions.sh and n_program.sh into program.sh
|
## Merges ofunctions.sh and n_program.sh into program.sh
|
||||||
## Adds installer
|
## Adds installer
|
||||||
|
@ -61,6 +61,8 @@ function __PREPROCESSOR_Constants {
|
||||||
'#### SetConfFileValue SUBSET ####'
|
'#### SetConfFileValue SUBSET ####'
|
||||||
'#### CheckRFC822 SUBSET ####'
|
'#### CheckRFC822 SUBSET ####'
|
||||||
'#### CleanUp SUBSET ####'
|
'#### CleanUp SUBSET ####'
|
||||||
|
'#### GenericTrapQuit SUBSET ####'
|
||||||
|
'#### FileMove SUBSET ####'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
## Generic and highly portable bash functions written in 2013-2019 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
## Generic and highly portable bash functions written in 2013-2022 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
||||||
|
|
||||||
#TODO: ExecTasks postponed arrays / files grow a lot. Consider having them "rolling" (cleaned at numberOfEvents)
|
#TODO: ExecTasks postponed arrays / files grow a lot. Consider having them "rolling" (cleaned at numberOfEvents)
|
||||||
#TODO: command line arguments don't take -AaqV for example
|
#TODO: command line arguments do not take merged args (-AaqV for example)
|
||||||
|
|
||||||
####################################################################################################################################################################
|
####################################################################################################################################################################
|
||||||
## To use in a program, define the following variables:
|
## To use in a program, define the following variables:
|
||||||
|
@ -14,6 +14,7 @@
|
||||||
## _LOGGER_VERBOSE=true/false
|
## _LOGGER_VERBOSE=true/false
|
||||||
## _LOGGER_ERR_ONLY=true/false
|
## _LOGGER_ERR_ONLY=true/false
|
||||||
## _LOGGER_PREFIX="date"/"time"/""
|
## _LOGGER_PREFIX="date"/"time"/""
|
||||||
|
## _LOGGER_WRITE_PARTIAL_LOGS=true/false
|
||||||
|
|
||||||
## Also, set the following trap in order to clean temporary files
|
## Also, set the following trap in order to clean temporary files
|
||||||
## trap GenericTrapQuit TERM EXIT HUP QUIT
|
## trap GenericTrapQuit TERM EXIT HUP QUIT
|
||||||
|
@ -30,8 +31,8 @@
|
||||||
#### OFUNCTIONS FULL SUBSET ####
|
#### OFUNCTIONS FULL SUBSET ####
|
||||||
#### OFUNCTIONS MINI SUBSET ####
|
#### OFUNCTIONS MINI SUBSET ####
|
||||||
#### OFUNCTIONS MICRO SUBSET ####
|
#### OFUNCTIONS MICRO SUBSET ####
|
||||||
_OFUNCTIONS_VERSION=2.3.0-dev-postRC2
|
_OFUNCTIONS_VERSION=2.5.1
|
||||||
_OFUNCTIONS_BUILD=2019052103
|
_OFUNCTIONS_BUILD=2023061401
|
||||||
#### _OFUNCTIONS_BOOTSTRAP SUBSET ####
|
#### _OFUNCTIONS_BOOTSTRAP SUBSET ####
|
||||||
_OFUNCTIONS_BOOTSTRAP=true
|
_OFUNCTIONS_BOOTSTRAP=true
|
||||||
#### _OFUNCTIONS_BOOTSTRAP SUBSET END ####
|
#### _OFUNCTIONS_BOOTSTRAP SUBSET END ####
|
||||||
|
@ -56,6 +57,8 @@ _LOGGER_SILENT=false
|
||||||
_LOGGER_VERBOSE=false
|
_LOGGER_VERBOSE=false
|
||||||
_LOGGER_ERR_ONLY=false
|
_LOGGER_ERR_ONLY=false
|
||||||
_LOGGER_PREFIX="date"
|
_LOGGER_PREFIX="date"
|
||||||
|
_LOGGER_WRITE_PARTIAL_LOGS=false # Writes partial log files to /tmp so sending logs via alerts can feed on them
|
||||||
|
_OFUNCTIONS_SHOW_SPINNER=true # Show spinner in ExecTasks function
|
||||||
if [ "$KEEP_LOGGING" == "" ]; then
|
if [ "$KEEP_LOGGING" == "" ]; then
|
||||||
KEEP_LOGGING=1801
|
KEEP_LOGGING=1801
|
||||||
fi
|
fi
|
||||||
|
@ -79,13 +82,35 @@ else
|
||||||
_LOGGER_VERBOSE=true
|
_LOGGER_VERBOSE=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$SLEEP_TIME" == "" ]; then # Leave the possibity to set SLEEP_TIME as environment variable when runinng with bash -x in order to avoid spamming console
|
if [ "$SLEEP_TIME" == "" ]; then # Leave the possibility to set SLEEP_TIME as environment variable when running with bash -x in order to avoid spamming console
|
||||||
SLEEP_TIME=.05
|
SLEEP_TIME=.05
|
||||||
fi
|
fi
|
||||||
#### DEBUG SUBSET END ####
|
#### DEBUG SUBSET END ####
|
||||||
|
|
||||||
|
# The variables SCRIPT_PID and TSTAMP needs to be declared as soon as the program begins. The function PoorMansRandomGenerator is needed for TSTAMP (since some systems date function does not give nanoseconds)
|
||||||
|
|
||||||
SCRIPT_PID=$$
|
SCRIPT_PID=$$
|
||||||
|
|
||||||
|
#### PoorMansRandomGenerator SUBSET ####
|
||||||
|
# Get a random number of digits length on Windows BusyBox alike, also works on most Unixes that have dd
|
||||||
|
function PoorMansRandomGenerator {
|
||||||
|
local digits="${1}" # The number of digits to generate
|
||||||
|
local number
|
||||||
|
|
||||||
|
# Some read bytes cannot be used, se we read twice the number of required bytes
|
||||||
|
dd if=/dev/urandom bs=$digits count=2 2> /dev/null | while read -r -n1 char; do
|
||||||
|
number=$number$(printf "%d" "'$char")
|
||||||
|
if [ ${#number} -ge $digits ]; then
|
||||||
|
echo ${number:0:$digits}
|
||||||
|
break;
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
#### PoorMansRandomGenerator SUBSET END ####
|
||||||
|
|
||||||
|
# Initial TSTMAP value before function declaration
|
||||||
|
TSTAMP=$(date '+%Y%m%dT%H%M%S').$(PoorMansRandomGenerator 5)
|
||||||
|
|
||||||
LOCAL_USER=$(whoami)
|
LOCAL_USER=$(whoami)
|
||||||
LOCAL_HOST=$(hostname)
|
LOCAL_HOST=$(hostname)
|
||||||
|
|
||||||
|
@ -116,56 +141,14 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Special note when remote target is on the same host as initiator (happens for unit tests): we'll have to differentiate RUN_DIR so remote CleanUp won't affect initiator.
|
## Special note when remote target is on the same host as initiator (happens for unit tests): we'll have to differentiate RUN_DIR so remote CleanUp won't affect initiator.
|
||||||
|
## If the same program gets remotely executed, add _REMOTE_EXECUTION=true to environment so it knows it has to write into a separate directory
|
||||||
|
## This will thus not affect local $RUN_DIR variables
|
||||||
if [ "$_REMOTE_EXECUTION" == true ]; then
|
if [ "$_REMOTE_EXECUTION" == true ]; then
|
||||||
mkdir -p "$RUN_DIR/$PROGRAM.remote"
|
mkdir -p "$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP"
|
||||||
RUN_DIR="$RUN_DIR/$PROGRAM.remote"
|
RUN_DIR="$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP"
|
||||||
fi
|
fi
|
||||||
#### RUN_DIR SUBSET END ####
|
#### RUN_DIR SUBSET END ####
|
||||||
|
|
||||||
#### PoorMansRandomGenerator SUBSET ####
|
|
||||||
# Get a random number on Windows BusyBox alike, also works on most Unixes that have dd, if dd is not found, then return $RANDOM
|
|
||||||
function PoorMansRandomGenerator {
|
|
||||||
local digits="${1}" # The number of digits to generate
|
|
||||||
local number
|
|
||||||
local isFirst=true
|
|
||||||
|
|
||||||
if type dd >/dev/null 2>&1; then
|
|
||||||
|
|
||||||
# Some read bytes can't be used, se we read twice the number of required bytes
|
|
||||||
dd if=/dev/urandom bs=$digits count=2 2> /dev/null | while read -r -n1 char; do
|
|
||||||
if [ $isFirst == false ] || [ $(printf "%d" "'$char") != "0" ]; then
|
|
||||||
number=$number$(printf "%d" "'$char")
|
|
||||||
isFirst=false
|
|
||||||
fi
|
|
||||||
if [ ${#number} -ge $digits ]; then
|
|
||||||
echo ${number:0:$digits}
|
|
||||||
break;
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
elif [ "$RANDOM" -ne 0 ]; then
|
|
||||||
echo $RANDOM
|
|
||||||
else
|
|
||||||
Logger "Cannot generate random number." "ERROR"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
function PoorMansRandomGenerator {
|
|
||||||
local digits="${1}" # The number of digits to generate
|
|
||||||
local number
|
|
||||||
|
|
||||||
# Some read bytes can't be used, se we read twice the number of required bytes
|
|
||||||
dd if=/dev/urandom bs=$digits count=2 2> /dev/null | while read -r -n1 char; do
|
|
||||||
number=$number$(printf "%d" "'$char")
|
|
||||||
if [ ${#number} -ge $digits ]; then
|
|
||||||
echo ${number:0:$digits}
|
|
||||||
break;
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
#### PoorMansRandomGenerator SUBSET END ####
|
|
||||||
|
|
||||||
# Initial TSTMAP value before function declaration
|
|
||||||
TSTAMP=$(date '+%Y%m%dT%H%M%S').$(PoorMansRandomGenerator 5)
|
|
||||||
|
|
||||||
# Default alert attachment filename
|
# Default alert attachment filename
|
||||||
ALERT_LOG_FILE="$RUN_DIR/$PROGRAM.$SCRIPT_PID.$TSTAMP.last.log"
|
ALERT_LOG_FILE="$RUN_DIR/$PROGRAM.$SCRIPT_PID.$TSTAMP.last.log"
|
||||||
|
|
||||||
|
@ -192,8 +175,8 @@ function _Logger {
|
||||||
echo -e "$logValue" >> "$LOG_FILE"
|
echo -e "$logValue" >> "$LOG_FILE"
|
||||||
|
|
||||||
# Build current log file for alerts if we have a sufficient environment
|
# Build current log file for alerts if we have a sufficient environment
|
||||||
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
|
if [ "$_LOGGER_WRITE_PARTIAL_LOGS" == true ] && [ "$RUN_DIR/$PROGRAM" != "/" ]; then
|
||||||
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
|
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -217,7 +200,7 @@ function RemoteLogger {
|
||||||
local prefix
|
local prefix
|
||||||
|
|
||||||
if [ "$_LOGGER_PREFIX" == "time" ]; then
|
if [ "$_LOGGER_PREFIX" == "time" ]; then
|
||||||
prefix="TIME: $SECONDS - "
|
prefix="RTIME: $SECONDS - "
|
||||||
elif [ "$_LOGGER_PREFIX" == "date" ]; then
|
elif [ "$_LOGGER_PREFIX" == "date" ]; then
|
||||||
prefix="R $(date) - "
|
prefix="R $(date) - "
|
||||||
else
|
else
|
||||||
|
@ -226,29 +209,29 @@ function RemoteLogger {
|
||||||
|
|
||||||
if [ "$level" == "CRITICAL" ]; then
|
if [ "$level" == "CRITICAL" ]; then
|
||||||
_Logger "" "$prefix\e[1;33;41m$value\e[0m" true
|
_Logger "" "$prefix\e[1;33;41m$value\e[0m" true
|
||||||
if [ $_DEBUG == true ]; then
|
if [ "$_DEBUG" == true ]; then
|
||||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "ERROR" ]; then
|
elif [ "$level" == "ERROR" ]; then
|
||||||
_Logger "" "$prefix\e[31m$value\e[0m" true
|
_Logger "" "$prefix\e[31m$value\e[0m" true
|
||||||
if [ $_DEBUG == true ]; then
|
if [ "$_DEBUG" == true ]; then
|
||||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "WARN" ]; then
|
elif [ "$level" == "WARN" ]; then
|
||||||
_Logger "" "$prefix\e[33m$value\e[0m" true
|
_Logger "" "$prefix\e[33m$value\e[0m" true
|
||||||
if [ $_DEBUG == true ]; then
|
if [ "$_DEBUG" == true ]; then
|
||||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "NOTICE" ]; then
|
elif [ "$level" == "NOTICE" ]; then
|
||||||
if [ $_LOGGER_ERR_ONLY != true ]; then
|
if [ "$_LOGGER_ERR_ONLY" != true ]; then
|
||||||
_Logger "" "$prefix$value"
|
_Logger "" "$prefix$value"
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "VERBOSE" ]; then
|
elif [ "$level" == "VERBOSE" ]; then
|
||||||
if [ $_LOGGER_VERBOSE == true ]; then
|
if [ "$_LOGGER_VERBOSE" == true ]; then
|
||||||
_Logger "" "$prefix$value"
|
_Logger "" "$prefix$value"
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
|
@ -303,24 +286,24 @@ function Logger {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Obfuscate _REMOTE_TOKEN in logs (for ssh_filter usage only in osync and obackup)
|
## Obfuscate _REMOTE_TOKEN in logs (for ssh_filter usage only in osync and obackup)
|
||||||
value="${value/env _REMOTE_TOKEN=$_REMOTE_TOKEN/__(o_O)__}"
|
value="${value/env _REMOTE_TOKEN=$_REMOTE_TOKEN/env _REMOTE_TOKEN=__o_O__}"
|
||||||
value="${value/env _REMOTE_TOKEN=\$_REMOTE_TOKEN/__(o_O)__}"
|
value="${value/env _REMOTE_TOKEN=\$_REMOTE_TOKEN/env _REMOTE_TOKEN=__o_O__}"
|
||||||
|
|
||||||
if [ "$level" == "CRITICAL" ]; then
|
if [ "$level" == "CRITICAL" ]; then
|
||||||
_Logger "$prefix($level):$value" "$prefix\e[1;33;41m$value\e[0m" true
|
_Logger "$prefix($level):$value" "$prefix\e[1;33;41m$value\e[0m" true
|
||||||
ERROR_ALERT=true
|
ERROR_ALERT=true
|
||||||
# ERROR_ALERT / WARN_ALERT is not set in main when Logger is called from a subprocess. Need to keep this flag.
|
# ERROR_ALERT / WARN_ALERT is not set in main when Logger is called from a subprocess. We need to create these flag files for ERROR_ALERT / WARN_ALERT to be picked up by Alert
|
||||||
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID.$TSTAMP"
|
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.ERROR_ALERT.$SCRIPT_PID.$TSTAMP"
|
||||||
return
|
return
|
||||||
elif [ "$level" == "ERROR" ]; then
|
elif [ "$level" == "ERROR" ]; then
|
||||||
_Logger "$prefix($level):$value" "$prefix\e[91m$value\e[0m" true
|
_Logger "$prefix($level):$value" "$prefix\e[91m$value\e[0m" true
|
||||||
ERROR_ALERT=true
|
ERROR_ALERT=true
|
||||||
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID.$TSTAMP"
|
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.ERROR_ALERT.$SCRIPT_PID.$TSTAMP"
|
||||||
return
|
return
|
||||||
elif [ "$level" == "WARN" ]; then
|
elif [ "$level" == "WARN" ]; then
|
||||||
_Logger "$prefix($level):$value" "$prefix\e[33m$value\e[0m" true
|
_Logger "$prefix($level):$value" "$prefix\e[33m$value\e[0m" true
|
||||||
WARN_ALERT=true
|
WARN_ALERT=true
|
||||||
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.warn.$SCRIPT_PID.$TSTAMP"
|
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.WARN_ALERT.$SCRIPT_PID.$TSTAMP"
|
||||||
return
|
return
|
||||||
elif [ "$level" == "NOTICE" ]; then
|
elif [ "$level" == "NOTICE" ]; then
|
||||||
if [ "$_LOGGER_ERR_ONLY" != true ]; then
|
if [ "$_LOGGER_ERR_ONLY" != true ]; then
|
||||||
|
@ -328,7 +311,7 @@ function Logger {
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "VERBOSE" ]; then
|
elif [ "$level" == "VERBOSE" ]; then
|
||||||
if [ $_LOGGER_VERBOSE == true ]; then
|
if [ "$_LOGGER_VERBOSE" == true ]; then
|
||||||
_Logger "$prefix($level):$value" "$prefix$value"
|
_Logger "$prefix($level):$value" "$prefix$value"
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
|
@ -441,25 +424,16 @@ function KillAllChilds {
|
||||||
return $errorcount
|
return $errorcount
|
||||||
}
|
}
|
||||||
|
|
||||||
#### CleanUp SUBSET ####
|
#### GenericTrapQuit SUBSET ####
|
||||||
function CleanUp {
|
|
||||||
if [ "$_DEBUG" != true ]; then
|
|
||||||
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP"
|
|
||||||
# Fix for sed -i requiring backup extension for BSD & Mac (see all sed -i statements)
|
|
||||||
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP.tmp"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
#### CleanUp SUBSET END ####
|
|
||||||
|
|
||||||
function GenericTrapQuit {
|
function GenericTrapQuit {
|
||||||
local exitcode=0
|
local exitcode=0
|
||||||
|
|
||||||
# Get ERROR / WARN alert flags from subprocesses that call Logger
|
# Get ERROR / WARN alert flags from subprocesses that call Logger
|
||||||
if [ -f "$RUN_DIR/$PROGRAM.Logger.warn.$SCRIPT_PID.$TSTAMP" ]; then
|
if [ -f "$RUN_DIR/$PROGRAM.WARN_ALERT.$SCRIPT_PID.$TSTAMP" ]; then
|
||||||
WARN_ALERT=true
|
WARN_ALERT=true
|
||||||
exitcode=2
|
exitcode=2
|
||||||
fi
|
fi
|
||||||
if [ -f "$RUN_DIR/$PROGRAM.Logger.error.$SCRIPT_PID.$TSTAMP" ]; then
|
if [ -f "$RUN_DIR/$PROGRAM.ERROR_ALERT.$SCRIPT_PID.$TSTAMP" ]; then
|
||||||
ERROR_ALERT=true
|
ERROR_ALERT=true
|
||||||
exitcode=1
|
exitcode=1
|
||||||
fi
|
fi
|
||||||
|
@ -468,6 +442,28 @@ function GenericTrapQuit {
|
||||||
exit $exitcode
|
exit $exitcode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#### GenericTrapQuit SUBSET END ####
|
||||||
|
|
||||||
|
#### CleanUp SUBSET ####
|
||||||
|
function CleanUp {
|
||||||
|
# Exit controlmaster before the socket gets deleted
|
||||||
|
if [ "$SSH_CONTROLMASTER" == true ] && [ "$SSH_CMD" != "" ]; then
|
||||||
|
$SSH_CMD -O exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$_DEBUG" != true ]; then
|
||||||
|
# Removing optional remote $RUN_DIR that goes into local $RUN_DIR
|
||||||
|
if [ -d "$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP" ]; then
|
||||||
|
rm -rf "$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP"
|
||||||
|
fi
|
||||||
|
# Removing all temporary run files
|
||||||
|
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP"
|
||||||
|
# Fix for sed -i requiring backup extension for BSD & Mac (see all sed -i statements)
|
||||||
|
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP.tmp"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#### CleanUp SUBSET END ####
|
||||||
|
|
||||||
#### OFUNCTIONS MICRO SUBSET END ####
|
#### OFUNCTIONS MICRO SUBSET END ####
|
||||||
|
|
||||||
|
@ -501,7 +497,11 @@ function SendAlert {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
body="$MAIL_ALERT_MSG"$'\n\n'"Last 1000 lines of current log"$'\n\n'"$(tail -n 1000 "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log")"
|
if [ "$_LOGGER_WRITE_PARTIAL_LOGS" == true ]; then
|
||||||
|
body="$MAIL_ALERT_MSG"$'\n\n'"Last 1000 lines of current log"$'\n\n'"$(tail -n 1000 "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP")"
|
||||||
|
else
|
||||||
|
body="$MAIL_ALERT_MSG"$'\n\n'"Last 1000 lines of current log"$'\n\n'"$(tail -n 1000 "$LOG_FILE")"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $ERROR_ALERT == true ]; then
|
if [ $ERROR_ALERT == true ]; then
|
||||||
subject="Error alert for $INSTANCE_ID"
|
subject="Error alert for $INSTANCE_ID"
|
||||||
|
@ -512,7 +512,7 @@ function SendAlert {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $runAlert == true ]; then
|
if [ $runAlert == true ]; then
|
||||||
subject="Currently runing - $subject"
|
subject="Currently running - $subject"
|
||||||
else
|
else
|
||||||
subject="Finished run - $subject"
|
subject="Finished run - $subject"
|
||||||
fi
|
fi
|
||||||
|
@ -571,7 +571,7 @@ function SendEmail {
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
Logger "No valid email adresses given." "WARN"
|
Logger "No valid email addresses given." "WARN"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -579,7 +579,7 @@ function SendEmail {
|
||||||
if [ "$MAIL_BODY_CHARSET" != "" ]; then
|
if [ "$MAIL_BODY_CHARSET" != "" ]; then
|
||||||
if type iconv > /dev/null 2>&1; then
|
if type iconv > /dev/null 2>&1; then
|
||||||
echo "$message" | iconv -f UTF-8 -t $MAIL_BODY_CHARSET -o "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.iconv.$SCRIPT_PID.$TSTAMP"
|
echo "$message" | iconv -f UTF-8 -t $MAIL_BODY_CHARSET -o "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.iconv.$SCRIPT_PID.$TSTAMP"
|
||||||
message="$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.iconv.$SCRIPT_PID.$TSTAMP)"
|
message="$(cat "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.iconv.$SCRIPT_PID.$TSTAMP")"
|
||||||
else
|
else
|
||||||
Logger "iconv utility not installed. Will not convert email charset." "NOTICE"
|
Logger "iconv utility not installed. Will not convert email charset." "NOTICE"
|
||||||
fi
|
fi
|
||||||
|
@ -602,8 +602,11 @@ function SendEmail {
|
||||||
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) -f "$senderMail" -H "exec openssl s_client -quiet -tls1_2 -starttls smtp -connect $smtpServer:$smtpPort" -au"$smtpUser" -ap"$smtpPassword" "$destinationMails"
|
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) -f "$senderMail" -H "exec openssl s_client -quiet -tls1_2 -starttls smtp -connect $smtpServer:$smtpPort" -au"$smtpUser" -ap"$smtpPassword" "$destinationMails"
|
||||||
elif [ "$encryption" == "ssl" ]; then
|
elif [ "$encryption" == "ssl" ]; then
|
||||||
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) -f "$senderMail" -H "exec openssl s_client -quiet -connect $smtpServer:$smtpPort" -au"$smtpUser" -ap"$smtpPassword" "$destinationMails"
|
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) -f "$senderMail" -H "exec openssl s_client -quiet -connect $smtpServer:$smtpPort" -au"$smtpUser" -ap"$smtpPassword" "$destinationMails"
|
||||||
|
elif [ "$encryption" == "none" ]; then
|
||||||
|
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) -f "$senderMail" -S "$smtpServer:$smtpPort" -au"$smtpUser" -ap"$smtpPassword" "$destinationMails"
|
||||||
else
|
else
|
||||||
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) -f "$senderMail" -S "$smtpServer:$smtpPort" -au"$smtpUser" -ap"$smtpPassword" "$destinationMails"
|
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) -f "$senderMail" -S "$smtpServer:$smtpPort" -au"$smtpUser" -ap"$smtpPassword" "$destinationMails"
|
||||||
|
Logger "Bogus email encryption used [$encryption]." "WARN"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
|
@ -688,7 +691,7 @@ function SendEmail {
|
||||||
encryption_string=
|
encryption_string=
|
||||||
elif [ "$encryption" == "tls" ]; then
|
elif [ "$encryption" == "tls" ]; then
|
||||||
encryption_string=-starttls
|
encryption_string=-starttls
|
||||||
elif [ "$encryption" == "ssl" ]:; then
|
elif [ "$encryption" == "ssl" ]; then
|
||||||
encryption_string=-ssl
|
encryption_string=-ssl
|
||||||
fi
|
fi
|
||||||
if [ "$smtpUser" != "" ] && [ "$smtpPassword" != "" ]; then
|
if [ "$smtpUser" != "" ] && [ "$smtpPassword" != "" ]; then
|
||||||
|
@ -742,7 +745,7 @@ function LoadConfigFile {
|
||||||
Logger "Cannot load configuration file [$configFile]. Cannot start." "CRITICAL"
|
Logger "Cannot load configuration file [$configFile]. Cannot start." "CRITICAL"
|
||||||
exit 1
|
exit 1
|
||||||
elif [[ "$configFile" != *".conf" ]]; then
|
elif [[ "$configFile" != *".conf" ]]; then
|
||||||
Logger "Wrong configuration file supplied [$configFile]. Cannot start." "CRITICAL"
|
Logger "Wrong configuration file supplied [$configFile], file extension is not .conf, Cannot start." "CRITICAL"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
revisionPresent="$(GetConfFileValue "$configFile" "CONFIG_FILE_REVISION" true)"
|
revisionPresent="$(GetConfFileValue "$configFile" "CONFIG_FILE_REVISION" true)"
|
||||||
|
@ -783,7 +786,7 @@ function _PerfProfiler { #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
_OFUNCTIONS_SPINNER="|/-\\"
|
_OFUNCTIONS_SPINNER="|/-\\"
|
||||||
function Spinner {
|
function Spinner {
|
||||||
if [ $_LOGGER_SILENT == true ] || [ "$_LOGGER_ERR_ONLY" == true ]; then
|
if [ "$_LOGGER_SILENT" == true ] || [ "$_LOGGER_ERR_ONLY" == true ] || [ "$_SYNC_ON_CHANGES" == "initiator" ] || [ "$_SYNC_ON_CHANGES" == "target" ] ; then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
printf " [%c] \b\b\b\b\b\b" "$_OFUNCTIONS_SPINNER"
|
printf " [%c] \b\b\b\b\b\b" "$_OFUNCTIONS_SPINNER"
|
||||||
|
@ -839,7 +842,7 @@ function ParallelExec {
|
||||||
## pid=$!
|
## pid=$!
|
||||||
## sleep 20 &
|
## sleep 20 &
|
||||||
## pid2=$!
|
## pid2=$!
|
||||||
## ExecTasks "some_identifier" 0 0 10 20 1 1800 true true false false 1 "$pid;$pid2"
|
## ExecTasks "$pid;$pid2" "some_identifier" 0 0 10 20 1 1800 true true false false 1
|
||||||
|
|
||||||
## Example of parallel execution of four commands, only if directories exist. Warn if execution takes more than 300 seconds. Stop if takes longer than 900 seconds. Exeute max 3 commands in parallel.
|
## Example of parallel execution of four commands, only if directories exist. Warn if execution takes more than 300 seconds. Stop if takes longer than 900 seconds. Exeute max 3 commands in parallel.
|
||||||
## commands="du -csh /var;du -csh /etc;du -csh /home;du -csh /usr"
|
## commands="du -csh /var;du -csh /etc;du -csh /home;du -csh /usr"
|
||||||
|
@ -862,7 +865,7 @@ function ExecTasks {
|
||||||
local mainInput="${1}" # Contains list of pids / commands separated by semicolons or filepath to list of pids / commands
|
local mainInput="${1}" # Contains list of pids / commands separated by semicolons or filepath to list of pids / commands
|
||||||
|
|
||||||
# Optional arguments
|
# Optional arguments
|
||||||
local id="${2:-base}" # Optional ID in order to identify global variables from this run (only bash variable names, no '-'). Global variables are WAIT_FOR_TASK_COMPLETION_$id and HARD_MAX_EXEC_TIME_REACHED_$id
|
local id="${2:-(undisclosed)}" # Optional ID in order to identify global variables from this run (only bash variable names, no '-'). Global variables are WAIT_FOR_TASK_COMPLETION_$id and HARD_MAX_EXEC_TIME_REACHED_$id
|
||||||
local readFromFile="${3:-false}" # Is mainInput / auxInput a semicolon separated list (true) or a filepath (false)
|
local readFromFile="${3:-false}" # Is mainInput / auxInput a semicolon separated list (true) or a filepath (false)
|
||||||
local softPerProcessTime="${4:-0}" # Max time (in seconds) a pid or command can run before a warning is logged, unless set to 0
|
local softPerProcessTime="${4:-0}" # Max time (in seconds) a pid or command can run before a warning is logged, unless set to 0
|
||||||
local hardPerProcessTime="${5:-0}" # Max time (in seconds) a pid or command can run before the given command / pid is stopped, unless set to 0
|
local hardPerProcessTime="${5:-0}" # Max time (in seconds) a pid or command can run before the given command / pid is stopped, unless set to 0
|
||||||
|
@ -912,7 +915,7 @@ function ExecTasks {
|
||||||
local currentCommand # Variable containing currently processed command
|
local currentCommand # Variable containing currently processed command
|
||||||
local currentCommandCondition # Variable containing currently processed conditional command
|
local currentCommandCondition # Variable containing currently processed conditional command
|
||||||
local commandsArrayPid=() # Array containing commands indexed by pids
|
local commandsArrayPid=() # Array containing commands indexed by pids
|
||||||
local commandsArrayOutput=() # Array contining command results indexed by pids
|
local commandsArrayOutput=() # Array containing command results indexed by pids
|
||||||
local postponedRetryCount=0 # Number of current postponed commands retries
|
local postponedRetryCount=0 # Number of current postponed commands retries
|
||||||
local postponedItemCount=0 # Number of commands that have been postponed (keep at least one in order to check once)
|
local postponedItemCount=0 # Number of commands that have been postponed (keep at least one in order to check once)
|
||||||
local postponedCounter=0
|
local postponedCounter=0
|
||||||
|
@ -944,6 +947,7 @@ function ExecTasks {
|
||||||
local softAlert=false # Does a soft alert need to be triggered, if yes, send an alert once
|
local softAlert=false # Does a soft alert need to be triggered, if yes, send an alert once
|
||||||
local failedPidsList # List containing failed pids with exit code separated by semicolons (eg : 2355:1;4534:2;2354:3)
|
local failedPidsList # List containing failed pids with exit code separated by semicolons (eg : 2355:1;4534:2;2354:3)
|
||||||
local randomOutputName # Random filename for command outputs
|
local randomOutputName # Random filename for command outputs
|
||||||
|
local currentRunningPids # String of pids running, used for debugging purposes only
|
||||||
|
|
||||||
# Initialise global variable
|
# Initialise global variable
|
||||||
eval "WAIT_FOR_TASK_COMPLETION_$id=\"\""
|
eval "WAIT_FOR_TASK_COMPLETION_$id=\"\""
|
||||||
|
@ -984,7 +988,7 @@ function ExecTasks {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $functionMode == "WaitForTaskCompletion" ]; then
|
if [ $functionMode == "WaitForTaskCompletion" ]; then
|
||||||
# Force first while loop condition to be true because we don't deal with counters but pids in WaitForTaskCompletion mode
|
# Force first while loop condition to be true because we do not deal with counters but pids in WaitForTaskCompletion mode
|
||||||
counter=$mainItemCount
|
counter=$mainItemCount
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -992,7 +996,7 @@ function ExecTasks {
|
||||||
|
|
||||||
# soft / hard execution time checks that needs to be a subfunction since it is called both from main loop and from parallelExec sub loop
|
# soft / hard execution time checks that needs to be a subfunction since it is called both from main loop and from parallelExec sub loop
|
||||||
function _ExecTasksTimeCheck {
|
function _ExecTasksTimeCheck {
|
||||||
if [ $spinner == true ]; then
|
if [ $spinner == true ] && [ "$_OFUNCTIONS_SHOW_SPINNER" != false ]; then
|
||||||
Spinner
|
Spinner
|
||||||
fi
|
fi
|
||||||
if [ $counting == true ]; then
|
if [ $counting == true ]; then
|
||||||
|
@ -1011,7 +1015,7 @@ function ExecTasks {
|
||||||
if [ $log_ttime -ne $exec_time ]; then # Fix when sleep time lower than 1 second
|
if [ $log_ttime -ne $exec_time ]; then # Fix when sleep time lower than 1 second
|
||||||
log_ttime=$exec_time
|
log_ttime=$exec_time
|
||||||
if [ $functionMode == "WaitForTaskCompletion" ]; then
|
if [ $functionMode == "WaitForTaskCompletion" ]; then
|
||||||
Logger "Current tasks still running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE"
|
Logger "Current tasks ID=$id still running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE"
|
||||||
elif [ $functionMode == "ParallelExec" ]; then
|
elif [ $functionMode == "ParallelExec" ]; then
|
||||||
Logger "There are $((mainItemCount-counter+postponedItemCount)) / $mainItemCount tasks in the queue of which $postponedItemCount are postponed. Currently, ${#pidsArray[@]} tasks running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE"
|
Logger "There are $((mainItemCount-counter+postponedItemCount)) / $mainItemCount tasks in the queue of which $postponedItemCount are postponed. Currently, ${#pidsArray[@]} tasks running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE"
|
||||||
fi
|
fi
|
||||||
|
@ -1057,6 +1061,11 @@ function ExecTasks {
|
||||||
function _ExecTasksPidsCheck {
|
function _ExecTasksPidsCheck {
|
||||||
newPidsArray=()
|
newPidsArray=()
|
||||||
|
|
||||||
|
if [ "$currentRunningPids" != "$(joinString " " ${pidsArray[@]})" ]; then
|
||||||
|
Logger "ExecTask running for pids [$(joinString " " ${pidsArray[@]})]." "DEBUG"
|
||||||
|
currentRunningPids="$(joinString " " ${pidsArray[@]})"
|
||||||
|
fi
|
||||||
|
|
||||||
for pid in "${pidsArray[@]}"; do
|
for pid in "${pidsArray[@]}"; do
|
||||||
if [ $(IsInteger $pid) -eq 1 ]; then
|
if [ $(IsInteger $pid) -eq 1 ]; then
|
||||||
if kill -0 $pid > /dev/null 2>&1; then
|
if kill -0 $pid > /dev/null 2>&1; then
|
||||||
|
@ -1064,7 +1073,7 @@ function ExecTasks {
|
||||||
pidState="$(eval $PROCESS_STATE_CMD)"
|
pidState="$(eval $PROCESS_STATE_CMD)"
|
||||||
if [ "$pidState" != "D" ] && [ "$pidState" != "Z" ]; then
|
if [ "$pidState" != "D" ] && [ "$pidState" != "Z" ]; then
|
||||||
|
|
||||||
# Check if pid hasn't run more than soft/hard perProcessTime
|
# Check if pid has not run more than soft/hard perProcessTime
|
||||||
pidsTimeArray[$pid]=$((SECONDS - seconds_begin))
|
pidsTimeArray[$pid]=$((SECONDS - seconds_begin))
|
||||||
if [ ${pidsTimeArray[$pid]} -gt $softPerProcessTime ]; then
|
if [ ${pidsTimeArray[$pid]} -gt $softPerProcessTime ]; then
|
||||||
if [ "$softAlert" != true ] && [ $softPerProcessTime -ne 0 ] && [ $noTimeErrorLog != true ]; then
|
if [ "$softAlert" != true ] && [ $softPerProcessTime -ne 0 ] && [ $noTimeErrorLog != true ]; then
|
||||||
|
@ -1108,13 +1117,13 @@ function ExecTasks {
|
||||||
retval=$?
|
retval=$?
|
||||||
# Check for valid exit codes
|
# Check for valid exit codes
|
||||||
if [ $(ArrayContains $retval "${validExitCodes[@]}") -eq 0 ]; then
|
if [ $(ArrayContains $retval "${validExitCodes[@]}") -eq 0 ]; then
|
||||||
if [ $noErrorLogsAtAll != true ]; then
|
if [ "$noErrorLogsAtAll" != true ]; then
|
||||||
Logger "${FUNCNAME[0]} called by [$id] finished monitoring pid [$pid] with exitcode [$retval]." "ERROR"
|
Logger "${FUNCNAME[0]} called by [$id] finished monitoring pid [$pid] with exitcode [$retval]." "ERROR"
|
||||||
if [ "$functionMode" == "ParallelExec" ]; then
|
if [ "$functionMode" == "ParallelExec" ]; then
|
||||||
Logger "Command was [${commandsArrayPid[$pid]}]." "ERROR"
|
Logger "Command was [${commandsArrayPid[$pid]}]." "ERROR"
|
||||||
fi
|
fi
|
||||||
if [ -f "${commandsArrayOutput[$pid]}" ]; then
|
if [ -f "${commandsArrayOutput[$pid]}" ]; then
|
||||||
Logger "Command output was [$(cat ${commandsArrayOutput[$pid]})\n]." "ERROR"
|
Logger "Truncated output:\n$(head -c16384 "${commandsArrayOutput[$pid]}")" "ERROR"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
errorcount=$((errorcount+1))
|
errorcount=$((errorcount+1))
|
||||||
|
@ -1124,6 +1133,11 @@ function ExecTasks {
|
||||||
else
|
else
|
||||||
failedPidsList="$failedPidsList;$pid:$retval"
|
failedPidsList="$failedPidsList;$pid:$retval"
|
||||||
fi
|
fi
|
||||||
|
elif [ "$_DEBUG" == true ]; then
|
||||||
|
if [ -f "${commandsArrayOutput[$pid]}" ]; then
|
||||||
|
Logger "${FUNCNAME[0]} called by [$id] finished monitoring pid [$pid] with exitcode [$retval]." "DEBUG"
|
||||||
|
Logger "Truncated output:\n$(head -c16384 "${commandsArrayOutput[$pid]}")" "DEBUG"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
Logger "${FUNCNAME[0]} called by [$id] finished monitoring pid [$pid] with exitcode [$retval]." "DEBUG"
|
Logger "${FUNCNAME[0]} called by [$id] finished monitoring pid [$pid] with exitcode [$retval]." "DEBUG"
|
||||||
fi
|
fi
|
||||||
|
@ -1216,7 +1230,7 @@ function ExecTasks {
|
||||||
postponedRetryCount=0
|
postponedRetryCount=0
|
||||||
postponedExecTime=0
|
postponedExecTime=0
|
||||||
fi
|
fi
|
||||||
if ([ $postponedRetryCount -lt $maxPostponeRetries ] && [ $postponedExecTime -ge $((minTimeBetweenRetries)) ]) || [ $isPostponedCommand == false ]; then
|
if ([ $postponedRetryCount -lt $maxPostponeRetries ] && [ $postponedExecTime -ge $minTimeBetweenRetries ]) || [ $isPostponedCommand == false ]; then
|
||||||
if [ "$currentCommandCondition" != "" ]; then
|
if [ "$currentCommandCondition" != "" ]; then
|
||||||
Logger "Checking condition [$currentCommandCondition] for command [$currentCommand]." "DEBUG"
|
Logger "Checking condition [$currentCommandCondition] for command [$currentCommand]." "DEBUG"
|
||||||
eval "$currentCommandCondition" &
|
eval "$currentCommandCondition" &
|
||||||
|
@ -1260,11 +1274,11 @@ function ExecTasks {
|
||||||
if [ $executeCommand == true ]; then
|
if [ $executeCommand == true ]; then
|
||||||
Logger "Running command [$currentCommand]." "DEBUG"
|
Logger "Running command [$currentCommand]." "DEBUG"
|
||||||
randomOutputName=$(date '+%Y%m%dT%H%M%S').$(PoorMansRandomGenerator 5)
|
randomOutputName=$(date '+%Y%m%dT%H%M%S').$(PoorMansRandomGenerator 5)
|
||||||
eval "$currentCommand" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$id.$pid.$randomOutputName.$SCRIPT_PID.$TSTAMP" 2>&1 &
|
eval "$currentCommand" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$id.$randomOutputName.$SCRIPT_PID.$TSTAMP" 2>&1 &
|
||||||
pid=$!
|
pid=$!
|
||||||
pidsArray+=($pid)
|
pidsArray+=($pid)
|
||||||
commandsArrayPid[$pid]="$currentCommand"
|
commandsArrayPid[$pid]="$currentCommand"
|
||||||
commandsArrayOutput[$pid]="$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$id.$pid.$randomOutputName.$SCRIPT_PID.$TSTAMP"
|
commandsArrayOutput[$pid]="$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$id.$randomOutputName.$SCRIPT_PID.$TSTAMP"
|
||||||
# Initialize pid execution time array
|
# Initialize pid execution time array
|
||||||
pidsTimeArray[$pid]=0
|
pidsTimeArray[$pid]=0
|
||||||
else
|
else
|
||||||
|
@ -1288,6 +1302,13 @@ function ExecTasks {
|
||||||
|
|
||||||
eval "WAIT_FOR_TASK_COMPLETION_$id=\"$failedPidsList\""
|
eval "WAIT_FOR_TASK_COMPLETION_$id=\"$failedPidsList\""
|
||||||
|
|
||||||
|
# CleanUp ExecTasks temp files
|
||||||
|
if [ "$_DEBUG" != true ]; then
|
||||||
|
[ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$id.$randomOutputName.$SCRIPT_PID.$TSTAMP" ] && rm -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$id.$randomOutputName.$SCRIPT_PID.$TSTAMP" > /dev/null 2>&1
|
||||||
|
[ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}-postponedMain.$id.$SCRIPT_PID.$TSTAMP" ] && rm -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}-postponedMain.$id.$SCRIPT_PID.$TSTAMP" > /dev/null 2>&1
|
||||||
|
[ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}-postponedAux.$id.$SCRIPT_PID.$TSTAMP" ] && rm -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}-postponedAux.$id.$SCRIPT_PID.$TSTAMP" > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $mainItemCount -eq 1 ]; then
|
if [ $mainItemCount -eq 1 ]; then
|
||||||
return $retval
|
return $retval
|
||||||
else
|
else
|
||||||
|
@ -1486,6 +1507,9 @@ function GetLocalOS {
|
||||||
*"Android"*)
|
*"Android"*)
|
||||||
LOCAL_OS="Android"
|
LOCAL_OS="Android"
|
||||||
;;
|
;;
|
||||||
|
*"qnap"*)
|
||||||
|
LOCAL_OS="Qnap"
|
||||||
|
;;
|
||||||
*"Linux"*)
|
*"Linux"*)
|
||||||
LOCAL_OS="Linux"
|
LOCAL_OS="Linux"
|
||||||
;;
|
;;
|
||||||
|
@ -1521,10 +1545,10 @@ function GetLocalOS {
|
||||||
|
|
||||||
# Get linux versions
|
# Get linux versions
|
||||||
if [ -f "/etc/os-release" ]; then
|
if [ -f "/etc/os-release" ]; then
|
||||||
localOsName=$(GetConfFileValue "/etc/os-release" "NAME" true)
|
localOsName="$(GetConfFileValue "/etc/os-release" "NAME" true)"
|
||||||
localOsVer=$(GetConfFileValue "/etc/os-release" "VERSION" true)
|
localOsVer="$(GetConfFileValue "/etc/os-release" "VERSION" true)"
|
||||||
elif [ "$LOCAL_OS" == "BusyBox" ]; then
|
elif [ "$LOCAL_OS" == "BusyBox" ]; then
|
||||||
localOsVer=$(ls --help 2>&1 | head -1 | cut -f2 -d' ')
|
localOsVer="$(ls --help 2>&1 | head -1 | cut -f2 -d' ')"
|
||||||
localOsName="BusyBox"
|
localOsName="BusyBox"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1630,7 +1654,7 @@ function GetRemoteOS {
|
||||||
local remoteOsVar
|
local remoteOsVar
|
||||||
|
|
||||||
$SSH_CMD env LC_ALL=C env _REMOTE_TOKEN="$_REMOTE_TOKEN" bash -s << 'ENDSSH' >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" 2>&1
|
$SSH_CMD env LC_ALL=C env _REMOTE_TOKEN="$_REMOTE_TOKEN" bash -s << 'ENDSSH' >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" 2>&1
|
||||||
|
_REMOTE_TOKEN="(o_0)"
|
||||||
|
|
||||||
function GetOs {
|
function GetOs {
|
||||||
local localOsVar
|
local localOsVar
|
||||||
|
@ -1665,7 +1689,7 @@ function GetOs {
|
||||||
localOsVer=$(grep "^VERSION=" "$osInfo")
|
localOsVer=$(grep "^VERSION=" "$osInfo")
|
||||||
localOsVer="${localOsVer##*=}"
|
localOsVer="${localOsVer##*=}"
|
||||||
elif [ "$localOsVar" == "BusyBox" ]; then
|
elif [ "$localOsVar" == "BusyBox" ]; then
|
||||||
localOsVer=`ls --help 2>&1 | head -1 | cut -f2 -d' '`
|
localOsVer="$(ls --help 2>&1 | head -1 | cut -f2 -d' ')"
|
||||||
localOsName="BusyBox"
|
localOsName="BusyBox"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1702,18 +1726,21 @@ ENDSSH
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
Logger "Cannot connect to remote system [$REMOTE_HOST] port [$REMOTE_PORT] as [$REMOTE_USER]." "CRITICAL"
|
Logger "Cannot connect to remote system [$REMOTE_HOST] port [$REMOTE_PORT] as [$REMOTE_USER]." "CRITICAL"
|
||||||
if [ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" ]; then
|
if [ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" ]; then
|
||||||
Logger "$(cat "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP")" "ERROR"
|
Logger "$(head -c16384 "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP")" "ERROR"
|
||||||
fi
|
fi
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" ]; then
|
if [ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" ]; then
|
||||||
remoteOsVar=$(cat "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP")
|
remoteOsVar="$(head -c16384 "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP")"
|
||||||
case $remoteOsVar in
|
case $remoteOsVar in
|
||||||
*"Android"*)
|
*"Android"*)
|
||||||
REMOTE_OS="Android"
|
REMOTE_OS="Android"
|
||||||
;;
|
;;
|
||||||
|
*"qnap"*)
|
||||||
|
REMOTE_OS="Qnap"
|
||||||
|
;;
|
||||||
*"Linux"*)
|
*"Linux"*)
|
||||||
REMOTE_OS="Linux"
|
REMOTE_OS="Linux"
|
||||||
;;
|
;;
|
||||||
|
@ -1768,7 +1795,6 @@ function RunLocalCommand {
|
||||||
eval "$command" > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" 2>&1 &
|
eval "$command" > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" 2>&1 &
|
||||||
|
|
||||||
ExecTasks $! "${FUNCNAME[0]}" false 0 0 0 $hardMaxTime true $SLEEP_TIME $KEEP_LOGGING
|
ExecTasks $! "${FUNCNAME[0]}" false 0 0 0 $hardMaxTime true $SLEEP_TIME $KEEP_LOGGING
|
||||||
#ExecTasks "${FUNCNAME[0]}" 0 0 $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME $SLEEP_TIME $KEEP_LOGGING true true false false 1 $!
|
|
||||||
retval=$?
|
retval=$?
|
||||||
if [ $retval -eq 0 ]; then
|
if [ $retval -eq 0 ]; then
|
||||||
Logger "Command succeded." "NOTICE"
|
Logger "Command succeded." "NOTICE"
|
||||||
|
@ -1777,13 +1803,9 @@ function RunLocalCommand {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $_LOGGER_VERBOSE == true ] || [ $retval -ne 0 ]; then
|
if [ $_LOGGER_VERBOSE == true ] || [ $retval -ne 0 ]; then
|
||||||
Logger "Command output:\n$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP)" "NOTICE"
|
Logger "Truncated output:\n$(head -c16384 "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP")" "NOTICE"
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$STOP_ON_CMD_ERROR" == true ] && [ $retval -ne 0 ]; then
|
|
||||||
Logger "Stopping on command execution error." "CRITICAL"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
return $retval
|
||||||
}
|
}
|
||||||
|
|
||||||
## Runs remote command $1 and waits for completition in $2 seconds
|
## Runs remote command $1 and waits for completition in $2 seconds
|
||||||
|
@ -1810,7 +1832,6 @@ function RunRemoteCommand {
|
||||||
Logger "cmd: $cmd" "DEBUG"
|
Logger "cmd: $cmd" "DEBUG"
|
||||||
eval "$cmd" &
|
eval "$cmd" &
|
||||||
ExecTasks $! "${FUNCNAME[0]}" false 0 0 0 $hardMaxTime true $SLEEP_TIME $KEEP_LOGGING
|
ExecTasks $! "${FUNCNAME[0]}" false 0 0 0 $hardMaxTime true $SLEEP_TIME $KEEP_LOGGING
|
||||||
#ExecTasks "${FUNCNAME[0]}" 0 0 $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME $SLEEP_TIME $KEEP_LOGGING true true false false 1 $!
|
|
||||||
retval=$?
|
retval=$?
|
||||||
if [ $retval -eq 0 ]; then
|
if [ $retval -eq 0 ]; then
|
||||||
Logger "Command succeded." "NOTICE"
|
Logger "Command succeded." "NOTICE"
|
||||||
|
@ -1818,15 +1839,10 @@ function RunRemoteCommand {
|
||||||
Logger "Command failed." "ERROR"
|
Logger "Command failed." "ERROR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" ] && ([ $_LOGGER_VERBOSE == true ] || [ $retval -ne 0 ])
|
if [ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" ] && ([ $_LOGGER_VERBOSE == true ] || [ $retval -ne 0 ]); then
|
||||||
then
|
Logger "Truncated output:\n$(head -c16384 "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP")" "NOTICE"
|
||||||
Logger "Command output:\n$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP)" "NOTICE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$STOP_ON_CMD_ERROR" == true ] && [ $retval -ne 0 ]; then
|
|
||||||
Logger "Stopping on command execution error." "CRITICAL"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
return $retval
|
||||||
}
|
}
|
||||||
|
|
||||||
function RunBeforeHook {
|
function RunBeforeHook {
|
||||||
|
@ -1845,7 +1861,14 @@ function RunBeforeHook {
|
||||||
fi
|
fi
|
||||||
if [ "$pids" != "" ]; then
|
if [ "$pids" != "" ]; then
|
||||||
ExecTasks $pids "${FUNCNAME[0]}" false 0 0 0 0 true $SLEEP_TIME $KEEP_LOGGING
|
ExecTasks $pids "${FUNCNAME[0]}" false 0 0 0 0 true $SLEEP_TIME $KEEP_LOGGING
|
||||||
#ExecTasks "${FUNCNAME[0]}" 0 0 0 0 true true false false 1 $pids
|
retval=$?
|
||||||
|
else
|
||||||
|
retval=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$STOP_ON_CMD_ERROR" == true ] && [ $retval -ne 0 ]; then
|
||||||
|
Logger "Stopping on command execution error." "CRITICAL"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1865,10 +1888,45 @@ function RunAfterHook {
|
||||||
fi
|
fi
|
||||||
if [ "$pids" != "" ]; then
|
if [ "$pids" != "" ]; then
|
||||||
ExecTasks $pids "${FUNCNAME[0]}" false 0 0 0 0 true $SLEEP_TIME $KEEP_LOGGING
|
ExecTasks $pids "${FUNCNAME[0]}" false 0 0 0 0 true $SLEEP_TIME $KEEP_LOGGING
|
||||||
#ExecTasks "${FUNCNAME[0]}" 0 0 0 0 true true false false 1 $pids
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function TimeCheck {
|
||||||
|
# Checks if more than deltatime seconds have passed since last check, which is stored in timefile
|
||||||
|
__CheckArguments 2 $# "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
|
local timefile="${1}"
|
||||||
|
local deltatime="${2}"
|
||||||
|
|
||||||
|
if [ -f "$timefile" ]; then
|
||||||
|
result=$(cat "$timefile")
|
||||||
|
tstamp=$(date +%s)
|
||||||
|
if [ $((tstamp-result)) -gt $deltatime ]; then
|
||||||
|
echo "$(date +%s)" > "$timefile"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "$(date +%s)" > "$timefile"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function Ping {
|
||||||
|
# Simple ping check
|
||||||
|
__CheckArguments 1 $# "$@"
|
||||||
|
|
||||||
|
local host="${1}"
|
||||||
|
|
||||||
|
local retval
|
||||||
|
|
||||||
|
eval "$PING_CMD $host > /dev/null 2>&1" &
|
||||||
|
ExecTasks $! "${FUNCNAME[0]}" false 0 0 60 180 true $SLEEP_TIME $KEEP_LOGGING
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function CheckConnectivityRemoteHost {
|
function CheckConnectivityRemoteHost {
|
||||||
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
|
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
|
@ -1879,7 +1937,6 @@ function CheckConnectivityRemoteHost {
|
||||||
if [ "$REMOTE_HOST_PING" != false ] && [ "$REMOTE_OPERATION" != false ]; then
|
if [ "$REMOTE_HOST_PING" != false ] && [ "$REMOTE_OPERATION" != false ]; then
|
||||||
eval "$PING_CMD $REMOTE_HOST > /dev/null 2>&1" &
|
eval "$PING_CMD $REMOTE_HOST > /dev/null 2>&1" &
|
||||||
ExecTasks $! "${FUNCNAME[0]}" false 0 0 60 180 true $SLEEP_TIME $KEEP_LOGGING
|
ExecTasks $! "${FUNCNAME[0]}" false 0 0 60 180 true $SLEEP_TIME $KEEP_LOGGING
|
||||||
#ExecTasks "${FUNCNAME[0]}" 0 0 60 180 $SLEEP_TIME $KEEP_LOGGING true true false false 1 $!
|
|
||||||
retval=$?
|
retval=$?
|
||||||
if [ $retval -ne 0 ]; then
|
if [ $retval -ne 0 ]; then
|
||||||
Logger "Cannot ping [$REMOTE_HOST]. Return code [$retval]." "WARN"
|
Logger "Cannot ping [$REMOTE_HOST]. Return code [$retval]." "WARN"
|
||||||
|
@ -1890,7 +1947,13 @@ function CheckConnectivityRemoteHost {
|
||||||
}
|
}
|
||||||
|
|
||||||
function CheckConnectivity3rdPartyHosts {
|
function CheckConnectivity3rdPartyHosts {
|
||||||
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
|
# Check if at least one host is reachable in order to diag internet
|
||||||
|
# third_party_hosts_ips=('1.1.1.1' '8.8.8.8' 'kernel.org' 'google.com')
|
||||||
|
# CheckConnectivity3rdPartyHosts $third_party_hosts_ips
|
||||||
|
|
||||||
|
__CheckArguments 0-1 $# "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
|
local remote_3rd_party_hosts="${1}" # Optional list of hosts to check
|
||||||
|
|
||||||
local remote3rdPartySuccess
|
local remote3rdPartySuccess
|
||||||
local retval
|
local retval
|
||||||
|
@ -1898,18 +1961,21 @@ function CheckConnectivity3rdPartyHosts {
|
||||||
|
|
||||||
if [ "$_PARANOIA_DEBUG" != true ]; then # Do not loose time in paranoia debug #__WITH_PARANOIA_DEBUG
|
if [ "$_PARANOIA_DEBUG" != true ]; then # Do not loose time in paranoia debug #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
if [ "$REMOTE_3RD_PARTY_HOSTS" != "" ]; then
|
if [ "$remote_3rd_party_hosts" == "" ]; then
|
||||||
|
remote_3rd_party_hosts="$REMOTE_3RD_PARTY_HOSTS"
|
||||||
|
fi
|
||||||
|
if [ "$remote_3rd_party_hosts" != "" ]; then
|
||||||
remote3rdPartySuccess=false
|
remote3rdPartySuccess=false
|
||||||
for i in $REMOTE_3RD_PARTY_HOSTS
|
for i in $remote_3rd_party_hosts
|
||||||
do
|
do
|
||||||
eval "$PING_CMD $i > /dev/null 2>&1" &
|
eval "$PING_CMD $i > /dev/null 2>&1" &
|
||||||
ExecTasks $! "${FUNCNAME[0]}" false 0 0 60 180 true $SLEEP_TIME $KEEP_LOGGING
|
ExecTasks $! "${FUNCNAME[0]}" false 0 0 60 180 true $SLEEP_TIME $KEEP_LOGGING
|
||||||
#ExecTasks "${FUNCNAME[0]}" 0 0 180 360 $SLEEP_TIME $KEEP_LOGGING true true false false 1 $!
|
|
||||||
retval=$?
|
retval=$?
|
||||||
if [ $retval -ne 0 ]; then
|
if [ $retval -ne 0 ]; then
|
||||||
Logger "Cannot ping 3rd party host [$i]. Return code [$retval]." "NOTICE"
|
Logger "Cannot ping 3rd party host [$i]. Return code [$retval]." "NOTICE"
|
||||||
else
|
else
|
||||||
remote3rdPartySuccess=true
|
remote3rdPartySuccess=true
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -1959,8 +2025,8 @@ function RsyncPatternsFromAdd {
|
||||||
__CheckArguments 2 $# "$@" #__WITH_PARANOIA_DEBUG
|
__CheckArguments 2 $# "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
## Check if the exclude list has a full path, and if not, add the config file path if there is one
|
## Check if the exclude list has a full path, and if not, add the config file path if there is one
|
||||||
if [ "$(basename $patternFrom)" == "$patternFrom" ]; then
|
if [ "$(basename "$patternFrom")" == "$patternFrom" ]; then
|
||||||
patternFrom="$(dirname $CONFIG_FILE)/$patternFrom"
|
patternFrom="$(dirname "$CONFIG_FILE")/$patternFrom"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -e "$patternFrom" ]; then
|
if [ -e "$patternFrom" ]; then
|
||||||
|
@ -1999,8 +2065,11 @@ function RsyncPatterns {
|
||||||
RsyncPatternsFromAdd "exclude" "$RSYNC_EXCLUDE_FROM"
|
RsyncPatternsFromAdd "exclude" "$RSYNC_EXCLUDE_FROM"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
# osync target-helper specific clause
|
||||||
|
if [ "$_SYNC_ON_CHANGES" != "target" ]; then
|
||||||
Logger "Bogus RSYNC_PATTERN_FIRST value in config file. Will not use rsync patterns." "WARN"
|
Logger "Bogus RSYNC_PATTERN_FIRST value in config file. Will not use rsync patterns." "WARN"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function PreInit {
|
function PreInit {
|
||||||
|
@ -2012,7 +2081,7 @@ function PreInit {
|
||||||
if [ "$SSH_COMPRESSION" != false ]; then
|
if [ "$SSH_COMPRESSION" != false ]; then
|
||||||
SSH_COMP=-C
|
SSH_COMP=-C
|
||||||
else
|
else
|
||||||
SSH_COMP=
|
SSH_COMP="-o Compression=no"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Ignore SSH known host verification
|
## Ignore SSH known host verification
|
||||||
|
@ -2020,6 +2089,16 @@ function PreInit {
|
||||||
SSH_OPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
|
SSH_OPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
## SSH ControlMaster Multiplexing
|
||||||
|
if [ "$SSH_CONTROLMASTER" == true ]; then
|
||||||
|
SSH_OPTS="$SSH_OPTS -o ControlMaster=auto -o ControlPersist=yes -o ControlPath=\"$RUN_DIR/$PROGRAM.ctrlm.%r@%h.$SCRIPT_PID.$TSTAMP\""
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Optional SSH arguments
|
||||||
|
if [ "$SSH_OPTIONAL_ARGS" != "" ]; then
|
||||||
|
SSH_OPTS="$SSH_OPTS $SSH_OPTIONAL_ARGS"
|
||||||
|
fi
|
||||||
|
|
||||||
## Support for older config files without RSYNC_EXECUTABLE option
|
## Support for older config files without RSYNC_EXECUTABLE option
|
||||||
if [ "$RSYNC_EXECUTABLE" == "" ]; then
|
if [ "$RSYNC_EXECUTABLE" == "" ]; then
|
||||||
RSYNC_EXECUTABLE=rsync
|
RSYNC_EXECUTABLE=rsync
|
||||||
|
@ -2043,7 +2122,7 @@ function PreInit {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Set compression executable and extension
|
## Set compression executable and extension
|
||||||
if [ "$(IsInteger $COMPRESSION_LEVEL)" -eq 0 ]; then
|
if [ "$(IsInteger "$COMPRESSION_LEVEL")" -eq 0 ]; then
|
||||||
COMPRESSION_LEVEL=3
|
COMPRESSION_LEVEL=3
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -2060,6 +2139,11 @@ function PostInit {
|
||||||
SSH_CMD="$(type -p sshpass) -f $SSH_PASSWORD_FILE $(type -p ssh) $SSH_COMP -q $SSH_OPTS $REMOTE_USER@$REMOTE_HOST -p $REMOTE_PORT"
|
SSH_CMD="$(type -p sshpass) -f $SSH_PASSWORD_FILE $(type -p ssh) $SSH_COMP -q $SSH_OPTS $REMOTE_USER@$REMOTE_HOST -p $REMOTE_PORT"
|
||||||
SCP_CMD="$(type -p sshpass) -f $SSH_PASSWORD_FILE $(type -p scp) $SSH_COMP -q -P $REMOTE_PORT"
|
SCP_CMD="$(type -p sshpass) -f $SSH_PASSWORD_FILE $(type -p scp) $SSH_COMP -q -P $REMOTE_PORT"
|
||||||
RSYNC_SSH_CMD="$(type -p sshpass) -f $SSH_PASSWORD_FILE $(type -p ssh) $SSH_COMP -q $SSH_OPTS -p $REMOTE_PORT"
|
RSYNC_SSH_CMD="$(type -p sshpass) -f $SSH_PASSWORD_FILE $(type -p ssh) $SSH_COMP -q $SSH_OPTS -p $REMOTE_PORT"
|
||||||
|
elif [ $KRB5 ]; then
|
||||||
|
SSH_PASSWORD=""
|
||||||
|
SSH_CMD="$(type -p ssh) $SSH_COMP -q $SSH_OPTS $REMOTE_USER@$REMOTE_HOST -p $REMOTE_PORT"
|
||||||
|
SCP_CMD="$(type -p scp) $SSH_COMP -q -P $REMOTE_PORT"
|
||||||
|
RSYNC_SSH_CMD="$(type -p ssh) $SSH_COMP -q $SSH_OPTS -p $REMOTE_PORT"
|
||||||
else
|
else
|
||||||
SSH_PASSWORD=""
|
SSH_PASSWORD=""
|
||||||
SSH_CMD=""
|
SSH_CMD=""
|
||||||
|
@ -2180,7 +2264,7 @@ function InitRemoteOSDependingSettings {
|
||||||
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
|
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
if [ "$REMOTE_OS" == "msys" ] || [ "$REMOTE_OS" == "Cygwin" ]; then
|
if [ "$REMOTE_OS" == "msys" ] || [ "$REMOTE_OS" == "Cygwin" ]; then
|
||||||
REMOTE_FIND_CMD=$(dirname $BASH)/find
|
REMOTE_FIND_CMD="$(dirname $BASH)/find"
|
||||||
else
|
else
|
||||||
REMOTE_FIND_CMD=find
|
REMOTE_FIND_CMD=find
|
||||||
fi
|
fi
|
||||||
|
@ -2196,6 +2280,16 @@ function InitRemoteOSDependingSettings {
|
||||||
|
|
||||||
## Set rsync default arguments (complete with -r or -d depending on recursivity later)
|
## Set rsync default arguments (complete with -r or -d depending on recursivity later)
|
||||||
RSYNC_DEFAULT_ARGS="-ltD -8"
|
RSYNC_DEFAULT_ARGS="-ltD -8"
|
||||||
|
|
||||||
|
## NPF-MOD: Regarding #242, we need to add --old-args if rsync > 3.2.3
|
||||||
|
#rsync_version=$("${RSYNC_EXECUTABLE}" --version 2>/dev/null| head -1 | awk '{print $3}')
|
||||||
|
#if [ $(VerComp $rsync_version 3.2.3) -eq 1 ]; then
|
||||||
|
# RSYNC_DEFAULT_ARGS="$RSYNC_DEFAULT_ARGS --old-args"
|
||||||
|
#fi
|
||||||
|
# NPF-MOD: Strangely enough, also happens on RHEL7 rsync 3.1.1
|
||||||
|
# Let's resolve this easier
|
||||||
|
export RSYNC_OLD_ARGS=1
|
||||||
|
|
||||||
if [ "$_DRYRUN" == true ]; then
|
if [ "$_DRYRUN" == true ]; then
|
||||||
RSYNC_DRY_ARG="-n"
|
RSYNC_DRY_ARG="-n"
|
||||||
DRY_WARNING="/!\ DRY RUN "
|
DRY_WARNING="/!\ DRY RUN "
|
||||||
|
@ -2203,6 +2297,7 @@ function InitRemoteOSDependingSettings {
|
||||||
RSYNC_DRY_ARG=""
|
RSYNC_DRY_ARG=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
RSYNC_ATTR_ARGS=""
|
RSYNC_ATTR_ARGS=""
|
||||||
if [ "$PRESERVE_PERMISSIONS" != false ]; then
|
if [ "$PRESERVE_PERMISSIONS" != false ]; then
|
||||||
RSYNC_ATTR_ARGS=$RSYNC_ATTR_ARGS" -p"
|
RSYNC_ATTR_ARGS=$RSYNC_ATTR_ARGS" -p"
|
||||||
|
@ -2232,8 +2327,11 @@ function InitRemoteOSDependingSettings {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ "$RSYNC_COMPRESS" == true ]; then
|
if [ "$RSYNC_COMPRESS" == true ]; then
|
||||||
if [ "$LOCAL_OS" != "MacOSX" ] && [ "$REMOTE_OS" != "MacOSX" ]; then
|
SKIP_COMPRESS_EXTENSIONS="--skip-compress=3fr/3g2/3gp/3gpp/7z/aac/ace/amr/apk/appx/appxbundle/arc/arj/arw/asf/avi/bz/bz2/cab/cr2/crypt[5678]/dat/dcr/deb/dmg/drc/ear/erf/flac/flv/gif/gpg/gz/iiq/jar/jp2/jpeg/jpg/h26[45]/k25/kdc/kgb/lha/lz/lzma/lzo/lzx/m4[apv]/mef/mkv/mos/mov/mp[34]/mpeg/mp[gv]/msi/nef/oga/ogg/ogv/opus/orf/pak/pef/png/qt/rar/r[0-9][0-9]/rz/rpm/rw2/rzip/s7z/sfark/sfx/sr2/srf/svgz/t[gb]z/tlz/txz/vob/wim/wma/wmv/xz/zip/zst"
|
||||||
RSYNC_DEFAULT_ARGS=$RSYNC_DEFAULT_ARGS" -zz --skip-compress=gz/xz/lz/lzma/lzo/rz/jpg/mp3/mp4/7z/bz2/rar/zip/sfark/s7z/ace/apk/arc/cab/dmg/jar/kgb/lzh/lha/lzx/pak/sfx"
|
if [ "$LOCAL_OS" == "Qnap" ] || [ "$REMOTE_OS" == "Qnap" ]; then
|
||||||
|
RSYNC_DEFAULT_ARGS=$RSYNC_DEFAULT_ARGS" -z $SKIP_COMPRESS_EXTENSIONS"
|
||||||
|
elif [ "$LOCAL_OS" != "MacOSX" ] && [ "$REMOTE_OS" != "MacOSX" ]; then
|
||||||
|
RSYNC_DEFAULT_ARGS=$RSYNC_DEFAULT_ARGS" -zz $SKIP_COMPRESS_EXTENSIONS"
|
||||||
else
|
else
|
||||||
Logger "Disabling compression skips on synchronization on [$LOCAL_OS] due to lack of support." "NOTICE"
|
Logger "Disabling compression skips on synchronization on [$LOCAL_OS] due to lack of support." "NOTICE"
|
||||||
fi
|
fi
|
||||||
|
@ -2354,7 +2452,7 @@ function GetConfFileValue () {
|
||||||
echo "$value"
|
echo "$value"
|
||||||
else
|
else
|
||||||
if [ $noError == true ]; then
|
if [ $noError == true ]; then
|
||||||
Logger "Cannot get value for [$name] in config file [$file]." "NOTICE"
|
Logger "Cannot get value for [$name] in config file [$file]." "DEBUG"
|
||||||
else
|
else
|
||||||
Logger "Cannot get value for [$name] in config file [$file]." "ERROR"
|
Logger "Cannot get value for [$name] in config file [$file]." "ERROR"
|
||||||
fi
|
fi
|
||||||
|
@ -2388,7 +2486,7 @@ function SetConfFileValue () {
|
||||||
else
|
else
|
||||||
echo "$name=$value" > "$file"
|
echo "$name=$value" > "$file"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
Logger "Config file [$file] does not exist. Failed to create it witn value [$name]." "ERROR"
|
Logger "Config file [$file] does not exist. Failed to create it with value [$name]." "ERROR"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -2417,4 +2515,168 @@ function WildcardFileExists () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Some MacOS versions might loose file ownsership when using mv from /tmp dir (see #175)
|
||||||
|
# This is a "mv" function wrapper that helps out with macOS
|
||||||
|
#### FileMove SUBSET ####
|
||||||
|
function FileMove () {
|
||||||
|
local source="${1}"
|
||||||
|
local dest="${2}"
|
||||||
|
|
||||||
|
# If file is symlink or OS is not Mac, just make a standard mv
|
||||||
|
if [ -L "$source" ] || [ "$LOCAL_OS" != "MacOSX" ]; then
|
||||||
|
mv -f "$source" "$dest"
|
||||||
|
return $?
|
||||||
|
elif [ -w "$source" ]; then
|
||||||
|
[ -f "$dest" ] && rm -f "$dest"
|
||||||
|
cp -p "$source" "$dest" && rm -f "$source"
|
||||||
|
return $?
|
||||||
|
else
|
||||||
|
return -1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
#### FileMove SUBSET END ####
|
||||||
|
|
||||||
|
#### InotifyWaitPoller SUBSET ####
|
||||||
|
|
||||||
|
# Checks directories every second for file changes using a static list
|
||||||
|
# Orignal code Copyright (c) 2020 Francesco Bianco <bianco@javanile.org>
|
||||||
|
# Improved version https://github.com/javanile/inotifywait-polling/pull/1 by adding timeouts, optional recursion, excludes and a couple of fixes
|
||||||
|
print_event () {
|
||||||
|
[[ -z "${events}" || "${events}" == *"$2"* ]] && echo "$1 $2 $3"
|
||||||
|
case "$2" in
|
||||||
|
CREATE)
|
||||||
|
[[ -z "${events}" || "${events}" == *"OPEN"* ]] && echo "$1 OPEN $3"
|
||||||
|
[[ -z "${events}" || "${events}" == *"MODIFY"* ]] && echo "$1 MODIFY $3"
|
||||||
|
[[ -z "${events}" || "${events}" == *"CLOSE"* ]] && echo "$1 CLOSE_WRITE,CLOSE $3"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function _InotifyWaitPoller () {
|
||||||
|
local path="${1}"
|
||||||
|
local includes="${2}"
|
||||||
|
local excludes="${3}"
|
||||||
|
local recursive="${4:-true}"
|
||||||
|
local monitor="${5:-false}"
|
||||||
|
local event_log_file="${6}"
|
||||||
|
local events="${7}"
|
||||||
|
local interval="${8}"
|
||||||
|
|
||||||
|
local include
|
||||||
|
local exclude
|
||||||
|
local find_results_file
|
||||||
|
local find_recursion
|
||||||
|
local find_includes=
|
||||||
|
local find_excludes=
|
||||||
|
local stop_loop=false
|
||||||
|
local find_cmd
|
||||||
|
local notable_event=false
|
||||||
|
|
||||||
|
find_results_file="$RUN_DIR/$PROGRAM._InotifyWaitPoller.${path//\//_}.$SCRIPT_PID.$TSTAMP"
|
||||||
|
|
||||||
|
IFS=';' read -r -a includes <<< "$includes"
|
||||||
|
for include in "${includes[@]}"; do
|
||||||
|
find_includes="$find_includes -iregex \"$include\""
|
||||||
|
done
|
||||||
|
|
||||||
|
IFS=';' read -r -a excludes <<< "$excludes"
|
||||||
|
for exclude in "${excludes[@]}"; do
|
||||||
|
find_excludes="$find_excludes ! -iregex \"$exclude\""
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $recursive != true ]; then
|
||||||
|
find_recursion=" -maxdepth 1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#[ "$event_log_file" != "" ] && [ -f "$event_log_file" ] && rm -f "$event_log_file" >/dev/null 2>&1
|
||||||
|
|
||||||
|
find_cmd="find \"$path\" ! -regex \"$RUN_DIR/$PROGRAM.*.$SCRIPT_PID.$TSTAMP\" $find_includes $find_excludes $find_recursion -printf \"%s %y %p\\n\" | sort -k3 - > \"$find_results_file\""
|
||||||
|
Logger "COMMAND: $find_cmd" "VERBOSE"
|
||||||
|
eval "$find_cmd"
|
||||||
|
|
||||||
|
while [ $stop_loop == false ]; do
|
||||||
|
sleep "$interval"
|
||||||
|
sign=
|
||||||
|
last_run_results=$(cat "$find_results_file")
|
||||||
|
eval "$find_cmd"
|
||||||
|
differences=$(diff <(echo "$last_run_results") <(cat "$find_results_file")) && true
|
||||||
|
if [ "$monitor" != true ] && [ "$notable_event" == true ]; then
|
||||||
|
stop_loop=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -z "$differences" ] && continue
|
||||||
|
while IFS= read line || [[ -n "${line}" ]]; do
|
||||||
|
if [[ "${line}" == "." ]]; then
|
||||||
|
while IFS=';' read -r item; do
|
||||||
|
event="$(echo "${item}" | cut -s -d':' -f1)"
|
||||||
|
focus="$(echo "${item}" | cut -s -d':' -f2)"
|
||||||
|
dir="$(dirname "${focus}")/"
|
||||||
|
file="$(basename "${focus}" | cut -d';' -f1)"
|
||||||
|
if [[ "${events}" == *"${event}"* ]]; then
|
||||||
|
[ "$event_log_file" != "" ] && printf "${dir}${file}\0" >> "$event_log_file" || print_event "${dir}" "${event}" "${file}"
|
||||||
|
notable_event=true
|
||||||
|
fi
|
||||||
|
done <<< "${sign}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
flag="$(echo "${line}" | cut -s -d' ' -f1)"
|
||||||
|
file="$(echo "${line}" | cut -s -d' ' -f4-)"
|
||||||
|
[[ -n "${file}" ]] || continue
|
||||||
|
[[ "${file}" != "$find_results_file" ]] || continue
|
||||||
|
case "${flag}" in
|
||||||
|
"<")
|
||||||
|
event=DELETE
|
||||||
|
;;
|
||||||
|
">")
|
||||||
|
event=CREATE
|
||||||
|
if [[ "${sign}" == *"DELETE:${file};"* ]]; then
|
||||||
|
event=MODIFY
|
||||||
|
sign="$(echo "${sign}" | sed "s#DELETE:${file};##g")"
|
||||||
|
elif [[ "${sign}" == *"DELETE:"* ]]; then
|
||||||
|
event=MOVED_TO
|
||||||
|
sign="$(echo "${sign}" | sed "s#DELETE:.*;##g")"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
sign+="${event}:${file};"
|
||||||
|
done <<< "$(echo -e "${differences}\n.")"
|
||||||
|
done
|
||||||
|
[ -f "$find_results_file" ] && rm -f "$find_results_file"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
# InotifyWaitPoller dirs exclusions recursive monitor_mode timeout opt_regex event_log events
|
||||||
|
function InotifyWaitPoller () {
|
||||||
|
local paths="${1}" # Comma separated list of paths
|
||||||
|
local includes="${2}" comma separated list of excludes in find regex format
|
||||||
|
local excludes="${3}" # Comma separated list of excludes in find regex format
|
||||||
|
local recursive="${4:-true}"
|
||||||
|
local monitor="${5:-false}"
|
||||||
|
local event_log_file="${6}" # optional event log file
|
||||||
|
local events="${7:-CREATE,MODIFY,MOVED_TO}" # possible events: CREATE,OPEN,MODIFY,CLOSE,CLOSE_WRITE,DELETE,MOVED_TO
|
||||||
|
local timeout="${8:-0}" # seconds
|
||||||
|
local interval="${9:-5}" # polling interval
|
||||||
|
|
||||||
|
local pids=
|
||||||
|
local path
|
||||||
|
local alive
|
||||||
|
local count=0
|
||||||
|
|
||||||
|
IFS=';' read -r -a paths <<< "$paths"
|
||||||
|
for path in "${paths[@]}"; do
|
||||||
|
if ! [ -e "$path" ]; then
|
||||||
|
Logger "Cannot watch [$path]. No such file or directory." "CRITICAL"
|
||||||
|
else
|
||||||
|
_InotifyWaitPoller "$path" "$includes" "$excludes" "$recursive" "$monitor" "$event_log_file" "$events" "$interval" &
|
||||||
|
pids="$pids;$!"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ "$pids" != "" ]; then
|
||||||
|
ExecTasks $pids "InotifyWaitPoller" false 0 0 0 $timeout
|
||||||
|
else
|
||||||
|
Logger "No directories available to watch." "CRITICAL"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
#### InotifyWaitPoller SUBSET END ####
|
||||||
|
|
||||||
#### OFUNCTIONS FULL SUBSET END ####
|
#### OFUNCTIONS FULL SUBSET END ####
|
||||||
|
|
|
@ -72,6 +72,8 @@ SSH_COMPRESSION=true
|
||||||
|
|
||||||
## Ignore ssh known hosts. DANGER WILL ROBINSON DANGER ! This can lead to security issues. Only enable this if you know what you're doing.
|
## Ignore ssh known hosts. DANGER WILL ROBINSON DANGER ! This can lead to security issues. Only enable this if you know what you're doing.
|
||||||
SSH_IGNORE_KNOWN_HOSTS=false
|
SSH_IGNORE_KNOWN_HOSTS=false
|
||||||
|
SSH_CONTROLMASTER=false
|
||||||
|
|
||||||
|
|
||||||
## Check for connectivity to remote host before launching remote sync task. Be sure the hosts responds to ping. Failing to ping will stop sync.
|
## Check for connectivity to remote host before launching remote sync task. Be sure the hosts responds to ping. Failing to ping will stop sync.
|
||||||
REMOTE_HOST_PING=false
|
REMOTE_HOST_PING=false
|
||||||
|
|
|
@ -16,10 +16,10 @@ INITIATOR_SYNC_DIR="${HOME}/osync-tests/initiator"
|
||||||
|
|
||||||
## Target is the system osync synchronizes to (can be the same system as the initiator in case of local sync tasks). The target directory can be a local or remote path.
|
## Target is the system osync synchronizes to (can be the same system as the initiator in case of local sync tasks). The target directory can be a local or remote path.
|
||||||
#TARGET_SYNC_DIR="${HOME}/osync-tests/target"
|
#TARGET_SYNC_DIR="${HOME}/osync-tests/target"
|
||||||
TARGET_SYNC_DIR="ssh://root@localhost:22/${HOME}/osync-tests/target"
|
TARGET_SYNC_DIR="ssh://root@localhost:44999/${HOME}/osync-tests/target"
|
||||||
|
|
||||||
## If the target system is remote, you can specify a RSA key (please use full path). If not defined, the default ~/.ssh/id_rsa will be used. See documentation for further information.
|
## If the target system is remote, you can specify a RSA key (please use full path). If not defined, the default ~/.ssh/id_rsa will be used. See documentation for further information.
|
||||||
SSH_RSA_PRIVATE_KEY="${HOME}/.ssh/id_rsa_local"
|
SSH_RSA_PRIVATE_KEY="${HOME}/.ssh/id_rsa_local_osync_tests"
|
||||||
|
|
||||||
## Alternatively, you may specify an SSH password file (less secure). Needs sshpass utility installed.
|
## Alternatively, you may specify an SSH password file (less secure). Needs sshpass utility installed.
|
||||||
SSH_PASSWORD_FILE=""
|
SSH_PASSWORD_FILE=""
|
||||||
|
@ -72,6 +72,8 @@ SSH_COMPRESSION=true
|
||||||
|
|
||||||
## Ignore ssh known hosts. DANGER WILL ROBINSON DANGER ! This can lead to security issues. Only enable this if you know what you're doing.
|
## Ignore ssh known hosts. DANGER WILL ROBINSON DANGER ! This can lead to security issues. Only enable this if you know what you're doing.
|
||||||
SSH_IGNORE_KNOWN_HOSTS=false
|
SSH_IGNORE_KNOWN_HOSTS=false
|
||||||
|
SSH_CONTROLMASTER=false
|
||||||
|
|
||||||
|
|
||||||
## Check for connectivity to remote host before launching remote sync task. Be sure the hosts responds to ping. Failing to ping will stop sync.
|
## Check for connectivity to remote host before launching remote sync task. Be sure the hosts responds to ping. Failing to ping will stop sync.
|
||||||
REMOTE_HOST_PING=true
|
REMOTE_HOST_PING=true
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# osync test suite 2019052002
|
# osync test suite 2023061401
|
||||||
|
|
||||||
|
|
||||||
# Allows the following environment variables
|
# Allows the following environment variables
|
||||||
# TRAVIS_RUN=[true|false]
|
# RUNNING_ON_GITHUB_ACTIONS=[true|false]
|
||||||
# SSH_PORT=22
|
# SSH_PORT=22
|
||||||
# SKIP_REMOTE=[true|false]
|
# SKIP_REMOTE=[true|false]
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
||||||
# for each test
|
# for each test
|
||||||
# files with spaces, subdirs
|
# files with spaces, subdirs
|
||||||
# largefileset (...large ?)
|
# largefileset (...large ?)
|
||||||
|
# quickremote test with controlmaster enabled
|
||||||
# exclusions
|
# exclusions
|
||||||
# conflict resolution initiator with backups / multiple backups
|
# conflict resolution initiator with backups / multiple backups
|
||||||
# conflict resolution target with backups / multiple backups
|
# conflict resolution target with backups / multiple backups
|
||||||
|
@ -42,24 +43,30 @@
|
||||||
# setfacl needs double ':' to be compatible with both linux and BSD
|
# setfacl needs double ':' to be compatible with both linux and BSD
|
||||||
# setfacl -m o::rwx file
|
# setfacl -m o::rwx file
|
||||||
|
|
||||||
|
# On Windows 10 bash, we need to create host SSH keys first with ssh-keygen -A
|
||||||
|
# Then start ssh with service ssh start
|
||||||
|
|
||||||
# TODO, use copies of config file on each test function
|
# TODO, use copies of config file on each test function
|
||||||
|
|
||||||
if [ "$SKIP_REMOTE" = "" ]; then
|
if [ "$SKIP_REMOTE" = "" ]; then
|
||||||
SKIP_REMOTE=false
|
SKIP_REMOTE=false
|
||||||
|
REMOTE_USER=root
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
homedir=$(eval echo ~${REMOTE_USER})
|
||||||
|
|
||||||
# drupal servers are often unreachable for whetever reason or give 0 bytes files
|
# drupal servers are often unreachable for whetever reason or give 0 bytes files
|
||||||
#LARGE_FILESET_URL="http://ftp.drupal.org/files/projects/drupal-8.2.2.tar.gz"
|
#LARGE_FILESET_URL="http://ftp.drupal.org/files/projects/drupal-8.2.2.tar.gz"
|
||||||
LARGE_FILESET_URL="http://www.netpower.fr/sites/default/files/osync-test-files.tar.gz"
|
LARGE_FILESET_URL="https://ftp.drupal.org/files/projects/drupal-11.0.10.tar.gz"
|
||||||
|
|
||||||
# Fakeroot for install / uninstall and test of executables
|
|
||||||
FAKEROOT="${HOME}/osync_test_install"
|
|
||||||
|
|
||||||
OSYNC_DIR="$(pwd)"
|
OSYNC_DIR="$(pwd)"
|
||||||
OSYNC_DIR=${OSYNC_DIR%%/dev*}
|
OSYNC_DIR=${OSYNC_DIR%%/dev*}
|
||||||
DEV_DIR="$OSYNC_DIR/dev"
|
DEV_DIR="$OSYNC_DIR/dev"
|
||||||
TESTS_DIR="$DEV_DIR/tests"
|
TESTS_DIR="$DEV_DIR/tests"
|
||||||
|
|
||||||
|
# Fakeroot for install / uninstall and test of executables
|
||||||
|
FAKEROOT="${homedir}/osync_test_install"
|
||||||
|
|
||||||
CONF_DIR="$TESTS_DIR/conf"
|
CONF_DIR="$TESTS_DIR/conf"
|
||||||
LOCAL_CONF="local.conf"
|
LOCAL_CONF="local.conf"
|
||||||
REMOTE_CONF="remote.conf"
|
REMOTE_CONF="remote.conf"
|
||||||
|
@ -72,7 +79,7 @@ OSYNC_UPGRADE="upgrade-v1.0x-v1.3x.sh"
|
||||||
TMP_FILE="$DEV_DIR/tmp"
|
TMP_FILE="$DEV_DIR/tmp"
|
||||||
|
|
||||||
|
|
||||||
OSYNC_TESTS_DIR="${HOME}/osync-tests"
|
OSYNC_TESTS_DIR="${homedir}/osync-tests"
|
||||||
INITIATOR_DIR="$OSYNC_TESTS_DIR/initiator"
|
INITIATOR_DIR="$OSYNC_TESTS_DIR/initiator"
|
||||||
TARGET_DIR="$OSYNC_TESTS_DIR/target"
|
TARGET_DIR="$OSYNC_TESTS_DIR/target"
|
||||||
OSYNC_WORKDIR=".osync_workdir"
|
OSYNC_WORKDIR=".osync_workdir"
|
||||||
|
@ -85,30 +92,56 @@ OSYNC_VERSION=1.x.y
|
||||||
OSYNC_MIN_VERSION=x
|
OSYNC_MIN_VERSION=x
|
||||||
OSYNC_IS_STABLE=maybe
|
OSYNC_IS_STABLE=maybe
|
||||||
|
|
||||||
|
PRIVKEY_NAME="id_rsa_local_osync_tests"
|
||||||
|
PUBKEY_NAME="${PRIVKEY_NAME}.pub"
|
||||||
|
|
||||||
function SetupSSH {
|
function SetupSSH {
|
||||||
echo -e 'y\n'| ssh-keygen -t rsa -b 2048 -N "" -f "${HOME}/.ssh/id_rsa_local"
|
echo "Setting up an ssh key to ${homedir}/.ssh/${PRIVKEY_NAME}"
|
||||||
if ! grep "$(cat ${HOME}/.ssh/id_rsa_local.pub)" "${HOME}/.ssh/authorized_keys"; then
|
echo -e 'y\n'| ssh-keygen -t rsa -b 2048 -N "" -f "${homedir}/.ssh/${PRIVKEY_NAME}"
|
||||||
echo "from=\"*\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command=\"$FAKEROOT/usr/local/bin/ssh_filter.sh SomeAlphaNumericToken9\" $(cat ${HOME}/.ssh/id_rsa_local.pub)" >> "${HOME}/.ssh/authorized_keys"
|
|
||||||
|
|
||||||
|
|
||||||
|
SSH_AUTH_LINE="from=\"*\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command=\"$FAKEROOT/usr/local/bin/ssh_filter.sh SomeAlphaNumericToken9\" $(cat ${homedir}/.ssh/${PUBKEY_NAME})"
|
||||||
|
echo "ls -alh ${homedir}"
|
||||||
|
ls -alh "${homedir}"
|
||||||
|
echo "ls -alh ${homedir}/.ssh"
|
||||||
|
ls -alh "${homedir}/.ssh"
|
||||||
|
|
||||||
|
if [ -f "${homedir}/.ssh/authorized_keys" ]; then
|
||||||
|
if ! grep "$(cat ${homedir}/.ssh/${PUBKEY_NAME})" "${homedir}/.ssh/authorized_keys"; then
|
||||||
|
echo "Adding auth line in authorized_keys file ${homedir}/.ssh/authorized_keys"
|
||||||
|
echo "$SSH_AUTH_LINE" >> "${homedir}/.ssh/authorized_keys"
|
||||||
fi
|
fi
|
||||||
chmod 600 "${HOME}/.ssh/authorized_keys"
|
else
|
||||||
|
echo "Creating authorized_keys file ${homedir}/.ssh/authorized_keys"
|
||||||
|
echo "$SSH_AUTH_LINE" >> "${homedir}/.ssh/authorized_keys"
|
||||||
|
fi
|
||||||
|
chmod 600 "${homedir}/.ssh/authorized_keys"
|
||||||
|
|
||||||
# Add localhost to known hosts so self connect works
|
# Add localhost to known hosts so self connect works
|
||||||
if [ -z "$(ssh-keygen -F localhost)" ]; then
|
if [ -z "$(ssh-keygen -F localhost)" ]; then
|
||||||
ssh-keyscan -H localhost >> "${HOME}/.ssh/known_hosts"
|
ssh-keyscan -H localhost >> "${homedir}/.ssh/known_hosts"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Update remote conf files with SSH port
|
# Update remote conf files with SSH port and file id location
|
||||||
sed -i.tmp 's#ssh://.*@localhost:[0-9]*/${HOME}/osync-tests/target#ssh://'$REMOTE_USER'@localhost:'$SSH_PORT'/${HOME}/osync-tests/target#' "$CONF_DIR/$REMOTE_CONF"
|
sed -i.tmp 's#ssh://.*@localhost:[0-9]*/${HOME}/osync-tests/target#ssh://'$REMOTE_USER'@localhost:'$SSH_PORT'/'${homedir}'/osync-tests/target#' "$CONF_DIR/$REMOTE_CONF"
|
||||||
|
sed -i.tmp2 's#SSH_RSA_PRIVATE_KEY="${HOME}/.ssh/id_rsa_local_osync_tests"#SSH_RSA_PRIVATE_KEY="'${homedir}'/.ssh/id_rsa_local_osync_tests"#' "$CONF_DIR/$REMOTE_CONF"
|
||||||
|
|
||||||
|
echo "ls -alh ${homedir}/.ssh"
|
||||||
|
ls -alh "${homedir}/.ssh"
|
||||||
|
echo "cat ${homedir}/.ssh/authorized_keys"
|
||||||
|
cat "${homedir}/.ssh/authorized_keys"
|
||||||
|
|
||||||
|
echo "###"
|
||||||
|
echo "END SETUP SSH"
|
||||||
}
|
}
|
||||||
|
|
||||||
function RemoveSSH {
|
function RemoveSSH {
|
||||||
local pubkey
|
echo "Now removing SSH keys"
|
||||||
|
if [ -f "${homedir}/.ssh/id_rsa_local_osync_tests" ]; then
|
||||||
if [ -f "${HOME}/.ssh/id_rsa_local" ]; then
|
echo "Restoring SSH authorized_keys file"
|
||||||
|
sed -i.bak "s|.*$(cat "${homedir}/.ssh/id_rsa_local_osync_tests.pub")||g" "${homedir}/.ssh/authorized_keys"
|
||||||
pubkey=$(cat "${HOME}/.ssh/id_rsa_local.pub")
|
rm -f "${homedir}/.ssh/{id_rsa_local_osync_tests.pub,id_rsa_local_osync_tests}"
|
||||||
sed -i.bak "s|.*$pubkey.*||g" "${HOME}/.ssh/authorized_keys"
|
|
||||||
rm -f "${HOME}/.ssh/{id_rsa_local.pub,id_rsa_local}"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,8 +201,16 @@ function PrepareLocalDirs () {
|
||||||
function oneTimeSetUp () {
|
function oneTimeSetUp () {
|
||||||
START_TIME=$SECONDS
|
START_TIME=$SECONDS
|
||||||
|
|
||||||
mkdir --parents "$FAKEROOT"
|
#echo "Running forced merge"
|
||||||
|
#cd "${DEV_DIR}"
|
||||||
|
#$SUDO_CMD ./merge.sh osync
|
||||||
|
echo "Setting security for files"
|
||||||
|
$SUDO_CMD find ${OSYNC_DIR} -exec chmod 755 {} \+
|
||||||
|
|
||||||
|
echo "Show content of osync dir"
|
||||||
|
ls -alh ${OSYNC_DIR}
|
||||||
|
echo "Running install.sh from ${OSYNC_DIR}"
|
||||||
|
$SUDO_CMD ${OSYNC_DIR}/install.sh --no-stats --prefix="${FAKEROOT}"
|
||||||
source "$DEV_DIR/ofunctions.sh"
|
source "$DEV_DIR/ofunctions.sh"
|
||||||
|
|
||||||
# Fix default umask because of ACL test that expects 0022 when creating test files
|
# Fix default umask because of ACL test that expects 0022 when creating test files
|
||||||
|
@ -180,18 +221,22 @@ function oneTimeSetUp () {
|
||||||
echo "Detected OS: $LOCAL_OS"
|
echo "Detected OS: $LOCAL_OS"
|
||||||
|
|
||||||
# Set some travis related changes
|
# Set some travis related changes
|
||||||
if [ "$TRAVIS_RUN" == true ]; then
|
if [ "$RUNNING_ON_GITHUB_ACTIONS" == true ]; then
|
||||||
echo "Running with travis settings"
|
echo "Running with GITHUB ACTIONS settings"
|
||||||
REMOTE_USER="travis"
|
#REMOTE_USER="runner"
|
||||||
|
REMOTE_USER="root" # WIP
|
||||||
|
homedir=$(eval echo ~${REMOTE_USER})
|
||||||
RHOST_PING=false
|
RHOST_PING=false
|
||||||
SetConfFileValue "$CONF_DIR/$REMOTE_CONF" "REMOTE_3RD_PARTY_HOSTS" ""
|
SetConfFileValue "$CONF_DIR/$REMOTE_CONF" "REMOTE_3RD_PARTY_HOSTS" ""
|
||||||
SetConfFileValue "$CONF_DIR/$REMOTE_CONF" "REMOTE_HOST_PING" false
|
SetConfFileValue "$CONF_DIR/$REMOTE_CONF" "REMOTE_HOST_PING" false
|
||||||
|
|
||||||
SetConfFileValue "$CONF_DIR/$OLD_CONF" "REMOTE_3RD_PARTY_HOSTS" ""
|
SetConfFileValue "$CONF_DIR/$OLD_CONF" "REMOTE_3RD_PARTY_HOSTS" ""
|
||||||
SetConfFileValue "$CONF_DIR/$OLD_CONF" "REMOTE_HOST_PING" false
|
SetConfFileValue "$CONF_DIR/$OLD_CONF" "REMOTE_HOST_PING" false
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "Running with local settings"
|
echo "Running with local settings"
|
||||||
REMOTE_USER="root"
|
REMOTE_USER="root"
|
||||||
|
homedir=$(eval echo ~${REMOTE_USER})
|
||||||
RHOST_PING=true
|
RHOST_PING=true
|
||||||
SetConfFileValue "$CONF_DIR/$REMOTE_CONF" "REMOTE_3RD_PARTY_HOSTS" "\"www.kernel.org www.google.com\""
|
SetConfFileValue "$CONF_DIR/$REMOTE_CONF" "REMOTE_3RD_PARTY_HOSTS" "\"www.kernel.org www.google.com\""
|
||||||
SetConfFileValue "$CONF_DIR/$REMOTE_CONF" "REMOTE_HOST_PING" true
|
SetConfFileValue "$CONF_DIR/$REMOTE_CONF" "REMOTE_HOST_PING" true
|
||||||
|
@ -200,9 +245,21 @@ function oneTimeSetUp () {
|
||||||
SetConfFileValue "$CONF_DIR/$OLD_CONF" "REMOTE_HOST_PING" true
|
SetConfFileValue "$CONF_DIR/$OLD_CONF" "REMOTE_HOST_PING" true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Fix test directories for Github actions
|
||||||
|
SetConfFileValue "$CONF_DIR/$LOCAL_CONF" INITIATOR_SYNC_DIR "\"${homedir}/osync-tests/initiator\""
|
||||||
|
SetConfFileValue "$CONF_DIR/$LOCAL_CONF" TARGET_SYNC_DIR "\"${homedir}/osync-tests/target\""
|
||||||
|
|
||||||
|
SetConfFileValue "$CONF_DIR/$REMOTE_CONF" INITIATOR_SYNC_DIR "\"${homedir}/osync-tests/initiator\""
|
||||||
|
|
||||||
|
SetConfFileValue "$CONF_DIR/$OLD_CONF" MASTER_SYNC_DIR "\"${homedir}/osync-tests/initiator\""
|
||||||
|
SetConfFileValue "$CONF_DIR/$OLD_CONF" SLAVE_SYNC_DIR "\"${homedir}/osync-tests/target\""
|
||||||
|
|
||||||
|
|
||||||
# Get default ssh port from env
|
# Get default ssh port from env
|
||||||
if [ "$SSH_PORT" == "" ]; then
|
if [ "$SSH_PORT" == "" ]; then
|
||||||
SSH_PORT=22
|
SSH_PORT=22
|
||||||
|
echo "Running with SSH_PORT=${SSH_PORT}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Setup modes per test
|
# Setup modes per test
|
||||||
|
@ -212,8 +269,8 @@ function oneTimeSetUp () {
|
||||||
readonly __confRemote=3
|
readonly __confRemote=3
|
||||||
|
|
||||||
osyncParameters=()
|
osyncParameters=()
|
||||||
osyncParameters[$__quickLocal]="--initiator=$INITIATOR_DIR --target=$TARGET_DIR --instance-id=quicklocal"
|
osyncParameters[$__quickLocal]="--initiator=$INITIATOR_DIR --target=$TARGET_DIR --instance-id=quicklocal --non-interactive"
|
||||||
osyncParameters[$__confLocal]="$CONF_DIR/$LOCAL_CONF"
|
osyncParameters[$__confLocal]="$CONF_DIR/$LOCAL_CONF --non-interactive"
|
||||||
|
|
||||||
osyncDaemonParameters=()
|
osyncDaemonParameters=()
|
||||||
|
|
||||||
|
@ -224,8 +281,8 @@ function oneTimeSetUp () {
|
||||||
|
|
||||||
# Do not check remote config on msys or cygwin since we don't have a local SSH server
|
# Do not check remote config on msys or cygwin since we don't have a local SSH server
|
||||||
if [ "$LOCAL_OS" != "msys" ] && [ "$LOCAL_OS" != "Cygwin" ] && [ $SKIP_REMOTE != true ]; then
|
if [ "$LOCAL_OS" != "msys" ] && [ "$LOCAL_OS" != "Cygwin" ] && [ $SKIP_REMOTE != true ]; then
|
||||||
osyncParameters[$__quickRemote]="--initiator=$INITIATOR_DIR --target=ssh://localhost:$SSH_PORT/$TARGET_DIR --rsakey=${HOME}/.ssh/id_rsa_local --instance-id=quickremote --remote-token=SomeAlphaNumericToken9"
|
osyncParameters[$__quickRemote]="--initiator=$INITIATOR_DIR --target=ssh://localhost:$SSH_PORT/$TARGET_DIR --rsakey=${homedir}/.ssh/id_rsa_local_osync_tests --instance-id=quickremote --remote-token=SomeAlphaNumericToken9 --non-interactive"
|
||||||
osyncParameters[$__confRemote]="$CONF_DIR/$REMOTE_CONF"
|
osyncParameters[$__confRemote]="$CONF_DIR/$REMOTE_CONF --non-interactive"
|
||||||
|
|
||||||
osyncDaemonParameters[$__remote]="$CONF_DIR/$REMOTE_CONF --on-changes"
|
osyncDaemonParameters[$__remote]="$CONF_DIR/$REMOTE_CONF --on-changes"
|
||||||
|
|
||||||
|
@ -291,7 +348,7 @@ function oneTimeTearDown () {
|
||||||
$SUDO_CMD ./install.sh --remove --no-stats --prefix="$FAKEROOT"
|
$SUDO_CMD ./install.sh --remove --no-stats --prefix="$FAKEROOT"
|
||||||
assertEquals "Uninstall failed" "0" $?
|
assertEquals "Uninstall failed" "0" $?
|
||||||
|
|
||||||
ELAPSED_TIME=$(($SECONDS - $START_TIME))
|
ELAPSED_TIME=$((SECONDS-START_TIME))
|
||||||
echo "It took $ELAPSED_TIME seconds to run these tests."
|
echo "It took $ELAPSED_TIME seconds to run these tests."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,6 +357,42 @@ function setUp () {
|
||||||
rm -rf "$TARGET_DIR"
|
rm -rf "$TARGET_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_SSH {
|
||||||
|
# Make sure we have SSH on your test server
|
||||||
|
# This has become kind of tricky on github actions servers
|
||||||
|
echo "Testing SSH"
|
||||||
|
|
||||||
|
failure=false
|
||||||
|
|
||||||
|
# Testing as "remote user"
|
||||||
|
echo "ls -alh ${homedir}/.ssh"
|
||||||
|
ls -alh "${homedir}/.ssh"
|
||||||
|
|
||||||
|
echo "Running SSH test as ${REMOTE_USER}"
|
||||||
|
# SSH_PORT and SSH_USER are set by oneTimeSetup
|
||||||
|
$SUDO_CMD ssh -i "${homedir}/.ssh/${PRIVKEY_NAME}" -p $SSH_PORT ${REMOTE_USER}@localhost "env _REMOTE_TOKEN=SomeAlphaNumericToken9 echo \"Remotely:\"; whoami; echo \"TEST OK\""
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "SSH test failed"
|
||||||
|
failure=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Testing as current user
|
||||||
|
#echo "ls -alh ${homedir}/.ssh"
|
||||||
|
#ls -alh "${homedir}/.ssh"
|
||||||
|
|
||||||
|
#echo "Running SSH test as $(whoami)"
|
||||||
|
#$SUDO_CMD ssh -i "${homedir}/.ssh/${PRIVKEY_NAME}" -p $SSH_PORT $(whoami)@localhost "env _REMOTE_TOKEN=SomeAlphaNumericToken9 echo \"Remotely:\"; whoami; echo \"TEST OK\""
|
||||||
|
#if [ $? -ne 0 ]; then
|
||||||
|
# echo "SSH test failed"
|
||||||
|
# failure=true
|
||||||
|
#fi
|
||||||
|
|
||||||
|
if [ $failure == true ]; then
|
||||||
|
exit 1 # Try to see if we can abort all tests
|
||||||
|
assertEquals "Test SSH failed" false $failure
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# This test has to be done everytime in order for osync executable to be fresh
|
# This test has to be done everytime in order for osync executable to be fresh
|
||||||
function test_Merge () {
|
function test_Merge () {
|
||||||
cd "$DEV_DIR"
|
cd "$DEV_DIR"
|
||||||
|
@ -319,7 +412,7 @@ function test_Merge () {
|
||||||
# Set osync version to stable while testing to avoid warning message
|
# Set osync version to stable while testing to avoid warning message
|
||||||
# Don't use SetConfFileValue here since for whatever reason Travis does not like creating a sed temporary file in $FAKEROOT
|
# Don't use SetConfFileValue here since for whatever reason Travis does not like creating a sed temporary file in $FAKEROOT
|
||||||
|
|
||||||
if [ "$TRAVIS_RUN" == true ]; then
|
if [ "$RUNNING_ON_GITHUB_ACTIONS" == true ]; then
|
||||||
$SUDO_CMD sed -i.tmp 's/^IS_STABLE=.*/IS_STABLE=true/' "$OSYNC_EXECUTABLE"
|
$SUDO_CMD sed -i.tmp 's/^IS_STABLE=.*/IS_STABLE=true/' "$OSYNC_EXECUTABLE"
|
||||||
else
|
else
|
||||||
sed -i.tmp 's/^IS_STABLE=.*/IS_STABLE=true/' "$OSYNC_EXECUTABLE"
|
sed -i.tmp 's/^IS_STABLE=.*/IS_STABLE=true/' "$OSYNC_EXECUTABLE"
|
||||||
|
@ -348,6 +441,15 @@ function test_LargeFileSet () {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_controlMaster () {
|
||||||
|
cd "$OSYNC_DIR"
|
||||||
|
|
||||||
|
PrepareLocalDirs
|
||||||
|
echo "Running with parameters ${osyncParameters[$__quickRemote]} --ssh-controlmaster"
|
||||||
|
REMOTE_HOST_PING=$REMOTE_PING $OSYNC_EXECUTABLE ${osyncParameters[$__quickRemote]} --ssh-controlmaster
|
||||||
|
assertEquals "Running quick remote test with controlmaster enabled." "0" $?
|
||||||
|
}
|
||||||
|
|
||||||
function test_Exclusions () {
|
function test_Exclusions () {
|
||||||
# Will sync except php files
|
# Will sync except php files
|
||||||
# RSYNC_EXCLUDE_PATTERN="*.php" is set at runtime for quicksync and in config files for other runs
|
# RSYNC_EXCLUDE_PATTERN="*.php" is set at runtime for quicksync and in config files for other runs
|
||||||
|
@ -378,9 +480,9 @@ function test_Exclusions () {
|
||||||
|
|
||||||
function test_Deletetion () {
|
function test_Deletetion () {
|
||||||
local iFile1="$INITIATOR_DIR/i fic"
|
local iFile1="$INITIATOR_DIR/i fic"
|
||||||
local iFile2="$INITIATOR_DIR/i foc"
|
local iFile2="$INITIATOR_DIR/i foc (something)"
|
||||||
local tFile1="$TARGET_DIR/t fic"
|
local tFile1="$TARGET_DIR/t fic"
|
||||||
local tFile2="$TARGET_DIR/t foc"
|
local tFile2="$TARGET_DIR/t foc [nothing]"
|
||||||
|
|
||||||
|
|
||||||
for i in "${osyncParameters[@]}"; do
|
for i in "${osyncParameters[@]}"; do
|
||||||
|
@ -496,7 +598,7 @@ function test_skip_deletion () {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# TRAVIS SPECIFIC - time limitation
|
# TRAVIS SPECIFIC - time limitation
|
||||||
if [ "$TRAVIS_RUN" != true ]; then
|
if [ "$RUNNING_ON_GITHUB_ACTIONS" != true ]; then
|
||||||
modes=('initiator' 'target' 'initiator,target')
|
modes=('initiator' 'target' 'initiator,target')
|
||||||
else
|
else
|
||||||
modes=('target')
|
modes=('target')
|
||||||
|
@ -657,7 +759,7 @@ function test_handle_symlinks () {
|
||||||
done
|
done
|
||||||
|
|
||||||
# TRAVIS SPECIFIC - time limitation
|
# TRAVIS SPECIFIC - time limitation
|
||||||
if [ "$TRAVIS_RUN" != true ]; then
|
if [ "$RUNNING_ON_GITHUB_ACTIONS" != true ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -776,13 +878,13 @@ function test_softdeletion_cleanup () {
|
||||||
|
|
||||||
touch "$file.new"
|
touch "$file.new"
|
||||||
|
|
||||||
if [ "$TRAVIS_RUN" == true ] || [ "$LOCAL_OS" == "BSD" ] || [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "WinNT10" ] || [ "$LOCAL_OS" == "msys" ] || [ "$LOCAL_OS" == "Cygwin" ]; then
|
if [ "$RUNNING_ON_GITHUB_ACTIONS" == true ] || [ "$LOCAL_OS" == "BSD" ] || [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "WinNT10" ] || [ "$LOCAL_OS" == "msys" ] || [ "$LOCAL_OS" == "Cygwin" ]; then
|
||||||
echo "Skipping changing ctime on file because travis / bsd / macos / Win10 / msys / cygwin does not support debugfs"
|
echo "Skipping changing ctime on file because travis / bsd / macos / Win10 / msys / cygwin does not support debugfs"
|
||||||
else
|
else
|
||||||
CreateOldFile "$file.old"
|
CreateOldFile "$file.old"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ "$TRAVIS_RUN" == true ] || [ "$LOCAL_OS" == "BSD" ] || [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "WinNT10" ] || [ "$LOCAL_OS" == "msys" ] || [ "$LOCAL_OS" == "Cygwin" ]; then
|
if [ "$RUNNING_ON_GITHUB_ACTIONS" == true ] || [ "$LOCAL_OS" == "BSD" ] || [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "WinNT10" ] || [ "$LOCAL_OS" == "msys" ] || [ "$LOCAL_OS" == "Cygwin" ]; then
|
||||||
echo "Skipping changing ctime on dir too"
|
echo "Skipping changing ctime on dir too"
|
||||||
else
|
else
|
||||||
CreateOldFile "$DirA" true
|
CreateOldFile "$DirA" true
|
||||||
|
@ -797,7 +899,7 @@ function test_softdeletion_cleanup () {
|
||||||
[ -f "$file.new" ]
|
[ -f "$file.new" ]
|
||||||
assertEquals "New softdeleted / backed up file [$file.new] exists." "0" $?
|
assertEquals "New softdeleted / backed up file [$file.new] exists." "0" $?
|
||||||
|
|
||||||
if [ "$TRAVIS_RUN" == true ] || [ "$LOCAL_OS" == "BSD" ] || [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "WinNT10" ] || [ "$LOCAL_OS" == "msys" ] || [ "$LOCAL_OS" == "Cygwin" ]; then
|
if [ "$RUNNING_ON_GITHUB_ACTIONS" == true ] || [ "$LOCAL_OS" == "BSD" ] || [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "WinNT10" ] || [ "$LOCAL_OS" == "msys" ] || [ "$LOCAL_OS" == "Cygwin" ]; then
|
||||||
[ ! -f "$file.old" ]
|
[ ! -f "$file.old" ]
|
||||||
assertEquals "Old softdeleted / backed up file [$file.old] is deleted permanently." "0" $?
|
assertEquals "Old softdeleted / backed up file [$file.old] is deleted permanently." "0" $?
|
||||||
else
|
else
|
||||||
|
@ -806,7 +908,7 @@ function test_softdeletion_cleanup () {
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$TRAVIS_RUN" == true ] || [ "$LOCAL_OS" == "BSD" ] || [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "WinNT10" ] || [ "$LOCAL_OS" == "msys" ] || [ "$LOCAL_OS" == "Cygwin" ]; then
|
if [ "$RUNNING_ON_GITHUB_ACTIONS" == true ] || [ "$LOCAL_OS" == "BSD" ] || [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "WinNT10" ] || [ "$LOCAL_OS" == "msys" ] || [ "$LOCAL_OS" == "Cygwin" ]; then
|
||||||
[ ! -d "$DirA" ]
|
[ ! -d "$DirA" ]
|
||||||
assertEquals "Old softdeleted / backed up directory [$dirA] is deleted permanently." "0" $?
|
assertEquals "Old softdeleted / backed up directory [$dirA] is deleted permanently." "0" $?
|
||||||
[ ! -d "$DirB" ]
|
[ ! -d "$DirB" ]
|
||||||
|
@ -823,7 +925,7 @@ function test_softdeletion_cleanup () {
|
||||||
|
|
||||||
function test_FileAttributePropagation () {
|
function test_FileAttributePropagation () {
|
||||||
|
|
||||||
if [ "$TRAVIS_RUN" == true ]; then
|
if [ "$RUNNING_ON_GITHUB_ACTIONS" == true ]; then
|
||||||
echo "Skipping FileAttributePropagation tests as travis does not support getfacl / setfacl."
|
echo "Skipping FileAttributePropagation tests as travis does not support getfacl / setfacl."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
@ -1322,7 +1424,6 @@ function test_ParallelExec () {
|
||||||
|
|
||||||
function test_timedExecution () {
|
function test_timedExecution () {
|
||||||
local arguments
|
local arguments
|
||||||
local warnExitCode
|
|
||||||
|
|
||||||
# Clever usage of indexes and exit codes
|
# Clever usage of indexes and exit codes
|
||||||
# osync exits with 0 when no problem detected
|
# osync exits with 0 when no problem detected
|
||||||
|
@ -1384,7 +1485,7 @@ function test_UpgradeConfRun () {
|
||||||
assertEquals "Conf file upgrade" "0" $?
|
assertEquals "Conf file upgrade" "0" $?
|
||||||
|
|
||||||
# Update remote conf files with SSH port
|
# Update remote conf files with SSH port
|
||||||
sed -i.tmp 's#ssh://.*@localhost:[0-9]*/${HOME}/osync-tests/target#ssh://'$REMOTE_USER'@localhost:'$SSH_PORT'/${HOME}/osync-tests/target#' "$CONF_DIR/$TMP_OLD_CONF"
|
sed -i.tmp 's#ssh://.*@localhost:[0-9]*/${homedir}/osync-tests/target#ssh://'$REMOTE_USER'@localhost:'$SSH_PORT'/${homedir}/osync-tests/target#' "$CONF_DIR/$TMP_OLD_CONF"
|
||||||
|
|
||||||
$OSYNC_EXECUTABLE "$CONF_DIR/$TMP_OLD_CONF"
|
$OSYNC_EXECUTABLE "$CONF_DIR/$TMP_OLD_CONF"
|
||||||
assertEquals "Upgraded conf file execution test" "0" $?
|
assertEquals "Upgraded conf file execution test" "0" $?
|
||||||
|
|
|
@ -0,0 +1,147 @@
|
||||||
|
Coding Standards
|
||||||
|
================
|
||||||
|
|
||||||
|
shFlags is more than just a simple 20 line shell script. It is a pretty
|
||||||
|
significant library of shell code that at first glance is not that easy to
|
||||||
|
understand. To improve code readability and usability, some guidelines have been
|
||||||
|
set down to make the code more understandable for anyone who wants to read or
|
||||||
|
modify it.
|
||||||
|
|
||||||
|
Function declaration
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
Declare functions using the following form:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
doSomething() {
|
||||||
|
echo 'done!'
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
One-line functions are allowed if they can fit within the 80 char line limit.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
doSomething() { echo 'done!'; }
|
||||||
|
```
|
||||||
|
|
||||||
|
Function documentation
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
Each function should be preceded by a header that provides the following:
|
||||||
|
|
||||||
|
1. A one-sentence summary of what the function does.
|
||||||
|
|
||||||
|
1. (optional) A longer description of what the function does, and perhaps some
|
||||||
|
special information that helps convey its usage better.
|
||||||
|
|
||||||
|
1. Args: a one-line summary of each argument of the form:
|
||||||
|
|
||||||
|
`name: type: description`
|
||||||
|
|
||||||
|
1. Output: a one-line summary of the output provided. Only output to STDOUT
|
||||||
|
must be documented, unless the output to STDERR is of significance (i.e. not
|
||||||
|
just an error message). The output should be of the form:
|
||||||
|
|
||||||
|
`type: description`
|
||||||
|
|
||||||
|
1. Returns: a one-line summary of the value returned. Returns in shell are
|
||||||
|
always integers, but if the output is a true/false for success (i.e. a
|
||||||
|
boolean), it should be noted. The output should be of the form:
|
||||||
|
|
||||||
|
`type: description`
|
||||||
|
|
||||||
|
Here is a sample header:
|
||||||
|
|
||||||
|
```
|
||||||
|
# Return valid getopt options using currently defined list of long options.
|
||||||
|
#
|
||||||
|
# This function builds a proper getopt option string for short (and long)
|
||||||
|
# options, using the current list of long options for reference.
|
||||||
|
#
|
||||||
|
# Args:
|
||||||
|
# _flags_optStr: integer: option string type (__FLAGS_OPTSTR_*)
|
||||||
|
# Output:
|
||||||
|
# string: generated option string for getopt
|
||||||
|
# Returns:
|
||||||
|
# boolean: success of operation (always returns True)
|
||||||
|
```
|
||||||
|
|
||||||
|
Variable and function names
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
All shFlags specific constants, variables, and functions will be prefixed
|
||||||
|
appropriately with 'flags'. This is to distinguish usage in the shFlags code
|
||||||
|
from users own scripts so that the shell name space remains predictable to
|
||||||
|
users. The exceptions here are the standard `assertEquals`, etc. functions.
|
||||||
|
|
||||||
|
All non built-in constants and variables will be surrounded with squiggle
|
||||||
|
brackets, e.g. `${flags_someVariable}` to improve code readability.
|
||||||
|
|
||||||
|
Due to some shells not supporting local variables in functions, care in the
|
||||||
|
naming and use of variables, both public and private, is very important.
|
||||||
|
Accidental overriding of the variables can occur easily if care is not taken as
|
||||||
|
all variables are technically global variables in some shells.
|
||||||
|
|
||||||
|
Type | Sample
|
||||||
|
---- | ------
|
||||||
|
global public constant | `FLAGS_TRUE`
|
||||||
|
global private constant | `__FLAGS_SHELL_FLAGS`
|
||||||
|
global public variable | `flags_variable`
|
||||||
|
global private variable | `__flags_variable`
|
||||||
|
global macro | `_FLAGS_SOME_MACRO_`
|
||||||
|
public function | `flags_function`
|
||||||
|
public function, local variable | ``flags_variable_`
|
||||||
|
private function | `_flags_function`
|
||||||
|
private function, local variable | `_flags_variable_`
|
||||||
|
|
||||||
|
Where it makes sense to improve readability, variables can have the first
|
||||||
|
letter of the second and later words capitalized. For example, the local
|
||||||
|
variable name for the help string length is `flags_helpStrLen_`.
|
||||||
|
|
||||||
|
There are three special-case global public variables used. They are used due to
|
||||||
|
overcome the limitations of shell scoping or to prevent forking. The three
|
||||||
|
variables are:
|
||||||
|
|
||||||
|
- `flags_error`
|
||||||
|
- `flags_output`
|
||||||
|
- `flags_return`
|
||||||
|
|
||||||
|
Local variable cleanup
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
As many shells do not support local variables, no support for cleanup of
|
||||||
|
variables is present either. As such, all variables local to a function must be
|
||||||
|
cleared up with the `unset` built-in command at the end of each function.
|
||||||
|
|
||||||
|
Indentation
|
||||||
|
-----------
|
||||||
|
|
||||||
|
Code block indentation is two (2) spaces, and tabs may not be used.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
if [ -z 'some string' ]; then
|
||||||
|
someFunction
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
|
Lines of code should be no longer than 80 characters unless absolutely
|
||||||
|
necessary. When lines are wrapped using the backslash character '\', subsequent
|
||||||
|
lines should be indented with four (4) spaces so as to differentiate from the
|
||||||
|
standard spacing of two characters, and tabs may not be used.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
for x in some set of very long set of arguments that make for a very long \
|
||||||
|
that extends much too long for one line
|
||||||
|
do
|
||||||
|
echo ${x}
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
|
When a conditional expression is written using the built-in [ command, and that
|
||||||
|
line must be wrapped, place the control || or && operators on the same line as
|
||||||
|
the expression where possible, with the list to be executed on its own line.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
[ -n 'some really long expression' -a -n 'some other long expr' ] && \
|
||||||
|
echo 'that was actually true!'
|
||||||
|
```
|
|
@ -1,10 +1,15 @@
|
||||||
# shUnit2
|
# shUnit2
|
||||||
|
|
||||||
shUnit2 is a [xUnit](http://en.wikipedia.org/wiki/XUnit) unit test framework for Bourne based shell scripts, and it is designed to work in a similar manner to [JUnit](http://www.junit.org), [PyUnit](http://pyunit.sourceforge.net), etc.. If you have ever had the desire to write a unit test for a shell script, shUnit2 can do the job.
|
shUnit2 is a [xUnit](http://en.wikipedia.org/wiki/XUnit) unit test framework for
|
||||||
|
Bourne based shell scripts, and it is designed to work in a similar manner to
|
||||||
|
[JUnit](http://www.junit.org), [PyUnit](http://pyunit.sourceforge.net), etc.. If
|
||||||
|
you have ever had the desire to write a unit test for a shell script, shUnit2
|
||||||
|
can do the job.
|
||||||
|
|
||||||
[](https://travis-ci.org/kward/shunit2)
|
[](https://app.travis-ci.com/github/kward/shunit2)
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
* [Introduction](#introduction)
|
* [Introduction](#introduction)
|
||||||
* [Credits / Contributors](#credits-contributors)
|
* [Credits / Contributors](#credits-contributors)
|
||||||
* [Feedback](#feedback)
|
* [Feedback](#feedback)
|
||||||
|
@ -21,47 +26,76 @@ shUnit2 is a [xUnit](http://en.wikipedia.org/wiki/XUnit) unit test framework for
|
||||||
* [Error Handling](#error-handling)
|
* [Error Handling](#error-handling)
|
||||||
* [Including Line Numbers in Asserts (Macros)](#including-line-numbers-in-asserts-macros)
|
* [Including Line Numbers in Asserts (Macros)](#including-line-numbers-in-asserts-macros)
|
||||||
* [Test Skipping](#test-skipping)
|
* [Test Skipping](#test-skipping)
|
||||||
|
* [Running specific tests from the command line](#cmd-line-args)
|
||||||
* [Appendix](#appendix)
|
* [Appendix](#appendix)
|
||||||
* [Getting help](#getting-help)
|
* [Getting help](#getting-help)
|
||||||
* [Zsh](#zsh)
|
* [Zsh](#zsh)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## <a name="introduction"></a> Introduction
|
## <a name="introduction"></a> Introduction
|
||||||
shUnit2 was originally developed to provide a consistent testing solution for [log4sh][log4sh], a shell based logging framework similar to [log4j](http://logging.apache.org). During the development of that product, a repeated problem of having things work just fine under one shell (`/bin/bash` on Linux to be specific), and then not working under another shell (`/bin/sh` on Solaris) kept coming up. Although several simple tests were run, they were not adequate and did not catch some corner cases. The decision was finally made to write a proper unit test framework after multiple brown-bag releases were made. _Research was done to look for an existing product that met the testing requirements, but no adequate product was found._
|
|
||||||
|
|
||||||
Tested Operating Systems (varies over time)
|
shUnit2 was originally developed to provide a consistent testing solution for
|
||||||
|
[log4sh][log4sh], a shell based logging framework similar to
|
||||||
|
[log4j](http://logging.apache.org). During the development of that product, a
|
||||||
|
repeated problem of having things work just fine under one shell (`/bin/bash` on
|
||||||
|
Linux to be specific), and then not working under another shell (`/bin/sh` on
|
||||||
|
Solaris) kept coming up. Although several simple tests were run, they were not
|
||||||
|
adequate and did not catch some corner cases. The decision was finally made to
|
||||||
|
write a proper unit test framework after multiple brown-bag releases were made.
|
||||||
|
_Research was done to look for an existing product that met the testing
|
||||||
|
requirements, but no adequate product was found._
|
||||||
|
|
||||||
* Cygwin
|
### Tested software
|
||||||
* FreeBSD (user supported)
|
|
||||||
* Linux (Gentoo, Ubuntu)
|
|
||||||
* Mac OS X
|
|
||||||
* Solaris 8, 9, 10 (inc. OpenSolaris)
|
|
||||||
|
|
||||||
Tested Shells
|
**Tested Operating Systems** (varies over time)
|
||||||
|
|
||||||
|
OS | Support | Verified
|
||||||
|
----------------------------------- | --------- | --------
|
||||||
|
Ubuntu Linux (14.04.05 LTS) | Travis CI | continuous
|
||||||
|
macOS High Sierra (10.13.3) | Travis CI | continuous
|
||||||
|
FreeBSD | user | unknown
|
||||||
|
Solaris 8, 9, 10 (inc. OpenSolaris) | user | unknown
|
||||||
|
Cygwin | user | unknown
|
||||||
|
|
||||||
|
**Tested Shells**
|
||||||
|
|
||||||
* Bourne Shell (__sh__)
|
* Bourne Shell (__sh__)
|
||||||
* BASH - GNU Bourne Again SHell (__bash__)
|
* BASH - GNU Bourne Again SHell (__bash__)
|
||||||
* DASH (__dash__)
|
* DASH - Debian Almquist Shell (__dash__)
|
||||||
* Korn Shell (__ksh__)
|
* Korn Shell - AT&T version of the Korn shell (__ksh__)
|
||||||
* pdksh - Public Domain Korn Shell (__pdksh__)
|
* mksh - MirBSD Korn Shell (__mksh__)
|
||||||
* zsh - Zsh (__zsh__) (since 2.1.2) _please see the Zsh shell errata for more information_
|
* zsh - Zsh (__zsh__) (since 2.1.2) _please see the Zsh shell errata for more information_
|
||||||
|
|
||||||
See the appropriate Release Notes for this release (`doc/RELEASE_NOTES-X.X.X.txt`) for the list of actual versions tested.
|
See the appropriate Release Notes for this release
|
||||||
|
(`doc/RELEASE_NOTES-X.X.X.txt`) for the list of actual versions tested.
|
||||||
|
|
||||||
### <a name="credits-contributors"></a> Credits / Contributors
|
### <a name="credits-contributors"></a> Credits / Contributors
|
||||||
A list of contributors to shUnit2 can be found in `doc/contributors.md`. Many thanks go out to all those who have contributed to make this a better tool.
|
|
||||||
|
|
||||||
shUnit2 is the original product of many hours of work by Kate Ward, the primary author of the code. For related software, check out https://github.com/kward.
|
A list of contributors to shUnit2 can be found in `doc/contributors.md`. Many
|
||||||
|
thanks go out to all those who have contributed to make this a better tool.
|
||||||
|
|
||||||
|
shUnit2 is the original product of many hours of work by Kate Ward, the primary
|
||||||
|
author of the code. For related software, check out https://github.com/kward.
|
||||||
|
|
||||||
### <a name="feedback"></a> Feedback
|
### <a name="feedback"></a> Feedback
|
||||||
Feedback is most certainly welcome for this document. Send your additions, comments and criticisms to the shunit2-users@google.com mailing list.
|
|
||||||
|
Feedback is most certainly welcome for this document. Send your questions,
|
||||||
|
comments, and criticisms via the
|
||||||
|
[shunit2-users](https://groups.google.com/a/forestent.com/forum/#!forum/shunit2-users/new)
|
||||||
|
forum (created 2018-12-09), or file an issue via
|
||||||
|
https://github.com/kward/shunit2/issues.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## <a name="quickstart"></a> Quickstart
|
## <a name="quickstart"></a> Quickstart
|
||||||
This section will give a very quick start to running unit tests with shUnit2. More information is located in later sections.
|
|
||||||
|
|
||||||
Here is a quick sample script to show how easy it is to write a unit test in shell. _Note: the script as it stands expects that you are running it from the "examples" directory._
|
This section will give a very quick start to running unit tests with shUnit2.
|
||||||
|
More information is located in later sections.
|
||||||
|
|
||||||
|
Here is a quick sample script to show how easy it is to write a unit test in
|
||||||
|
shell. _Note: the script as it stands expects that you are running it from the
|
||||||
|
"examples" directory._
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
|
@ -72,7 +106,7 @@ testEquality() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Load shUnit2.
|
# Load shUnit2.
|
||||||
. ./shunit2
|
. ../shunit2
|
||||||
```
|
```
|
||||||
|
|
||||||
Running the unit test should give results similar to the following.
|
Running the unit test should give results similar to the following.
|
||||||
|
@ -87,14 +121,38 @@ Ran 1 test.
|
||||||
OK
|
OK
|
||||||
```
|
```
|
||||||
|
|
||||||
W00t! You've just run your first successful unit test. So, what just happened? Quite a bit really, and it all happened simply by sourcing the `shunit2` library. The basic functionality for the script above goes like this:
|
W00t! You've just run your first successful unit test. So, what just happened?
|
||||||
|
Quite a bit really, and it all happened simply by sourcing the `shunit2`
|
||||||
|
library. The basic functionality for the script above goes like this:
|
||||||
|
|
||||||
* When shUnit2 is sourced, it will walk through any functions defined whose name starts with the string `test`, and add those to an internal list of tests to execute. Once a list of test functions to be run has been determined, shunit2 will go to work.
|
* When shUnit2 is sourced, it will walk through any functions defined whose name
|
||||||
* Before any tests are executed, shUnit2 again looks for a function, this time one named `oneTimeSetUp()`. If it exists, it will be run. This function is normally used to setup the environment for all tests to be run. Things like creating directories for output or setting environment variables are good to place here. Just so you know, you can also declare a corresponding function named `oneTimeTearDown()` function that does the same thing, but once all the tests have been completed. It is good for removing temporary directories, etc.
|
starts with the string `test`, and add those to an internal list of tests to
|
||||||
* shUnit2 is now ready to run tests. Before doing so though, it again looks for another function that might be declared, one named `setUp()`. If the function exists, it will be run before each test. It is good for resetting the environment so that each test starts with a clean slate. **At this stage, the first test is finally run.** The success of the test is recorded for a report that will be generated later. After the test is run, shUnit2 looks for a final function that might be declared, one named `tearDown()`. If it exists, it will be run after each test. It is a good place for cleaning up after each test, maybe doing things like removing files that were created, or removing directories. This set of steps, `setUp() > test() > tearDown()`, is repeated for all of the available tests.
|
execute. Once a list of test functions to be run has been determined, shunit2
|
||||||
* Once all the work is done, shUnit2 will generate the nice report you saw above. A summary of all the successes and failures will be given so that you know how well your code is doing.
|
will go to work.
|
||||||
|
* Before any tests are executed, shUnit2 again looks for a function, this time
|
||||||
|
one named `oneTimeSetUp()`. If it exists, it will be run. This function is
|
||||||
|
normally used to setup the environment for all tests to be run. Things like
|
||||||
|
creating directories for output or setting environment variables are good to
|
||||||
|
place here. Just so you know, you can also declare a corresponding function
|
||||||
|
named `oneTimeTearDown()` function that does the same thing, but once all the
|
||||||
|
tests have been completed. It is good for removing temporary directories, etc.
|
||||||
|
* shUnit2 is now ready to run tests. Before doing so though, it again looks for
|
||||||
|
another function that might be declared, one named `setUp()`. If the function
|
||||||
|
exists, it will be run before each test. It is good for resetting the
|
||||||
|
environment so that each test starts with a clean slate. **At this stage, the
|
||||||
|
first test is finally run.** The success of the test is recorded for a report
|
||||||
|
that will be generated later. After the test is run, shUnit2 looks for a final
|
||||||
|
function that might be declared, one named `tearDown()`. If it exists, it will
|
||||||
|
be run after each test. It is a good place for cleaning up after each test,
|
||||||
|
maybe doing things like removing files that were created, or removing
|
||||||
|
directories. This set of steps, `setUp() > test() > tearDown()`, is repeated
|
||||||
|
for all of the available tests.
|
||||||
|
* Once all the work is done, shUnit2 will generate the nice report you saw
|
||||||
|
above. A summary of all the successes and failures will be given so that you
|
||||||
|
know how well your code is doing.
|
||||||
|
|
||||||
We should now try adding a test that fails. Change your unit test to look like this.
|
We should now try adding a test that fails. Change your unit test to look like
|
||||||
|
this.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
|
@ -110,12 +168,30 @@ testPartyLikeItIs1999() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Load shUnit2.
|
# Load shUnit2.
|
||||||
. ./shunit2
|
. ../shunit2
|
||||||
```
|
```
|
||||||
|
|
||||||
So, what did you get? I guess it told you that this isn't 1999. Bummer, eh? Hopefully, you noticed a couple of things that were different about the second test. First, we added an optional message that the user will see if the assert fails. Second, we did comparisons of strings instead of integers as in the first test. It doesn't matter whether you are testing for equality of strings or integers. Both work equally well with shUnit2.
|
So, what did you get? I guess it told you that this isn't 1999. Bummer, eh?
|
||||||
|
Hopefully, you noticed a couple of things that were different about the second
|
||||||
|
test. First, we added an optional message that the user will see if the assert
|
||||||
|
fails. Second, we did comparisons of strings instead of integers as in the first
|
||||||
|
test. It doesn't matter whether you are testing for equality of strings or
|
||||||
|
integers. Both work equally well with shUnit2.
|
||||||
|
|
||||||
Hopefully, this is enough to get you started with unit testing. If you want a ton more examples, take a look at the tests provided with [log4sh][log4sh] or [shFlags][shflags]. Both provide excellent examples of more advanced usage. shUnit2 was after all written to meet the unit testing need that [log4sh][log4sh] had.
|
Hopefully, this is enough to get you started with unit testing. If you want a
|
||||||
|
ton more examples, take a look at the tests provided with [log4sh][log4sh] or
|
||||||
|
[shFlags][shflags]. Both provide excellent examples of more advanced usage.
|
||||||
|
shUnit2 was after all written to meet the unit testing need that
|
||||||
|
[log4sh][log4sh] had.
|
||||||
|
|
||||||
|
If you are using distribution packaged shUnit2 which is accessible from
|
||||||
|
`/usr/bin/shunit2` such as Debian, you can load shUnit2 without specifying its
|
||||||
|
path. So the last 2 lines in the above can be replaced by:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Load shUnit2.
|
||||||
|
. shunit2
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -123,139 +199,212 @@ Hopefully, this is enough to get you started with unit testing. If you want a to
|
||||||
|
|
||||||
### <a name="general-info"></a> General Info
|
### <a name="general-info"></a> General Info
|
||||||
|
|
||||||
Any string values passed should be properly quoted -- they should must be surrounded by single-quote (`'`) or double-quote (`"`) characters -- so that the shell will properly parse them.
|
Any string values passed should be properly quoted -- they should be
|
||||||
|
surrounded by single-quote (`'`) or double-quote (`"`) characters -- so that the
|
||||||
|
shell will properly parse them.
|
||||||
|
|
||||||
### <a name="asserts"></a> Asserts
|
### <a name="asserts"></a> Asserts
|
||||||
|
|
||||||
`assertEquals [message] expected actual`
|
assertEquals [message] expected actual
|
||||||
|
|
||||||
Asserts that _expected_ and _actual_ are equal to one another. The _expected_ and _actual_ values can be either strings or integer values as both will be treated as strings. The _message_ is optional, and must be quoted.
|
Asserts that _expected_ and _actual_ are equal to one another. The _expected_
|
||||||
|
and _actual_ values can be either strings or integer values as both will be
|
||||||
|
treated as strings. The _message_ is optional, and must be quoted.
|
||||||
|
|
||||||
`assertNotEquals [message] unexpected actual`
|
assertNotEquals [message] unexpected actual
|
||||||
|
|
||||||
Asserts that _unexpected_ and _actual_ are not equal to one another. The _unexpected_ and _actual_ values can be either strings or integer values as both will be treaded as strings. The _message_ is optional, and must be quoted.
|
Asserts that _unexpected_ and _actual_ are not equal to one another. The
|
||||||
|
_unexpected_ and _actual_ values can be either strings or integer values as both
|
||||||
|
will be treated as strings. The _message_ is optional, and must be quoted.
|
||||||
|
|
||||||
`assertSame [message] expected actual`
|
assertSame [message] expected actual
|
||||||
|
|
||||||
This function is functionally equivalent to `assertEquals`.
|
This function is functionally equivalent to `assertEquals`.
|
||||||
|
|
||||||
`assertNotSame [message] unexpected actual`
|
assertNotSame [message] unexpected actual
|
||||||
|
|
||||||
This function is functionally equivalent to `assertNotEquals`.
|
This function is functionally equivalent to `assertNotEquals`.
|
||||||
|
|
||||||
`assertNull [message] value`
|
assertContains [message] container content
|
||||||
|
|
||||||
Asserts that _value_ is _null_, or in shell terms, a zero-length string. The _value_ must be a string as an integer value does not translate into a zero-length string. The _message_ is optional, and must be quoted.
|
Asserts that _container_ contains _content_. The _container_ and _content_
|
||||||
|
values can be either strings or integer values as both will be treated as
|
||||||
|
strings. The _message_ is optional, and must be quoted.
|
||||||
|
|
||||||
`assertNotNull [message] value`
|
assertNotContains [message] container content
|
||||||
|
|
||||||
Asserts that _value_ is _not null_, or in shell terms, a non-empty string. The _value_ may be a string or an integer as the later will be parsed as a non-empty string value. The _message_ is optional, and must be quoted.
|
Asserts that _container_ does not contain _content_. The _container_ and
|
||||||
|
_content_ values can be either strings or integer values as both will be treated
|
||||||
|
as strings. The _message_ is optional, and must be quoted.
|
||||||
|
|
||||||
`assertTrue [message] condition`
|
assertNull [message] value
|
||||||
|
|
||||||
Asserts that a given shell test _condition_ is _true_. The condition can be as simple as a shell _true_ value (the value `0` -- equivalent to `${SHUNIT_TRUE}`), or a more sophisticated shell conditional expression. The _message_ is optional, and must be quoted.
|
Asserts that _value_ is _null_, or in shell terms, a zero-length string. The
|
||||||
|
_value_ must be a string as an integer value does not translate into a zero-
|
||||||
|
length string. The _message_ is optional, and must be quoted.
|
||||||
|
|
||||||
A sophisticated shell conditional expression is equivalent to what the __if__ or __while__ shell built-ins would use (more specifically, what the __test__ command would use). Testing for example whether some value is greater than another value can be done this way.
|
assertNotNull [message] value
|
||||||
|
|
||||||
`assertTrue "[ 34 -gt 23 ]"`
|
Asserts that _value_ is _not null_, or in shell terms, a non-empty string. The
|
||||||
|
_value_ may be a string or an integer as the latter will be parsed as a non-empty
|
||||||
|
string value. The _message_ is optional, and must be quoted.
|
||||||
|
|
||||||
Testing for the ability to read a file can also be done. This particular test will fail.
|
assertTrue [message] condition
|
||||||
|
|
||||||
`assertTrue 'test failed' "[ -r /some/non-existant/file' ]"`
|
Asserts that a given shell test _condition_ is _true_. The condition can be as
|
||||||
|
simple as a shell _true_ value (the value `0` -- equivalent to
|
||||||
|
`${SHUNIT_TRUE}`), or a more sophisticated shell conditional expression. The
|
||||||
|
_message_ is optional, and must be quoted.
|
||||||
|
|
||||||
As the expressions are standard shell __test__ expressions, it is possible to string multiple expressions together with `-a` and `-o` in the standard fashion. This test will succeed as the entire expression evaluates to _true_.
|
A sophisticated shell conditional expression is equivalent to what the __if__ or
|
||||||
|
__while__ shell built-ins would use (more specifically, what the __test__
|
||||||
|
command would use). Testing for example whether some value is greater than
|
||||||
|
another value can be done this way.
|
||||||
|
|
||||||
`assertTrue 'test failed' '[ 1 -eq 1 -a 2 -eq 2 ]'`
|
assertTrue "[ 34 -gt 23 ]"
|
||||||
|
|
||||||
_One word of warning: be very careful with your quoting as shell is not the most forgiving of bad quoting, and things will fail in strange ways._
|
Testing for the ability to read a file can also be done. This particular test
|
||||||
|
will fail.
|
||||||
|
|
||||||
`assertFalse [message] condition`
|
assertTrue 'test failed' "[ -r /some/non-existant/file ]"
|
||||||
|
|
||||||
Asserts that a given shell test _condition_ is _false_. The condition can be as simple as a shell _false_ value (the value `1` -- equivalent to `${SHUNIT_FALSE}`), or a more sophisticated shell conditional expression. The _message_ is optional, and must be quoted.
|
As the expressions are standard shell __test__ expressions, it is possible to
|
||||||
|
string multiple expressions together with `-a` and `-o` in the standard fashion.
|
||||||
|
This test will succeed as the entire expression evaluates to _true_.
|
||||||
|
|
||||||
|
assertTrue 'test failed' '[ 1 -eq 1 -a 2 -eq 2 ]'
|
||||||
|
|
||||||
|
<i>One word of warning: be very careful with your quoting as shell is not the
|
||||||
|
most forgiving of bad quoting, and things will fail in strange ways.</i>
|
||||||
|
|
||||||
|
assertFalse [message] condition
|
||||||
|
|
||||||
|
Asserts that a given shell test _condition_ is _false_. The condition can be as
|
||||||
|
simple as a shell _false_ value (the value `1` -- equivalent to
|
||||||
|
`${SHUNIT_FALSE}`), or a more sophisticated shell conditional expression. The
|
||||||
|
_message_ is optional, and must be quoted.
|
||||||
|
|
||||||
_For examples of more sophisticated expressions, see `assertTrue`._
|
_For examples of more sophisticated expressions, see `assertTrue`._
|
||||||
|
|
||||||
### <a name="failures"></a> Failures
|
### <a name="failures"></a> Failures
|
||||||
|
|
||||||
Just to clarify, failures __do not__ test the various arguments against one another. Failures simply fail, optionally with a message, and that is all they do. If you need to test arguments against one another, use asserts.
|
Just to clarify, failures __do not__ test the various arguments against one
|
||||||
|
another. Failures simply fail, optionally with a message, and that is all they
|
||||||
|
do. If you need to test arguments against one another, use asserts.
|
||||||
|
|
||||||
If all failures do is fail, why might one use them? There are times when you may have some very complicated logic that you need to test, and the simple asserts provided are simply not adequate. You can do your own validation of the code, use an `assertTrue ${SHUNIT_TRUE}` if your own tests succeeded, and use a failure to record a failure.
|
If all failures do is fail, why might one use them? There are times when you may
|
||||||
|
have some very complicated logic that you need to test, and the simple asserts
|
||||||
|
provided are simply not adequate. You can do your own validation of the code,
|
||||||
|
use an `assertTrue ${SHUNIT_TRUE}` if your own tests succeeded, and use a
|
||||||
|
failure to record a failure.
|
||||||
|
|
||||||
`fail [message]`
|
fail [message]
|
||||||
|
|
||||||
Fails the test immediately. The _message_ is optional, and must be quoted.
|
Fails the test immediately. The _message_ is optional, and must be quoted.
|
||||||
|
|
||||||
`failNotEquals [message] unexpected actual`
|
failNotEquals [message] unexpected actual
|
||||||
|
|
||||||
Fails the test immediately, reporting that the _unexpected_ and _actual_ values are not equal to one another. The _message_ is optional, and must be quoted.
|
Fails the test immediately, reporting that the _unexpected_ and _actual_ values
|
||||||
|
are not equal to one another. The _message_ is optional, and must be quoted.
|
||||||
|
|
||||||
_Note: no actual comparison of unexpected and actual is done._
|
_Note: no actual comparison of unexpected and actual is done._
|
||||||
|
|
||||||
`failSame [message] expected actual`
|
failSame [message] expected actual
|
||||||
|
|
||||||
Fails the test immediately, reporting that the _expected_ and _actual_ values are the same. The _message_ is optional, and must be quoted.
|
Fails the test immediately, reporting that the _expected_ and _actual_ values
|
||||||
|
are the same. The _message_ is optional, and must be quoted.
|
||||||
|
|
||||||
_Note: no actual comparison of expected and actual is done._
|
_Note: no actual comparison of expected and actual is done._
|
||||||
|
|
||||||
`failNotSame [message] expected actual`
|
failNotSame [message] expected actual
|
||||||
|
|
||||||
Fails the test immediately, reporting that the _expected_ and _actual_ values are not the same. The _message_ is optional, and must be quoted.
|
Fails the test immediately, reporting that the _expected_ and _actual_ values
|
||||||
|
are not the same. The _message_ is optional, and must be quoted.
|
||||||
|
|
||||||
_Note: no actual comparison of expected and actual is done._
|
_Note: no actual comparison of expected and actual is done._
|
||||||
|
|
||||||
|
failFound [message] content
|
||||||
|
|
||||||
|
Fails the test immediately, reporting that the _content_ was found. The
|
||||||
|
_message_ is optional, and must be quoted.
|
||||||
|
|
||||||
|
_Note: no actual search of content is done._
|
||||||
|
|
||||||
|
failNotFound [message] content
|
||||||
|
|
||||||
|
Fails the test immediately, reporting that the _content_ was not found. The
|
||||||
|
_message_ is optional, and must be quoted.
|
||||||
|
|
||||||
|
_Note: no actual search of content is done._
|
||||||
|
|
||||||
### <a name="setup-teardown"></a> Setup/Teardown
|
### <a name="setup-teardown"></a> Setup/Teardown
|
||||||
|
|
||||||
`oneTimeSetUp`
|
oneTimeSetUp
|
||||||
|
|
||||||
This function can be be optionally overridden by the user in their test suite.
|
|
||||||
|
|
||||||
If this function exists, it will be called once before any tests are run. It is useful to prepare a common environment for all tests.
|
|
||||||
|
|
||||||
`oneTimeTearDown`
|
|
||||||
|
|
||||||
This function can be be optionally overridden by the user in their test suite.
|
|
||||||
|
|
||||||
If this function exists, it will be called once after all tests are completed. It is useful to clean up the environment after all tests.
|
|
||||||
|
|
||||||
`setUp`
|
|
||||||
|
|
||||||
This function can be be optionally overridden by the user in their test suite.
|
|
||||||
|
|
||||||
If this function exists, it will be called before each test is run. It is useful to reset the environment before each test.
|
|
||||||
|
|
||||||
`tearDown`
|
|
||||||
|
|
||||||
This function can be be optionally overridden by the user in their test suite.
|
|
||||||
|
|
||||||
If this function exists, it will be called after each test completes. It is useful to clean up the environment after each test.
|
|
||||||
|
|
||||||
### <a name="skipping"></a> Skipping
|
|
||||||
|
|
||||||
`startSkipping`
|
|
||||||
|
|
||||||
This function forces the remaining _assert_ and _fail_ functions to be "skipped", i.e. they will have no effect. Each function skipped will be recorded so that the total of asserts and fails will not be altered.
|
|
||||||
|
|
||||||
`endSkipping`
|
|
||||||
|
|
||||||
This function returns calls to the _assert_ and _fail_ functions to their default behavior, i.e. they will be called.
|
|
||||||
|
|
||||||
`isSkipping`
|
|
||||||
|
|
||||||
This function returns the current state of skipping. It can be compared against `${SHUNIT_TRUE}` or `${SHUNIT_FALSE}` if desired.
|
|
||||||
|
|
||||||
### <a name="suites"></a> Suites
|
|
||||||
|
|
||||||
The default behavior of shUnit2 is that all tests will be found dynamically. If you have a specific set of tests you want to run, or you don't want to use the standard naming scheme of prefixing your tests with `test`, these functions are for you. Most users will never use them though.
|
|
||||||
|
|
||||||
`suite`
|
|
||||||
|
|
||||||
This function can be optionally overridden by the user in their test suite.
|
This function can be optionally overridden by the user in their test suite.
|
||||||
|
|
||||||
If this function exists, it will be called when `shunit2` is sourced. If it does not exist, shUnit2 will search the parent script for all functions beginning with the word `test`, and they will be added dynamically to the test suite.
|
If this function exists, it will be called once before any tests are run. It is
|
||||||
|
useful to prepare a common environment for all tests.
|
||||||
|
|
||||||
`suite_addTest name`
|
oneTimeTearDown
|
||||||
|
|
||||||
This function adds a function named _name_ to the list of tests scheduled for execution as part of this test suite. This function should only be called from within the `suite()` function.
|
This function can be optionally overridden by the user in their test suite.
|
||||||
|
|
||||||
|
If this function exists, it will be called once after all tests are completed.
|
||||||
|
It is useful to clean up the environment after all tests.
|
||||||
|
|
||||||
|
setUp
|
||||||
|
|
||||||
|
This function can be optionally overridden by the user in their test suite.
|
||||||
|
|
||||||
|
If this function exists, it will be called before each test is run. It is useful
|
||||||
|
to reset the environment before each test.
|
||||||
|
|
||||||
|
tearDown
|
||||||
|
|
||||||
|
This function can be optionally overridden by the user in their test suite.
|
||||||
|
|
||||||
|
If this function exists, it will be called after each test completes. It is
|
||||||
|
useful to clean up the environment after each test.
|
||||||
|
|
||||||
|
### <a name="skipping"></a> Skipping
|
||||||
|
|
||||||
|
startSkipping
|
||||||
|
|
||||||
|
This function forces the remaining _assert_ and _fail_ functions to be
|
||||||
|
"skipped", i.e. they will have no effect. Each function skipped will be recorded
|
||||||
|
so that the total of asserts and fails will not be altered.
|
||||||
|
|
||||||
|
endSkipping
|
||||||
|
|
||||||
|
This function returns calls to the _assert_ and _fail_ functions to their
|
||||||
|
default behavior, i.e. they will be called.
|
||||||
|
|
||||||
|
isSkipping
|
||||||
|
|
||||||
|
This function returns the current state of skipping. It can be compared against
|
||||||
|
`${SHUNIT_TRUE}` or `${SHUNIT_FALSE}` if desired.
|
||||||
|
|
||||||
|
### <a name="suites"></a> Suites
|
||||||
|
|
||||||
|
The default behavior of shUnit2 is that all tests will be found dynamically. If
|
||||||
|
you have a specific set of tests you want to run, or you don't want to use the
|
||||||
|
standard naming scheme of prefixing your tests with `test`, these functions are
|
||||||
|
for you. Most users will never use them though.
|
||||||
|
|
||||||
|
suite
|
||||||
|
|
||||||
|
This function can be optionally overridden by the user in their test suite.
|
||||||
|
|
||||||
|
If this function exists, it will be called when `shunit2` is sourced. If it does
|
||||||
|
not exist, shUnit2 will search the parent script for all functions beginning
|
||||||
|
with the word `test`, and they will be added dynamically to the test suite.
|
||||||
|
|
||||||
|
suite_addTest name
|
||||||
|
|
||||||
|
This function adds a function named _name_ to the list of tests scheduled for
|
||||||
|
execution as part of this test suite. This function should only be called from
|
||||||
|
within the `suite()` function.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -263,7 +412,8 @@ This function adds a function named _name_ to the list of tests scheduled for ex
|
||||||
|
|
||||||
### <a name="some-constants-you-can-use"></a> Some constants you can use
|
### <a name="some-constants-you-can-use"></a> Some constants you can use
|
||||||
|
|
||||||
There are several constants provided by shUnit2 as variables that might be of use to you.
|
There are several constants provided by shUnit2 as variables that might be of
|
||||||
|
use to you.
|
||||||
|
|
||||||
*Predefined*
|
*Predefined*
|
||||||
|
|
||||||
|
@ -280,22 +430,32 @@ There are several constants provided by shUnit2 as variables that might be of us
|
||||||
| Constant | Value |
|
| Constant | Value |
|
||||||
| ----------------- | ----- |
|
| ----------------- | ----- |
|
||||||
| SHUNIT\_CMD\_EXPR | Override which `expr` command is used. By default `expr` is used, except on BSD systems where `gexpr` is used. |
|
| SHUNIT\_CMD\_EXPR | Override which `expr` command is used. By default `expr` is used, except on BSD systems where `gexpr` is used. |
|
||||||
| SHUNIT\_COLOR | Enable colorized output. Options are 'auto', 'always', or 'never', with 'auto' being the default. |
|
| SHUNIT\_COLOR | Enable colorized output. Options are 'auto', 'always', or 'none', with 'auto' being the default. |
|
||||||
| SHUNIT\_PARENT | The filename of the shell script containing the tests. This is needed specifically for Zsh support. |
|
| SHUNIT\_PARENT | The filename of the shell script containing the tests. This is needed specifically for Zsh support. |
|
||||||
| SHUNIT\_TEST\_PREFIX | Define this variable to add a prefix in front of each test name that is output in the test report. |
|
| SHUNIT\_TEST\_PREFIX | Define this variable to add a prefix in front of each test name that is output in the test report. |
|
||||||
|
|
||||||
### <a name="error-handling"></a> Error handling
|
### <a name="error-handling"></a> Error handling
|
||||||
|
|
||||||
The constants values `SHUNIT_TRUE`, `SHUNIT_FALSE`, and `SHUNIT_ERROR` are returned from nearly every function to indicate the success or failure of the function. Additionally the variable `flags_error` is filled with a detailed error message if any function returns with a `SHUNIT_ERROR` value.
|
The constants values `SHUNIT_TRUE`, `SHUNIT_FALSE`, and `SHUNIT_ERROR` are
|
||||||
|
returned from nearly every function to indicate the success or failure of the
|
||||||
|
function. Additionally the variable `flags_error` is filled with a detailed
|
||||||
|
error message if any function returns with a `SHUNIT_ERROR` value.
|
||||||
|
|
||||||
### <a name="including-line-numbers-in-asserts-macros"></a> Including Line Numbers in Asserts (Macros)
|
### <a name="including-line-numbers-in-asserts-macros"></a> Including Line Numbers in Asserts (Macros)
|
||||||
|
|
||||||
If you include lots of assert statements in an individual test function, it can become difficult to determine exactly which assert was thrown unless your messages are unique. To help somewhat, line numbers can be included in the assert messages. To enable this, a special shell "macro" must be used rather than the standard assert calls. _Shell doesn't actually have macros; the name is used here as the operation is similar to a standard macro._
|
If you include lots of assert statements in an individual test function, it can
|
||||||
|
become difficult to determine exactly which assert was thrown unless your
|
||||||
|
messages are unique. To help somewhat, line numbers can be included in the
|
||||||
|
assert messages. To enable this, a special shell "macro" must be used rather
|
||||||
|
than the standard assert calls. _Shell doesn't actually have macros; the name is
|
||||||
|
used here as the operation is similar to a standard macro._
|
||||||
|
|
||||||
For example, to include line numbers for a `assertEquals()` function call, replace the `assertEquals()` with `${_ASSERT_EQUALS_}`.
|
For example, to include line numbers for a `assertEquals()` function call,
|
||||||
|
replace the `assertEquals()` with `${_ASSERT_EQUALS_}`.
|
||||||
|
|
||||||
_**Example** -- Asserts with and without line numbers_
|
_**Example** -- Asserts with and without line numbers_
|
||||||
```sh
|
|
||||||
|
```shell
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# file: examples/lineno_test.sh
|
# file: examples/lineno_test.sh
|
||||||
|
|
||||||
|
@ -309,20 +469,36 @@ testLineNo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Load shUnit2.
|
# Load shUnit2.
|
||||||
. ./shunit2
|
. ../shunit2
|
||||||
```
|
```
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
1. Due to how shell parses command-line arguments, all strings used with macros should be quoted twice. Namely, single-quotes must be converted to single-double-quotes, and vice-versa. If the string being passed is absolutely for sure not empty, the extra quoting is not necessary.<br/><br/>Normal `assertEquals` call.<br/>`assertEquals 'some message' 'x' ''`<br/><br/>Macro `_ASSERT_EQUALS_` call. Note the extra quoting around the _message_ and the _null_ value.<br/>`_ASSERT_EQUALS_ '"some message"' 'x' '""'`
|
1. Due to how shell parses command-line arguments, _**all strings used with
|
||||||
|
macros should be quoted twice**_. Namely, single-quotes must be converted to single-double-quotes, and vice-versa.<br/>
|
||||||
|
<br/>
|
||||||
|
Normal `assertEquals` call.<br/>
|
||||||
|
`assertEquals 'some message' 'x' ''`<br/>
|
||||||
|
<br/>
|
||||||
|
Macro `_ASSERT_EQUALS_` call. Note the extra quoting around the _message_ and
|
||||||
|
the _null_ value.<br/>
|
||||||
|
`_ASSERT_EQUALS_ '"some message"' 'x' '""'`
|
||||||
|
|
||||||
1. Line numbers are not supported in all shells. If a shell does not support them, no errors will be thrown. Supported shells include: __bash__ (>=3.0), __ksh__, __pdksh__, and __zsh__.
|
1. Line numbers are not supported in all shells. If a shell does not support
|
||||||
|
them, no errors will be thrown. Supported shells include: __bash__ (>=3.0),
|
||||||
|
__ksh__, __mksh__, and __zsh__.
|
||||||
|
|
||||||
### <a name="test-skipping"></a> Test Skipping
|
### <a name="test-skipping"></a> Test Skipping
|
||||||
|
|
||||||
There are times where the test code you have written is just not applicable to the system you are running on. This section describes how to skip these tests but maintain the total test count.
|
There are times where the test code you have written is just not applicable to
|
||||||
|
the system you are running on. This section describes how to skip these tests
|
||||||
|
but maintain the total test count.
|
||||||
|
|
||||||
Probably the easiest example would be shell code that is meant to run under the __bash__ shell, but the unit test is running under the Bourne shell. There are things that just won't work. The following test code demonstrates two sample functions, one that will be run under any shell, and the another that will run only under the __bash__ shell.
|
Probably the easiest example would be shell code that is meant to run under the
|
||||||
|
__bash__ shell, but the unit test is running under the Bourne shell. There are
|
||||||
|
things that just won't work. The following test code demonstrates two sample
|
||||||
|
functions, one that will be run under any shell, and the another that will run
|
||||||
|
only under the __bash__ shell.
|
||||||
|
|
||||||
_**Example** -- math include_
|
_**Example** -- math include_
|
||||||
```sh
|
```sh
|
||||||
|
@ -371,10 +547,11 @@ oneTimeSetUp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Load and run shUnit2.
|
# Load and run shUnit2.
|
||||||
. ./shunit2
|
. ../shunit2
|
||||||
```
|
```
|
||||||
|
|
||||||
Running the above test under the __bash__ shell will result in the following output.
|
Running the above test under the __bash__ shell will result in the following
|
||||||
|
output.
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ /bin/bash math_test.sh
|
$ /bin/bash math_test.sh
|
||||||
|
@ -385,7 +562,8 @@ Ran 1 test.
|
||||||
OK
|
OK
|
||||||
```
|
```
|
||||||
|
|
||||||
But, running the test under any other Unix shell will result in the following output.
|
But, running the test under any other Unix shell will result in the following
|
||||||
|
output.
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ /bin/ksh math_test.sh
|
$ /bin/ksh math_test.sh
|
||||||
|
@ -396,9 +574,33 @@ Ran 1 test.
|
||||||
OK (skipped=1)
|
OK (skipped=1)
|
||||||
```
|
```
|
||||||
|
|
||||||
As you can see, the total number of tests has not changed, but the report indicates that some tests were skipped.
|
As you can see, the total number of tests has not changed, but the report
|
||||||
|
indicates that some tests were skipped.
|
||||||
|
|
||||||
Skipping can be controlled with the following functions: `startSkipping()`, `endSkipping()`, and `isSkipping()`. Once skipping is enabled, it will remain enabled until the end of the current test function call, after which skipping is disabled.
|
Skipping can be controlled with the following functions: `startSkipping()`,
|
||||||
|
`endSkipping()`, and `isSkipping()`. Once skipping is enabled, it will remain
|
||||||
|
enabled until the end of the current test function call, after which skipping is
|
||||||
|
disabled.
|
||||||
|
|
||||||
|
### <a name="cmd-line-args"></a> Running specific tests from the command line.
|
||||||
|
|
||||||
|
When running a test script, you may override the default set of tests, or the suite-specified set of tests, by providing additional arguments on the command line. Each additional argument after the `--` marker is assumed to be the name of a test function to be run in the order specified. e.g.
|
||||||
|
|
||||||
|
```console
|
||||||
|
test-script.sh -- testOne testTwo otherFunction
|
||||||
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
```console
|
||||||
|
shunit2 test-script.sh testOne testTwo otherFunction
|
||||||
|
```
|
||||||
|
|
||||||
|
In either case, three functions will be run as tests, `testOne`, `testTwo`, and `otherFunction`. Note that the function `otherFunction` would not normally be run by `shunit2` as part of the implicit collection of tests as it's function name does not match the test function name pattern `test*`.
|
||||||
|
|
||||||
|
If a specified test function does not exist, `shunit2` will still attempt to run that function and thereby cause a failure which `shunit2` will catch and mark as a failed test. All other tests will run normally.
|
||||||
|
|
||||||
|
The specification of tests does not affect how `shunit2` looks for and executes the setup and tear down functions, which will still run as expected.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -406,29 +608,36 @@ Skipping can be controlled with the following functions: `startSkipping()`, `end
|
||||||
|
|
||||||
### <a name="getting-help"></a> Getting Help
|
### <a name="getting-help"></a> Getting Help
|
||||||
|
|
||||||
For help, please send requests to either the shunit2-users@googlegroups.com mailing list (archives available on the web at http://groups.google.com/group/shunit2-users) or directly to Kate Ward <kate dot ward at forestent dot com>.
|
For help, please send requests to either the shunit2-users@forestent.com mailing
|
||||||
|
list (archives available on the web at
|
||||||
|
https://groups.google.com/a/forestent.com/forum/#!forum/shunit2-users) or
|
||||||
|
directly to Kate Ward <kate dot ward at forestent dot com>.
|
||||||
|
|
||||||
### <a name="zsh"></a> Zsh
|
### <a name="zsh"></a> Zsh
|
||||||
|
|
||||||
For compatibility with Zsh, there is one requirement that must be met -- the `shwordsplit` option must be set. There are three ways to accomplish this.
|
For compatibility with Zsh, there is one requirement that must be met -- the
|
||||||
|
`shwordsplit` option must be set. There are three ways to accomplish this.
|
||||||
|
|
||||||
1. In the unit-test script, add the following shell code snippet before sourcing the `shunit2` library.
|
1. In the unit-test script, add the following shell code snippet before sourcing
|
||||||
|
the `shunit2` library.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
setopt shwordsplit
|
setopt shwordsplit
|
||||||
```
|
```
|
||||||
|
|
||||||
1. When invoking __zsh__ from either the command-line or as a script with `#!`, add the `-y` parameter.
|
2. When invoking __zsh__ from either the command-line or as a script with `#!`,
|
||||||
|
add the `-y` parameter.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
#! /bin/zsh -y
|
#! /bin/zsh -y
|
||||||
```
|
```
|
||||||
|
|
||||||
1. When invoking __zsh__ from the command-line, add `-o shwordsplit --` as parameters before the script name.
|
3. When invoking __zsh__ from the command-line, add `-o shwordsplit --` as
|
||||||
|
parameters before the script name.
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ zsh -o shwordsplit -- some_script
|
$ zsh -o shwordsplit -- some_script
|
||||||
```
|
```
|
||||||
|
|
||||||
[log4sh]: https://github.com/kward/log4sh
|
[log4sh]: https://github.com/kward/log4sh
|
||||||
[shflags]: https://github.com/kward/shflags
|
[shflags]: https://github.com/kward/shflags
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
#! /bin/sh
|
||||||
|
#
|
||||||
|
# Initialize the local git hooks this repository.
|
||||||
|
# https://git-scm.com/docs/githooks
|
||||||
|
|
||||||
|
topLevel=$(git rev-parse --show-toplevel)
|
||||||
|
if ! cd "${topLevel}"; then
|
||||||
|
echo "filed to cd into topLevel directory '${topLevel}'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
hooksDir="${topLevel}/.githooks"
|
||||||
|
if ! hooksPath=$(git config core.hooksPath); then
|
||||||
|
hooksPath="${topLevel}/.git/hooks"
|
||||||
|
fi
|
||||||
|
|
||||||
|
src="${hooksDir}/generic"
|
||||||
|
echo "linking hooks..."
|
||||||
|
for hook in \
|
||||||
|
applypatch-msg \
|
||||||
|
pre-applypatch \
|
||||||
|
post-applypatch \
|
||||||
|
pre-commit \
|
||||||
|
pre-merge-commit \
|
||||||
|
prepare-commit-msg \
|
||||||
|
commit-msg \
|
||||||
|
post-commit \
|
||||||
|
pre-rebase \
|
||||||
|
post-checkout \
|
||||||
|
post-merge \
|
||||||
|
pre-push \
|
||||||
|
pre-receive \
|
||||||
|
update \
|
||||||
|
post-receive \
|
||||||
|
post-update \
|
||||||
|
push-to-checkout \
|
||||||
|
pre-auto-gc \
|
||||||
|
post-rewrite \
|
||||||
|
sendemail-validate \
|
||||||
|
fsmonitor-watchman \
|
||||||
|
p4-pre-submit \
|
||||||
|
post-index-change
|
||||||
|
do
|
||||||
|
echo " ${hook}"
|
||||||
|
dest="${hooksPath}/${hook}"
|
||||||
|
ln -sf "${src}" "${dest}"
|
||||||
|
done
|
|
@ -3,7 +3,7 @@
|
||||||
#
|
#
|
||||||
# Versions determines the versions of all installed shells.
|
# Versions determines the versions of all installed shells.
|
||||||
#
|
#
|
||||||
# Copyright 2008-2018 Kate Ward. All Rights Reserved.
|
# Copyright 2008-2020 Kate Ward. All Rights Reserved.
|
||||||
# Released under the Apache 2.0 License.
|
# Released under the Apache 2.0 License.
|
||||||
#
|
#
|
||||||
# Author: kate.ward@forestent.com (Kate Ward)
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
ARGV0=`basename "$0"`
|
ARGV0=`basename "$0"`
|
||||||
LSB_RELEASE='/etc/lsb-release'
|
LSB_RELEASE='/etc/lsb-release'
|
||||||
VERSIONS_SHELLS='ash /bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/zsh /bin/sh /usr/xpg4/bin/sh /sbin/sh'
|
VERSIONS_SHELLS='ash /bin/bash /bin/dash /bin/ksh /bin/mksh /bin/pdksh /bin/zsh /usr/xpg4/bin/sh /bin/sh /sbin/sh'
|
||||||
|
|
||||||
true; TRUE=$?
|
true; TRUE=$?
|
||||||
false; FALSE=$?
|
false; FALSE=$?
|
||||||
|
@ -49,6 +49,10 @@ versions_osName() {
|
||||||
10.11|10.11.[0-9]*) os_name_='Mac OS X El Capitan' ;;
|
10.11|10.11.[0-9]*) os_name_='Mac OS X El Capitan' ;;
|
||||||
10.12|10.12.[0-9]*) os_name_='macOS Sierra' ;;
|
10.12|10.12.[0-9]*) os_name_='macOS Sierra' ;;
|
||||||
10.13|10.13.[0-9]*) os_name_='macOS High Sierra' ;;
|
10.13|10.13.[0-9]*) os_name_='macOS High Sierra' ;;
|
||||||
|
10.14|10.14.[0-9]*) os_name_='macOS Mojave' ;;
|
||||||
|
10.15|10.15.[0-9]*) os_name_='macOS Catalina' ;;
|
||||||
|
11.*) os_name_='macOS Big Sur' ;;
|
||||||
|
12.*) os_name_='macOS Monterey' ;;
|
||||||
*) os_name_='macOS' ;;
|
*) os_name_='macOS' ;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
|
@ -133,10 +137,11 @@ versions_shellVersion() {
|
||||||
|
|
||||||
version_=''
|
version_=''
|
||||||
case ${shell_} in
|
case ${shell_} in
|
||||||
/sbin/sh) ;; # SunOS
|
# SunOS shells.
|
||||||
/usr/xpg4/bin/sh)
|
/sbin/sh) ;;
|
||||||
version_=`versions_shell_xpg4 "${shell_}"`
|
/usr/xpg4/bin/sh) version_=`versions_shell_xpg4 "${shell_}"` ;;
|
||||||
;; # SunOS
|
|
||||||
|
# Generic shell.
|
||||||
*/sh)
|
*/sh)
|
||||||
# This could be one of any number of shells. Try until one fits.
|
# This could be one of any number of shells. Try until one fits.
|
||||||
version_=''
|
version_=''
|
||||||
|
@ -147,16 +152,22 @@ versions_shellVersion() {
|
||||||
[ -z "${version_}" ] && version_=`versions_shell_xpg4 "${shell_}"`
|
[ -z "${version_}" ] && version_=`versions_shell_xpg4 "${shell_}"`
|
||||||
[ -z "${version_}" ] && version_=`versions_shell_zsh "${shell_}"`
|
[ -z "${version_}" ] && version_=`versions_shell_zsh "${shell_}"`
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
# Specific shells.
|
||||||
ash) version_=`versions_shell_ash "${shell_}"` ;;
|
ash) version_=`versions_shell_ash "${shell_}"` ;;
|
||||||
|
# bash - Bourne Again SHell (https://www.gnu.org/software/bash/)
|
||||||
*/bash) version_=`versions_shell_bash "${shell_}"` ;;
|
*/bash) version_=`versions_shell_bash "${shell_}"` ;;
|
||||||
*/dash)
|
*/dash) version_=`versions_shell_dash` ;;
|
||||||
# Assuming Ubuntu Linux until somebody comes up with a better test. The
|
# ksh - KornShell (http://www.kornshell.com/)
|
||||||
# following test will return an empty string if dash is not installed.
|
|
||||||
version_=`versions_shell_dash`
|
|
||||||
;;
|
|
||||||
*/ksh) version_=`versions_shell_ksh "${shell_}"` ;;
|
*/ksh) version_=`versions_shell_ksh "${shell_}"` ;;
|
||||||
|
# mksh - MirBSD Korn Shell (http://www.mirbsd.org/mksh.htm)
|
||||||
|
*/mksh) version_=`versions_shell_ksh "${shell_}"` ;;
|
||||||
|
# pdksh - Public Domain Korn Shell (http://web.cs.mun.ca/~michael/pdksh/)
|
||||||
*/pdksh) version_=`versions_shell_pdksh "${shell_}"` ;;
|
*/pdksh) version_=`versions_shell_pdksh "${shell_}"` ;;
|
||||||
|
# zsh (https://www.zsh.org/)
|
||||||
*/zsh) version_=`versions_shell_zsh "${shell_}"` ;;
|
*/zsh) version_=`versions_shell_zsh "${shell_}"` ;;
|
||||||
|
|
||||||
|
# Unrecognized shell.
|
||||||
*) version_='invalid'
|
*) version_='invalid'
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
@ -173,6 +184,8 @@ versions_shell_bash() {
|
||||||
$1 --version : 2>&1 |grep 'GNU bash' |sed 's/.*version \([^ ]*\).*/\1/'
|
$1 --version : 2>&1 |grep 'GNU bash' |sed 's/.*version \([^ ]*\).*/\1/'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Assuming Ubuntu Linux until somebody comes up with a better test. The
|
||||||
|
# following test will return an empty string if dash is not installed.
|
||||||
versions_shell_dash() {
|
versions_shell_dash() {
|
||||||
eval dpkg >/dev/null 2>&1
|
eval dpkg >/dev/null 2>&1
|
||||||
[ $? -eq 127 ] && return # Return if dpkg not found.
|
[ $? -eq 127 ] && return # Return if dpkg not found.
|
||||||
|
@ -193,6 +206,10 @@ versions_shell_ksh() {
|
||||||
else
|
else
|
||||||
versions_version_=''
|
versions_version_=''
|
||||||
fi
|
fi
|
||||||
|
if [ -z "${versions_version_}" ]; then
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
versions_version_=`${versions_shell_} -c 'echo ${KSH_VERSION}'`
|
||||||
|
fi
|
||||||
if [ -z "${versions_version_}" ]; then
|
if [ -z "${versions_version_}" ]; then
|
||||||
_versions_have_strings
|
_versions_have_strings
|
||||||
versions_version_=`strings "${versions_shell_}" 2>&1 \
|
versions_version_=`strings "${versions_shell_}" 2>&1 \
|
||||||
|
@ -207,6 +224,14 @@ versions_shell_ksh() {
|
||||||
unset versions_shell_ versions_version_
|
unset versions_shell_ versions_version_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# mksh - MirBSD Korn Shell (http://www.mirbsd.org/mksh.htm)
|
||||||
|
# mksh is a successor to pdksh (Public Domain Korn Shell).
|
||||||
|
versions_shell_mksh() {
|
||||||
|
versions_shell_ksh
|
||||||
|
}
|
||||||
|
|
||||||
|
# pdksh - Public Domain Korn Shell
|
||||||
|
# pdksh is an obsolete shell, which was replaced by mksh (among others).
|
||||||
versions_shell_pdksh() {
|
versions_shell_pdksh() {
|
||||||
_versions_have_strings
|
_versions_have_strings
|
||||||
strings "$1" 2>&1 \
|
strings "$1" 2>&1 \
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,64 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# vim:et:ft=sh:sts=2:sw=2
|
||||||
|
#
|
||||||
|
# shunit2 unit test for running subset(s) of tests based upon command line args.
|
||||||
|
#
|
||||||
|
# Copyright 2008-2021 Kate Ward. All Rights Reserved.
|
||||||
|
# Released under the Apache 2.0 license.
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# https://github.com/kward/shunit2
|
||||||
|
#
|
||||||
|
# Also shows how non-default tests or a arbitrary subset of tests can be run.
|
||||||
|
#
|
||||||
|
# Disable source following.
|
||||||
|
# shellcheck disable=SC1090,SC1091
|
||||||
|
|
||||||
|
# Load test helpers.
|
||||||
|
. ./shunit2_test_helpers
|
||||||
|
|
||||||
|
CUSTOM_TEST_RAN=''
|
||||||
|
|
||||||
|
# This test does not normally run because it does not begin "test*". Will be
|
||||||
|
# run by setting the arguments to the script to include the name of this test.
|
||||||
|
custom_test() {
|
||||||
|
# Arbitrary assert.
|
||||||
|
assertTrue 0
|
||||||
|
# The true intent is to set this variable, which will be tested below.
|
||||||
|
CUSTOM_TEST_RAN='yup, we ran'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Verify that `customTest()` ran.
|
||||||
|
testCustomTestRan() {
|
||||||
|
assertNotNull "'custom_test()' did not run" "${CUSTOM_TEST_RAN}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Fail if this test runs, which is shouldn't if arguments are set correctly.
|
||||||
|
testShouldFail() {
|
||||||
|
fail 'testShouldFail should not be run if argument parsing works'
|
||||||
|
}
|
||||||
|
|
||||||
|
oneTimeSetUp() {
|
||||||
|
th_oneTimeSetUp
|
||||||
|
}
|
||||||
|
|
||||||
|
# If zero/one argument(s) are provided, this test is being run in it's
|
||||||
|
# entirety, and therefore we want to set the arguments to the script to
|
||||||
|
# (simulate and) test the processing of command-line specified tests. If we
|
||||||
|
# don't, then the "test_will_fail" test will run (by default) and the overall
|
||||||
|
# test will fail.
|
||||||
|
#
|
||||||
|
# However, if two or more arguments are provided, then assume this test script
|
||||||
|
# is being run by hand to experiment with command-line test specification, and
|
||||||
|
# then don't override the user provided arguments.
|
||||||
|
if [ "$#" -le 1 ]; then
|
||||||
|
# We set the arguments in a POSIX way, inasmuch as we can;
|
||||||
|
# helpful tip:
|
||||||
|
# https://unix.stackexchange.com/questions/258512/how-to-remove-a-positional-parameter-from
|
||||||
|
set -- '--' 'custom_test' 'testCustomTestRan'
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Load and run shunit2.
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
|
||||||
|
. "${TH_SHUNIT}"
|
|
@ -3,12 +3,16 @@
|
||||||
#
|
#
|
||||||
# shunit2 unit test for assert functions.
|
# shunit2 unit test for assert functions.
|
||||||
#
|
#
|
||||||
# Copyright 2008-2017 Kate Ward. All Rights Reserved.
|
# Copyright 2008-2021 Kate Ward. All Rights Reserved.
|
||||||
# Released under the Apache 2.0 license.
|
# Released under the Apache 2.0 license.
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Author: kate.ward@forestent.com (Kate Ward)
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
# https://github.com/kward/shunit2
|
# https://github.com/kward/shunit2
|
||||||
#
|
#
|
||||||
|
# In this file, all assert calls under test must be wrapped in () so they do not
|
||||||
|
# influence the metrics of the test itself.
|
||||||
|
#
|
||||||
# Disable source following.
|
# Disable source following.
|
||||||
# shellcheck disable=SC1090,SC1091
|
# shellcheck disable=SC1090,SC1091
|
||||||
|
|
||||||
|
@ -22,175 +26,377 @@ stderrF="${TMPDIR:-/tmp}/STDERR"
|
||||||
commonEqualsSame() {
|
commonEqualsSame() {
|
||||||
fn=$1
|
fn=$1
|
||||||
|
|
||||||
( ${fn} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
# These should succeed.
|
||||||
th_assertTrueWithNoOutput 'equal' $? "${stdoutF}" "${stderrF}"
|
|
||||||
|
|
||||||
( ${fn} "${MSG}" 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
desc='equal'
|
||||||
th_assertTrueWithNoOutput 'equal; with msg' $? "${stdoutF}" "${stderrF}"
|
if (${fn} 'x' 'x' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
|
||||||
( ${fn} 'abc def' 'abc def' >"${stdoutF}" 2>"${stderrF}" )
|
desc='equal_with_message'
|
||||||
th_assertTrueWithNoOutput 'equal with spaces' $? "${stdoutF}" "${stderrF}"
|
if (${fn} 'some message' 'x' 'x' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
|
||||||
( ${fn} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
desc='equal_with_spaces'
|
||||||
th_assertFalseWithOutput 'not equal' $? "${stdoutF}" "${stderrF}"
|
if (${fn} 'abc def' 'abc def' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
|
||||||
( ${fn} '' '' >"${stdoutF}" 2>"${stderrF}" )
|
desc='equal_null_values'
|
||||||
th_assertTrueWithNoOutput 'null values' $? "${stdoutF}" "${stderrF}"
|
if (${fn} '' '' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
|
||||||
( ${fn} arg1 >"${stdoutF}" 2>"${stderrF}" )
|
# These should fail.
|
||||||
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
|
|
||||||
|
|
||||||
( ${fn} arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" )
|
desc='not_equal'
|
||||||
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
|
if (${fn} 'x' 'y' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
fail "${desc}: expected a failure"
|
||||||
|
_showTestOutput
|
||||||
|
else
|
||||||
|
th_assertFalseWithOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
commonNotEqualsSame() {
|
commonNotEqualsSame() {
|
||||||
fn=$1
|
fn=$1
|
||||||
|
|
||||||
( ${fn} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
# These should succeed.
|
||||||
th_assertTrueWithNoOutput 'not same' $? "${stdoutF}" "${stderrF}"
|
|
||||||
|
|
||||||
( ${fn} "${MSG}" 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
desc='not_same'
|
||||||
th_assertTrueWithNoOutput 'not same, with msg' $? "${stdoutF}" "${stderrF}"
|
if (${fn} 'x' 'y' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
|
||||||
( ${fn} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
desc='not_same_with_message'
|
||||||
th_assertFalseWithOutput 'same' $? "${stdoutF}" "${stderrF}"
|
if (${fn} 'some message' 'x' 'y' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
|
||||||
( ${fn} '' '' >"${stdoutF}" 2>"${stderrF}" )
|
# These should fail.
|
||||||
th_assertFalseWithOutput 'null values' $? "${stdoutF}" "${stderrF}"
|
|
||||||
|
|
||||||
( ${fn} arg1 >"${stdoutF}" 2>"${stderrF}" )
|
desc='same'
|
||||||
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
|
if (${fn} 'x' 'x' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
fail "${desc}: expected a failure"
|
||||||
|
_showTestOutput
|
||||||
|
else
|
||||||
|
th_assertFalseWithOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
|
|
||||||
( ${fn} arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" )
|
desc='unequal_null_values'
|
||||||
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
|
if (${fn} '' '' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
fail "${desc}: expected a failure"
|
||||||
|
_showTestOutput
|
||||||
|
else
|
||||||
|
th_assertFalseWithOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testAssertEquals() {
|
testAssertEquals() { commonEqualsSame 'assertEquals'; }
|
||||||
commonEqualsSame 'assertEquals'
|
testAssertNotEquals() { commonNotEqualsSame 'assertNotEquals'; }
|
||||||
|
testAssertSame() { commonEqualsSame 'assertSame'; }
|
||||||
|
testAssertNotSame() { commonNotEqualsSame 'assertNotSame'; }
|
||||||
|
|
||||||
|
testAssertContains() {
|
||||||
|
# Content is present.
|
||||||
|
while read -r desc container content; do
|
||||||
|
if (assertContains "${container}" "${content}" >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
done <<EOF
|
||||||
|
abc_at_start abcdef abc
|
||||||
|
bcd_in_middle abcdef bcd
|
||||||
|
def_at_end abcdef def
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Content missing.
|
||||||
|
while read -r desc container content; do
|
||||||
|
if (assertContains "${container}" "${content}" >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
else
|
||||||
|
th_assertFalseWithOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
|
done <<EOF
|
||||||
|
xyz_not_present abcdef xyz
|
||||||
|
zab_contains_start abcdef zab
|
||||||
|
efg_contains_end abcdef efg
|
||||||
|
acf_has_parts abcdef acf
|
||||||
|
EOF
|
||||||
|
|
||||||
|
desc="content_starts_with_dash"
|
||||||
|
if (assertContains 'abc -Xabc def' '-Xabc' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
|
||||||
|
desc="contains_with_message"
|
||||||
|
if (assertContains 'some message' 'abcdef' 'abc' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testAssertNotEquals() {
|
testAssertNotContains() {
|
||||||
commonNotEqualsSame 'assertNotEquals'
|
# Content not present.
|
||||||
}
|
while read -r desc container content; do
|
||||||
|
if (assertNotContains "${container}" "${content}" >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
done <<EOF
|
||||||
|
xyz_not_present abcdef xyz
|
||||||
|
zab_contains_start abcdef zab
|
||||||
|
efg_contains_end abcdef efg
|
||||||
|
acf_has_parts abcdef acf
|
||||||
|
EOF
|
||||||
|
|
||||||
testAssertSame() {
|
# Content present.
|
||||||
commonEqualsSame 'assertSame'
|
while read -r desc container content; do
|
||||||
}
|
if (assertNotContains "${container}" "${content}" >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
fail "${desc}: expected a failure"
|
||||||
|
_showTestOutput
|
||||||
|
else
|
||||||
|
th_assertFalseWithOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
|
done <<EOF
|
||||||
|
abc_is_present abcdef abc
|
||||||
|
EOF
|
||||||
|
|
||||||
testAssertNotSame() {
|
desc='not_contains_with_message'
|
||||||
commonNotEqualsSame 'assertNotSame'
|
if (assertNotContains 'some message' 'abcdef' 'xyz' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testAssertNull() {
|
testAssertNull() {
|
||||||
( assertNull '' >"${stdoutF}" 2>"${stderrF}" )
|
while read -r desc value; do
|
||||||
th_assertTrueWithNoOutput 'null' $? "${stdoutF}" "${stderrF}"
|
if (assertNull "${value}" >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
else
|
||||||
|
th_assertFalseWithOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
|
done <<'EOF'
|
||||||
|
x_alone x
|
||||||
|
x_double_quote_a x"a
|
||||||
|
x_single_quote_a x'a
|
||||||
|
x_dollar_a x$a
|
||||||
|
x_backtick_a x`a
|
||||||
|
EOF
|
||||||
|
|
||||||
( assertNull "${MSG}" '' >"${stdoutF}" 2>"${stderrF}" )
|
desc='null_without_message'
|
||||||
th_assertTrueWithNoOutput 'null, with msg' $? "${stdoutF}" "${stderrF}"
|
if (assertNull '' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
|
||||||
( assertNull 'x' >"${stdoutF}" 2>"${stderrF}" )
|
desc='null_with_message'
|
||||||
th_assertFalseWithOutput 'not null' $? "${stdoutF}" "${stderrF}"
|
if (assertNull 'some message' '' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
|
||||||
( assertNull >"${stdoutF}" 2>"${stderrF}" )
|
desc='x_is_not_null'
|
||||||
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
|
if (assertNull 'x' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
fail "${desc}: expected a failure"
|
||||||
( assertNull arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" )
|
_showTestOutput
|
||||||
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
|
else
|
||||||
|
th_assertFalseWithOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testAssertNotNull()
|
testAssertNotNull() {
|
||||||
{
|
while read -r desc value; do
|
||||||
( assertNotNull 'x' >"${stdoutF}" 2>"${stderrF}" )
|
if (assertNotNull "${value}" >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
th_assertTrueWithNoOutput 'not null' $? "${stdoutF}" "${stderrF}"
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
done <<'EOF'
|
||||||
|
x_alone x
|
||||||
|
x_double_quote_b x"b
|
||||||
|
x_single_quote_b x'b
|
||||||
|
x_dollar_b x$b
|
||||||
|
x_backtick_b x`b
|
||||||
|
EOF
|
||||||
|
|
||||||
( assertNotNull "${MSG}" 'x' >"${stdoutF}" 2>"${stderrF}" )
|
desc='not_null_with_message'
|
||||||
th_assertTrueWithNoOutput 'not null, with msg' $? "${stdoutF}" "${stderrF}"
|
if (assertNotNull 'some message' 'x' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
|
||||||
( assertNotNull 'x"b' >"${stdoutF}" 2>"${stderrF}" )
|
desc="double_ticks_are_null"
|
||||||
th_assertTrueWithNoOutput 'not null, with double-quote' $? \
|
if (assertNotNull '' >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
"${stdoutF}" "${stderrF}"
|
fail "${desc}: expected a failure"
|
||||||
|
_showTestOutput
|
||||||
( assertNotNull "x'b" >"${stdoutF}" 2>"${stderrF}" )
|
else
|
||||||
th_assertTrueWithNoOutput 'not null, with single-quote' $? \
|
th_assertFalseWithOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
"${stdoutF}" "${stderrF}"
|
fi
|
||||||
|
|
||||||
# shellcheck disable=SC2016
|
|
||||||
( assertNotNull 'x$b' >"${stdoutF}" 2>"${stderrF}" )
|
|
||||||
th_assertTrueWithNoOutput 'not null, with dollar' $? \
|
|
||||||
"${stdoutF}" "${stderrF}"
|
|
||||||
|
|
||||||
( assertNotNull 'x`b' >"${stdoutF}" 2>"${stderrF}" )
|
|
||||||
th_assertTrueWithNoOutput 'not null, with backtick' $? \
|
|
||||||
"${stdoutF}" "${stderrF}"
|
|
||||||
|
|
||||||
( assertNotNull '' >"${stdoutF}" 2>"${stderrF}" )
|
|
||||||
th_assertFalseWithOutput 'null' $? "${stdoutF}" "${stderrF}"
|
|
||||||
|
|
||||||
# There is no test for too few arguments as $1 might actually be null.
|
|
||||||
|
|
||||||
( assertNotNull arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" )
|
|
||||||
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
testAssertTrue() {
|
testAssertTrue() {
|
||||||
( assertTrue 0 >"${stdoutF}" 2>"${stderrF}" )
|
# True values.
|
||||||
th_assertTrueWithNoOutput 'true' $? "${stdoutF}" "${stderrF}"
|
while read -r desc value; do
|
||||||
|
if (assertTrue "${value}" >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
done <<'EOF'
|
||||||
|
zero 0
|
||||||
|
zero_eq_zero [ 0 -eq 0 ]
|
||||||
|
EOF
|
||||||
|
|
||||||
( assertTrue "${MSG}" 0 >"${stdoutF}" 2>"${stderrF}" )
|
# Not true values.
|
||||||
th_assertTrueWithNoOutput 'true, with msg' $? "${stdoutF}" "${stderrF}"
|
while read -r desc value; do
|
||||||
|
if (assertTrue "${value}" >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
fail "${desc}: expected a failure"
|
||||||
|
_showTestOutput
|
||||||
|
else
|
||||||
|
th_assertFalseWithOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
|
done <<EOF
|
||||||
|
one 1
|
||||||
|
zero_eq_1 [ 0 -eq 1 ]
|
||||||
|
null
|
||||||
|
EOF
|
||||||
|
|
||||||
( assertTrue '[ 0 -eq 0 ]' >"${stdoutF}" 2>"${stderrF}" )
|
desc='true_with_message'
|
||||||
th_assertTrueWithNoOutput 'true condition' $? "${stdoutF}" "${stderrF}"
|
if (assertTrue 'some message' 0 >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
( assertTrue 1 >"${stdoutF}" 2>"${stderrF}" )
|
else
|
||||||
th_assertFalseWithOutput 'false' $? "${stdoutF}" "${stderrF}"
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
( assertTrue '[ 0 -eq 1 ]' >"${stdoutF}" 2>"${stderrF}" )
|
fi
|
||||||
th_assertFalseWithOutput 'false condition' $? "${stdoutF}" "${stderrF}"
|
|
||||||
|
|
||||||
( assertTrue '' >"${stdoutF}" 2>"${stderrF}" )
|
|
||||||
th_assertFalseWithOutput 'null' $? "${stdoutF}" "${stderrF}"
|
|
||||||
|
|
||||||
( assertTrue >"${stdoutF}" 2>"${stderrF}" )
|
|
||||||
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
|
|
||||||
|
|
||||||
( assertTrue arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" )
|
|
||||||
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
testAssertFalse() {
|
testAssertFalse() {
|
||||||
( assertFalse 1 >"${stdoutF}" 2>"${stderrF}" )
|
# False values.
|
||||||
th_assertTrueWithNoOutput 'false' $? "${stdoutF}" "${stderrF}"
|
while read -r desc value; do
|
||||||
|
if (assertFalse "${value}" >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
done <<EOF
|
||||||
|
one 1
|
||||||
|
zero_eq_1 [ 0 -eq 1 ]
|
||||||
|
null
|
||||||
|
EOF
|
||||||
|
|
||||||
( assertFalse "${MSG}" 1 >"${stdoutF}" 2>"${stderrF}" )
|
# Not true values.
|
||||||
th_assertTrueWithNoOutput 'false, with msg' $? "${stdoutF}" "${stderrF}"
|
while read -r desc value; do
|
||||||
|
if (assertFalse "${value}" >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
fail "${desc}: expected a failure"
|
||||||
|
_showTestOutput
|
||||||
|
else
|
||||||
|
th_assertFalseWithOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
|
done <<'EOF'
|
||||||
|
zero 0
|
||||||
|
zero_eq_zero [ 0 -eq 0 ]
|
||||||
|
EOF
|
||||||
|
|
||||||
( assertFalse '[ 0 -eq 1 ]' >"${stdoutF}" 2>"${stderrF}" )
|
desc='false_with_message'
|
||||||
th_assertTrueWithNoOutput 'false condition' $? "${stdoutF}" "${stderrF}"
|
if (assertFalse 'some message' 1 >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
th_assertTrueWithNoOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
else
|
||||||
|
fail "${desc}: unexpected failure"
|
||||||
|
_showTestOutput
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
( assertFalse 0 >"${stdoutF}" 2>"${stderrF}" )
|
FUNCTIONS='
|
||||||
th_assertFalseWithOutput 'true' $? "${stdoutF}" "${stderrF}"
|
assertEquals assertNotEquals
|
||||||
|
assertSame assertNotSame
|
||||||
|
assertContains assertNotContains
|
||||||
|
assertNull assertNotNull
|
||||||
|
assertTrue assertFalse
|
||||||
|
'
|
||||||
|
|
||||||
( assertFalse '[ 0 -eq 0 ]' >"${stdoutF}" 2>"${stderrF}" )
|
testTooFewArguments() {
|
||||||
th_assertFalseWithOutput 'true condition' $? "${stdoutF}" "${stderrF}"
|
for fn in ${FUNCTIONS}; do
|
||||||
|
# These functions support zero arguments.
|
||||||
|
case "${fn}" in
|
||||||
|
assertNull) continue ;;
|
||||||
|
assertNotNull) continue ;;
|
||||||
|
esac
|
||||||
|
|
||||||
( assertFalse '' >"${stdoutF}" 2>"${stderrF}" )
|
desc="${fn}"
|
||||||
th_assertFalseWithOutput 'true condition' $? "${stdoutF}" "${stderrF}"
|
if (${fn} >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
fail "${desc}: expected a failure"
|
||||||
|
_showTestOutput
|
||||||
|
else
|
||||||
|
got=$? want=${SHUNIT_ERROR}
|
||||||
|
assertEquals "${desc}: incorrect return code" "${got}" "${want}"
|
||||||
|
th_assertFalseWithError "${desc}" "${got}" "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
( assertFalse >"${stdoutF}" 2>"${stderrF}" )
|
testTooManyArguments() {
|
||||||
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
|
for fn in ${FUNCTIONS}; do
|
||||||
|
desc="${fn}"
|
||||||
( assertFalse arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" )
|
if (${fn} arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
|
fail "${desc}: expected a failure"
|
||||||
|
_showTestOutput
|
||||||
|
else
|
||||||
|
got=$? want=${SHUNIT_ERROR}
|
||||||
|
assertEquals "${desc}: incorrect return code" "${got}" "${want}"
|
||||||
|
th_assertFalseWithError "${desc}" "${got}" "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
oneTimeSetUp() {
|
oneTimeSetUp() {
|
||||||
th_oneTimeSetUp
|
th_oneTimeSetUp
|
||||||
|
|
||||||
MSG='This is a test message'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# showTestOutput for the most recently run test.
|
||||||
|
_showTestOutput() { th_showOutput "${SHUNIT_FALSE}" "${stdoutF}" "${stderrF}"; }
|
||||||
|
|
||||||
# Load and run shunit2.
|
# Load and run shunit2.
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
|
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# vim:et:ft=sh:sts=2:sw=2
|
# vim:et:ft=sh:sts=2:sw=2
|
||||||
#
|
#
|
||||||
# shUnit2 unit test for failure functions
|
# shUnit2 unit test for failure functions. These functions do not test values.
|
||||||
#
|
#
|
||||||
# Copyright 2008-2017 Kate Ward. All Rights Reserved.
|
# Copyright 2008-2021 Kate Ward. All Rights Reserved.
|
||||||
# Released under the LGPL (GNU Lesser General Public License)
|
# Released under the Apache 2.0 license.
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Author: kate.ward@forestent.com (Kate Ward)
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
# https://github.com/kward/shunit2
|
# https://github.com/kward/shunit2
|
||||||
|
@ -20,60 +21,114 @@ stderrF="${TMPDIR:-/tmp}/STDERR"
|
||||||
. ./shunit2_test_helpers
|
. ./shunit2_test_helpers
|
||||||
|
|
||||||
testFail() {
|
testFail() {
|
||||||
( fail >"${stdoutF}" 2>"${stderrF}" )
|
# Test without a message.
|
||||||
th_assertFalseWithOutput 'fail' $? "${stdoutF}" "${stderrF}"
|
desc='fail_without_message'
|
||||||
|
if ( fail >"${stdoutF}" 2>"${stderrF}" ); then
|
||||||
|
fail "${desc}: expected a failure"
|
||||||
|
th_showOutput
|
||||||
|
else
|
||||||
|
th_assertFalseWithOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
|
|
||||||
( fail "${MSG}" >"${stdoutF}" 2>"${stderrF}" )
|
# Test with a message.
|
||||||
th_assertFalseWithOutput 'fail with msg' $? "${stdoutF}" "${stderrF}"
|
desc='fail_with_message'
|
||||||
|
if ( fail 'some message' >"${stdoutF}" 2>"${stderrF}" ); then
|
||||||
( fail arg1 >"${stdoutF}" 2>"${stderrF}" )
|
fail "${desc}: expected a failure"
|
||||||
th_assertFalseWithOutput 'too many arguments' $? "${stdoutF}" "${stderrF}"
|
th_showOutput
|
||||||
|
else
|
||||||
|
th_assertFalseWithOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testFailNotEquals() {
|
# FN_TESTS hold all the functions to be tested.
|
||||||
( failNotEquals 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
# shellcheck disable=SC2006
|
||||||
th_assertFalseWithOutput 'same' $? "${stdoutF}" "${stderrF}"
|
FN_TESTS=`
|
||||||
|
# fn num_args pattern
|
||||||
|
cat <<EOF
|
||||||
|
fail 1
|
||||||
|
failNotEquals 3 but was:
|
||||||
|
failFound 2 found:
|
||||||
|
failNotFound 2 not found:
|
||||||
|
failSame 3 not same
|
||||||
|
failNotSame 3 but was:
|
||||||
|
EOF
|
||||||
|
`
|
||||||
|
|
||||||
( failNotEquals "${MSG}" 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
testFailsWithArgs() {
|
||||||
th_assertFalseWithOutput 'same with msg' $? "${stdoutF}" "${stderrF}"
|
echo "${FN_TESTS}" |\
|
||||||
|
while read -r fn num_args pattern; do
|
||||||
|
case "${fn}" in
|
||||||
|
fail) continue ;;
|
||||||
|
esac
|
||||||
|
|
||||||
( failNotEquals 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
# Test without a message.
|
||||||
th_assertFalseWithOutput 'not same' $? "${stdoutF}" "${stderrF}"
|
desc="${fn}_without_message"
|
||||||
|
if ( ${fn} arg1 arg2 >"${stdoutF}" 2>"${stderrF}" ); then
|
||||||
|
fail "${desc}: expected a failure"
|
||||||
|
th_showOutput
|
||||||
|
else
|
||||||
|
th_assertFalseWithOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
|
|
||||||
( failNotEquals '' '' >"${stdoutF}" 2>"${stderrF}" )
|
# Test with a message.
|
||||||
th_assertFalseWithOutput 'null values' $? "${stdoutF}" "${stderrF}"
|
arg1='' arg2=''
|
||||||
|
case ${num_args} in
|
||||||
|
1) ;;
|
||||||
|
2) arg1='arg1' ;;
|
||||||
|
3) arg1='arg1' arg2='arg2' ;;
|
||||||
|
esac
|
||||||
|
|
||||||
( failNotEquals >"${stdoutF}" 2>"${stderrF}" )
|
desc="${fn}_with_message"
|
||||||
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
|
if ( ${fn} 'some message' ${arg1} ${arg2} >"${stdoutF}" 2>"${stderrF}" ); then
|
||||||
|
fail "${desc}: expected a failure"
|
||||||
( failNotEquals arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" )
|
th_showOutput
|
||||||
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
|
else
|
||||||
|
th_assertFalseWithOutput "${desc}" $? "${stdoutF}" "${stderrF}"
|
||||||
|
if ! grep -- "${pattern}" "${stdoutF}" >/dev/null; then
|
||||||
|
fail "${desc}: incorrect message to STDOUT"
|
||||||
|
th_showOutput
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
testFailSame() {
|
testTooFewArguments() {
|
||||||
( failSame 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
echo "${FN_TESTS}" \
|
||||||
th_assertFalseWithOutput 'same' $? "${stdoutF}" "${stderrF}"
|
|while read -r fn num_args pattern; do
|
||||||
|
# Skip functions that support a single message argument.
|
||||||
|
if [ "${num_args}" -eq 1 ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
( failSame "${MSG}" 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
desc="${fn}"
|
||||||
th_assertFalseWithOutput 'same with msg' $? "${stdoutF}" "${stderrF}"
|
if (${fn} >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
fail "${desc}: expected a failure"
|
||||||
|
_showTestOutput
|
||||||
|
else
|
||||||
|
got=$? want=${SHUNIT_ERROR}
|
||||||
|
assertEquals "${desc}: incorrect return code" "${got}" "${want}"
|
||||||
|
th_assertFalseWithError "${desc}" "${got}" "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
( failSame 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
testTooManyArguments() {
|
||||||
th_assertFalseWithOutput 'not same' $? "${stdoutF}" "${stderrF}"
|
echo "${FN_TESTS}" \
|
||||||
|
|while read -r fn num_args pattern; do
|
||||||
( failSame '' '' >"${stdoutF}" 2>"${stderrF}" )
|
desc="${fn}"
|
||||||
th_assertFalseWithOutput 'null values' $? "${stdoutF}" "${stderrF}"
|
if (${fn} arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}"); then
|
||||||
|
fail "${desc}: expected a failure"
|
||||||
( failSame >"${stdoutF}" 2>"${stderrF}" )
|
_showTestOutput
|
||||||
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
|
else
|
||||||
|
got=$? want=${SHUNIT_ERROR}
|
||||||
( failSame arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" )
|
assertEquals "${desc}: incorrect return code" "${got}" "${want}"
|
||||||
th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
|
th_assertFalseWithError "${desc}" "${got}" "${stdoutF}" "${stderrF}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
oneTimeSetUp() {
|
oneTimeSetUp() {
|
||||||
th_oneTimeSetUp
|
th_oneTimeSetUp
|
||||||
|
|
||||||
MSG='This is a test message'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Load and run shUnit2.
|
# Load and run shUnit2.
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
#! /bin/sh
|
||||||
|
# vim:et:ft=sh:sts=2:sw=2
|
||||||
|
#
|
||||||
|
# shUnit2 unit tests for general commands.
|
||||||
|
#
|
||||||
|
# Copyright 2008-2021 Kate Ward. All Rights Reserved.
|
||||||
|
# Released under the Apache 2.0 license.
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
|
# https://github.com/kward/shunit2
|
||||||
|
#
|
||||||
|
# Disable source following.
|
||||||
|
# shellcheck disable=SC1090,SC1091
|
||||||
|
|
||||||
|
# These variables will be overridden by the test helpers.
|
||||||
|
stdoutF="${TMPDIR:-/tmp}/STDOUT"
|
||||||
|
stderrF="${TMPDIR:-/tmp}/STDERR"
|
||||||
|
|
||||||
|
# Load test helpers.
|
||||||
|
. ./shunit2_test_helpers
|
||||||
|
|
||||||
|
testSkipping() {
|
||||||
|
# We shouldn't be skipping to start.
|
||||||
|
if isSkipping; then
|
||||||
|
th_error 'skipping *should not be* enabled'
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
startSkipping
|
||||||
|
was_skipping_started=${SHUNIT_FALSE}
|
||||||
|
if isSkipping; then was_skipping_started=${SHUNIT_TRUE}; fi
|
||||||
|
|
||||||
|
endSkipping
|
||||||
|
was_skipping_ended=${SHUNIT_FALSE}
|
||||||
|
if isSkipping; then was_skipping_ended=${SHUNIT_TRUE}; fi
|
||||||
|
|
||||||
|
assertEquals "skipping wasn't started" "${was_skipping_started}" "${SHUNIT_TRUE}"
|
||||||
|
assertNotEquals "skipping wasn't ended" "${was_skipping_ended}" "${SHUNIT_TRUE}"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
testStartSkippingWithMessage() {
|
||||||
|
unittestF="${SHUNIT_TMPDIR}/unittest"
|
||||||
|
sed 's/^#//' >"${unittestF}" <<\EOF
|
||||||
|
## Start skipping with a message.
|
||||||
|
#testSkipping() {
|
||||||
|
# startSkipping 'SKIP-a-Dee-Doo-Dah'
|
||||||
|
#}
|
||||||
|
#SHUNIT_COLOR='none'
|
||||||
|
#. ${TH_SHUNIT}
|
||||||
|
EOF
|
||||||
|
# Ignoring errors with `|| :` as we only care about `FAILED` in the output.
|
||||||
|
( exec "${SHELL:-sh}" "${unittestF}" >"${stdoutF}" 2>"${stderrF}" ) || :
|
||||||
|
if ! grep '\[skipping\] SKIP-a-Dee-Doo-Dah' "${stderrF}" >/dev/null; then
|
||||||
|
fail 'skipping message was not generated'
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
testStartSkippingWithoutMessage() {
|
||||||
|
unittestF="${SHUNIT_TMPDIR}/unittest"
|
||||||
|
sed 's/^#//' >"${unittestF}" <<\EOF
|
||||||
|
## Start skipping with a message.
|
||||||
|
#testSkipping() {
|
||||||
|
# startSkipping
|
||||||
|
#}
|
||||||
|
#SHUNIT_COLOR='none'
|
||||||
|
#. ${TH_SHUNIT}
|
||||||
|
EOF
|
||||||
|
# Ignoring errors with `|| :` as we only care about `FAILED` in the output.
|
||||||
|
( exec "${SHELL:-sh}" "${unittestF}" >"${stdoutF}" 2>"${stderrF}" ) || :
|
||||||
|
if grep '\[skipping\]' "${stderrF}" >/dev/null; then
|
||||||
|
fail 'skipping message was unexpectedly generated'
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
setUp() {
|
||||||
|
for f in "${stdoutF}" "${stderrF}"; do
|
||||||
|
cp /dev/null "${f}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Reconfigure coloring as some tests override default behavior.
|
||||||
|
_shunit_configureColor "${SHUNIT_COLOR_DEFAULT}"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034,SC2153
|
||||||
|
SHUNIT_CMD_TPUT=${__SHUNIT_CMD_TPUT}
|
||||||
|
}
|
||||||
|
|
||||||
|
oneTimeSetUp() {
|
||||||
|
SHUNIT_COLOR_DEFAULT="${SHUNIT_COLOR}"
|
||||||
|
th_oneTimeSetUp
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load and run shUnit2.
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
|
||||||
|
. "${TH_SHUNIT}"
|
|
@ -3,17 +3,15 @@
|
||||||
#
|
#
|
||||||
# shunit2 unit test for macros.
|
# shunit2 unit test for macros.
|
||||||
#
|
#
|
||||||
# Copyright 2008-2017 Kate Ward. All Rights Reserved.
|
# Copyright 2008-2021 Kate Ward. All Rights Reserved.
|
||||||
# Released under the Apache 2.0 license.
|
# Released under the Apache 2.0 license.
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Author: kate.ward@forestent.com (Kate Ward)
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
# https://github.com/kward/shunit2
|
# https://github.com/kward/shunit2
|
||||||
#
|
#
|
||||||
### ShellCheck http://www.shellcheck.net/
|
|
||||||
# Disable source following.
|
# Disable source following.
|
||||||
# shellcheck disable=SC1090,SC1091
|
# shellcheck disable=SC1090,SC1091
|
||||||
# Presence of LINENO variable is checked.
|
|
||||||
# shellcheck disable=SC2039
|
|
||||||
|
|
||||||
# These variables will be overridden by the test helpers.
|
# These variables will be overridden by the test helpers.
|
||||||
stdoutF="${TMPDIR:-/tmp}/STDOUT"
|
stdoutF="${TMPDIR:-/tmp}/STDOUT"
|
||||||
|
@ -23,215 +21,223 @@ stderrF="${TMPDIR:-/tmp}/STDERR"
|
||||||
. ./shunit2_test_helpers
|
. ./shunit2_test_helpers
|
||||||
|
|
||||||
testAssertEquals() {
|
testAssertEquals() {
|
||||||
# Start skipping if LINENO not available.
|
isLinenoWorking || startSkipping
|
||||||
[ -z "${LINENO:-}" ] && startSkipping
|
|
||||||
|
|
||||||
( ${_ASSERT_EQUALS_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_EQUALS_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_EQUALS_ failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_EQUALS_ failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
|
|
||||||
( ${_ASSERT_EQUALS_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_EQUALS_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_EQUALS_ (with a message) failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_EQUALS_ w/ msg failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testAssertNotEquals() {
|
testAssertNotEquals() {
|
||||||
# Start skipping if LINENO not available.
|
isLinenoWorking || startSkipping
|
||||||
[ -z "${LINENO:-}" ] && startSkipping
|
|
||||||
|
|
||||||
( ${_ASSERT_NOT_EQUALS_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_NOT_EQUALS_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_NOT_EQUALS_ failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_NOT_EQUALS_ failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
|
|
||||||
( ${_ASSERT_NOT_EQUALS_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_NOT_EQUALS_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_NOT_EQUALS_ (with a message) failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_NOT_EQUALS_ w/ msg failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testSame() {
|
testSame() {
|
||||||
# Start skipping if LINENO not available.
|
isLinenoWorking || startSkipping
|
||||||
[ -z "${LINENO:-}" ] && startSkipping
|
|
||||||
|
|
||||||
( ${_ASSERT_SAME_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_SAME_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_SAME_ failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_SAME_ failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
|
|
||||||
( ${_ASSERT_SAME_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_SAME_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_SAME_ (with a message) failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_SAME_ w/ msg failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testNotSame() {
|
testNotSame() {
|
||||||
# Start skipping if LINENO not available.
|
isLinenoWorking || startSkipping
|
||||||
[ -z "${LINENO:-}" ] && startSkipping
|
|
||||||
|
|
||||||
( ${_ASSERT_NOT_SAME_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_NOT_SAME_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_NOT_SAME_ failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_NOT_SAME_ failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
|
|
||||||
( ${_ASSERT_NOT_SAME_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_NOT_SAME_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_NOT_SAME_ (with a message) failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_NOT_SAME_ w/ msg failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testNull() {
|
testNull() {
|
||||||
# Start skipping if LINENO not available.
|
isLinenoWorking || startSkipping
|
||||||
[ -z "${LINENO:-}" ] && startSkipping
|
|
||||||
|
|
||||||
( ${_ASSERT_NULL_} 'x' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_NULL_} 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_NULL_ failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_NULL_ failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
|
|
||||||
( ${_ASSERT_NULL_} '"some msg"' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_NULL_} '"some msg"' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_NULL_ (with a message) failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_NULL_ w/ msg failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testNotNull()
|
testNotNull() {
|
||||||
{
|
isLinenoWorking || startSkipping
|
||||||
# start skipping if LINENO not available
|
|
||||||
[ -z "${LINENO:-}" ] && startSkipping
|
|
||||||
|
|
||||||
( ${_ASSERT_NOT_NULL_} '' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_NOT_NULL_} '' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_NOT_NULL_ failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_NOT_NULL_ failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
|
|
||||||
( ${_ASSERT_NOT_NULL_} '"some msg"' '""' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_NOT_NULL_} '"some msg"' '""' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_NOT_NULL_ (with a message) failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_NOT_NULL_ w/ msg failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stdoutF}" "${stderrF}" >&2
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testAssertTrue() {
|
testAssertTrue() {
|
||||||
# Start skipping if LINENO not available.
|
isLinenoWorking || startSkipping
|
||||||
[ -z "${LINENO:-}" ] && startSkipping
|
|
||||||
|
|
||||||
( ${_ASSERT_TRUE_} "${SHUNIT_FALSE}" >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_TRUE_} "${SHUNIT_FALSE}" >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_TRUE_ failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_TRUE_ failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
|
|
||||||
( ${_ASSERT_TRUE_} '"some msg"' "${SHUNIT_FALSE}" >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_TRUE_} '"some msg"' "${SHUNIT_FALSE}" >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_TRUE_ (with a message) failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_TRUE_ w/ msg failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testAssertFalse() {
|
testAssertFalse() {
|
||||||
# Start skipping if LINENO not available.
|
isLinenoWorking || startSkipping
|
||||||
[ -z "${LINENO:-}" ] && startSkipping
|
|
||||||
|
|
||||||
( ${_ASSERT_FALSE_} "${SHUNIT_TRUE}" >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_FALSE_} "${SHUNIT_TRUE}" >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_FALSE_ failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_FALSE_ failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
|
|
||||||
( ${_ASSERT_FALSE_} '"some msg"' "${SHUNIT_TRUE}" >"${stdoutF}" 2>"${stderrF}" )
|
( ${_ASSERT_FALSE_} '"some msg"' "${SHUNIT_TRUE}" >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_ASSERT_FALSE_ (with a message) failed to produce an ASSERT message'
|
||||||
assertTrue '_ASSERT_FALSE_ w/ msg failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testFail() {
|
testFail() {
|
||||||
# Start skipping if LINENO not available.
|
isLinenoWorking || startSkipping
|
||||||
[ -z "${LINENO:-}" ] && startSkipping
|
|
||||||
|
|
||||||
( ${_FAIL_} >"${stdoutF}" 2>"${stderrF}" )
|
( ${_FAIL_} >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_FAIL_ failed to produce an ASSERT message'
|
||||||
assertTrue '_FAIL_ failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
|
|
||||||
( ${_FAIL_} '"some msg"' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_FAIL_} '"some msg"' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_FAIL_ (with a message) failed to produce an ASSERT message'
|
||||||
assertTrue '_FAIL_ w/ msg failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testFailNotEquals()
|
testFailNotEquals() {
|
||||||
{
|
isLinenoWorking || startSkipping
|
||||||
# start skipping if LINENO not available
|
|
||||||
[ -z "${LINENO:-}" ] && startSkipping
|
|
||||||
|
|
||||||
( ${_FAIL_NOT_EQUALS_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_FAIL_NOT_EQUALS_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_FAIL_NOT_EQUALS_ failed to produce an ASSERT message'
|
||||||
assertTrue '_FAIL_NOT_EQUALS_ failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
|
|
||||||
( ${_FAIL_NOT_EQUALS_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_FAIL_NOT_EQUALS_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_FAIL_NOT_EQUALS_ (with a message) failed to produce an ASSERT message'
|
||||||
assertTrue '_FAIL_NOT_EQUALS_ w/ msg failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testFailSame() {
|
testFailSame() {
|
||||||
# Start skipping if LINENO not available.
|
isLinenoWorking || startSkipping
|
||||||
[ -z "${LINENO:-}" ] && startSkipping
|
|
||||||
|
|
||||||
( ${_FAIL_SAME_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_FAIL_SAME_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_FAIL_SAME_ failed to produce an ASSERT message'
|
||||||
assertTrue '_FAIL_SAME_ failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
|
|
||||||
( ${_FAIL_SAME_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_FAIL_SAME_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_FAIL_SAME_ (with a message) failed to produce an ASSERT message'
|
||||||
assertTrue '_FAIL_SAME_ w/ msg failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
testFailNotSame() {
|
testFailNotSame() {
|
||||||
# Start skipping if LINENO not available.
|
isLinenoWorking || startSkipping
|
||||||
[ -z "${LINENO:-}" ] && startSkipping
|
|
||||||
|
|
||||||
( ${_FAIL_NOT_SAME_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_FAIL_NOT_SAME_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_FAIL_NOT_SAME_ failed to produce an ASSERT message'
|
||||||
assertTrue '_FAIL_NOT_SAME_ failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
|
|
||||||
( ${_FAIL_NOT_SAME_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
( ${_FAIL_NOT_SAME_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
|
if ! wasAssertGenerated; then
|
||||||
rtrn=$?
|
fail '_FAIL_NOT_SAME_ (with a message) failed to produce an ASSERT message'
|
||||||
assertTrue '_FAIL_NOT_SAME_ w/ msg failure' ${rtrn}
|
showTestOutput
|
||||||
[ "${rtrn}" -ne "${SHUNIT_TRUE}" ] && cat "${stderrF}" >&2
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
oneTimeSetUp() {
|
oneTimeSetUp() {
|
||||||
th_oneTimeSetUp
|
th_oneTimeSetUp
|
||||||
|
|
||||||
|
if ! isLinenoWorking; then
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
th_warn '${LINENO} is not working for this shell. Tests will be skipped.'
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# isLinenoWorking returns true if the `$LINENO` shell variable works properly.
|
||||||
|
isLinenoWorking() {
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
ln='eval echo "${LINENO:-}"'
|
||||||
|
case ${ln} in
|
||||||
|
[0-9]*) return "${SHUNIT_TRUE}" ;;
|
||||||
|
-[0-9]*) return "${SHUNIT_FALSE}" ;; # The dash shell produces negative values.
|
||||||
|
esac
|
||||||
|
return "${SHUNIT_FALSE}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# showTestOutput for the most recently run test.
|
||||||
|
showTestOutput() { th_showOutput "${SHUNIT_FALSE}" "${stdoutF}" "${stderrF}"; }
|
||||||
|
|
||||||
|
# wasAssertGenerated returns true if an ASSERT was generated to STDOUT.
|
||||||
|
wasAssertGenerated() { grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null; }
|
||||||
|
|
||||||
# Disable output coloring as it breaks the tests.
|
# Disable output coloring as it breaks the tests.
|
||||||
SHUNIT_COLOR='none'; export SHUNIT_COLOR
|
SHUNIT_COLOR='none'; export SHUNIT_COLOR
|
||||||
|
|
||||||
|
|
|
@ -3,19 +3,17 @@
|
||||||
#
|
#
|
||||||
# shUnit2 unit tests of miscellaneous things
|
# shUnit2 unit tests of miscellaneous things
|
||||||
#
|
#
|
||||||
# Copyright 2008-2018 Kate Ward. All Rights Reserved.
|
# Copyright 2008-2021 Kate Ward. All Rights Reserved.
|
||||||
# Released under the Apache 2.0 license.
|
# Released under the Apache 2.0 license.
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Author: kate.ward@forestent.com (Kate Ward)
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
# https://github.com/kward/shunit2
|
# https://github.com/kward/shunit2
|
||||||
#
|
#
|
||||||
### ShellCheck http://www.shellcheck.net/
|
# Allow usage of legacy backticked `...` notation instead of $(...).
|
||||||
# $() are not fully portable (POSIX != portable).
|
|
||||||
# shellcheck disable=SC2006
|
# shellcheck disable=SC2006
|
||||||
# Disable source following.
|
# Disable source following.
|
||||||
# shellcheck disable=SC1090,SC1091
|
# shellcheck disable=SC1090,SC1091
|
||||||
# Not wanting to escape single quotes.
|
|
||||||
# shellcheck disable=SC1003
|
|
||||||
|
|
||||||
# These variables will be overridden by the test helpers.
|
# These variables will be overridden by the test helpers.
|
||||||
stdoutF="${TMPDIR:-/tmp}/STDOUT"
|
stdoutF="${TMPDIR:-/tmp}/STDOUT"
|
||||||
|
@ -41,14 +39,18 @@ testUnboundVariable() {
|
||||||
#SHUNIT_COLOR='none'
|
#SHUNIT_COLOR='none'
|
||||||
#. ${TH_SHUNIT}
|
#. ${TH_SHUNIT}
|
||||||
EOF
|
EOF
|
||||||
( exec "${SHUNIT_SHELL:-sh}" "${unittestF}" >"${stdoutF}" 2>"${stderrF}" )
|
if ( exec "${SHELL:-sh}" "${unittestF}" >"${stdoutF}" 2>"${stderrF}" ); then
|
||||||
assertFalse 'expected a non-zero exit value' $?
|
fail 'expected a non-zero exit value'
|
||||||
grep '^ASSERT:Unknown failure' "${stdoutF}" >/dev/null
|
fi
|
||||||
assertTrue 'assert message was not generated' $?
|
if ! grep '^ASSERT:unknown failure' "${stdoutF}" >/dev/null; then
|
||||||
grep '^Ran [0-9]* test' "${stdoutF}" >/dev/null
|
fail 'assert message was not generated'
|
||||||
assertTrue 'test count message was not generated' $?
|
fi
|
||||||
grep '^FAILED' "${stdoutF}" >/dev/null
|
if ! grep '^Ran [0-9]* test' "${stdoutF}" >/dev/null; then
|
||||||
assertTrue 'failure message was not generated' $?
|
fail 'test count message was not generated'
|
||||||
|
fi
|
||||||
|
if ! grep '^FAILED' "${stdoutF}" >/dev/null; then
|
||||||
|
fail 'failure message was not generated'
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# assertEquals repeats message argument.
|
# assertEquals repeats message argument.
|
||||||
|
@ -57,7 +59,8 @@ testIssue7() {
|
||||||
# Disable coloring so 'ASSERT:' lines can be matched correctly.
|
# Disable coloring so 'ASSERT:' lines can be matched correctly.
|
||||||
_shunit_configureColor 'none'
|
_shunit_configureColor 'none'
|
||||||
|
|
||||||
( assertEquals 'Some message.' 1 2 >"${stdoutF}" 2>"${stderrF}" )
|
# Ignoring errors with `|| :` as we only care about the message in this test.
|
||||||
|
( assertEquals 'Some message.' 1 2 >"${stdoutF}" 2>"${stderrF}" ) || :
|
||||||
diff "${stdoutF}" - >/dev/null <<EOF
|
diff "${stdoutF}" - >/dev/null <<EOF
|
||||||
ASSERT:Some message. expected:<1> but was:<2>
|
ASSERT:Some message. expected:<1> but was:<2>
|
||||||
EOF
|
EOF
|
||||||
|
@ -77,19 +80,37 @@ testIssue29() {
|
||||||
#SHUNIT_TEST_PREFIX='--- '
|
#SHUNIT_TEST_PREFIX='--- '
|
||||||
#. ${TH_SHUNIT}
|
#. ${TH_SHUNIT}
|
||||||
EOF
|
EOF
|
||||||
( exec "${SHUNIT_SHELL:-sh}" "${unittestF}" >"${stdoutF}" 2>"${stderrF}" )
|
( exec "${SHELL:-sh}" "${unittestF}" >"${stdoutF}" 2>"${stderrF}" )
|
||||||
grep '^--- test_assert' "${stdoutF}" >/dev/null
|
grep '^--- test_assert' "${stdoutF}" >/dev/null
|
||||||
rtrn=$?
|
rtrn=$?
|
||||||
assertEquals "${SHUNIT_TRUE}" "${rtrn}"
|
assertEquals "${SHUNIT_TRUE}" "${rtrn}"
|
||||||
[ "${rtrn}" -eq "${SHUNIT_TRUE}" ] || cat "${stdoutF}" >&2
|
[ "${rtrn}" -eq "${SHUNIT_TRUE}" ] || cat "${stdoutF}" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Test that certain external commands sometimes "stubbed" by users are escaped.
|
||||||
|
testIssue54() {
|
||||||
|
for c in mkdir rm cat chmod sed; do
|
||||||
|
if grep "^[^#]*${c} " "${TH_SHUNIT}" | grep -qv "command ${c}"; then
|
||||||
|
fail "external call to ${c} not protected somewhere"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# shellcheck disable=2016
|
||||||
|
if grep '^[^#]*[^ ] *\[' "${TH_SHUNIT}" | grep -qv '${__SHUNIT_BUILTIN} \['; then
|
||||||
|
fail 'call to [ not protected somewhere'
|
||||||
|
fi
|
||||||
|
# shellcheck disable=2016
|
||||||
|
if grep '^[^#]* *\.' "${TH_SHUNIT}" | grep -qv '${__SHUNIT_BUILTIN} \.'; then
|
||||||
|
fail 'call to . not protected somewhere'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# shUnit2 should not exit with 0 when it has syntax errors.
|
# shUnit2 should not exit with 0 when it has syntax errors.
|
||||||
# https://github.com/kward/shunit2/issues/69
|
# https://github.com/kward/shunit2/issues/69
|
||||||
testIssue69() {
|
testIssue69() {
|
||||||
unittestF="${SHUNIT_TMPDIR}/unittest"
|
unittestF="${SHUNIT_TMPDIR}/unittest"
|
||||||
|
|
||||||
for t in Equals NotEquals Null NotNull Same NotSame True False; do
|
# Note: assertNull not tested as zero arguments == null, which is valid.
|
||||||
|
for t in Equals NotEquals NotNull Same NotSame True False; do
|
||||||
assert="assert${t}"
|
assert="assert${t}"
|
||||||
sed 's/^#//' >"${unittestF}" <<EOF
|
sed 's/^#//' >"${unittestF}" <<EOF
|
||||||
## Asserts with invalid argument counts should be counted as failures.
|
## Asserts with invalid argument counts should be counted as failures.
|
||||||
|
@ -97,7 +118,8 @@ testIssue69() {
|
||||||
#SHUNIT_COLOR='none'
|
#SHUNIT_COLOR='none'
|
||||||
#. ${TH_SHUNIT}
|
#. ${TH_SHUNIT}
|
||||||
EOF
|
EOF
|
||||||
( exec "${SHUNIT_SHELL:-sh}" "${unittestF}" >"${stdoutF}" 2>"${stderrF}" )
|
# Ignoring errors with `|| :` as we only care about `FAILED` in the output.
|
||||||
|
( exec "${SHELL:-sh}" "${unittestF}" >"${stdoutF}" 2>"${stderrF}" ) || :
|
||||||
grep '^FAILED' "${stdoutF}" >/dev/null
|
grep '^FAILED' "${stdoutF}" >/dev/null
|
||||||
assertTrue "failure message for ${assert} was not generated" $?
|
assertTrue "failure message for ${assert} was not generated" $?
|
||||||
done
|
done
|
||||||
|
@ -114,7 +136,8 @@ testIssue77() {
|
||||||
#SHUNIT_COLOR='none'
|
#SHUNIT_COLOR='none'
|
||||||
#. ${TH_SHUNIT}
|
#. ${TH_SHUNIT}
|
||||||
EOF
|
EOF
|
||||||
( exec "${SHUNIT_SHELL:-sh}" "${unittestF}" >"${stdoutF}" 2>"${stderrF}" )
|
# Ignoring errors with `|| :` as we only care about `FAILED` in the output.
|
||||||
|
( exec "${SHELL:-sh}" "${unittestF}" ) >"${stdoutF}" 2>"${stderrF}" || :
|
||||||
grep '^FAILED' "${stdoutF}" >/dev/null
|
grep '^FAILED' "${stdoutF}" >/dev/null
|
||||||
assertTrue "failure of ${func}() did not end test" $?
|
assertTrue "failure of ${func}() did not end test" $?
|
||||||
done
|
done
|
||||||
|
@ -135,9 +158,24 @@ testIssue84() {
|
||||||
#SHUNIT_TEST_PREFIX='--- '
|
#SHUNIT_TEST_PREFIX='--- '
|
||||||
#. ${TH_SHUNIT}
|
#. ${TH_SHUNIT}
|
||||||
EOF
|
EOF
|
||||||
( exec "${SHUNIT_SHELL:-sh}" "${unittestF}" >"${stdoutF}" 2>"${stderrF}" )
|
# Ignoring errors with `|| :` as we only care about `FAILED` in the output.
|
||||||
grep '^FAILED' "${stdoutF}" >/dev/null
|
( exec "${SHELL:-sh}" "${unittestF}" >"${stdoutF}" 2>"${stderrF}" ) || :
|
||||||
assertTrue "failure message for ${assert} was not generated" $?
|
if ! grep '^FAILED' "${stdoutF}" >/dev/null; then
|
||||||
|
fail 'failure message was not generated'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Demonstrate that asserts are no longer executed in subshells.
|
||||||
|
# https://github.com/kward/shunit2/issues/123
|
||||||
|
#
|
||||||
|
# NOTE: this test only works if the `${BASH_SUBSHELL}` variable is present.
|
||||||
|
testIssue123() {
|
||||||
|
if [ -z "${BASH_SUBSHELL:-}" ]; then
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
startSkipping 'The ${BASH_SUBSHELL} variable is unavailable in this shell.'
|
||||||
|
fi
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
assertTrue 'not in subshell' '[[ ${BASH_SUBSHELL} -eq 0 ]]'
|
||||||
}
|
}
|
||||||
|
|
||||||
testPrepForSourcing() {
|
testPrepForSourcing() {
|
||||||
|
@ -146,55 +184,6 @@ testPrepForSourcing() {
|
||||||
assertEquals './abc' "`_shunit_prepForSourcing 'abc'`"
|
assertEquals './abc' "`_shunit_prepForSourcing 'abc'`"
|
||||||
}
|
}
|
||||||
|
|
||||||
testEscapeCharInStr() {
|
|
||||||
while read -r desc char str want; do
|
|
||||||
got=`_shunit_escapeCharInStr "${char}" "${str}"`
|
|
||||||
assertEquals "${desc}" "${want}" "${got}"
|
|
||||||
done <<'EOF'
|
|
||||||
backslash \ '' ''
|
|
||||||
backslash_pre \ \def \\def
|
|
||||||
backslash_mid \ abc\def abc\\def
|
|
||||||
backslash_post \ abc\ abc\\
|
|
||||||
quote " '' ''
|
|
||||||
quote_pre " "def \"def
|
|
||||||
quote_mid " abc"def abc\"def
|
|
||||||
quote_post " abc" abc\"
|
|
||||||
string $ '' ''
|
|
||||||
string_pre $ $def \$def
|
|
||||||
string_mid $ abc$def abc\$def
|
|
||||||
string_post $ abc$ abc\$
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# TODO(20170924:kward) fix or remove.
|
|
||||||
# actual=`_shunit_escapeCharInStr "'" ''`
|
|
||||||
# assertEquals '' "${actual}"
|
|
||||||
# assertEquals "abc\\'" `_shunit_escapeCharInStr "'" "abc'"`
|
|
||||||
# assertEquals "abc\\'def" `_shunit_escapeCharInStr "'" "abc'def"`
|
|
||||||
# assertEquals "\\'def" `_shunit_escapeCharInStr "'" "'def"`
|
|
||||||
|
|
||||||
# # Must put the backtick in a variable so the shell doesn't misinterpret it
|
|
||||||
# # while inside a backticked sequence (e.g. `echo '`'` would fail).
|
|
||||||
# backtick='`'
|
|
||||||
# actual=`_shunit_escapeCharInStr ${backtick} ''`
|
|
||||||
# assertEquals '' "${actual}"
|
|
||||||
# assertEquals '\`abc' \
|
|
||||||
# `_shunit_escapeCharInStr "${backtick}" ${backtick}'abc'`
|
|
||||||
# assertEquals 'abc\`' \
|
|
||||||
# `_shunit_escapeCharInStr "${backtick}" 'abc'${backtick}`
|
|
||||||
# assertEquals 'abc\`def' \
|
|
||||||
# `_shunit_escapeCharInStr "${backtick}" 'abc'${backtick}'def'`
|
|
||||||
}
|
|
||||||
|
|
||||||
testEscapeCharInStr_specialChars() {
|
|
||||||
# Make sure our forward slash doesn't upset sed.
|
|
||||||
assertEquals '/' "`_shunit_escapeCharInStr '\' '/'`"
|
|
||||||
|
|
||||||
# Some shells escape these differently.
|
|
||||||
# TODO(20170924:kward) fix or remove.
|
|
||||||
#assertEquals '\\a' `_shunit_escapeCharInStr '\' '\a'`
|
|
||||||
#assertEquals '\\b' `_shunit_escapeCharInStr '\' '\b'`
|
|
||||||
}
|
|
||||||
|
|
||||||
# Test the various ways of declaring functions.
|
# Test the various ways of declaring functions.
|
||||||
#
|
#
|
||||||
# Prefixing (then stripping) with comment symbol so these functions aren't
|
# Prefixing (then stripping) with comment symbol so these functions aren't
|
||||||
|
@ -223,23 +212,61 @@ testExtractTestFunctions() {
|
||||||
#func_with_test_vars() {
|
#func_with_test_vars() {
|
||||||
# testVariable=1234
|
# testVariable=1234
|
||||||
#}
|
#}
|
||||||
|
## Function with keyword but no parenthesis
|
||||||
|
#function test6 { echo '6'; }
|
||||||
|
## Function with keyword but no parenthesis, multi-line
|
||||||
|
#function test7 {
|
||||||
|
# echo '7';
|
||||||
|
#}
|
||||||
|
## Function with no parenthesis, '{' on next line
|
||||||
|
#function test8
|
||||||
|
#{
|
||||||
|
# echo '8'
|
||||||
|
#}
|
||||||
|
## Function with hyphenated name
|
||||||
|
#test-9() {
|
||||||
|
# echo '9';
|
||||||
|
#}
|
||||||
|
## Function without parenthesis or keyword
|
||||||
|
#test_foobar { echo 'hello world'; }
|
||||||
|
## Function with multiple function keywords
|
||||||
|
#function function test_test_test() { echo 'lorem'; }
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
actual=`_shunit_extractTestFunctions "${f}"`
|
actual=`_shunit_extractTestFunctions "${f}"`
|
||||||
assertEquals 'testABC test_def testG3 test4 test5' "${actual}"
|
assertEquals 'testABC test_def testG3 test4 test5 test6 test7 test8 test-9' "${actual}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test that certain external commands sometimes "stubbed" by users
|
testColors() {
|
||||||
# are escaped. See Issue #54.
|
while read -r cmd colors desc; do
|
||||||
testProtectedCommands() {
|
SHUNIT_CMD_TPUT=${cmd}
|
||||||
for c in mkdir rm cat chmod; do
|
want=${colors} got=`_shunit_colors`
|
||||||
grep "^[^#]*${c} " "${TH_SHUNIT}" | grep -qv "command ${c}"
|
assertEquals "${desc}: incorrect number of colors;" \
|
||||||
assertFalse "external call to ${c} not protected somewhere" $?
|
"${got}" "${want}"
|
||||||
done
|
done <<'EOF'
|
||||||
grep '^[^#]*[^ ] *\[' "${TH_SHUNIT}" | grep -qv 'command \['
|
missing_tput 16 missing tput command
|
||||||
assertFalse "call to [ ... ] not protected somewhere" $?
|
mock_tput 256 mock tput command
|
||||||
grep '^[^#]* *\.' "${TH_SHUNIT}" | grep -qv 'command \.'
|
EOF
|
||||||
assertFalse "call to . not protected somewhere" $?
|
}
|
||||||
|
|
||||||
|
testColorsWitoutTERM() {
|
||||||
|
SHUNIT_CMD_TPUT='mock_tput'
|
||||||
|
got=`TERM='' _shunit_colors`
|
||||||
|
want=16
|
||||||
|
assertEquals "${got}" "${want}"
|
||||||
|
}
|
||||||
|
|
||||||
|
mock_tput() {
|
||||||
|
if [ -z "${TERM}" ]; then
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
echo 'tput: No value for $TERM and no -T specified'
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
if [ "$1" = 'colors' ]; then
|
||||||
|
echo 256
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
setUp() {
|
setUp() {
|
||||||
|
@ -249,6 +276,9 @@ setUp() {
|
||||||
|
|
||||||
# Reconfigure coloring as some tests override default behavior.
|
# Reconfigure coloring as some tests override default behavior.
|
||||||
_shunit_configureColor "${SHUNIT_COLOR_DEFAULT}"
|
_shunit_configureColor "${SHUNIT_COLOR_DEFAULT}"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034,SC2153
|
||||||
|
SHUNIT_CMD_TPUT=${__SHUNIT_CMD_TPUT}
|
||||||
}
|
}
|
||||||
|
|
||||||
oneTimeSetUp() {
|
oneTimeSetUp() {
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
#! /bin/sh
|
||||||
|
# vim:et:ft=sh:sts=2:sw=2
|
||||||
|
#
|
||||||
|
# shUnit2 unit tests for `shopt` support.
|
||||||
|
#
|
||||||
|
# Copyright 2008-2021 Kate Ward. All Rights Reserved.
|
||||||
|
# Released under the Apache 2.0 license.
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
|
# https://github.com/kward/shunit2
|
||||||
|
#
|
||||||
|
# Disable source following.
|
||||||
|
# shellcheck disable=SC1090,SC1091
|
||||||
|
|
||||||
|
# Load test helpers.
|
||||||
|
. ./shunit2_test_helpers
|
||||||
|
|
||||||
|
# Call shopt from a variable so it can be mocked if it doesn't work.
|
||||||
|
SHOPT_CMD='shopt'
|
||||||
|
|
||||||
|
testNullglob() {
|
||||||
|
isShoptWorking || startSkipping
|
||||||
|
|
||||||
|
nullglob=$(${SHOPT_CMD} nullglob |cut -f2)
|
||||||
|
|
||||||
|
# Test without nullglob.
|
||||||
|
${SHOPT_CMD} -u nullglob
|
||||||
|
assertEquals 'test without nullglob' 0 0
|
||||||
|
|
||||||
|
# Test with nullglob.
|
||||||
|
${SHOPT_CMD} -s nullglob
|
||||||
|
assertEquals 'test with nullglob' 1 1
|
||||||
|
|
||||||
|
# Reset nullglob.
|
||||||
|
if [ "${nullglob}" = "on" ]; then
|
||||||
|
${SHOPT_CMD} -s nullglob
|
||||||
|
else
|
||||||
|
${SHOPT_CMD} -u nullglob
|
||||||
|
fi
|
||||||
|
|
||||||
|
unset nullglob
|
||||||
|
}
|
||||||
|
|
||||||
|
oneTimeSetUp() {
|
||||||
|
th_oneTimeSetUp
|
||||||
|
|
||||||
|
if ! isShoptWorking; then
|
||||||
|
SHOPT_CMD='mock_shopt'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# isShoptWorking returns true if the `shopt` shell command is available.
|
||||||
|
# NOTE: `shopt` is not defined as part of the POSIX standard.
|
||||||
|
isShoptWorking() {
|
||||||
|
# shellcheck disable=SC2039,SC3044
|
||||||
|
( shopt >/dev/null 2>&1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
mock_shopt() {
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
echo "nullglob off"
|
||||||
|
fi
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load and run shUnit2.
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT="$0"
|
||||||
|
. "${TH_SHUNIT}"
|
|
@ -3,8 +3,9 @@
|
||||||
#
|
#
|
||||||
# shUnit2 unit test for standalone operation.
|
# shUnit2 unit test for standalone operation.
|
||||||
#
|
#
|
||||||
# Copyright 2010-2017 Kate Ward. All Rights Reserved.
|
# Copyright 2008-2021 Kate Ward. All Rights Reserved.
|
||||||
# Released under the Apache 2.0 license.
|
# Released under the Apache 2.0 license.
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Author: kate.ward@forestent.com (Kate Ward)
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
# https://github.com/kward/shunit2
|
# https://github.com/kward/shunit2
|
||||||
|
@ -13,13 +14,10 @@
|
||||||
# the name of a unit test script, works. When run, this script determines if it
|
# the name of a unit test script, works. When run, this script determines if it
|
||||||
# is running as a standalone program, and calls main() if it is.
|
# is running as a standalone program, and calls main() if it is.
|
||||||
#
|
#
|
||||||
### ShellCheck http://www.shellcheck.net/
|
|
||||||
# $() are not fully portable (POSIX != portable).
|
|
||||||
# shellcheck disable=SC2006
|
|
||||||
# Disable source following.
|
# Disable source following.
|
||||||
# shellcheck disable=SC1090,SC1091
|
# shellcheck disable=SC1090,SC1091
|
||||||
|
|
||||||
ARGV0="`basename "$0"`"
|
ARGV0=$(basename "$0")
|
||||||
|
|
||||||
# Load test helpers.
|
# Load test helpers.
|
||||||
. ./shunit2_test_helpers
|
. ./shunit2_test_helpers
|
||||||
|
@ -32,7 +30,7 @@ main() {
|
||||||
${TH_SHUNIT} "${ARGV0}"
|
${TH_SHUNIT} "${ARGV0}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Are we running as a standalone?
|
# Run main() if are running as a standalone script.
|
||||||
if [ "${ARGV0}" = 'shunit2_test_standalone.sh' ]; then
|
if [ "${ARGV0}" = 'shunit2_standalone_test.sh' ]; then
|
||||||
if [ $# -gt 0 ]; then main "$@"; else main; fi
|
main "$@"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -2,25 +2,27 @@
|
||||||
#
|
#
|
||||||
# shUnit2 unit test common functions
|
# shUnit2 unit test common functions
|
||||||
#
|
#
|
||||||
# Copyright 2008 Kate Ward. All Rights Reserved.
|
# Copyright 2008-2021 Kate Ward. All Rights Reserved.
|
||||||
# Released under the Apache 2.0 license.
|
# Released under the Apache 2.0 license.
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Author: kate.ward@forestent.com (Kate Ward)
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
# https://github.com/kward/shunit2
|
# https://github.com/kward/shunit2
|
||||||
#
|
#
|
||||||
### ShellCheck (http://www.shellcheck.net/)
|
### ShellCheck (http://www.shellcheck.net/)
|
||||||
# Commands are purposely escaped so they can be mocked outside shUnit2.
|
|
||||||
# shellcheck disable=SC1001,SC1012
|
|
||||||
# expr may be antiquated, but it is the only solution in some cases.
|
# expr may be antiquated, but it is the only solution in some cases.
|
||||||
# shellcheck disable=SC2003
|
# shellcheck disable=SC2003
|
||||||
# $() are not fully portable (POSIX != portable).
|
# $() are not fully portable (POSIX != portable).
|
||||||
# shellcheck disable=SC2006
|
# shellcheck disable=SC2006
|
||||||
|
|
||||||
|
# Exit immediately if a simple command exits with a non-zero status.
|
||||||
|
set -e
|
||||||
|
|
||||||
# Treat unset variables as an error when performing parameter expansion.
|
# Treat unset variables as an error when performing parameter expansion.
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
# Set shwordsplit for zsh.
|
# Set shwordsplit for zsh.
|
||||||
\[ -n "${ZSH_VERSION:-}" ] && setopt shwordsplit
|
[ -n "${ZSH_VERSION:-}" ] && setopt shwordsplit
|
||||||
|
|
||||||
#
|
#
|
||||||
# Constants.
|
# Constants.
|
||||||
|
@ -33,11 +35,11 @@ TH_SHUNIT=${SHUNIT_INC:-./shunit2}; export TH_SHUNIT
|
||||||
# non-empty value to enable debug output, or TRACE to enable trace
|
# non-empty value to enable debug output, or TRACE to enable trace
|
||||||
# output.
|
# output.
|
||||||
TRACE=${TRACE:+'th_trace '}
|
TRACE=${TRACE:+'th_trace '}
|
||||||
\[ -n "${TRACE}" ] && DEBUG=1
|
[ -n "${TRACE}" ] && DEBUG=1
|
||||||
\[ -z "${TRACE}" ] && TRACE=':'
|
[ -z "${TRACE}" ] && TRACE=':'
|
||||||
|
|
||||||
DEBUG=${DEBUG:+'th_debug '}
|
DEBUG=${DEBUG:+'th_debug '}
|
||||||
\[ -z "${DEBUG}" ] && DEBUG=':'
|
[ -z "${DEBUG}" ] && DEBUG=':'
|
||||||
|
|
||||||
#
|
#
|
||||||
# Variables.
|
# Variables.
|
||||||
|
@ -50,12 +52,12 @@ th_RANDOM=0
|
||||||
#
|
#
|
||||||
|
|
||||||
# Logging functions.
|
# Logging functions.
|
||||||
th_trace() { echo "${MY_NAME}:TRACE $*" >&2; }
|
th_trace() { echo "test:TRACE $*" >&2; }
|
||||||
th_debug() { echo "${MY_NAME}:DEBUG $*" >&2; }
|
th_debug() { echo "test:DEBUG $*" >&2; }
|
||||||
th_info() { echo "${MY_NAME}:INFO $*" >&2; }
|
th_info() { echo "test:INFO $*" >&2; }
|
||||||
th_warn() { echo "${MY_NAME}:WARN $*" >&2; }
|
th_warn() { echo "test:WARN $*" >&2; }
|
||||||
th_error() { echo "${MY_NAME}:ERROR $*" >&2; }
|
th_error() { echo "test:ERROR $*" >&2; }
|
||||||
th_fatal() { echo "${MY_NAME}:FATAL $*" >&2; }
|
th_fatal() { echo "test:FATAL $*" >&2; }
|
||||||
|
|
||||||
# Output subtest name.
|
# Output subtest name.
|
||||||
th_subtest() { echo " $*" >&2; }
|
th_subtest() { echo " $*" >&2; }
|
||||||
|
@ -73,20 +75,20 @@ th_oneTimeSetUp() {
|
||||||
th_generateRandom() {
|
th_generateRandom() {
|
||||||
tfgr_random=${th_RANDOM}
|
tfgr_random=${th_RANDOM}
|
||||||
|
|
||||||
while \[ "${tfgr_random}" = "${th_RANDOM}" ]; do
|
while [ "${tfgr_random}" = "${th_RANDOM}" ]; do
|
||||||
# shellcheck disable=SC2039
|
# shellcheck disable=SC2039
|
||||||
if \[ -n "${RANDOM:-}" ]; then
|
if [ -n "${RANDOM:-}" ]; then
|
||||||
# $RANDOM works
|
# $RANDOM works
|
||||||
# shellcheck disable=SC2039
|
# shellcheck disable=SC2039
|
||||||
tfgr_random=${RANDOM}${RANDOM}${RANDOM}$$
|
tfgr_random=${RANDOM}${RANDOM}${RANDOM}$$
|
||||||
elif \[ -r '/dev/urandom' ]; then
|
elif [ -r '/dev/urandom' ]; then
|
||||||
tfgr_random=`od -vAn -N4 -tu4 </dev/urandom |sed 's/^[^0-9]*//'`
|
tfgr_random=`od -vAn -N4 -tu4 </dev/urandom |sed 's/^[^0-9]*//'`
|
||||||
else
|
else
|
||||||
tfgr_date=`date '+%H%M%S'`
|
tfgr_date=`date '+%H%M%S'`
|
||||||
tfgr_random=`expr "${tfgr_date}" \* $$`
|
tfgr_random=`expr "${tfgr_date}" \* $$`
|
||||||
unset tfgr_date
|
unset tfgr_date
|
||||||
fi
|
fi
|
||||||
\[ "${tfgr_random}" = "${th_RANDOM}" ] && sleep 1
|
[ "${tfgr_random}" = "${th_RANDOM}" ] && sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
th_RANDOM=${tfgr_random}
|
th_RANDOM=${tfgr_random}
|
||||||
|
@ -127,12 +129,13 @@ th_assertTrueWithNoOutput() {
|
||||||
th_stdout_=$3
|
th_stdout_=$3
|
||||||
th_stderr_=$4
|
th_stderr_=$4
|
||||||
|
|
||||||
assertTrue "${th_test_}; expected return value of zero" "${th_rtrn_}"
|
assertEquals "${th_test_}: expected return value of true" "${SHUNIT_TRUE}" "${th_rtrn_}"
|
||||||
\[ "${th_rtrn_}" -ne "${SHUNIT_TRUE}" ] && \cat "${th_stderr_}"
|
assertFalse "${th_test_}: expected no output to STDOUT" "[ -s '${th_stdout_}' ]"
|
||||||
assertFalse "${th_test_}; expected no output to STDOUT" \
|
assertFalse "${th_test_}: expected no output to STDERR" "[ -s '${th_stderr_}' ]"
|
||||||
"[ -s '${th_stdout_}' ]"
|
# shellcheck disable=SC2166
|
||||||
assertFalse "${th_test_}; expected no output to STDERR" \
|
if [ -s "${th_stdout_}" -o -s "${th_stderr_}" ]; then
|
||||||
"[ -s '${th_stderr_}' ]"
|
_th_showOutput "${SHUNIT_FALSE}" "${th_stdout_}" "${th_stderr_}"
|
||||||
|
fi
|
||||||
|
|
||||||
unset th_test_ th_rtrn_ th_stdout_ th_stderr_
|
unset th_test_ th_rtrn_ th_stdout_ th_stderr_
|
||||||
}
|
}
|
||||||
|
@ -152,13 +155,13 @@ th_assertFalseWithOutput()
|
||||||
th_stdout_=$3
|
th_stdout_=$3
|
||||||
th_stderr_=$4
|
th_stderr_=$4
|
||||||
|
|
||||||
assertFalse "${th_test_}; expected non-zero return value" "${th_rtrn_}"
|
assertNotEquals "${th_test_}: expected non-true return value" "${SHUNIT_TRUE}" "${th_rtrn_}"
|
||||||
assertTrue "${th_test_}; expected output to STDOUT" \
|
assertTrue "${th_test_}: expected output to STDOUT" "[ -s '${th_stdout_}' ]"
|
||||||
"[ -s '${th_stdout_}' ]"
|
assertFalse "${th_test_}: expected no output to STDERR" "[ -s '${th_stderr_}' ]"
|
||||||
assertFalse "${th_test_}; expected no output to STDERR" \
|
# shellcheck disable=SC2166
|
||||||
"[ -s '${th_stderr_}' ]"
|
if ! [ -s "${th_stdout_}" -a ! -s "${th_stderr_}" ]; then
|
||||||
\[ -s "${th_stdout_}" -a ! -s "${th_stderr_}" ] || \
|
|
||||||
_th_showOutput "${SHUNIT_FALSE}" "${th_stdout_}" "${th_stderr_}"
|
_th_showOutput "${SHUNIT_FALSE}" "${th_stdout_}" "${th_stderr_}"
|
||||||
|
fi
|
||||||
|
|
||||||
unset th_test_ th_rtrn_ th_stdout_ th_stderr_
|
unset th_test_ th_rtrn_ th_stdout_ th_stderr_
|
||||||
}
|
}
|
||||||
|
@ -177,13 +180,13 @@ th_assertFalseWithError() {
|
||||||
th_stdout_=$3
|
th_stdout_=$3
|
||||||
th_stderr_=$4
|
th_stderr_=$4
|
||||||
|
|
||||||
assertFalse "${th_test_}; expected non-zero return value" "${th_rtrn_}"
|
assertFalse "${th_test_}: expected non-zero return value" "${th_rtrn_}"
|
||||||
assertFalse "${th_test_}; expected no output to STDOUT" \
|
assertFalse "${th_test_}: expected no output to STDOUT" "[ -s '${th_stdout_}' ]"
|
||||||
"[ -s '${th_stdout_}' ]"
|
assertTrue "${th_test_}: expected output to STDERR" "[ -s '${th_stderr_}' ]"
|
||||||
assertTrue "${th_test_}; expected output to STDERR" \
|
# shellcheck disable=SC2166
|
||||||
"[ -s '${th_stderr_}' ]"
|
if ! [ ! -s "${th_stdout_}" -a -s "${th_stderr_}" ]; then
|
||||||
\[ ! -s "${th_stdout_}" -a -s "${th_stderr_}" ] || \
|
|
||||||
_th_showOutput "${SHUNIT_FALSE}" "${th_stdout_}" "${th_stderr_}"
|
_th_showOutput "${SHUNIT_FALSE}" "${th_stdout_}" "${th_stderr_}"
|
||||||
|
fi
|
||||||
|
|
||||||
unset th_test_ th_rtrn_ th_stdout_ th_stderr_
|
unset th_test_ th_rtrn_ th_stdout_ th_stderr_
|
||||||
}
|
}
|
||||||
|
@ -193,8 +196,8 @@ th_assertFalseWithError() {
|
||||||
# they are either written to disk, or recognized as an error the file is empty.
|
# they are either written to disk, or recognized as an error the file is empty.
|
||||||
th_clearReturn() { cp /dev/null "${returnF}"; }
|
th_clearReturn() { cp /dev/null "${returnF}"; }
|
||||||
th_queryReturn() {
|
th_queryReturn() {
|
||||||
if \[ -s "${returnF}" ]; then
|
if [ -s "${returnF}" ]; then
|
||||||
th_return=`\cat "${returnF}"`
|
th_return=`cat "${returnF}"`
|
||||||
else
|
else
|
||||||
th_return=${SHUNIT_ERROR}
|
th_return=${SHUNIT_ERROR}
|
||||||
fi
|
fi
|
||||||
|
@ -204,22 +207,26 @@ th_queryReturn() {
|
||||||
# Providing external and internal calls to the showOutput helper function.
|
# Providing external and internal calls to the showOutput helper function.
|
||||||
th_showOutput() { _th_showOutput "$@"; }
|
th_showOutput() { _th_showOutput "$@"; }
|
||||||
_th_showOutput() {
|
_th_showOutput() {
|
||||||
_th_return_=$1
|
if isSkipping; then
|
||||||
_th_stdout_=$2
|
return
|
||||||
_th_stderr_=$3
|
fi
|
||||||
|
|
||||||
isSkipping
|
_th_return_="${1:-${returnF}}"
|
||||||
if \[ $? -eq "${SHUNIT_FALSE}" -a "${_th_return_}" != "${SHUNIT_TRUE}" ]; then
|
_th_stdout_="${2:-${stdoutF}}"
|
||||||
if \[ -n "${_th_stdout_}" -a -s "${_th_stdout_}" ]; then
|
_th_stderr_="${3:-${stderrF}}"
|
||||||
|
|
||||||
|
if [ "${_th_return_}" != "${SHUNIT_TRUE}" ]; then
|
||||||
|
# shellcheck disable=SC2166
|
||||||
|
if [ -n "${_th_stdout_}" -a -s "${_th_stdout_}" ]; then
|
||||||
echo '>>> STDOUT' >&2
|
echo '>>> STDOUT' >&2
|
||||||
\cat "${_th_stdout_}" >&2
|
cat "${_th_stdout_}" >&2
|
||||||
|
echo '<<< STDOUT' >&2
|
||||||
fi
|
fi
|
||||||
if \[ -n "${_th_stderr_}" -a -s "${_th_stderr_}" ]; then
|
# shellcheck disable=SC2166
|
||||||
|
if [ -n "${_th_stderr_}" -a -s "${_th_stderr_}" ]; then
|
||||||
echo '>>> STDERR' >&2
|
echo '>>> STDERR' >&2
|
||||||
\cat "${_th_stderr_}" >&2
|
cat "${_th_stderr_}" >&2
|
||||||
fi
|
echo '<<< STDERR' >&2
|
||||||
if \[ -n "${_th_stdout_}" -o -n "${_th_stderr_}" ]; then
|
|
||||||
echo '<<< end output' >&2
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#
|
#
|
||||||
# Unit test suite runner.
|
# Unit test suite runner.
|
||||||
#
|
#
|
||||||
# Copyright 2008-2017 Kate Ward. All Rights Reserved.
|
# Copyright 2008-2020 Kate Ward. All Rights Reserved.
|
||||||
# Released under the Apache 2.0 license.
|
# Released under the Apache 2.0 license.
|
||||||
#
|
#
|
||||||
# Author: kate.ward@forestent.com (Kate Ward)
|
# Author: kate.ward@forestent.com (Kate Ward)
|
||||||
|
@ -12,6 +12,20 @@
|
||||||
# This script runs all the unit tests that can be found, and generates a nice
|
# This script runs all the unit tests that can be found, and generates a nice
|
||||||
# report of the tests.
|
# report of the tests.
|
||||||
#
|
#
|
||||||
|
### Sample usage:
|
||||||
|
#
|
||||||
|
# Run all tests for all shells.
|
||||||
|
# $ ./test_runner
|
||||||
|
#
|
||||||
|
# Run all tests for single shell.
|
||||||
|
# $ ./test_runner -s /bin/bash
|
||||||
|
#
|
||||||
|
# Run single test for all shells.
|
||||||
|
# $ ./test_runner -t shunit_asserts_test.sh
|
||||||
|
#
|
||||||
|
# Run single test for single shell.
|
||||||
|
# $ ./test_runner -s /bin/bash -t shunit_asserts_test.sh
|
||||||
|
#
|
||||||
### ShellCheck (http://www.shellcheck.net/)
|
### ShellCheck (http://www.shellcheck.net/)
|
||||||
# Disable source following.
|
# Disable source following.
|
||||||
# shellcheck disable=SC1090,SC1091
|
# shellcheck disable=SC1090,SC1091
|
||||||
|
@ -25,8 +39,10 @@
|
||||||
RUNNER_LOADED=0
|
RUNNER_LOADED=0
|
||||||
|
|
||||||
RUNNER_ARGV0=`basename "$0"`
|
RUNNER_ARGV0=`basename "$0"`
|
||||||
RUNNER_SHELLS='/bin/sh ash /bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/zsh'
|
RUNNER_SHELLS='/bin/sh ash /bin/bash /bin/dash /bin/ksh /bin/mksh /bin/zsh'
|
||||||
RUNNER_TEST_SUFFIX='_test.sh'
|
RUNNER_TEST_SUFFIX='_test.sh'
|
||||||
|
true; RUNNER_TRUE=$?
|
||||||
|
false; RUNNER_FALSE=$?
|
||||||
|
|
||||||
runner_warn() { echo "runner:WARN $*" >&2; }
|
runner_warn() { echo "runner:WARN $*" >&2; }
|
||||||
runner_error() { echo "runner:ERROR $*" >&2; }
|
runner_error() { echo "runner:ERROR $*" >&2; }
|
||||||
|
@ -36,7 +52,7 @@ runner_usage() {
|
||||||
echo "usage: ${RUNNER_ARGV0} [-e key=val ...] [-s shell(s)] [-t test(s)]"
|
echo "usage: ${RUNNER_ARGV0} [-e key=val ...] [-s shell(s)] [-t test(s)]"
|
||||||
}
|
}
|
||||||
|
|
||||||
_runner_tests() { echo ./*${RUNNER_TEST_SUFFIX} |sed 's#./##g'; }
|
_runner_tests() { echo ./*${RUNNER_TEST_SUFFIX} |sed 's#\./##g'; }
|
||||||
_runner_testName() {
|
_runner_testName() {
|
||||||
# shellcheck disable=SC1117
|
# shellcheck disable=SC1117
|
||||||
_runner_testName_=`expr "${1:-}" : "\(.*\)${RUNNER_TEST_SUFFIX}"`
|
_runner_testName_=`expr "${1:-}" : "\(.*\)${RUNNER_TEST_SUFFIX}"`
|
||||||
|
@ -114,6 +130,7 @@ for key in ${env}; do
|
||||||
done
|
done
|
||||||
|
|
||||||
# Run tests.
|
# Run tests.
|
||||||
|
runner_passing_=${RUNNER_TRUE}
|
||||||
for shell in ${shells}; do
|
for shell in ${shells}; do
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
@ -127,20 +144,20 @@ EOF
|
||||||
# Check for existence of shell.
|
# Check for existence of shell.
|
||||||
shell_bin=${shell}
|
shell_bin=${shell}
|
||||||
shell_name=''
|
shell_name=''
|
||||||
shell_present=${FALSE}
|
shell_present=${RUNNER_FALSE}
|
||||||
case ${shell} in
|
case ${shell} in
|
||||||
ash)
|
ash)
|
||||||
shell_bin=`which busybox |grep -v '^no busybox'`
|
shell_bin=`command -v busybox`
|
||||||
[ $? -eq "${TRUE}" -a -n "${shell_bin}" ] && shell_present="${TRUE}"
|
[ $? -eq "${RUNNER_TRUE}" ] && shell_present="${RUNNER_TRUE}"
|
||||||
shell_bin="${shell_bin} ash"
|
shell_bin="${shell_bin:+${shell_bin} }ash"
|
||||||
shell_name=${shell}
|
shell_name=${shell}
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
[ -x "${shell_bin}" ] && shell_present="${TRUE}"
|
[ -x "${shell_bin}" ] && shell_present="${RUNNER_TRUE}"
|
||||||
shell_name=`basename "${shell}"`
|
shell_name=`basename "${shell}"`
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
if [ "${shell_present}" -eq "${FALSE}" ]; then
|
if [ "${shell_present}" -eq "${RUNNER_FALSE}" ]; then
|
||||||
runner_warn "unable to run tests with the ${shell_name} shell"
|
runner_warn "unable to run tests with the ${shell_name} shell"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
@ -157,9 +174,18 @@ EOF
|
||||||
# ${shell_bin} needs word splitting.
|
# ${shell_bin} needs word splitting.
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
( exec ${shell_bin} "./${t}" 2>&1; )
|
( exec ${shell_bin} "./${t}" 2>&1; )
|
||||||
|
shell_passing=$?
|
||||||
|
if [ "${shell_passing}" -ne "${RUNNER_TRUE}" ]; then
|
||||||
|
runner_warn "${shell_bin} not passing"
|
||||||
|
fi
|
||||||
|
test "${runner_passing_}" -eq ${RUNNER_TRUE} -a ${shell_passing} -eq ${RUNNER_TRUE}
|
||||||
|
runner_passing_=$?
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
return ${runner_passing_}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Execute main() if this is run in standalone mode (i.e. not from a unit test).
|
# Execute main() if this is run in standalone mode (i.e. not from a unit test).
|
||||||
[ -z "${SHUNIT_VERSION}" ] && main "$@"
|
if [ -z "${SHUNIT_VERSION}" ]; then
|
||||||
|
main "$@"
|
||||||
|
fi
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
###### osync - Rsync based two way sync engine with fault tolerance
|
|
||||||
###### (C) 2013-2017 by Orsiris de Jong (www.netpower.fr)
|
|
||||||
###### osync-target-helper v1.2.2+ config file rev 2017061901
|
|
||||||
|
|
||||||
## ---------- GENERAL OPTIONS
|
|
||||||
|
|
||||||
## Sync job identification
|
|
||||||
INSTANCE_ID="sync_test"
|
|
||||||
|
|
||||||
## Directories to synchronize.
|
|
||||||
## Initiator is the system main osync runs on. The initiator directory must be a remote path for osync target helper to contact.
|
|
||||||
INITIATOR_SYNC_DIR="ssh://backupuser@yourhost.old:22//home/git/osync/dir1"
|
|
||||||
|
|
||||||
## Target is the system osync synchronizes to. The target directory must be a local.
|
|
||||||
TARGET_SYNC_DIR="/home/git/osync/dir2"
|
|
||||||
|
|
||||||
## If the target system is remote, you can specify a RSA key (please use full path). If not defined, the default ~/.ssh/id_rsa will be used. See documentation for further information.
|
|
||||||
SSH_RSA_PRIVATE_KEY="/home/backupuser/.ssh/id_rsa"
|
|
||||||
|
|
||||||
## Alternatively, you may specify an SSH password file (less secure). Needs sshpass utility installed.
|
|
||||||
SSH_PASSWORD_FILE=""
|
|
||||||
|
|
||||||
## When using ssh filter, you must specify a remote token matching the one setup in authorized_keys
|
|
||||||
_REMOTE_TOKEN=SomeAlphaNumericToken9
|
|
||||||
|
|
||||||
## Log file location. Leaving this empty will create a logfile at /var/log/osync_version_SYNC_ID.log (or current directory if /var/log doesn't exist)
|
|
||||||
LOGFILE=""
|
|
||||||
|
|
||||||
## If enabled, synchronization on remote system will be processed as superuser. See documentation for /etc/sudoers file configuration.
|
|
||||||
SUDO_EXEC=no
|
|
||||||
|
|
||||||
## ---------- REMOTE SYNC OPTIONS
|
|
||||||
|
|
||||||
## ssh compression should be used unless your remote connection is good enough (LAN)
|
|
||||||
SSH_COMPRESSION=yes
|
|
||||||
|
|
||||||
## Ignore ssh known hosts. DANGER WILL ROBINSON DANGER ! This can lead to security issues. Only enable this if you know what you're doing.
|
|
||||||
SSH_IGNORE_KNOWN_HOSTS=no
|
|
||||||
|
|
||||||
## Check for connectivity to remote host before launching remote sync task. Be sure the hosts responds to ping. Failing to ping will stop sync.
|
|
||||||
REMOTE_HOST_PING=no
|
|
||||||
|
|
||||||
## Check for internet access by pinging one or more 3rd party hosts before remote sync task. Leave empty if you don't want this check to be be performed. Failing to ping will stop sync.
|
|
||||||
## If you use this function, you should set more than one 3rd party host, and be sure you can ping them.
|
|
||||||
## Be aware some DNS like opendns redirect false hostnames. Also, this adds an extra execution time of a bit less than a minute.
|
|
||||||
REMOTE_3RD_PARTY_HOSTS="www.kernel.org www.google.com"
|
|
||||||
|
|
||||||
## Minimum time (in seconds) in file monitor /daemon mode between modification detection and sync task in order to let copy operations finish.
|
|
||||||
MIN_WAIT=60
|
|
||||||
|
|
||||||
## Maximum time (in seconds) waiting in file monitor / daemon mode. After this time, sync is run.
|
|
||||||
## Use 0 to wait indefinitely.
|
|
||||||
MAX_WAIT=7200
|
|
||||||
|
|
||||||
## ---------- ALERT OPTIONS
|
|
||||||
|
|
||||||
## List of alert mails separated by spaces
|
|
||||||
## Most Unix systems (including Win10 bash) have mail support out of the box
|
|
||||||
## Just make sure that the current user has enough privileges to use mail / mutt / sendmail and that the mail system is configured to allow outgoing mails
|
|
||||||
## on pfSense platform, smtp support needs to be configured in System > Advanced > Notifications
|
|
||||||
DESTINATION_MAILS="your@alert.tld"
|
|
||||||
|
|
||||||
## Optional change of mail body encoding (using iconv)
|
|
||||||
## By default, all mails are sent in UTF-8 format without header (because of maximum compatibility of all platforms)
|
|
||||||
## You may specify an optional encoding here (like "ISO-8859-1" or whatever iconv can handle)
|
|
||||||
MAIL_BODY_CHARSET=""
|
|
||||||
|
|
||||||
## Additional mail parameters needed for Android / Busybox / Cygwin / MSYS
|
|
||||||
## Android & Busybox use sendmail (and openssl if encryption is needed)
|
|
||||||
## MSYS & Cygwin Windows mail support relies on mailsend.exe from muquit, http://github.com/muquit/mailsend which needs to be in %PATH% environment variable
|
|
||||||
SENDER_MAIL="alert@your.system.tld"
|
|
||||||
SMTP_SERVER=smtp.your.isp.tld
|
|
||||||
SMTP_PORT=25
|
|
||||||
# encryption can be tls, ssl or none
|
|
||||||
SMTP_ENCRYPTION=none
|
|
||||||
SMTP_USER=
|
|
||||||
SMTP_PASSWORD=
|
|
369
install.sh
369
install.sh
|
@ -10,15 +10,15 @@ PROGRAM_BINARY=$PROGRAM".sh"
|
||||||
PROGRAM_BATCH=$PROGRAM"-batch.sh"
|
PROGRAM_BATCH=$PROGRAM"-batch.sh"
|
||||||
SSH_FILTER="ssh_filter.sh"
|
SSH_FILTER="ssh_filter.sh"
|
||||||
|
|
||||||
SCRIPT_BUILD=2019052001
|
SCRIPT_BUILD=2025012001
|
||||||
INSTANCE_ID="installer-$SCRIPT_BUILD"
|
INSTANCE_ID="installer-$SCRIPT_BUILD"
|
||||||
|
|
||||||
## osync / obackup / pmocr / zsnap install script
|
## osync / obackup / pmocr / zsnap install script
|
||||||
## Tested on RHEL / CentOS 6 & 7, Fedora 23, Debian 7 & 8, Mint 17 and FreeBSD 8, 10 and 11
|
## Tested on RHEL / CentOS 6 & 7, Fedora 23, Debian 7 & 8, Mint 17 and FreeBSD 8, 10 and 11
|
||||||
## Please adapt this to fit your distro needs
|
## Please adapt this to fit your distro needs
|
||||||
|
|
||||||
_OFUNCTIONS_VERSION=2.3.0-dev-postRC2
|
_OFUNCTIONS_VERSION=2.5.1
|
||||||
_OFUNCTIONS_BUILD=2019052103
|
_OFUNCTIONS_BUILD=2023061401
|
||||||
_OFUNCTIONS_BOOTSTRAP=true
|
_OFUNCTIONS_BOOTSTRAP=true
|
||||||
|
|
||||||
if ! type "$BASH" > /dev/null; then
|
if ! type "$BASH" > /dev/null; then
|
||||||
|
@ -41,6 +41,8 @@ _LOGGER_SILENT=false
|
||||||
_LOGGER_VERBOSE=false
|
_LOGGER_VERBOSE=false
|
||||||
_LOGGER_ERR_ONLY=false
|
_LOGGER_ERR_ONLY=false
|
||||||
_LOGGER_PREFIX="date"
|
_LOGGER_PREFIX="date"
|
||||||
|
_LOGGER_WRITE_PARTIAL_LOGS=false # Writes partial log files to /tmp so sending logs via alerts can feed on them
|
||||||
|
_OFUNCTIONS_SHOW_SPINNER=true # Show spinner in ExecTasks function
|
||||||
if [ "$KEEP_LOGGING" == "" ]; then
|
if [ "$KEEP_LOGGING" == "" ]; then
|
||||||
KEEP_LOGGING=1801
|
KEEP_LOGGING=1801
|
||||||
fi
|
fi
|
||||||
|
@ -59,12 +61,32 @@ else
|
||||||
_LOGGER_VERBOSE=true
|
_LOGGER_VERBOSE=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$SLEEP_TIME" == "" ]; then # Leave the possibity to set SLEEP_TIME as environment variable when runinng with bash -x in order to avoid spamming console
|
if [ "$SLEEP_TIME" == "" ]; then # Leave the possibility to set SLEEP_TIME as environment variable when running with bash -x in order to avoid spamming console
|
||||||
SLEEP_TIME=.05
|
SLEEP_TIME=.05
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# The variables SCRIPT_PID and TSTAMP needs to be declared as soon as the program begins. The function PoorMansRandomGenerator is needed for TSTAMP (since some systems date function does not give nanoseconds)
|
||||||
|
|
||||||
SCRIPT_PID=$$
|
SCRIPT_PID=$$
|
||||||
|
|
||||||
|
# Get a random number of digits length on Windows BusyBox alike, also works on most Unixes that have dd
|
||||||
|
function PoorMansRandomGenerator {
|
||||||
|
local digits="${1}" # The number of digits to generate
|
||||||
|
local number
|
||||||
|
|
||||||
|
# Some read bytes cannot be used, se we read twice the number of required bytes
|
||||||
|
dd if=/dev/urandom bs=$digits count=2 2> /dev/null | while read -r -n1 char; do
|
||||||
|
number=$number$(printf "%d" "'$char")
|
||||||
|
if [ ${#number} -ge $digits ]; then
|
||||||
|
echo ${number:0:$digits}
|
||||||
|
break;
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initial TSTMAP value before function declaration
|
||||||
|
TSTAMP=$(date '+%Y%m%dT%H%M%S').$(PoorMansRandomGenerator 5)
|
||||||
|
|
||||||
LOCAL_USER=$(whoami)
|
LOCAL_USER=$(whoami)
|
||||||
LOCAL_HOST=$(hostname)
|
LOCAL_HOST=$(hostname)
|
||||||
|
|
||||||
|
@ -94,53 +116,13 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Special note when remote target is on the same host as initiator (happens for unit tests): we'll have to differentiate RUN_DIR so remote CleanUp won't affect initiator.
|
## Special note when remote target is on the same host as initiator (happens for unit tests): we'll have to differentiate RUN_DIR so remote CleanUp won't affect initiator.
|
||||||
|
## If the same program gets remotely executed, add _REMOTE_EXECUTION=true to environment so it knows it has to write into a separate directory
|
||||||
|
## This will thus not affect local $RUN_DIR variables
|
||||||
if [ "$_REMOTE_EXECUTION" == true ]; then
|
if [ "$_REMOTE_EXECUTION" == true ]; then
|
||||||
mkdir -p "$RUN_DIR/$PROGRAM.remote"
|
mkdir -p "$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP"
|
||||||
RUN_DIR="$RUN_DIR/$PROGRAM.remote"
|
RUN_DIR="$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get a random number on Windows BusyBox alike, also works on most Unixes that have dd, if dd is not found, then return $RANDOM
|
|
||||||
function PoorMansRandomGenerator {
|
|
||||||
local digits="${1}" # The number of digits to generate
|
|
||||||
local number
|
|
||||||
local isFirst=true
|
|
||||||
|
|
||||||
if type dd >/dev/null 2>&1; then
|
|
||||||
|
|
||||||
# Some read bytes can't be used, se we read twice the number of required bytes
|
|
||||||
dd if=/dev/urandom bs=$digits count=2 2> /dev/null | while read -r -n1 char; do
|
|
||||||
if [ $isFirst == false ] || [ $(printf "%d" "'$char") != "0" ]; then
|
|
||||||
number=$number$(printf "%d" "'$char")
|
|
||||||
isFirst=false
|
|
||||||
fi
|
|
||||||
if [ ${#number} -ge $digits ]; then
|
|
||||||
echo ${number:0:$digits}
|
|
||||||
break;
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
elif [ "$RANDOM" -ne 0 ]; then
|
|
||||||
echo $RANDOM
|
|
||||||
else
|
|
||||||
Logger "Cannot generate random number." "ERROR"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
function PoorMansRandomGenerator {
|
|
||||||
local digits="${1}" # The number of digits to generate
|
|
||||||
local number
|
|
||||||
|
|
||||||
# Some read bytes can't be used, se we read twice the number of required bytes
|
|
||||||
dd if=/dev/urandom bs=$digits count=2 2> /dev/null | while read -r -n1 char; do
|
|
||||||
number=$number$(printf "%d" "'$char")
|
|
||||||
if [ ${#number} -ge $digits ]; then
|
|
||||||
echo ${number:0:$digits}
|
|
||||||
break;
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Initial TSTMAP value before function declaration
|
|
||||||
TSTAMP=$(date '+%Y%m%dT%H%M%S').$(PoorMansRandomGenerator 5)
|
|
||||||
|
|
||||||
# Default alert attachment filename
|
# Default alert attachment filename
|
||||||
ALERT_LOG_FILE="$RUN_DIR/$PROGRAM.$SCRIPT_PID.$TSTAMP.last.log"
|
ALERT_LOG_FILE="$RUN_DIR/$PROGRAM.$SCRIPT_PID.$TSTAMP.last.log"
|
||||||
|
|
||||||
|
@ -165,8 +147,8 @@ function _Logger {
|
||||||
echo -e "$logValue" >> "$LOG_FILE"
|
echo -e "$logValue" >> "$LOG_FILE"
|
||||||
|
|
||||||
# Build current log file for alerts if we have a sufficient environment
|
# Build current log file for alerts if we have a sufficient environment
|
||||||
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
|
if [ "$_LOGGER_WRITE_PARTIAL_LOGS" == true ] && [ "$RUN_DIR/$PROGRAM" != "/" ]; then
|
||||||
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
|
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -190,7 +172,7 @@ function RemoteLogger {
|
||||||
local prefix
|
local prefix
|
||||||
|
|
||||||
if [ "$_LOGGER_PREFIX" == "time" ]; then
|
if [ "$_LOGGER_PREFIX" == "time" ]; then
|
||||||
prefix="TIME: $SECONDS - "
|
prefix="RTIME: $SECONDS - "
|
||||||
elif [ "$_LOGGER_PREFIX" == "date" ]; then
|
elif [ "$_LOGGER_PREFIX" == "date" ]; then
|
||||||
prefix="R $(date) - "
|
prefix="R $(date) - "
|
||||||
else
|
else
|
||||||
|
@ -199,29 +181,29 @@ function RemoteLogger {
|
||||||
|
|
||||||
if [ "$level" == "CRITICAL" ]; then
|
if [ "$level" == "CRITICAL" ]; then
|
||||||
_Logger "" "$prefix\e[1;33;41m$value\e[0m" true
|
_Logger "" "$prefix\e[1;33;41m$value\e[0m" true
|
||||||
if [ $_DEBUG == true ]; then
|
if [ "$_DEBUG" == true ]; then
|
||||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "ERROR" ]; then
|
elif [ "$level" == "ERROR" ]; then
|
||||||
_Logger "" "$prefix\e[31m$value\e[0m" true
|
_Logger "" "$prefix\e[31m$value\e[0m" true
|
||||||
if [ $_DEBUG == true ]; then
|
if [ "$_DEBUG" == true ]; then
|
||||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "WARN" ]; then
|
elif [ "$level" == "WARN" ]; then
|
||||||
_Logger "" "$prefix\e[33m$value\e[0m" true
|
_Logger "" "$prefix\e[33m$value\e[0m" true
|
||||||
if [ $_DEBUG == true ]; then
|
if [ "$_DEBUG" == true ]; then
|
||||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "NOTICE" ]; then
|
elif [ "$level" == "NOTICE" ]; then
|
||||||
if [ $_LOGGER_ERR_ONLY != true ]; then
|
if [ "$_LOGGER_ERR_ONLY" != true ]; then
|
||||||
_Logger "" "$prefix$value"
|
_Logger "" "$prefix$value"
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "VERBOSE" ]; then
|
elif [ "$level" == "VERBOSE" ]; then
|
||||||
if [ $_LOGGER_VERBOSE == true ]; then
|
if [ "$_LOGGER_VERBOSE" == true ]; then
|
||||||
_Logger "" "$prefix$value"
|
_Logger "" "$prefix$value"
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
|
@ -270,24 +252,24 @@ function Logger {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Obfuscate _REMOTE_TOKEN in logs (for ssh_filter usage only in osync and obackup)
|
## Obfuscate _REMOTE_TOKEN in logs (for ssh_filter usage only in osync and obackup)
|
||||||
value="${value/env _REMOTE_TOKEN=$_REMOTE_TOKEN/__(o_O)__}"
|
value="${value/env _REMOTE_TOKEN=$_REMOTE_TOKEN/env _REMOTE_TOKEN=__o_O__}"
|
||||||
value="${value/env _REMOTE_TOKEN=\$_REMOTE_TOKEN/__(o_O)__}"
|
value="${value/env _REMOTE_TOKEN=\$_REMOTE_TOKEN/env _REMOTE_TOKEN=__o_O__}"
|
||||||
|
|
||||||
if [ "$level" == "CRITICAL" ]; then
|
if [ "$level" == "CRITICAL" ]; then
|
||||||
_Logger "$prefix($level):$value" "$prefix\e[1;33;41m$value\e[0m" true
|
_Logger "$prefix($level):$value" "$prefix\e[1;33;41m$value\e[0m" true
|
||||||
ERROR_ALERT=true
|
ERROR_ALERT=true
|
||||||
# ERROR_ALERT / WARN_ALERT is not set in main when Logger is called from a subprocess. Need to keep this flag.
|
# ERROR_ALERT / WARN_ALERT is not set in main when Logger is called from a subprocess. We need to create these flag files for ERROR_ALERT / WARN_ALERT to be picked up by Alert
|
||||||
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID.$TSTAMP"
|
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.ERROR_ALERT.$SCRIPT_PID.$TSTAMP"
|
||||||
return
|
return
|
||||||
elif [ "$level" == "ERROR" ]; then
|
elif [ "$level" == "ERROR" ]; then
|
||||||
_Logger "$prefix($level):$value" "$prefix\e[91m$value\e[0m" true
|
_Logger "$prefix($level):$value" "$prefix\e[91m$value\e[0m" true
|
||||||
ERROR_ALERT=true
|
ERROR_ALERT=true
|
||||||
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID.$TSTAMP"
|
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.ERROR_ALERT.$SCRIPT_PID.$TSTAMP"
|
||||||
return
|
return
|
||||||
elif [ "$level" == "WARN" ]; then
|
elif [ "$level" == "WARN" ]; then
|
||||||
_Logger "$prefix($level):$value" "$prefix\e[33m$value\e[0m" true
|
_Logger "$prefix($level):$value" "$prefix\e[33m$value\e[0m" true
|
||||||
WARN_ALERT=true
|
WARN_ALERT=true
|
||||||
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.warn.$SCRIPT_PID.$TSTAMP"
|
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.WARN_ALERT.$SCRIPT_PID.$TSTAMP"
|
||||||
return
|
return
|
||||||
elif [ "$level" == "NOTICE" ]; then
|
elif [ "$level" == "NOTICE" ]; then
|
||||||
if [ "$_LOGGER_ERR_ONLY" != true ]; then
|
if [ "$_LOGGER_ERR_ONLY" != true ]; then
|
||||||
|
@ -295,7 +277,7 @@ function Logger {
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "VERBOSE" ]; then
|
elif [ "$level" == "VERBOSE" ]; then
|
||||||
if [ $_LOGGER_VERBOSE == true ]; then
|
if [ "$_LOGGER_VERBOSE" == true ]; then
|
||||||
_Logger "$prefix($level):$value" "$prefix$value"
|
_Logger "$prefix($level):$value" "$prefix$value"
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
|
@ -398,23 +380,15 @@ function KillAllChilds {
|
||||||
return $errorcount
|
return $errorcount
|
||||||
}
|
}
|
||||||
|
|
||||||
function CleanUp {
|
|
||||||
if [ "$_DEBUG" != true ]; then
|
|
||||||
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP"
|
|
||||||
# Fix for sed -i requiring backup extension for BSD & Mac (see all sed -i statements)
|
|
||||||
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP.tmp"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function GenericTrapQuit {
|
function GenericTrapQuit {
|
||||||
local exitcode=0
|
local exitcode=0
|
||||||
|
|
||||||
# Get ERROR / WARN alert flags from subprocesses that call Logger
|
# Get ERROR / WARN alert flags from subprocesses that call Logger
|
||||||
if [ -f "$RUN_DIR/$PROGRAM.Logger.warn.$SCRIPT_PID.$TSTAMP" ]; then
|
if [ -f "$RUN_DIR/$PROGRAM.WARN_ALERT.$SCRIPT_PID.$TSTAMP" ]; then
|
||||||
WARN_ALERT=true
|
WARN_ALERT=true
|
||||||
exitcode=2
|
exitcode=2
|
||||||
fi
|
fi
|
||||||
if [ -f "$RUN_DIR/$PROGRAM.Logger.error.$SCRIPT_PID.$TSTAMP" ]; then
|
if [ -f "$RUN_DIR/$PROGRAM.ERROR_ALERT.$SCRIPT_PID.$TSTAMP" ]; then
|
||||||
ERROR_ALERT=true
|
ERROR_ALERT=true
|
||||||
exitcode=1
|
exitcode=1
|
||||||
fi
|
fi
|
||||||
|
@ -424,6 +398,25 @@ function GenericTrapQuit {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function CleanUp {
|
||||||
|
# Exit controlmaster before the socket gets deleted
|
||||||
|
if [ "$SSH_CONTROLMASTER" == true ] && [ "$SSH_CMD" != "" ]; then
|
||||||
|
$SSH_CMD -O exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$_DEBUG" != true ]; then
|
||||||
|
# Removing optional remote $RUN_DIR that goes into local $RUN_DIR
|
||||||
|
if [ -d "$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP" ]; then
|
||||||
|
rm -rf "$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP"
|
||||||
|
fi
|
||||||
|
# Removing all temporary run files
|
||||||
|
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP"
|
||||||
|
# Fix for sed -i requiring backup extension for BSD & Mac (see all sed -i statements)
|
||||||
|
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP.tmp"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Get current install.sh path from http://stackoverflow.com/a/246128/2635443
|
# Get current install.sh path from http://stackoverflow.com/a/246128/2635443
|
||||||
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
@ -433,62 +426,6 @@ _STATS=1
|
||||||
ACTION="install"
|
ACTION="install"
|
||||||
FAKEROOT=""
|
FAKEROOT=""
|
||||||
|
|
||||||
function GetCommandlineArguments {
|
|
||||||
for i in "$@"; do
|
|
||||||
case $i in
|
|
||||||
--prefix=*)
|
|
||||||
FAKEROOT="${i##*=}"
|
|
||||||
;;
|
|
||||||
--silent)
|
|
||||||
_LOGGER_SILENT=true
|
|
||||||
;;
|
|
||||||
--no-stats)
|
|
||||||
_STATS=0
|
|
||||||
;;
|
|
||||||
--remove)
|
|
||||||
ACTION="uninstall"
|
|
||||||
;;
|
|
||||||
--help|-h|-?)
|
|
||||||
Usage
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
Logger "Unknown option '$i'" "ERROR"
|
|
||||||
Usage
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
GetCommandlineArguments "$@"
|
|
||||||
|
|
||||||
CONF_DIR=$FAKEROOT/etc/$PROGRAM
|
|
||||||
BIN_DIR="$FAKEROOT/usr/local/bin"
|
|
||||||
SERVICE_DIR_INIT=$FAKEROOT/etc/init.d
|
|
||||||
# Should be /usr/lib/systemd/system, but /lib/systemd/system exists on debian & rhel / fedora
|
|
||||||
SERVICE_DIR_SYSTEMD_SYSTEM=$FAKEROOT/lib/systemd/system
|
|
||||||
SERVICE_DIR_SYSTEMD_USER=$FAKEROOT/etc/systemd/user
|
|
||||||
SERVICE_DIR_OPENRC=$FAKEROOT/etc/init.d
|
|
||||||
|
|
||||||
if [ "$PROGRAM" == "osync" ]; then
|
|
||||||
SERVICE_NAME="osync-srv"
|
|
||||||
TARGET_HELPER_SERVICE_NAME="osync-target-helper-srv"
|
|
||||||
|
|
||||||
TARGET_HELPER_SERVICE_FILE_INIT="$TARGET_HELPER_SERVICE_NAME"
|
|
||||||
TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM="$TARGET_HELPER_SERVICE_NAME@.service"
|
|
||||||
TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER="$TARGET_HELPER_SERVICE_NAME@.service.user"
|
|
||||||
TARGET_HELPER_SERVICE_FILE_OPENRC="$TARGET_HELPER_SERVICE_NAME-openrc"
|
|
||||||
elif [ "$PROGRAM" == "pmocr" ]; then
|
|
||||||
SERVICE_NAME="pmocr-srv"
|
|
||||||
fi
|
|
||||||
|
|
||||||
SERVICE_FILE_INIT="$SERVICE_NAME"
|
|
||||||
SERVICE_FILE_SYSTEMD_SYSTEM="$SERVICE_NAME@.service"
|
|
||||||
SERVICE_FILE_SYSTEMD_USER="$SERVICE_NAME@.service.user"
|
|
||||||
SERVICE_FILE_OPENRC="$SERVICE_NAME-openrc"
|
|
||||||
|
|
||||||
## Generic code
|
|
||||||
|
|
||||||
## Default log file
|
## Default log file
|
||||||
if [ -w "$FAKEROOT/var/log" ]; then
|
if [ -w "$FAKEROOT/var/log" ]; then
|
||||||
LOG_FILE="$FAKEROOT/var/log/$PROGRAM-install.log"
|
LOG_FILE="$FAKEROOT/var/log/$PROGRAM-install.log"
|
||||||
|
@ -547,6 +484,9 @@ function GetLocalOS {
|
||||||
*"Android"*)
|
*"Android"*)
|
||||||
LOCAL_OS="Android"
|
LOCAL_OS="Android"
|
||||||
;;
|
;;
|
||||||
|
*"qnap"*)
|
||||||
|
LOCAL_OS="Qnap"
|
||||||
|
;;
|
||||||
*"Linux"*)
|
*"Linux"*)
|
||||||
LOCAL_OS="Linux"
|
LOCAL_OS="Linux"
|
||||||
;;
|
;;
|
||||||
|
@ -582,10 +522,10 @@ function GetLocalOS {
|
||||||
|
|
||||||
# Get linux versions
|
# Get linux versions
|
||||||
if [ -f "/etc/os-release" ]; then
|
if [ -f "/etc/os-release" ]; then
|
||||||
localOsName=$(GetConfFileValue "/etc/os-release" "NAME" true)
|
localOsName="$(GetConfFileValue "/etc/os-release" "NAME" true)"
|
||||||
localOsVer=$(GetConfFileValue "/etc/os-release" "VERSION" true)
|
localOsVer="$(GetConfFileValue "/etc/os-release" "VERSION" true)"
|
||||||
elif [ "$LOCAL_OS" == "BusyBox" ]; then
|
elif [ "$LOCAL_OS" == "BusyBox" ]; then
|
||||||
localOsVer=$(ls --help 2>&1 | head -1 | cut -f2 -d' ')
|
localOsVer="$(ls --help 2>&1 | head -1 | cut -f2 -d' ')"
|
||||||
localOsName="BusyBox"
|
localOsName="BusyBox"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -634,16 +574,52 @@ function GetConfFileValue () {
|
||||||
echo "$value"
|
echo "$value"
|
||||||
else
|
else
|
||||||
if [ $noError == true ]; then
|
if [ $noError == true ]; then
|
||||||
Logger "Cannot get value for [$name] in config file [$file]." "NOTICE"
|
Logger "Cannot get value for [$name] in config file [$file]." "DEBUG"
|
||||||
else
|
else
|
||||||
Logger "Cannot get value for [$name] in config file [$file]." "ERROR"
|
Logger "Cannot get value for [$name] in config file [$file]." "ERROR"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function CleanUp {
|
||||||
|
# Exit controlmaster before the socket gets deleted
|
||||||
|
if [ "$SSH_CONTROLMASTER" == true ] && [ "$SSH_CMD" != "" ]; then
|
||||||
|
$SSH_CMD -O exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$_DEBUG" != true ]; then
|
||||||
|
# Removing optional remote $RUN_DIR that goes into local $RUN_DIR
|
||||||
|
if [ -d "$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP" ]; then
|
||||||
|
rm -rf "$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP"
|
||||||
|
fi
|
||||||
|
# Removing all temporary run files
|
||||||
|
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP"
|
||||||
|
# Fix for sed -i requiring backup extension for BSD & Mac (see all sed -i statements)
|
||||||
|
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP.tmp"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function GenericTrapQuit {
|
||||||
|
local exitcode=0
|
||||||
|
|
||||||
|
# Get ERROR / WARN alert flags from subprocesses that call Logger
|
||||||
|
if [ -f "$RUN_DIR/$PROGRAM.WARN_ALERT.$SCRIPT_PID.$TSTAMP" ]; then
|
||||||
|
WARN_ALERT=true
|
||||||
|
exitcode=2
|
||||||
|
fi
|
||||||
|
if [ -f "$RUN_DIR/$PROGRAM.ERROR_ALERT.$SCRIPT_PID.$TSTAMP" ]; then
|
||||||
|
ERROR_ALERT=true
|
||||||
|
exitcode=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
CleanUp
|
||||||
|
exit $exitcode
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function SetLocalOSSettings {
|
function SetLocalOSSettings {
|
||||||
USER=root
|
USER=root
|
||||||
|
DO_INIT=true
|
||||||
|
|
||||||
# LOCAL_OS and LOCAL_OS_FULL are global variables set at GetLocalOS
|
# LOCAL_OS and LOCAL_OS_FULL are global variables set at GetLocalOS
|
||||||
|
|
||||||
|
@ -653,10 +629,12 @@ function SetLocalOSSettings {
|
||||||
;;
|
;;
|
||||||
*"MacOSX"*)
|
*"MacOSX"*)
|
||||||
GROUP=admin
|
GROUP=admin
|
||||||
|
DO_INIT=false
|
||||||
;;
|
;;
|
||||||
*"msys"*|*"Cygwin"*)
|
*"Cygwin"*|*"Android"*|*"msys"*|*"BusyBox"*)
|
||||||
USER=""
|
USER=""
|
||||||
GROUP=""
|
GROUP=""
|
||||||
|
DO_INIT=false
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
GROUP=root
|
GROUP=root
|
||||||
|
@ -677,15 +655,26 @@ function SetLocalOSSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetInit {
|
function GetInit {
|
||||||
|
init="none"
|
||||||
if [ -f /sbin/openrc-run ]; then
|
if [ -f /sbin/openrc-run ]; then
|
||||||
init="openrc"
|
init="openrc"
|
||||||
Logger "Detected openrc." "NOTICE"
|
Logger "Detected openrc." "NOTICE"
|
||||||
|
elif [ -f /usr/lib/systemd/systemd ]; then
|
||||||
|
init="systemd"
|
||||||
|
Logger "Detected systemd." "NOTICE"
|
||||||
elif [ -f /sbin/init ]; then
|
elif [ -f /sbin/init ]; then
|
||||||
|
if type -p file > /dev/null 2>&1; then
|
||||||
if file /sbin/init | grep systemd > /dev/null; then
|
if file /sbin/init | grep systemd > /dev/null; then
|
||||||
init="systemd"
|
init="systemd"
|
||||||
Logger "Detected systemd." "NOTICE"
|
Logger "Detected systemd." "NOTICE"
|
||||||
else
|
else
|
||||||
init="initV"
|
init="initV"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
init="initV"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $init == "initV" ]; then
|
||||||
Logger "Detected initV." "NOTICE"
|
Logger "Detected initV." "NOTICE"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
@ -741,15 +730,14 @@ function CopyFile {
|
||||||
local overwrite="${8:-false}"
|
local overwrite="${8:-false}"
|
||||||
|
|
||||||
local userGroup=""
|
local userGroup=""
|
||||||
local oldFileName
|
|
||||||
|
|
||||||
if [ "$destFileName" == "" ]; then
|
if [ "$destFileName" == "" ]; then
|
||||||
destFileName="$sourceFileName"
|
destFileName="$sourceFileName"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$destPath/$destFileName" ] && [ $overwrite == false ]; then
|
if [ -f "$destPath/$destFileName" ] && [ $overwrite == false ]; then
|
||||||
destfileName="$sourceFileName.new"
|
destFileName="$sourceFileName.new"
|
||||||
Logger "Copying [$sourceFileName] to [$destPath/$destFilename]." "NOTICE"
|
Logger "Copying [$sourceFileName] to [$destPath/$destFileName]." "NOTICE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cp "$sourcePath/$sourceFileName" "$destPath/$destFileName"
|
cp "$sourcePath/$sourceFileName" "$destPath/$destFileName"
|
||||||
|
@ -837,11 +825,11 @@ function CopyServiceFiles {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$SCRIPT_PATH/$TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM" ]; then
|
if [ -f "$SCRIPT_PATH/$TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM" ]; then
|
||||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_SYSTEMD_SYSTEM" "$TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM" "$SERVICE_FILE_SYSTEMD_SYSTEM" "" "" "" true
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_SYSTEMD_SYSTEM" "$TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM" "$TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM" "" "" "" true
|
||||||
Logger "Created optional service [$TARGET_HELPER_SERVICE_NAME] with same specifications as below." "NOTICE"
|
Logger "Created optional service [$TARGET_HELPER_SERVICE_NAME] with same specifications as below." "NOTICE"
|
||||||
fi
|
fi
|
||||||
if [ -f "$SCRIPT_PATH/$TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER" ]; then
|
if [ -f "$SCRIPT_PATH/$TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER" ]; then
|
||||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_SYSTEMD_USER" "$TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER" "$SERVICE_FILE_SYSTEMD_USER" "" "" "" true
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_SYSTEMD_USER" "$TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER" "$TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER" "" "" "" true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
@ -853,7 +841,7 @@ function CopyServiceFiles {
|
||||||
#CreateDir "$SERVICE_DIR_INIT"
|
#CreateDir "$SERVICE_DIR_INIT"
|
||||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_INIT" "$SERVICE_FILE_INIT" "$SERVICE_FILE_INIT" "755" "" "" true
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_INIT" "$SERVICE_FILE_INIT" "$SERVICE_FILE_INIT" "755" "" "" true
|
||||||
if [ -f "$SCRIPT_PATH/$TARGET_HELPER_SERVICE_FILE_INIT" ]; then
|
if [ -f "$SCRIPT_PATH/$TARGET_HELPER_SERVICE_FILE_INIT" ]; then
|
||||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_INIT" "$TARGET_HELPER_SERVICE_FILE_INIT" "$SERVICE_FILE_INIT" "755" "" "" true
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_INIT" "$TARGET_HELPER_SERVICE_FILE_INIT" "$TARGET_HELPER_SERVICE_FILE_INIT" "755" "" "" true
|
||||||
Logger "Created optional service [$TARGET_HELPER_SERVICE_NAME] with same specifications as below." "NOTICE"
|
Logger "Created optional service [$TARGET_HELPER_SERVICE_NAME] with same specifications as below." "NOTICE"
|
||||||
fi
|
fi
|
||||||
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_INIT]." "NOTICE"
|
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_INIT]." "NOTICE"
|
||||||
|
@ -863,7 +851,7 @@ function CopyServiceFiles {
|
||||||
# Rename service to usual service file
|
# Rename service to usual service file
|
||||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_OPENRC" "$SERVICE_FILE_OPENRC" "$SERVICE_FILE_INIT" "755" "" "" true
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_OPENRC" "$SERVICE_FILE_OPENRC" "$SERVICE_FILE_INIT" "755" "" "" true
|
||||||
if [ -f "$SCRPT_PATH/$TARGET_HELPER_SERVICE_FILE_OPENRC" ]; then
|
if [ -f "$SCRPT_PATH/$TARGET_HELPER_SERVICE_FILE_OPENRC" ]; then
|
||||||
CopyFile "$SCRIPT_PATH" "$TARGET_HELPER_SERVICE_DIR_OPENRC" "$SERVICE_FILE_OPENRC" "$SERVICE_FILE_INIT" "755" "" "" true
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_OPENRC" "$TARGET_HELPER_SERVICE_FILE_OPENRC" "$TARGET_HELPER_SERVICE_FILE_OPENRC" "755" "" "" true
|
||||||
Logger "Created optional service [$TARGET_HELPER_SERVICE_NAME] with same specifications as below." "NOTICE"
|
Logger "Created optional service [$TARGET_HELPER_SERVICE_NAME] with same specifications as below." "NOTICE"
|
||||||
fi
|
fi
|
||||||
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_OPENRC]." "NOTICE"
|
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_OPENRC]." "NOTICE"
|
||||||
|
@ -874,14 +862,14 @@ function CopyServiceFiles {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Statistics {
|
function Statistics {
|
||||||
if type wget > /dev/null; then
|
if type wget > /dev/null 2>&1; then
|
||||||
wget -qO- "$STATS_LINK" > /dev/null 2>&1
|
wget -qO- "$STATS_LINK" > /dev/null 2>&1
|
||||||
if [ $? == 0 ]; then
|
if [ $? == 0 ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if type curl > /dev/null; then
|
if type curl > /dev/null 2>&1; then
|
||||||
curl "$STATS_LINK" -o /dev/null > /dev/null 2>&1
|
curl "$STATS_LINK" -o /dev/null > /dev/null 2>&1
|
||||||
if [ $? == 0 ]; then
|
if [ $? == 0 ]; then
|
||||||
return 0
|
return 0
|
||||||
|
@ -919,10 +907,22 @@ function RemoveAll {
|
||||||
else
|
else
|
||||||
Logger "Skipping removal of [$BIN_DIR/$SSH_FILTER] because other programs present that need it." "NOTICE"
|
Logger "Skipping removal of [$BIN_DIR/$SSH_FILTER] because other programs present that need it." "NOTICE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Try to uninstall every possible service file
|
||||||
|
if [ $init == "systemd" ]; then
|
||||||
RemoveFile "$SERVICE_DIR_SYSTEMD_SYSTEM/$SERVICE_FILE_SYSTEMD_SYSTEM"
|
RemoveFile "$SERVICE_DIR_SYSTEMD_SYSTEM/$SERVICE_FILE_SYSTEMD_SYSTEM"
|
||||||
RemoveFile "$SERVICE_DIR_SYSTEMD_USER/$SERVICE_FILE_SYSTEMD_USER"
|
RemoveFile "$SERVICE_DIR_SYSTEMD_USER/$SERVICE_FILE_SYSTEMD_USER"
|
||||||
|
RemoveFile "$SERVICE_DIR_SYSTEMD_SYSTEM/$TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM"
|
||||||
|
RemoveFile "$SERVICE_DIR_SYSTEMD_USER/$TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER"
|
||||||
|
elif [ $init == "initV" ]; then
|
||||||
RemoveFile "$SERVICE_DIR_INIT/$SERVICE_FILE_INIT"
|
RemoveFile "$SERVICE_DIR_INIT/$SERVICE_FILE_INIT"
|
||||||
|
RemoveFile "$SERVICE_DIR_INIT/$TARGET_HELPER_SERVICE_FILE_INIT"
|
||||||
|
elif [ $init == "openrc" ]; then
|
||||||
|
RemoveFile "$SERVICE_DIR_OPENRC/$SERVICE_FILE_OPENRC"
|
||||||
|
RemoveFile "$SERVICE_DIR_OPENRC/$TARGET_HELPER_SERVICE_FILE_OPENRC"
|
||||||
|
else
|
||||||
|
Logger "Can uninstall only from initV, systemd or openRC." "WARN"
|
||||||
|
fi
|
||||||
Logger "Skipping configuration files in [$CONF_DIR]. You may remove this directory manually." "NOTICE"
|
Logger "Skipping configuration files in [$CONF_DIR]. You may remove this directory manually." "NOTICE"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -936,26 +936,65 @@ function Usage {
|
||||||
exit 127
|
exit 127
|
||||||
}
|
}
|
||||||
|
|
||||||
function TrapQuit {
|
|
||||||
local exitcode=0
|
|
||||||
|
|
||||||
# Get ERROR / WARN alert flags from subprocesses that call Logger
|
|
||||||
if [ -f "$RUN_DIR/$PROGRAM.Logger.warn.$SCRIPT_PID.$TSTAMP" ]; then
|
|
||||||
WARN_ALERT=true
|
|
||||||
exitcode=2
|
|
||||||
fi
|
|
||||||
if [ -f "$RUN_DIR/$PROGRAM.Logger.error.$SCRIPT_PID.$TSTAMP" ]; then
|
|
||||||
ERROR_ALERT=true
|
|
||||||
exitcode=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
CleanUp
|
|
||||||
exit $exitcode
|
|
||||||
}
|
|
||||||
|
|
||||||
############################## Script entry point
|
############################## Script entry point
|
||||||
|
|
||||||
trap TrapQuit TERM EXIT HUP QUIT
|
function GetCommandlineArguments {
|
||||||
|
for i in "$@"; do
|
||||||
|
case $i in
|
||||||
|
--prefix=*)
|
||||||
|
FAKEROOT="${i##*=}"
|
||||||
|
;;
|
||||||
|
--silent)
|
||||||
|
_LOGGER_SILENT=true
|
||||||
|
;;
|
||||||
|
--no-stats)
|
||||||
|
_STATS=0
|
||||||
|
;;
|
||||||
|
--remove)
|
||||||
|
ACTION="uninstall"
|
||||||
|
;;
|
||||||
|
--help|-h|-?)
|
||||||
|
Usage
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
Logger "Unknown option '$i'" "ERROR"
|
||||||
|
Usage
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
GetCommandlineArguments "$@"
|
||||||
|
|
||||||
|
CONF_DIR=$FAKEROOT/etc/$PROGRAM
|
||||||
|
BIN_DIR="$FAKEROOT/usr/local/bin"
|
||||||
|
SERVICE_DIR_INIT=$FAKEROOT/etc/init.d
|
||||||
|
# Should be /usr/lib/systemd/system, but /lib/systemd/system exists on debian & rhel / fedora
|
||||||
|
SERVICE_DIR_SYSTEMD_SYSTEM=$FAKEROOT/lib/systemd/system
|
||||||
|
SERVICE_DIR_SYSTEMD_USER=$FAKEROOT/etc/systemd/user
|
||||||
|
SERVICE_DIR_OPENRC=$FAKEROOT/etc/init.d
|
||||||
|
|
||||||
|
if [ "$PROGRAM" == "osync" ]; then
|
||||||
|
SERVICE_NAME="osync-srv"
|
||||||
|
TARGET_HELPER_SERVICE_NAME="osync-target-helper-srv"
|
||||||
|
|
||||||
|
TARGET_HELPER_SERVICE_FILE_INIT="$TARGET_HELPER_SERVICE_NAME"
|
||||||
|
TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM="$TARGET_HELPER_SERVICE_NAME@.service"
|
||||||
|
TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER="$TARGET_HELPER_SERVICE_NAME@.service.user"
|
||||||
|
TARGET_HELPER_SERVICE_FILE_OPENRC="$TARGET_HELPER_SERVICE_NAME-openrc"
|
||||||
|
elif [ "$PROGRAM" == "pmocr" ]; then
|
||||||
|
SERVICE_NAME="pmocr-srv"
|
||||||
|
fi
|
||||||
|
|
||||||
|
SERVICE_FILE_INIT="$SERVICE_NAME"
|
||||||
|
SERVICE_FILE_SYSTEMD_SYSTEM="$SERVICE_NAME@.service"
|
||||||
|
SERVICE_FILE_SYSTEMD_USER="$SERVICE_NAME@.service.user"
|
||||||
|
SERVICE_FILE_OPENRC="$SERVICE_NAME-openrc"
|
||||||
|
|
||||||
|
## Generic code
|
||||||
|
|
||||||
|
trap GenericTrapQuit TERM EXIT HUP QUIT
|
||||||
|
|
||||||
if [ ! -w "$(dirname $LOG_FILE)" ]; then
|
if [ ! -w "$(dirname $LOG_FILE)" ]; then
|
||||||
echo "Cannot write to log [$(dirname $LOG_FILE)]."
|
echo "Cannot write to log [$(dirname $LOG_FILE)]."
|
||||||
|
@ -968,7 +1007,11 @@ umask 0022
|
||||||
|
|
||||||
GetLocalOS
|
GetLocalOS
|
||||||
SetLocalOSSettings
|
SetLocalOSSettings
|
||||||
GetInit
|
# On Mac OS this always produces a warning which causes the installer to fail with exit code 2
|
||||||
|
# Since we know it won't work anyway, and that's fine, just skip this step
|
||||||
|
if $DO_INIT; then
|
||||||
|
GetInit
|
||||||
|
fi
|
||||||
|
|
||||||
STATS_LINK="http://instcount.netpower.fr?program=$PROGRAM&version=$PROGRAM_VERSION&os=$OS&action=$ACTION"
|
STATS_LINK="http://instcount.netpower.fr?program=$PROGRAM&version=$PROGRAM_VERSION&os=$OS&action=$ACTION"
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
SUBPROGRAM=osync
|
SUBPROGRAM=osync
|
||||||
PROGRAM="$SUBPROGRAM-batch" # Batch program to run osync / obackup instances sequentially and rerun failed ones
|
PROGRAM="$SUBPROGRAM-batch" # Batch program to run osync / obackup instances sequentially and rerun failed ones
|
||||||
AUTHOR="(L) 2013-2018 by Orsiris de Jong"
|
AUTHOR="(L) 2013-2020 by Orsiris de Jong"
|
||||||
CONTACT="http://www.netpower.fr - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr - ozy@netpower.fr"
|
||||||
PROGRAM_BUILD=2018100201
|
PROGRAM_BUILD=2020031502
|
||||||
|
|
||||||
## Runs an osync /obackup instance for every conf file found
|
## Runs an osync /obackup instance for every conf file found
|
||||||
## If an instance fails, run it again if time permits
|
## If an instance fails, run it again if time permits
|
||||||
|
@ -34,9 +34,6 @@ elif [ -w /var/tmp ]; then
|
||||||
else
|
else
|
||||||
RUN_DIR=.
|
RUN_DIR=.
|
||||||
fi
|
fi
|
||||||
|
|
||||||
trap TrapQuit TERM EXIT HUP QUIT
|
|
||||||
|
|
||||||
# No need to edit under this line ##############################################################
|
# No need to edit under this line ##############################################################
|
||||||
|
|
||||||
#### RemoteLogger SUBSET ####
|
#### RemoteLogger SUBSET ####
|
||||||
|
@ -57,8 +54,8 @@ function _Logger {
|
||||||
echo -e "$logValue" >> "$LOG_FILE"
|
echo -e "$logValue" >> "$LOG_FILE"
|
||||||
|
|
||||||
# Build current log file for alerts if we have a sufficient environment
|
# Build current log file for alerts if we have a sufficient environment
|
||||||
if [ "$RUN_DIR/$PROGRAM" != "/" ]; then
|
if [ "$_LOGGER_WRITE_PARTIAL_LOGS" == true ] && [ "$RUN_DIR/$PROGRAM" != "/" ]; then
|
||||||
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP.log"
|
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM._Logger.$SCRIPT_PID.$TSTAMP"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -82,7 +79,7 @@ function RemoteLogger {
|
||||||
local prefix
|
local prefix
|
||||||
|
|
||||||
if [ "$_LOGGER_PREFIX" == "time" ]; then
|
if [ "$_LOGGER_PREFIX" == "time" ]; then
|
||||||
prefix="TIME: $SECONDS - "
|
prefix="RTIME: $SECONDS - "
|
||||||
elif [ "$_LOGGER_PREFIX" == "date" ]; then
|
elif [ "$_LOGGER_PREFIX" == "date" ]; then
|
||||||
prefix="R $(date) - "
|
prefix="R $(date) - "
|
||||||
else
|
else
|
||||||
|
@ -91,29 +88,29 @@ function RemoteLogger {
|
||||||
|
|
||||||
if [ "$level" == "CRITICAL" ]; then
|
if [ "$level" == "CRITICAL" ]; then
|
||||||
_Logger "" "$prefix\e[1;33;41m$value\e[0m" true
|
_Logger "" "$prefix\e[1;33;41m$value\e[0m" true
|
||||||
if [ $_DEBUG == true ]; then
|
if [ "$_DEBUG" == true ]; then
|
||||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "ERROR" ]; then
|
elif [ "$level" == "ERROR" ]; then
|
||||||
_Logger "" "$prefix\e[31m$value\e[0m" true
|
_Logger "" "$prefix\e[31m$value\e[0m" true
|
||||||
if [ $_DEBUG == true ]; then
|
if [ "$_DEBUG" == true ]; then
|
||||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "WARN" ]; then
|
elif [ "$level" == "WARN" ]; then
|
||||||
_Logger "" "$prefix\e[33m$value\e[0m" true
|
_Logger "" "$prefix\e[33m$value\e[0m" true
|
||||||
if [ $_DEBUG == true ]; then
|
if [ "$_DEBUG" == true ]; then
|
||||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "NOTICE" ]; then
|
elif [ "$level" == "NOTICE" ]; then
|
||||||
if [ $_LOGGER_ERR_ONLY != true ]; then
|
if [ "$_LOGGER_ERR_ONLY" != true ]; then
|
||||||
_Logger "" "$prefix$value"
|
_Logger "" "$prefix$value"
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "VERBOSE" ]; then
|
elif [ "$level" == "VERBOSE" ]; then
|
||||||
if [ $_LOGGER_VERBOSE == true ]; then
|
if [ "$_LOGGER_VERBOSE" == true ]; then
|
||||||
_Logger "" "$prefix$value"
|
_Logger "" "$prefix$value"
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
|
@ -163,24 +160,24 @@ function Logger {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Obfuscate _REMOTE_TOKEN in logs (for ssh_filter usage only in osync and obackup)
|
## Obfuscate _REMOTE_TOKEN in logs (for ssh_filter usage only in osync and obackup)
|
||||||
value="${value/env _REMOTE_TOKEN=$_REMOTE_TOKEN/__(o_O)__}"
|
value="${value/env _REMOTE_TOKEN=$_REMOTE_TOKEN/env _REMOTE_TOKEN=__o_O__}"
|
||||||
value="${value/env _REMOTE_TOKEN=\$_REMOTE_TOKEN/__(o_O)__}"
|
value="${value/env _REMOTE_TOKEN=\$_REMOTE_TOKEN/env _REMOTE_TOKEN=__o_O__}"
|
||||||
|
|
||||||
if [ "$level" == "CRITICAL" ]; then
|
if [ "$level" == "CRITICAL" ]; then
|
||||||
_Logger "$prefix($level):$value" "$prefix\e[1;33;41m$value\e[0m" true
|
_Logger "$prefix($level):$value" "$prefix\e[1;33;41m$value\e[0m" true
|
||||||
ERROR_ALERT=true
|
ERROR_ALERT=true
|
||||||
# ERROR_ALERT / WARN_ALERT is not set in main when Logger is called from a subprocess. Need to keep this flag.
|
# ERROR_ALERT / WARN_ALERT is not set in main when Logger is called from a subprocess. We need to create these flag files for ERROR_ALERT / WARN_ALERT to be picked up by Alert
|
||||||
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID.$TSTAMP"
|
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.ERROR_ALERT.$SCRIPT_PID.$TSTAMP"
|
||||||
return
|
return
|
||||||
elif [ "$level" == "ERROR" ]; then
|
elif [ "$level" == "ERROR" ]; then
|
||||||
_Logger "$prefix($level):$value" "$prefix\e[91m$value\e[0m" true
|
_Logger "$prefix($level):$value" "$prefix\e[91m$value\e[0m" true
|
||||||
ERROR_ALERT=true
|
ERROR_ALERT=true
|
||||||
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID.$TSTAMP"
|
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.ERROR_ALERT.$SCRIPT_PID.$TSTAMP"
|
||||||
return
|
return
|
||||||
elif [ "$level" == "WARN" ]; then
|
elif [ "$level" == "WARN" ]; then
|
||||||
_Logger "$prefix($level):$value" "$prefix\e[33m$value\e[0m" true
|
_Logger "$prefix($level):$value" "$prefix\e[33m$value\e[0m" true
|
||||||
WARN_ALERT=true
|
WARN_ALERT=true
|
||||||
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.warn.$SCRIPT_PID.$TSTAMP"
|
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.WARN_ALERT.$SCRIPT_PID.$TSTAMP"
|
||||||
return
|
return
|
||||||
elif [ "$level" == "NOTICE" ]; then
|
elif [ "$level" == "NOTICE" ]; then
|
||||||
if [ "$_LOGGER_ERR_ONLY" != true ]; then
|
if [ "$_LOGGER_ERR_ONLY" != true ]; then
|
||||||
|
@ -188,7 +185,7 @@ function Logger {
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "VERBOSE" ]; then
|
elif [ "$level" == "VERBOSE" ]; then
|
||||||
if [ $_LOGGER_VERBOSE == true ]; then
|
if [ "$_LOGGER_VERBOSE" == true ]; then
|
||||||
_Logger "$prefix($level):$value" "$prefix$value"
|
_Logger "$prefix($level):$value" "$prefix$value"
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
|
@ -205,6 +202,41 @@ function Logger {
|
||||||
_Logger "Value was: $prefix$value" "Value was: $prefix$value" true
|
_Logger "Value was: $prefix$value" "Value was: $prefix$value" true
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
function CleanUp {
|
||||||
|
# Exit controlmaster before the socket gets deleted
|
||||||
|
if [ "$SSH_CONTROLMASTER" == true ] && [ "$SSH_CMD" != "" ]; then
|
||||||
|
$SSH_CMD -O exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$_DEBUG" != true ]; then
|
||||||
|
# Removing optional remote $RUN_DIR that goes into local $RUN_DIR
|
||||||
|
if [ -d "$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP" ]; then
|
||||||
|
rm -rf "$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP"
|
||||||
|
fi
|
||||||
|
# Removing all temporary run files
|
||||||
|
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP"
|
||||||
|
# Fix for sed -i requiring backup extension for BSD & Mac (see all sed -i statements)
|
||||||
|
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP.tmp"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function GenericTrapQuit {
|
||||||
|
local exitcode=0
|
||||||
|
|
||||||
|
# Get ERROR / WARN alert flags from subprocesses that call Logger
|
||||||
|
if [ -f "$RUN_DIR/$PROGRAM.WARN_ALERT.$SCRIPT_PID.$TSTAMP" ]; then
|
||||||
|
WARN_ALERT=true
|
||||||
|
exitcode=2
|
||||||
|
fi
|
||||||
|
if [ -f "$RUN_DIR/$PROGRAM.ERROR_ALERT.$SCRIPT_PID.$TSTAMP" ]; then
|
||||||
|
ERROR_ALERT=true
|
||||||
|
exitcode=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
CleanUp
|
||||||
|
exit $exitcode
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function CheckEnvironment {
|
function CheckEnvironment {
|
||||||
## osync / obackup executable full path can be set here if it cannot be found on the system
|
## osync / obackup executable full path can be set here if it cannot be found on the system
|
||||||
|
@ -294,6 +326,8 @@ function Usage {
|
||||||
exit 128
|
exit 128
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trap GenericTrapQuit TERM EXIT HUP QUIT
|
||||||
|
|
||||||
opts=""
|
opts=""
|
||||||
for i in "$@"
|
for i in "$@"
|
||||||
do
|
do
|
||||||
|
|
|
@ -9,13 +9,13 @@
|
||||||
##### Any other command will return a "syntax error"
|
##### Any other command will return a "syntax error"
|
||||||
##### For details, see ssh_filter.log
|
##### For details, see ssh_filter.log
|
||||||
|
|
||||||
SCRIPT_BUILD=2017020802
|
# BUILD=2017020802
|
||||||
|
|
||||||
## Allow sudo
|
## Allow sudo
|
||||||
SUDO_EXEC=yes
|
SUDO_EXEC=true
|
||||||
|
|
||||||
## Log all valid commands too
|
## Log all valid commands too
|
||||||
_DEBUG=no
|
_DEBUG=false
|
||||||
|
|
||||||
## Set remote token in authorized_keys
|
## Set remote token in authorized_keys
|
||||||
if [ "$1" != "" ]; then
|
if [ "$1" != "" ]; then
|
||||||
|
@ -25,12 +25,12 @@ fi
|
||||||
LOG_FILE="${HOME}/.ssh/ssh_filter.log"
|
LOG_FILE="${HOME}/.ssh/ssh_filter.log"
|
||||||
|
|
||||||
function Log {
|
function Log {
|
||||||
DATE=$(date)
|
DATE="$(date)"
|
||||||
echo "$DATE - $1" >> "$LOG_FILE"
|
echo "$DATE - $1" >> "$LOG_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
function Go {
|
function Go {
|
||||||
if [ "$_DEBUG" == "yes" ]; then
|
if [ "$_DEBUG" == true ]; then
|
||||||
Log "Executing [$SSH_ORIGINAL_COMMAND]."
|
Log "Executing [$SSH_ORIGINAL_COMMAND]."
|
||||||
fi
|
fi
|
||||||
eval "$SSH_ORIGINAL_COMMAND"
|
eval "$SSH_ORIGINAL_COMMAND"
|
||||||
|
@ -38,7 +38,7 @@ function Go {
|
||||||
|
|
||||||
case "${SSH_ORIGINAL_COMMAND}" in
|
case "${SSH_ORIGINAL_COMMAND}" in
|
||||||
*"env _REMOTE_TOKEN=$_REMOTE_TOKEN"*)
|
*"env _REMOTE_TOKEN=$_REMOTE_TOKEN"*)
|
||||||
if [ "$SUDO_EXEC" != "yes" ] && [[ $SSH_ORIGINAL_COMMAND == *"sudo "* ]]; then
|
if [ "$SUDO_EXEC" != true ] && [[ $SSH_ORIGINAL_COMMAND == *"sudo "* ]]; then
|
||||||
Log "Command [$SSH_ORIGINAL_COMMAND] contains sudo which is not allowed."
|
Log "Command [$SSH_ORIGINAL_COMMAND] contains sudo which is not allowed."
|
||||||
echo "Syntax error unexpected end of file"
|
echo "Syntax error unexpected end of file"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
###### osync - Rsync based two way sync engine with fault tolerance
|
###### osync - Rsync based two way sync engine with fault tolerance
|
||||||
###### (C) 2013-2019 by Orsiris de Jong (www.netpower.fr)
|
###### (C) 2013-2023 by Orsiris de Jong (www.netpower.fr)
|
||||||
|
|
||||||
[GENERAL]
|
[GENERAL]
|
||||||
CONFIG_FILE_REVISION=1.3.0
|
CONFIG_FILE_REVISION=1.3.0
|
||||||
|
@ -21,6 +21,9 @@ SSH_RSA_PRIVATE_KEY="/home/backupuser/.ssh/id_rsa"
|
||||||
## Alternatively, you may specify an SSH password file (less secure). Needs sshpass utility installed.
|
## Alternatively, you may specify an SSH password file (less secure). Needs sshpass utility installed.
|
||||||
SSH_PASSWORD_FILE=""
|
SSH_PASSWORD_FILE=""
|
||||||
|
|
||||||
|
## use the KRB5 credential cache to access SSH or rsync
|
||||||
|
#KRB5=true
|
||||||
|
|
||||||
## When using ssh filter, you must specify a remote token matching the one setup in authorized_keys
|
## When using ssh filter, you must specify a remote token matching the one setup in authorized_keys
|
||||||
_REMOTE_TOKEN=SomeAlphaNumericToken9
|
_REMOTE_TOKEN=SomeAlphaNumericToken9
|
||||||
|
|
||||||
|
@ -62,14 +65,33 @@ RSYNC_EXCLUDE_FROM=""
|
||||||
## List elements separator char. You may set an alternative separator char for your directories lists above.
|
## List elements separator char. You may set an alternative separator char for your directories lists above.
|
||||||
PATH_SEPARATOR_CHAR=";"
|
PATH_SEPARATOR_CHAR=";"
|
||||||
|
|
||||||
|
## By default, osync stores its state into the replica_path/.osync_workdir/state
|
||||||
|
## This behavior can be changed for initiator or slave by overriding the following with an absolute path to a statedir, ex /opt/osync_state/initiator
|
||||||
|
## If osync runs locally, initiator and target state dirs **must** be different
|
||||||
|
INITIATOR_CUSTOM_STATE_DIR=""
|
||||||
|
TARGET_CUSTOM_STATE_DIR=""
|
||||||
|
|
||||||
[REMOTE_OPTIONS]
|
[REMOTE_OPTIONS]
|
||||||
|
|
||||||
## ssh compression should be used unless your remote connection is good enough (LAN)
|
## ssh compression should be used on WAN links, unless your remote connection is good enough (LAN), in which case it would slow down things
|
||||||
SSH_COMPRESSION=true
|
SSH_COMPRESSION=false
|
||||||
|
|
||||||
|
## Optional ssh options. Example to lower CPU usage on ssh compression, one can specify '-T -c arcfour -o Compression=no -x'
|
||||||
|
## -T = turn off pseudo-tty, -c arcfour = weakest but fasted ssh encryption (destination must accept "Ciphers arcfour" in sshd_config), -x turns off X11 forwarding
|
||||||
|
## arcfour isn't accepted on most newer systems, you may then prefer any AES encryption if processor has aes-ni hardware acceleration
|
||||||
|
## If the system does not provide hardware assisted acceleration, chacha20-poly1305@openssh.com is a good cipher to select
|
||||||
|
## See: https://wiki.csnu.org/index.php/SSH_ciphers_speed_comparison
|
||||||
|
## -o Compression=no is already handled by SSH_COMPRESSION option
|
||||||
|
## Uncomment the following line to use those optimizations, on secured links only
|
||||||
|
#SSH_OPTIONAL_ARGS="-T -c aes128-ctr -x"
|
||||||
|
#SSH_OPTIONAL_ARGS="-T -c chacha20-poly1305@openssh.com -x"
|
||||||
|
|
||||||
## Ignore ssh known hosts. DANGER WILL ROBINSON DANGER ! This can lead to security issues. Only enable this if you know what you're doing.
|
## Ignore ssh known hosts. DANGER WILL ROBINSON DANGER ! This can lead to security issues. Only enable this if you know what you're doing.
|
||||||
SSH_IGNORE_KNOWN_HOSTS=false
|
SSH_IGNORE_KNOWN_HOSTS=false
|
||||||
|
|
||||||
|
## Use a single TCP connection for all SSH calls. Will make remote sync faster, but may work less good on lossy links.
|
||||||
|
SSH_CONTROLMASTER=false
|
||||||
|
|
||||||
## Check for connectivity to remote host before launching remote sync task. Be sure the hosts responds to ping. Failing to ping will stop sync.
|
## Check for connectivity to remote host before launching remote sync task. Be sure the hosts responds to ping. Failing to ping will stop sync.
|
||||||
REMOTE_HOST_PING=false
|
REMOTE_HOST_PING=false
|
||||||
|
|
||||||
|
@ -81,7 +103,7 @@ REMOTE_3RD_PARTY_HOSTS="www.kernel.org www.google.com"
|
||||||
[MISC_OPTIONS]
|
[MISC_OPTIONS]
|
||||||
|
|
||||||
## Optional arguments passed to rsync executable. The following are already managed by the program and shoul never be passed here
|
## Optional arguments passed to rsync executable. The following are already managed by the program and shoul never be passed here
|
||||||
## -r -l -p -t -g -o -D -E - u- i- n --executability -A -X -L -K -H -8 -zz –skip-compress –checksum –bwlimit –partial –partial-dir –no-whole-file –whole-file –backup –backup-dir –suffix
|
## -r -l -p -t -g -o -D -E - u- i- n --executability -A -X -L -K -H -8 --zz -–skip-compress -–checksum –-bwlimit –-partial –-partial-dir –-no-whole-file –-whole-file –-backup –-backup-dir –-suffix
|
||||||
## --exclude --exclude-from --include --include-from --list-only --stats
|
## --exclude --exclude-from --include --include-from --list-only --stats
|
||||||
## When dealing with different filesystems for sync, or using SMB mountpoints, try adding --modify-window=2 --omit-dir-times as optional arguments.
|
## When dealing with different filesystems for sync, or using SMB mountpoints, try adding --modify-window=2 --omit-dir-times as optional arguments.
|
||||||
RSYNC_OPTIONAL_ARGS=""
|
RSYNC_OPTIONAL_ARGS=""
|
||||||
|
@ -127,7 +149,7 @@ MAX_WAIT=7200
|
||||||
[BACKUP_DELETE_OPTIONS]
|
[BACKUP_DELETE_OPTIONS]
|
||||||
|
|
||||||
## Log a list of conflictual files (EXPERIMENTAL)
|
## Log a list of conflictual files (EXPERIMENTAL)
|
||||||
LOG_CONFLICTS=true
|
LOG_CONFLICTS=false
|
||||||
## Send an email when conflictual files are found (implies LOG_CONFLICTS)
|
## Send an email when conflictual files are found (implies LOG_CONFLICTS)
|
||||||
ALERT_CONFLICTS=false
|
ALERT_CONFLICTS=false
|
||||||
## Enabling this option will keep a backup of a file on the target replica if it gets updated from the source replica. Backups will be made to .osync_workdir/backups
|
## Enabling this option will keep a backup of a file on the target replica if it gets updated from the source replica. Backups will be made to .osync_workdir/backups
|
||||||
|
@ -166,13 +188,15 @@ PARTIAL=false
|
||||||
DELTA_COPIES=true
|
DELTA_COPIES=true
|
||||||
|
|
||||||
[ALERT_OPTIONS]
|
[ALERT_OPTIONS]
|
||||||
|
|
||||||
## List of alert mails separated by spaces
|
## List of alert mails separated by spaces
|
||||||
## Most Unix systems (including Win10 bash) have mail support out of the box
|
## Most Unix systems (including Win10 bash) have mail support out of the box
|
||||||
## Just make sure that the current user has enough privileges to use mail / mutt / sendmail and that the mail system is configured to allow outgoing mails
|
## Just make sure that the current user has enough privileges to use mail / mutt / sendmail and that the mail system is configured to allow outgoing mails
|
||||||
## on pfSense platform, smtp support needs to be configured in System > Advanced > Notifications
|
## on pfSense platform, smtp support needs to be configured in System > Advanced > Notifications
|
||||||
DESTINATION_MAILS="your@alert.tld"
|
DESTINATION_MAILS="your@alert.tld"
|
||||||
|
|
||||||
|
## By default, only sync warnings / errors are sent by mail. This default behavior can be overrided here
|
||||||
|
ALWAYS_SEND_MAILS=false
|
||||||
|
|
||||||
## Optional change of mail body encoding (using iconv)
|
## Optional change of mail body encoding (using iconv)
|
||||||
## By default, all mails are sent in UTF-8 format without header (because of maximum compatibility of all platforms)
|
## By default, all mails are sent in UTF-8 format without header (because of maximum compatibility of all platforms)
|
||||||
## You may specify an optional encoding here (like "ISO-8859-1" or whatever iconv can handle)
|
## You may specify an optional encoding here (like "ISO-8859-1" or whatever iconv can handle)
|
||||||
|
@ -191,7 +215,7 @@ SMTP_PASSWORD=
|
||||||
|
|
||||||
[EXECUTION_HOOKS]
|
[EXECUTION_HOOKS]
|
||||||
|
|
||||||
## Commands can will be run before and / or after sync process (remote execution will only happen if REMOTE_OPERATION is set).
|
## Commands can will be run before and / or after sync process
|
||||||
LOCAL_RUN_BEFORE_CMD=""
|
LOCAL_RUN_BEFORE_CMD=""
|
||||||
LOCAL_RUN_AFTER_CMD=""
|
LOCAL_RUN_AFTER_CMD=""
|
||||||
|
|
||||||
|
@ -202,7 +226,7 @@ REMOTE_RUN_AFTER_CMD=""
|
||||||
MAX_EXEC_TIME_PER_CMD_BEFORE=0
|
MAX_EXEC_TIME_PER_CMD_BEFORE=0
|
||||||
MAX_EXEC_TIME_PER_CMD_AFTER=0
|
MAX_EXEC_TIME_PER_CMD_AFTER=0
|
||||||
|
|
||||||
## Stops osync execution if one of the above commands fail
|
## Stops osync execution if one of the above before commands fail
|
||||||
STOP_ON_CMD_ERROR=true
|
STOP_ON_CMD_ERROR=true
|
||||||
|
|
||||||
## Run local and remote after sync commands even on failure
|
## Run local and remote after sync commands even on failure
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
###### osync - Rsync based two way sync engine with fault tolerance
|
###### osync - Rsync based two way sync engine with fault tolerance
|
||||||
###### (C) 2013-2018 by Orsiris de Jong (www.netpower.fr)
|
###### (C) 2013-2020 by Orsiris de Jong (www.netpower.fr)
|
||||||
###### v1.3x target helper config file rev 2018100101
|
|
||||||
|
|
||||||
## ---------- GENERAL OPTIONS
|
[GENERAL]
|
||||||
|
CONFIG_FILE_REVISION=1.3.0
|
||||||
|
|
||||||
## Sync job identification
|
## Sync job identification
|
||||||
INSTANCE_ID="target_test"
|
INSTANCE_ID="target_test"
|
||||||
|
@ -30,18 +30,18 @@ _REMOTE_TOKEN=SomeAlphaNumericToken9
|
||||||
LOGFILE=""
|
LOGFILE=""
|
||||||
|
|
||||||
## If enabled, synchronization on remote system will be processed as superuser. See documentation for /etc/sudoers file configuration.
|
## If enabled, synchronization on remote system will be processed as superuser. See documentation for /etc/sudoers file configuration.
|
||||||
SUDO_EXEC=no
|
SUDO_EXEC=false
|
||||||
|
|
||||||
## ---------- REMOTE SYNC OPTIONS
|
## ---------- REMOTE SYNC OPTIONS
|
||||||
|
|
||||||
## ssh compression should be used unless your remote connection is good enough (LAN)
|
## ssh compression should be used unless your remote connection is good enough (LAN)
|
||||||
SSH_COMPRESSION=yes
|
SSH_COMPRESSION=true
|
||||||
|
|
||||||
## Ignore ssh known hosts. DANGER WILL ROBINSON DANGER ! This can lead to security issues. Only enable this if you know what you're doing.
|
## Ignore ssh known hosts. DANGER WILL ROBINSON DANGER ! This can lead to security issues. Only enable this if you know what you're doing.
|
||||||
SSH_IGNORE_KNOWN_HOSTS=no
|
SSH_IGNORE_KNOWN_HOSTS=false
|
||||||
|
|
||||||
## Check for connectivity to remote host before launching remote sync task. Be sure the hosts responds to ping. Failing to ping will stop sync.
|
## Check for connectivity to remote host before launching remote sync task. Be sure the hosts responds to ping. Failing to ping will stop sync.
|
||||||
REMOTE_HOST_PING=no
|
REMOTE_HOST_PING=false
|
||||||
|
|
||||||
## Check for internet access by pinging one or more 3rd party hosts before remote sync task. Leave empty if you don't want this check to be be performed. Failing to ping will stop sync.
|
## Check for internet access by pinging one or more 3rd party hosts before remote sync task. Leave empty if you don't want this check to be be performed. Failing to ping will stop sync.
|
||||||
## If you use this function, you should set more than one 3rd party host, and be sure you can ping them.
|
## If you use this function, you should set more than one 3rd party host, and be sure you can ping them.
|
||||||
|
@ -58,7 +58,7 @@ MIN_WAIT=60
|
||||||
## Use 0 to wait indefinitely.
|
## Use 0 to wait indefinitely.
|
||||||
MAX_WAIT=7200
|
MAX_WAIT=7200
|
||||||
|
|
||||||
## ---------- ALERT OPTIONS
|
[ALERT_OPTIONS]
|
||||||
|
|
||||||
## List of alert mails separated by spaces
|
## List of alert mails separated by spaces
|
||||||
## Most Unix systems (including Win10 bash) have mail support out of the box
|
## Most Unix systems (including Win10 bash) have mail support out of the box
|
||||||
|
@ -82,7 +82,7 @@ SMTP_ENCRYPTION=none
|
||||||
SMTP_USER=
|
SMTP_USER=
|
||||||
SMTP_PASSWORD=
|
SMTP_PASSWORD=
|
||||||
|
|
||||||
## ---------- EXECUTION HOOKS
|
[EXECUTION_HOOKS]
|
||||||
|
|
||||||
## Commands can will be run before and / or after sync process (remote execution will only happen if REMOTE_OPERATION is set).
|
## Commands can will be run before and / or after sync process (remote execution will only happen if REMOTE_OPERATION is set).
|
||||||
LOCAL_RUN_BEFORE_CMD=""
|
LOCAL_RUN_BEFORE_CMD=""
|
||||||
|
@ -96,7 +96,7 @@ MAX_EXEC_TIME_PER_CMD_BEFORE=0
|
||||||
MAX_EXEC_TIME_PER_CMD_AFTER=0
|
MAX_EXEC_TIME_PER_CMD_AFTER=0
|
||||||
|
|
||||||
## Stops osync execution if one of the above commands fail
|
## Stops osync execution if one of the above commands fail
|
||||||
STOP_ON_CMD_ERROR=yes
|
STOP_ON_CMD_ERROR=true
|
||||||
|
|
||||||
## Run local and remote after sync commands even on failure
|
## Run local and remote after sync commands even on failure
|
||||||
RUN_AFTER_CMD_ON_ERROR=no
|
RUN_AFTER_CMD_ON_ERROR=false
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
PROGRAM="osync instance upgrade script"
|
PROGRAM="osync instance upgrade script"
|
||||||
SUBPROGRAM="osync"
|
SUBPROGRAM="osync"
|
||||||
AUTHOR="(C) 2016-2019 by Orsiris de Jong"
|
AUTHOR="(C) 2016-2020 by Orsiris de Jong"
|
||||||
CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr"
|
||||||
OLD_PROGRAM_VERSION="v1.0x-v1.2x"
|
OLD_PROGRAM_VERSION="v1.0x-v1.2x"
|
||||||
NEW_PROGRAM_VERSION="v1.3x"
|
NEW_PROGRAM_VERSION="v1.3x"
|
||||||
CONFIG_FILE_REVISION=1.3.0
|
CONFIG_FILE_REVISION=1.3.0
|
||||||
PROGRAM_BUILD=2019052105
|
PROGRAM_BUILD=2020012201
|
||||||
|
|
||||||
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
|
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
|
||||||
if ! type "$BASH" > /dev/null; then
|
if ! type "$BASH" > /dev/null; then
|
||||||
|
@ -41,6 +41,7 @@ RSYNC_EXCLUDE_FROM
|
||||||
PATH_SEPARATOR_CHAR
|
PATH_SEPARATOR_CHAR
|
||||||
SSH_COMPRESSION
|
SSH_COMPRESSION
|
||||||
SSH_IGNORE_KNOWN_HOSTS
|
SSH_IGNORE_KNOWN_HOSTS
|
||||||
|
SSH_CONTROLMASTER
|
||||||
REMOTE_HOST_PING
|
REMOTE_HOST_PING
|
||||||
REMOTE_3RD_PARTY_HOSTS
|
REMOTE_3RD_PARTY_HOSTS
|
||||||
RSYNC_OPTIONAL_ARGS
|
RSYNC_OPTIONAL_ARGS
|
||||||
|
@ -69,6 +70,7 @@ CONFLICT_PREVALANCE
|
||||||
SOFT_DELETE
|
SOFT_DELETE
|
||||||
SOFT_DELETE_DAYS
|
SOFT_DELETE_DAYS
|
||||||
SKIP_DELETION
|
SKIP_DELETION
|
||||||
|
SYNC_TYPE
|
||||||
RESUME_SYNC
|
RESUME_SYNC
|
||||||
RESUME_TRY
|
RESUME_TRY
|
||||||
FORCE_STRANGER_LOCK_RESUME
|
FORCE_STRANGER_LOCK_RESUME
|
||||||
|
@ -115,6 +117,7 @@ include
|
||||||
true
|
true
|
||||||
false
|
false
|
||||||
false
|
false
|
||||||
|
false
|
||||||
'www.kernel.org www.google.com'
|
'www.kernel.org www.google.com'
|
||||||
''
|
''
|
||||||
true
|
true
|
||||||
|
@ -133,7 +136,7 @@ true
|
||||||
1801
|
1801
|
||||||
60
|
60
|
||||||
7200
|
7200
|
||||||
true
|
false
|
||||||
false
|
false
|
||||||
true
|
true
|
||||||
false
|
false
|
||||||
|
@ -142,6 +145,7 @@ initiator
|
||||||
true
|
true
|
||||||
30
|
30
|
||||||
''
|
''
|
||||||
|
''
|
||||||
true
|
true
|
||||||
2
|
2
|
||||||
false
|
false
|
||||||
|
@ -226,22 +230,6 @@ function Usage {
|
||||||
exit 128
|
exit 128
|
||||||
}
|
}
|
||||||
|
|
||||||
function CheckEnvironment {
|
|
||||||
if [ "$REMOTE_OPERATION" == "yes" ] || [ "$REMOTE_OPERATION" == true ]; then
|
|
||||||
if ! type -p ssh > /dev/null 2>&1
|
|
||||||
then
|
|
||||||
Logger "ssh not present. Cannot start sync." "CRITICAL"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! type -p rsync > /dev/null 2>&1
|
|
||||||
then
|
|
||||||
Logger "rsync not present. Sync cannot start." "CRITICAL"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function LoadConfigFile {
|
function LoadConfigFile {
|
||||||
local config_file="${1}"
|
local config_file="${1}"
|
||||||
|
|
||||||
|
@ -268,134 +256,134 @@ function _RenameStateFilesLocal {
|
||||||
# Make sure there is no ending slash
|
# Make sure there is no ending slash
|
||||||
state_dir="${state_dir%/}/"
|
state_dir="${state_dir%/}/"
|
||||||
|
|
||||||
if [ -f "$state_dir""master"$TREE_CURRENT_FILENAME ]; then
|
if [ -f "${state_dir}master${TREE_CURRENT_FILENAME}" ]; then
|
||||||
mv -f "$state_dir""master"$TREE_CURRENT_FILENAME "$state_dir""initiator"$TREE_CURRENT_FILENAME
|
mv -f "${state_dir}master${TREE_CURRENT_FILENAME}" "${state_dir}initiator${TREE_CURRENT_FILENAME}"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"master"$TREE_CURRENT_FILENAME
|
echo "Error while rewriting ${state_dir}master${TREE_CURRENT_FILENAME}"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -f "$state_dir""master"$TREE_AFTER_FILENAME ]; then
|
if [ -f "${state_dir}master${TREE_AFTER_FILENAME}" ]; then
|
||||||
mv -f "$state_dir""master"$TREE_AFTER_FILENAME "$state_dir""initiator"$TREE_AFTER_FILENAME
|
mv -f "${state_dir}master${TREE_AFTER_FILENAME}" "${state_dir}initiator${TREE_AFTER_FILENAME}"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"master"$TREE_AFTER_FILENAME
|
echo "Error while rewriting ${state_dir}master${TREE_AFTER_FILENAME}"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -f "$state_dir""master"$DELETED_LIST_FILENAME ]; then
|
if [ -f "${state_dir}master${DELETED_LIST_FILENAME}" ]; then
|
||||||
mv -f "$state_dir""master"$DELETED_LIST_FILENAME "$state_dir""initiator"$DELETED_LIST_FILENAME
|
mv -f "${state_dir}master${DELETED_LIST_FILENAME}" "${state_dir}initiator${DELETED_LIST_FILENAME}"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"master"$DELETED_LIST_FILENAME
|
echo "Error while rewriting ${state_dir}master${DELETED_LIST_FILENAME}"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
if [ -f "$state_dir""master"$FAILED_DELETE_LIST_FILENAME ]; then
|
if [ -f "${state_dir}master${FAILED_DELETE_LIST_FILENAME}" ]; then
|
||||||
mv -f "$state_dir""master"$FAILED_DELETE_LIST_FILENAME "$state_dir""initiator"$FAILED_DELETE_LIST_FILENAME
|
mv -f "${state_dir}master${FAILED_DELETE_LIST_FILENAME}" "${state_dir}initiator${FAILED_DELETE_LIST_FILENAME}"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"master"$FAILED_DELETE_LIST_FILENAME
|
echo "Error while rewriting ${state_dir}master${FAILED_DELETE_LIST_FILENAME}"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$state_dir""master"$TREE_CURRENT_FILENAME"-dry" ]; then
|
if [ -f "${state_dir}master${TREE_CURRENT_FILENAME}-dry" ]; then
|
||||||
mv -f "$state_dir""master"$TREE_CURRENT_FILENAME"-dry" "$state_dir""initiator"$TREE_CURRENT_FILENAME"-dry"
|
mv -f "${state_dir}master${TREE_CURRENT_FILENAME}-dry" "${state_dir}initiator${TREE_CURRENT_FILENAME}-dry"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"master"$TREE_CURRENT_FILENAME"-dry"
|
echo "Error while rewriting ${state_dir}master${TREE_CURRENT_FILENAME}-dry"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -f "$state_dir""master"$TREE_AFTER_FILENAME"-dry" ]; then
|
if [ -f "${state_dir}master${TREE_AFTER_FILENAME}-dry" ]; then
|
||||||
mv -f "$state_dir""master"$TREE_AFTER_FILENAME"-dry" "$state_dir""initiator"$TREE_AFTER_FILENAME"-dry"
|
mv -f "${state_dir}master${TREE_AFTER_FILENAME}-dry" "${state_dir}initiator${TREE_AFTER_FILENAME}-dry"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"master"$TREE_AFTER_FILENAME"-dry"
|
echo "Error while rewriting ${state_dir}master${TREE_AFTER_FILENAME}-dry"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -f "$state_dir""master"$DELETED_LIST_FILENAME"-dry" ]; then
|
if [ -f "${state_dir}master${DELETED_LIST_FILENAME}-dry" ]; then
|
||||||
mv -f "$state_dir""master"$DELETED_LIST_FILENAME"-dry" "$state_dir""initiator"$DELETED_LIST_FILENAME"-dry"
|
mv -f "${state_dir}master${DELETED_LIST_FILENAME}-dry" "${state_dir}initiator${DELETED_LIST_FILENAME}-dry"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"master"$DELETED_LIST_FILENAME"-dry"
|
echo "Error while rewriting ${state_dir}master${DELETED_LIST_FILENAME}-dry"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -f "$state_dir""master"$FAILED_DELETE_LIST_FILENAME"-dry" ]; then
|
if [ -f "${state_dir}master${FAILED_DELETE_LIST_FILENAME}-dry" ]; then
|
||||||
mv -f "$state_dir""master"$FAILED_DELETE_LIST_FILENAME"-dry" "$state_dir""initiator"$FAILED_DELETE_LIST_FILENAME"-dry"
|
mv -f "${state_dir}master${FAILED_DELETE_LIST_FILENAME}-dry" "${state_dir}initiator${FAILED_DELETE_LIST_FILENAME}-dry"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"master"$FAILED_DELETE_LIST_FILENAME"-dry"
|
echo "Error while rewriting ${state_dir}master${FAILED_DELETE_LIST_FILENAME}-dry"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$state_dir""slave"$TREE_CURRENT_FILENAME ]; then
|
if [ -f "${state_dir}slave${TREE_CURRENT_FILENAME}" ]; then
|
||||||
mv -f "$state_dir""slave"$TREE_CURRENT_FILENAME "$state_dir""target"$TREE_CURRENT_FILENAME
|
mv -f "${state_dir}slave${TREE_CURRENT_FILENAME}" "${state_dir}target${TREE_CURRENT_FILENAME}"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"slave"$TREE_CURRENT_FILENAME
|
echo "Error while rewriting ${state_dir}slave${TREE_CURRENT_FILENAME}"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -f "$state_dir""slave"$TREE_AFTER_FILENAME ]; then
|
if [ -f "${state_dir}slave${TREE_AFTER_FILENAME}" ]; then
|
||||||
mv -f "$state_dir""slave"$TREE_AFTER_FILENAME "$state_dir""target"$TREE_AFTER_FILENAME
|
mv -f "${state_dir}slave${TREE_AFTER_FILENAME}" "${state_dir}target${TREE_AFTER_FILENAME}"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"slave"$TREE_AFTER_FILENAME
|
echo "Error while rewriting ${state_dir}slave${TREE_AFTER_FILENAME}"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -f "$state_dir""slave"$DELETED_LIST_FILENAME ]; then
|
if [ -f "${state_dir}slave${DELETED_LIST_FILENAME}" ]; then
|
||||||
mv -f "$state_dir""slave"$DELETED_LIST_FILENAME "$state_dir""target"$DELETED_LIST_FILENAME
|
mv -f "${state_dir}slave${DELETED_LIST_FILENAME}" "${state_dir}target${DELETED_LIST_FILENAME}"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"slave"$DELETED_LIST_FILENAME
|
echo "Error while rewriting ${state_dir}slave${DELETED_LIST_FILENAME}"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -f "$state_dir""slave"$FAILED_DELETE_LIST_FILENAME ]; then
|
if [ -f "${state_dir}slave${FAILED_DELETE_LIST_FILENAME}" ]; then
|
||||||
mv -f "$state_dir""slave"$FAILED_DELETE_LIST_FILENAME "$state_dir""target"$FAILED_DELETE_LIST_FILENAME
|
mv -f "${state_dir}slave${FAILED_DELETE_LIST_FILENAME}" "${state_dir}target${FAILED_DELETE_LIST_FILENAME}"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"slave"$FAILED_DELETE_LIST_FILENAME
|
echo "Error while rewriting ${state_dir}slave${FAILED_DELETE_LIST_FILENAME}"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$state_dir""slave"$TREE_CURRENT_FILENAME"-dry" ]; then
|
if [ -f "${state_dir}slave${TREE_CURRENT_FILENAME}-dry" ]; then
|
||||||
mv -f "$state_dir""slave"$TREE_CURRENT_FILENAME"-dry" "$state_dir""target"$TREE_CURRENT_FILENAME"-dry"
|
mv -f "${state_dir}slave${TREE_CURRENT_FILENAME}-dry" "${state_dir}target${TREE_CURRENT_FILENAME}-dry"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"slave"$TREE_CURRENT_FILENAME"-dry"
|
echo "Error while rewriting ${state_dir}slave${TREE_CURRENT_FILENAME}-dry"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -f "$state_dir""slave"$TREE_AFTER_FILENAME"-dry" ]; then
|
if [ -f "${state_dir}slave${TREE_AFTER_FILENAME}-dry" ]; then
|
||||||
mv -f "$state_dir""slave"$TREE_AFTER_FILENAME"-dry" "$state_dir""target"$TREE_AFTER_FILENAME"-dry"
|
mv -f "${state_dir}slave${TREE_AFTER_FILENAME}-dry" "${state_dir}target${TREE_AFTER_FILENAME}-dry"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"slave"$TREE_AFTER_FILENAME"-dry"
|
echo "Error while rewriting ${state_dir}slave${TREE_AFTER_FILENAME}-dry"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -f "$state_dir""slave"$DELETED_LIST_FILENAME"-dry" ]; then
|
if [ -f "${state_dir}slave${DELETED_LIST_FILENAME}-dry" ]; then
|
||||||
mv -f "$state_dir""slave"$DELETED_LIST_FILENAME"-dry" "$state_dir""target"$DELETED_LIST_FILENAME"-dry"
|
mv -f "${state_dir}slave${DELETED_LIST_FILENAME}-dry" "${state_dir}target${DELETED_LIST_FILENAME}-dry"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"slave"$DELETED_LIST_FILENAME"-dry"
|
echo "Error while rewriting ${state_dir}slave${DELETED_LIST_FILENAME}-dry"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -f "$state_dir""slave"$FAILED_DELETE_LIST_FILENAME"-dry" ]; then
|
if [ -f "${state_dir}slave${FAILED_DELETE_LIST_FILENAME}-dry" ]; then
|
||||||
mv -f "$state_dir""slave"$FAILED_DELETE_LIST_FILENAME"-dry" "$state_dir""target"$FAILED_DELETE_LIST_FILENAME"-dry"
|
mv -f "${state_dir}slave${FAILED_DELETE_LIST_FILENAME}-dry" "${state_dir}target${FAILED_DELETE_LIST_FILENAME}-dry"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"slave"$FAILED_DELETE_LIST_FILENAME"-dry"
|
echo "Error while rewriting ${state_dir}slave${FAILED_DELETE_LIST_FILENAME}-dry"
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
|
@ -418,24 +406,24 @@ $SSH_CMD state_dir="${1}" DELETED_LIST_FILENAME="$DELETED_LIST_FILENAME" FAILED_
|
||||||
state_dir="${state_dir%/}/"
|
state_dir="${state_dir%/}/"
|
||||||
rewrite=false
|
rewrite=false
|
||||||
|
|
||||||
if [ -f "$state_dir""master"$DELETED_LIST_FILENAME ]; then
|
if [ -f "${state_dir}master${DELETED_LIST_FILENAME}" ]; then
|
||||||
mv -f "$state_dir""master"$DELETED_LIST_FILENAME "$state_dir""initiator"$DELETED_LIST_FILENAME
|
mv -f "${state_dir}master${DELETED_LIST_FILENAME}" "${state_dir}initiator${DELETED_LIST_FILENAME}"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"master"$DELETED_LIST_FILENAME
|
echo "Error while rewriting "$state_dir"master"$DELETED_LIST_FILENAME
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -f "$state_dir""master"$FAILED_DELETE_LIST_FILENAME ]; then
|
if [ -f "${state_dir}master${FAILED_DELETE_LIST_FILENAME}" ]; then
|
||||||
mv -f "$state_dir""master"$FAILED_DELETE_LIST_FILENAME "$state_dir""initiator"$FAILED_DELETE_LIST_FILENAME
|
mv -f "${state_dir}master${FAILED_DELETE_LIST_FILENAME}" "${state_dir}initiator${FAILED_DELETE_LIST_FILENAME}"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"master"$FAILED_DELETE_LIST_FILENAME
|
echo "Error while rewriting "$state_dir"master"$FAILED_DELETE_LIST_FILENAME
|
||||||
else
|
else
|
||||||
rewrite=true
|
rewrite=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -f "$state_dir""master"$FAILED_DELETE_LIST_FILENAME"-dry" ]; then
|
if [ -f "${state_dir}master${FAILED_DELETE_LIST_FILENAME}-dry" ]; then
|
||||||
mv -f "$state_dir""master"$FAILED_DELETE_LIST_FILENAME"-dry" "$state_dir""initiator"$FAILED_DELETE_LIST_FILENAME"-dry"
|
mv -f "${state_dir}master${FAILED_DELETE_LIST_FILENAME}-dry" "${state_dir}initiator${FAILED_DELETE_LIST_FILENAME}-dry"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo "Error while rewriting "$state_dir"master"$FAILED_DELETE_LIST_FILENAME"-dry"
|
echo "Error while rewriting "$state_dir"master"$FAILED_DELETE_LIST_FILENAME"-dry"
|
||||||
else
|
else
|
||||||
|
@ -520,13 +508,13 @@ function AddMissingConfigOptionsAndFixBooleans {
|
||||||
echo "Added missing ${KEYWORDS[$counter]} config option with default option [${VALUES[$counter]}]"
|
echo "Added missing ${KEYWORDS[$counter]} config option with default option [${VALUES[$counter]}]"
|
||||||
else
|
else
|
||||||
# Not the most elegant but the quickest way :)
|
# Not the most elegant but the quickest way :)
|
||||||
if grep "^${KEYWORDS[$counter]}=yes" > /dev/null "$config_file"; then
|
if grep "^${KEYWORDS[$counter]}=yes$" > /dev/null "$config_file"; then
|
||||||
sed -i'.tmp' 's/^'${KEYWORDS[$counter]}'=.*/'${KEYWORDS[$counter]}'=true/g' "$config_file"
|
sed -i'.tmp' 's/^'${KEYWORDS[$counter]}'=.*/'${KEYWORDS[$counter]}'=true/g' "$config_file"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Cannot rewrite ${[KEYWORDS[$counter]} boolean to true."
|
echo "Cannot rewrite ${[KEYWORDS[$counter]} boolean to true."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
elif grep "^${KEYWORDS[$counter]}=no" > /dev/null "$config_file"; then
|
elif grep "^${KEYWORDS[$counter]}=no$" > /dev/null "$config_file"; then
|
||||||
sed -i'.tmp' 's/^'${KEYWORDS[$counter]}'=.*/'${KEYWORDS[$counter]}'=false/g' "$config_file"
|
sed -i'.tmp' 's/^'${KEYWORDS[$counter]}'=.*/'${KEYWORDS[$counter]}'=false/g' "$config_file"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Cannot rewrite ${[KEYWORDS[$counter]} boolean to false."
|
echo "Cannot rewrite ${[KEYWORDS[$counter]} boolean to false."
|
||||||
|
@ -563,7 +551,6 @@ function UpdateConfigHeader {
|
||||||
fi
|
fi
|
||||||
# "onfig file rev" to deal with earlier variants of the file where c was lower or uppercase
|
# "onfig file rev" to deal with earlier variants of the file where c was lower or uppercase
|
||||||
sed -i'.tmp' 's/.*onfig file rev.*//' "$config_file"
|
sed -i'.tmp' 's/.*onfig file rev.*//' "$config_file"
|
||||||
rm -f "$config_file.tmp"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -605,8 +592,14 @@ elif [ "$1" != "" ] && [ -f "$1" ] && [ -w "$1" ]; then
|
||||||
RewriteOldConfigFiles "$CONF_FILE"
|
RewriteOldConfigFiles "$CONF_FILE"
|
||||||
AddMissingConfigOptionsAndFixBooleans "$CONF_FILE"
|
AddMissingConfigOptionsAndFixBooleans "$CONF_FILE"
|
||||||
UpdateConfigHeader "$CONF_FILE"
|
UpdateConfigHeader "$CONF_FILE"
|
||||||
|
if [ -d "$MASTER_SYNC_DIR" ]; then
|
||||||
RenameStateFiles "$MASTER_SYNC_DIR"
|
RenameStateFiles "$MASTER_SYNC_DIR"
|
||||||
|
fi
|
||||||
|
if [ -d "$SLAVE_SYNC_DIR" ]; then
|
||||||
RenameStateFiles "$SLAVE_SYNC_DIR"
|
RenameStateFiles "$SLAVE_SYNC_DIR"
|
||||||
|
fi
|
||||||
|
rm -f "$CONF_FILE.tmp"
|
||||||
|
echo "Configuration file upgrade finished."
|
||||||
else
|
else
|
||||||
Usage
|
Usage
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue