Skip to content

Commit 1ae7dc0

Browse files
## [0.5.0] - 2020-11-11
### Added - Added support for creating `.sha256sums` file for config xml and info files for `generate_config_info` command using `-m` and `--sha256sums_file` options. This will allow for integrity verification of the config info file as well, specially since it now contains code description. ### Removed - Removed `sha256sums` tag from config info file for `generate_config_info` command if `-m` is not passed.
1 parent c44b361 commit 1ae7dc0

File tree

3 files changed

+169
-22
lines changed

3 files changed

+169
-22
lines changed

CHANGELOG.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ All notable changes to this project will be documented in this file.
2020
`-`
2121

2222

23+
## [0.5.0] - 2020-11-11
24+
25+
### Added
26+
- Added support for creating `.sha256sums` file for config xml and info files for `generate_config_info` command using `-m` and `--sha256sums_file` options. This will allow for integrity verification of the config info file as well, specially since it now contains code description.
27+
28+
### Removed
29+
- Removed `sha256sums` tag from config info file for `generate_config_info` command if `-m` is not passed.
30+
31+
2332
## [0.4.0] - 2020-11-09
2433

2534
### Added
@@ -63,8 +72,9 @@ All notable changes to this project will be documented in this file.
6372
##
6473

6574

66-
[unreleased]: https://github.com/Taskomater/tasker_config_utils/compare/v0.4.0...HEAD
67-
[0.3.0]: https://github.com/Taskomater/tasker_config_utils/compare/v0.3.0...v0.4.0
75+
[unreleased]: https://github.com/Taskomater/tasker_config_utils/compare/v0.5.0...HEAD
76+
[0.5.0]: https://github.com/Taskomater/tasker_config_utils/compare/v0.4.0...v0.5.0
77+
[0.4.0]: https://github.com/Taskomater/tasker_config_utils/compare/v0.3.0...v0.4.0
6878
[0.3.0]: https://github.com/Taskomater/tasker_config_utils/compare/v0.2.2...v0.3.0
6979
[0.2.2]: https://github.com/Taskomater/tasker_config_utils/compare/v0.2.1...v0.2.2
7080
[0.2.1]: https://github.com/Taskomater/tasker_config_utils/compare/v0.2.0...v0.2.1

README.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ This is a project that provides bash util script(s) to extract information and m
4141

4242
### Downloads
4343

44-
Latest version is `v0.4.0`.
44+
Latest version is `v0.5.0`.
4545

4646
- [GitHub releases](https://github.com/Taskomater/tasker_config_utils/releases).
4747
##
@@ -357,15 +357,19 @@ Usage:
357357
358358
Available command_options:
359359
[ -h | --help ] display this help screen
360+
[ --help-extra ] display more help about how this command works
360361
[ -v | -vv ] set verbose level to 1 or 2
361362
[ -a ] extract all info
362363
[ -c ] put task help in a code block
364+
[ -m ] create sha256sums file config xml and info files
363365
[ -p ] extract info of a specific project
364366
[ -s ] add script signature at end of config info file
365367
[ --text_description=<description> ]
366368
text description of config
367369
[ --code_description=<description> ]
368370
code description of config
371+
[ --sha256sums_file=<path> ]
372+
path to sha256sums file
369373
370374
371375
The options '-a' and '-p' set the generate_config_info_mode of the
@@ -382,7 +386,7 @@ depending on XML file size.
382386
The '-p' option sets the generate_config_info_mode to "project"
383387
mode. If this is passed, then exported_tasker_config should be
384388
the path to a Tasker exported "Project" XML file of which the
385-
project info needs to be generated. You may optionally pass a
389+
config info needs to be generated. You may optionally pass a
386390
Tasker "Data Backup" XML file instead. Only the info of profiles,
387391
scenes and tasks belonging to the project will be generated. The
388392
project_name should be the Tasker project name which was exported to
@@ -405,6 +409,14 @@ The string passed with the '--code_description' option will be added
405409
under the 'Code Description' heading at the end in a markdown code
406410
block.
407411
412+
The '-m' option will create a sha256sum file for exported_tasker_config
413+
and exported_tasker_config_info files. The sha256sum file will by
414+
default be created in same directory as exported_tasker_config_info
415+
and the same basename except with a '.sha256sums' extension but a path can
416+
be passed with '--sha256sums_file' option. If '-m' is not passed, then
417+
the sha256sums of the exported_tasker_config xml file will be added to
418+
the exported_tasker_config_info file instead.
419+
408420
Set verbose level to 1 or 2 to get more info when running
409421
tasker_config_utils generate_config_info command.
410422
@@ -432,10 +444,10 @@ files on export.
432444

433445
##### Examples:
434446

435-
- Generate a markdown project info file for a given tasker config file.
447+
- Generate a markdown config info file for a given tasker config file.
436448
`tasker_config_utils generate_config_info -v -a "config.xml" "config.md"`
437449

438-
- Generate a markdown project info file of a specific project.
450+
- Generate a markdown config info file of a specific project.
439451
`tasker_config_utils generate_config_info -v -p "Foo_Bar.prf.xml" "Foo_Bar-out.prf.md" "Foo Bar"`
440452
##
441453

tasker_config_utils

+141-16
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
#description: various tasker config utils
1111
#author: agnostic-apollo
1212
#usage: run "bash tasker_config_utils --help"
13-
#date: 06-Nov-2020
13+
#date: 11-Nov-2020
1414
#bash version: 4.0 or higher
1515
#credits: -
1616
#license: MIT License
17-
version=0.4.0
17+
version=0.5.0
1818

1919

2020

@@ -91,9 +91,11 @@ new_exported_tasker_project="" #default to none
9191

9292
exported_tasker_config="" #default to none
9393
exported_tasker_config_info="" #default to none
94+
exported_tasker_config_sha256sums="" #default to none
9495
generate_config_info_mode="" #default to none
9596
put_task_help_in_code_block=0 #default to 0
9697
add_script_signature_to_config_info=0 #default to 0
98+
create_sha256sums_file=0 #default to 0
9799

98100
tasker_config_utils_verbose_level=0 #default to log level 0
99101
tasker_config_utils_args_verbose_level=0 #set this to "1" manually, if you want to debug arguments received
@@ -1163,15 +1165,15 @@ tasker_config_utils_generate_config_info() {
11631165
fi
11641166

11651167
#find sha256sum of exported_tasker_config
1166-
exported_tasker_config_sha256sum="$(sha256sum "$exported_tasker_config")"
1168+
exported_tasker_config_sha256sum_value="$(sha256sum "$exported_tasker_config")"
11671169
return_value=$?
11681170
if [ $return_value -ne 0 ]; then
11691171
tasker_config_utils_log_errors "Failed to find sha256sum of exported_tasker_config"
11701172
return $return_value
11711173
fi
11721174

11731175
#remove filename from sha256sum of exported_tasker_config
1174-
exported_tasker_config_sha256sum="$(echo "$exported_tasker_config_sha256sum" | cut -d " " -f 1)"
1176+
exported_tasker_config_sha256sum_value="$(echo "$exported_tasker_config_sha256sum_value" | cut -d " " -f 1)"
11751177
return_value=$?
11761178
if [ $return_value -ne 0 ]; then
11771179
tasker_config_utils_log_errors "Failed to remove filename from sha256sum of exported_tasker_config"
@@ -1391,7 +1393,12 @@ tasker_config_utils_generate_config_info() {
13911393
export_info=$'\n\n&nbsp;\n'"## Export Info:"
13921394
export_info+=$'\n**Tasker Version:** `'"$tasker_version"'` '
13931395
export_info+=$'\n**Timestamp:** `'"$timestamp"'` '
1394-
export_info+=$'\n**sha256sum:** `'"$exported_tasker_config_sha256sum"'` '
1396+
1397+
#if create_sha256sums_file is not enabled
1398+
if [[ "$create_sha256sums_file" != "1" ]]; then
1399+
export_info+=$'\n**sha256sum:** `'"$exported_tasker_config_sha256sum_value"'` '
1400+
fi
1401+
13951402
export_info+=$'\n&nbsp;'
13961403

13971404
profiles_name_list=$'\n\n&nbsp;\n'"## Profile Names:"
@@ -1746,11 +1753,28 @@ tasker_config_utils_generate_config_info() {
17461753

17471754

17481755
tasker_config_utils_log_literal 1 "\n"
1749-
tasker_config_utils_log 1 "Writing All Info To Output File"
1756+
tasker_config_utils_log 1 "Creating config info file at \"$exported_tasker_config_info\""
1757+
1758+
exported_tasker_config_basename="${exported_tasker_config##*/}" #strip longest match of */ from start
1759+
1760+
exported_tasker_config_info_basename="${exported_tasker_config_info##*/}" #strip longest match of */ from start
1761+
exported_tasker_config_info_directory="${exported_tasker_config_info:0:${#exported_tasker_config_info} - ${#exported_tasker_config_info_basename}}" #substring from 0 to position of basename
1762+
exported_tasker_config_info_basename_without_file_extension="${exported_tasker_config_info_basename%.[^.]*}" #strip shortest match of . plus at least one non-dot char from end
1763+
1764+
exported_tasker_config_info_file_extension="${exported_tasker_config_info_basename:${#exported_tasker_config_info_basename_without_file_extension} + 1}" #substring from length of basename_without_extension plus one to end
1765+
#if basename_without_extension is not set but extension is set, set extension to basename_without_extension
1766+
if [[ -z "$exported_tasker_config_info_basename_without_file_extension" ]] && [[ ! -z "$exported_tasker_config_info_file_extension" ]]; then
1767+
exported_tasker_config_info_basename_without_file_extension=".$exported_tasker_config_info_file_extension"
1768+
exported_tasker_config_info_file_extension=""
1769+
fi
1770+
#remove trailing slashes if not root
1771+
case $exported_tasker_config_info_directory in *[!/]*/) exported_tasker_config_info_directory=${exported_tasker_config_info_directory%"${exported_tasker_config_info_directory##*[!/]}"};; *[/]) exported_tasker_config_info_directory="/";; esac
1772+
1773+
17501774

17511775
#if generate_config_info_mode is set to "all"
17521776
if [[ "$generate_config_info_mode" == "all" ]]; then
1753-
exported_tasker_config_info_name=$(basename "$exported_tasker_config_info" | cut -d '.' -f 1 | sed 's/_/ /g')
1777+
exported_tasker_config_info_name=$(echo "$exported_tasker_config_info_basename" | cut -d '.' -f 1 | sed 's/_/ /g')
17541778
exported_tasker_config_info_output="# $exported_tasker_config_info_name"
17551779
#if generate_config_info_mode is set to "project"
17561780
elif [[ "$generate_config_info_mode" == "project" ]]; then
@@ -1762,9 +1786,7 @@ tasker_config_utils_generate_config_info() {
17621786

17631787

17641788

1765-
###Create project info file at exported_tasker_config_info
1766-
tasker_config_utils_log_literal 1 "\n"
1767-
tasker_config_utils_log 1 "Creating project info file at exported_tasker_config_info \"$exported_tasker_config_info\""
1789+
###Create config info file at exported_tasker_config_info
17681790

17691791
#create exported_tasker_config_info parent directory if it does not exist
17701792
tasker_config_utils_create_parent_path "$exported_tasker_config_info" "exported_tasker_config_info"
@@ -1778,7 +1800,7 @@ tasker_config_utils_generate_config_info() {
17781800
echo -n "" > "$exported_tasker_config_info"
17791801
return_value=$?
17801802
if [ $return_value -ne 0 ]; then
1781-
tasker_config_utils_log_errors "Failed to create project info file at exported_tasker_config_info \"$exported_tasker_config_info\""
1803+
tasker_config_utils_log_errors "Failed to create config info file at exported_tasker_config_info \"$exported_tasker_config_info\""
17821804
return $return_value
17831805
fi
17841806

@@ -1811,8 +1833,87 @@ tasker_config_utils_generate_config_info() {
18111833
#write exported_tasker_config_info_output to exported_tasker_config_info file
18121834
echo "$exported_tasker_config_info_output" >> "$exported_tasker_config_info"
18131835
return_value=$?
1836+
if [ $return_value -ne 0 ]; then
1837+
tasker_config_utils_log_errors "Failed to write to config info file at exported_tasker_config_info \"$exported_tasker_config_info\""
1838+
return $return_value
1839+
fi
1840+
18141841

1815-
return $return_value
1842+
1843+
###Create config sha256sums file at exported_tasker_config_sha256sums
1844+
1845+
#if create_sha256sums_file is enabled
1846+
if [[ "$create_sha256sums_file" == "1" ]]; then
1847+
#find sha256sum of exported_tasker_config_info
1848+
exported_tasker_config_info_sha256sum_value="$(sha256sum "$exported_tasker_config_info")"
1849+
return_value=$?
1850+
if [ $return_value -ne 0 ]; then
1851+
tasker_config_utils_log_errors "Failed to find sha256sum of exported_tasker_config_info"
1852+
return $return_value
1853+
fi
1854+
1855+
#remove filename from sha256sum of exported_tasker_config_info
1856+
exported_tasker_config_info_sha256sum_value="$(echo "$exported_tasker_config_info_sha256sum_value" | cut -d " " -f 1)"
1857+
return_value=$?
1858+
if [ $return_value -ne 0 ]; then
1859+
tasker_config_utils_log_errors "Failed to remove filename from sha256sum of exported_tasker_config_info"
1860+
return $return_value
1861+
fi
1862+
1863+
#if exported_tasker_config_sha256sums is not set
1864+
if [ -z "$exported_tasker_config_sha256sums" ]; then
1865+
#set exported_tasker_config_sha256sums_basename to a name with the same basename as the config info file
1866+
exported_tasker_config_sha256sums_basename="${exported_tasker_config_info_basename_without_file_extension}.sha256sums"
1867+
1868+
#set exported_tasker_config_sha256sums to a file with the same basename as the config info file in the same directory as the config info
1869+
#if exported_tasker_config_info_directory is not set
1870+
if [ -z "$exported_tasker_config_info_directory" ]; then
1871+
exported_tasker_config_sha256sums="$exported_tasker_config_sha256sums_basename"
1872+
else
1873+
exported_tasker_config_sha256sums="$exported_tasker_config_info_directory/$exported_tasker_config_sha256sums_basename"
1874+
fi
1875+
else
1876+
#create exported_tasker_config_sha256sums parent directory if it does not exist
1877+
tasker_config_utils_create_parent_path "$exported_tasker_config_sha256sums" "exported_tasker_config_sha256sums"
1878+
return_value=$?
1879+
if [ $return_value -ne 0 ]; then
1880+
tasker_config_utils_log_errors "tasker_config_utils_create_parent_path failed with exit code $return_value"
1881+
return $return_value
1882+
fi
1883+
fi
1884+
1885+
exported_tasker_config_sha256sums_output=""
1886+
exported_tasker_config_sha256sums_output+="$exported_tasker_config_sha256sum_value $exported_tasker_config_basename"$'\n'
1887+
exported_tasker_config_sha256sums_output+="$exported_tasker_config_info_sha256sum_value $exported_tasker_config_info_basename"
1888+
1889+
1890+
tasker_config_utils_log 1 "Creating config sha256sums file at \"$exported_tasker_config_sha256sums\""
1891+
1892+
#create empty file at exported_tasker_config_sha256sums
1893+
echo -n "" > "$exported_tasker_config_sha256sums"
1894+
return_value=$?
1895+
if [ $return_value -ne 0 ]; then
1896+
tasker_config_utils_log_errors "Failed to create config sha256sums file at exported_tasker_config_sha256sums \"$exported_tasker_config_sha256sums\""
1897+
return $return_value
1898+
fi
1899+
1900+
#if exported_tasker_config_sha256sums file is not found
1901+
if [ ! -f "$exported_tasker_config_sha256sums" ]; then
1902+
tasker_config_utils_log_errors "Failed to find \"$exported_tasker_config_sha256sums\" file"
1903+
return 1
1904+
fi
1905+
1906+
#write exported_tasker_config_sha256sums_output to exported_tasker_config_sha256sums file
1907+
echo "$exported_tasker_config_sha256sums_output" >> "$exported_tasker_config_sha256sums"
1908+
return_value=$?
1909+
if [ $return_value -ne 0 ]; then
1910+
tasker_config_utils_log_errors "Failed to write to config sha256sums file at exported_tasker_config_sha256sums \"$exported_tasker_config_sha256sums\""
1911+
return $return_value
1912+
fi
1913+
fi
1914+
1915+
1916+
return 0
18161917

18171918
}
18181919

@@ -2268,7 +2369,7 @@ process_tasker_config_utils_parameters () {
22682369
generate_config_info)
22692370
command_type="$sub_command"
22702371
tasker_config_utils_log_args "Parsing sub_command: '${sub_command}'"
2271-
optspec=":hvacps-:"
2372+
optspec=":hvacmps-:"
22722373
#process generate_config_info command options
22732374
while getopts "$optspec" opt; do
22742375
case ${opt} in
@@ -2302,6 +2403,15 @@ process_tasker_config_utils_parameters () {
23022403
tasker_config_utils_log_arg_errors "No parameters set for option: '--${OPTARG%=*}'"
23032404
exit_tasker_config_utils_on_error "$command_type"
23042405
;;
2406+
sha256sums_file=?*)
2407+
val="$long_optargs"
2408+
tasker_config_utils_log_args "Parsing option: '--${OPTARG%=*}', value: '${val}'"
2409+
exported_tasker_config_sha256sums="$(echo "$val")" #remove trailing newlines
2410+
;;
2411+
sha256sums_file | sha256sums_file=)
2412+
tasker_config_utils_log_arg_errors "No parameters set for option: '--${OPTARG%=*}'"
2413+
exit_tasker_config_utils_on_error "$command_type"
2414+
;;
23052415
text_description=?*)
23062416
val="$long_optargs"
23072417
tasker_config_utils_log_args "Parsing option: '--${OPTARG%=*}', value: '${val}'"
@@ -2343,6 +2453,10 @@ process_tasker_config_utils_parameters () {
23432453
tasker_config_utils_log_args "Parsing option: '-${opt}'"
23442454
put_task_help_in_code_block="1"
23452455
;;
2456+
m)
2457+
tasker_config_utils_log_args "Parsing option: '-${opt}'"
2458+
create_sha256sums_file="1"
2459+
;;
23462460
p)
23472461
tasker_config_utils_log_args "Parsing option: '-${opt}'"
23482462
generate_config_info_mode="project"
@@ -2672,12 +2786,15 @@ Available command_options:
26722786
[ -v | -vv ] set verbose level to 1 or 2
26732787
[ -a ] extract all info
26742788
[ -c ] put task help in a code block
2789+
[ -m ] create sha256sums file config xml and info files
26752790
[ -p ] extract info of a specific project
26762791
[ -s ] add script signature at end of config info file
26772792
[ --text_description=<description> ]
26782793
text description of config
26792794
[ --code_description=<description> ]
26802795
code description of config
2796+
[ --sha256sums_file=<path> ]
2797+
path to sha256sums file
26812798
26822799
26832800
The options '-a' and '-p' set the generate_config_info_mode of the
@@ -2694,7 +2811,7 @@ depending on XML file size.
26942811
The '-p' option sets the generate_config_info_mode to "project"
26952812
mode. If this is passed, then exported_tasker_config should be
26962813
the path to a Tasker exported "Project" XML file of which the
2697-
project info needs to be generated. You may optionally pass a
2814+
config info needs to be generated. You may optionally pass a
26982815
Tasker "Data Backup" XML file instead. Only the info of profiles,
26992816
scenes and tasks belonging to the project will be generated. The
27002817
project_name should be the Tasker project name which was exported to
@@ -2717,6 +2834,14 @@ The string passed with the '--code_description' option will be added
27172834
under the 'Code Description' heading at the end in a markdown code
27182835
block.
27192836
2837+
The '-m' option will create a sha256sum file for exported_tasker_config
2838+
and exported_tasker_config_info files. The sha256sum file will by
2839+
default be created in same directory as exported_tasker_config_info
2840+
and the same basename except with a '.sha256sums' extension but a path can
2841+
be passed with '--sha256sums_file' option. If '-m' is not passed, then
2842+
the sha256sums of the exported_tasker_config xml file will be added to
2843+
the exported_tasker_config_info file instead.
2844+
27202845
Set verbose level to 1 or 2 to get more info when running
27212846
tasker_config_utils generate_config_info command.
27222847
@@ -2753,10 +2878,10 @@ show_tasker_config_utils_generate_config_info_help_extra () {
27532878
27542879
##### Examples:
27552880
2756-
- Generate a markdown project info file for a given tasker config file.
2881+
- Generate a markdown config info file for a given tasker config file.
27572882
`tasker_config_utils generate_config_info -v -a "config.xml" "config.md"`
27582883
2759-
- Generate a markdown project info file of a specific project.
2884+
- Generate a markdown config info file of a specific project.
27602885
`tasker_config_utils generate_config_info -v -p "Foo_Bar.prf.xml" "Foo_Bar-out.prf.md" "Foo Bar"`
27612886
TASKER_CONFIG_UTILS_HELP_EOF
27622887

0 commit comments

Comments
 (0)