10
10
# description: various tasker config utils
11
11
# author: agnostic-apollo
12
12
# usage: run "bash tasker_config_utils --help"
13
- # date: 06 -Nov-2020
13
+ # date: 11 -Nov-2020
14
14
# bash version: 4.0 or higher
15
15
# credits: -
16
16
# license: MIT License
17
- version=0.4 .0
17
+ version=0.5 .0
18
18
19
19
20
20
@@ -91,9 +91,11 @@ new_exported_tasker_project="" #default to none
91
91
92
92
exported_tasker_config=" " # default to none
93
93
exported_tasker_config_info=" " # default to none
94
+ exported_tasker_config_sha256sums=" " # default to none
94
95
generate_config_info_mode=" " # default to none
95
96
put_task_help_in_code_block=0 # default to 0
96
97
add_script_signature_to_config_info=0 # default to 0
98
+ create_sha256sums_file=0 # default to 0
97
99
98
100
tasker_config_utils_verbose_level=0 # default to log level 0
99
101
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() {
1163
1165
fi
1164
1166
1165
1167
# 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 " ) "
1167
1169
return_value=$?
1168
1170
if [ $return_value -ne 0 ]; then
1169
1171
tasker_config_utils_log_errors " Failed to find sha256sum of exported_tasker_config"
1170
1172
return $return_value
1171
1173
fi
1172
1174
1173
1175
# 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) "
1175
1177
return_value=$?
1176
1178
if [ $return_value -ne 0 ]; then
1177
1179
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() {
1391
1393
export_info=$' \n\n \n ' " ## Export Info:"
1392
1394
export_info+=$' \n **Tasker Version:** `' " $tasker_version " ' ` '
1393
1395
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
+
1395
1402
export_info+=$' \n '
1396
1403
1397
1404
profiles_name_list=$' \n\n \n ' " ## Profile Names:"
@@ -1746,11 +1753,28 @@ tasker_config_utils_generate_config_info() {
1746
1753
1747
1754
1748
1755
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
+
1750
1774
1751
1775
# if generate_config_info_mode is set to "all"
1752
1776
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' )
1754
1778
exported_tasker_config_info_output=" # $exported_tasker_config_info_name "
1755
1779
# if generate_config_info_mode is set to "project"
1756
1780
elif [[ " $generate_config_info_mode " == " project" ]]; then
@@ -1762,9 +1786,7 @@ tasker_config_utils_generate_config_info() {
1762
1786
1763
1787
1764
1788
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
1768
1790
1769
1791
# create exported_tasker_config_info parent directory if it does not exist
1770
1792
tasker_config_utils_create_parent_path " $exported_tasker_config_info " " exported_tasker_config_info"
@@ -1778,7 +1800,7 @@ tasker_config_utils_generate_config_info() {
1778
1800
echo -n " " > " $exported_tasker_config_info "
1779
1801
return_value=$?
1780
1802
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 \" "
1782
1804
return $return_value
1783
1805
fi
1784
1806
@@ -1811,8 +1833,87 @@ tasker_config_utils_generate_config_info() {
1811
1833
# write exported_tasker_config_info_output to exported_tasker_config_info file
1812
1834
echo " $exported_tasker_config_info_output " >> " $exported_tasker_config_info "
1813
1835
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
+
1814
1841
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
1816
1917
1817
1918
}
1818
1919
@@ -2268,7 +2369,7 @@ process_tasker_config_utils_parameters () {
2268
2369
generate_config_info)
2269
2370
command_type=" $sub_command "
2270
2371
tasker_config_utils_log_args " Parsing sub_command: '${sub_command} '"
2271
- optspec=" :hvacps -:"
2372
+ optspec=" :hvacmps -:"
2272
2373
# process generate_config_info command options
2273
2374
while getopts " $optspec " opt; do
2274
2375
case ${opt} in
@@ -2302,6 +2403,15 @@ process_tasker_config_utils_parameters () {
2302
2403
tasker_config_utils_log_arg_errors " No parameters set for option: '--${OPTARG% =* } '"
2303
2404
exit_tasker_config_utils_on_error " $command_type "
2304
2405
;;
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
+ ;;
2305
2415
text_description=?* )
2306
2416
val=" $long_optargs "
2307
2417
tasker_config_utils_log_args " Parsing option: '--${OPTARG% =* } ', value: '${val} '"
@@ -2343,6 +2453,10 @@ process_tasker_config_utils_parameters () {
2343
2453
tasker_config_utils_log_args " Parsing option: '-${opt} '"
2344
2454
put_task_help_in_code_block=" 1"
2345
2455
;;
2456
+ m)
2457
+ tasker_config_utils_log_args " Parsing option: '-${opt} '"
2458
+ create_sha256sums_file=" 1"
2459
+ ;;
2346
2460
p)
2347
2461
tasker_config_utils_log_args " Parsing option: '-${opt} '"
2348
2462
generate_config_info_mode=" project"
@@ -2672,12 +2786,15 @@ Available command_options:
2672
2786
[ -v | -vv ] set verbose level to 1 or 2
2673
2787
[ -a ] extract all info
2674
2788
[ -c ] put task help in a code block
2789
+ [ -m ] create sha256sums file config xml and info files
2675
2790
[ -p ] extract info of a specific project
2676
2791
[ -s ] add script signature at end of config info file
2677
2792
[ --text_description=<description> ]
2678
2793
text description of config
2679
2794
[ --code_description=<description> ]
2680
2795
code description of config
2796
+ [ --sha256sums_file=<path> ]
2797
+ path to sha256sums file
2681
2798
2682
2799
2683
2800
The options '-a' and '-p' set the generate_config_info_mode of the
@@ -2694,7 +2811,7 @@ depending on XML file size.
2694
2811
The '-p' option sets the generate_config_info_mode to "project"
2695
2812
mode. If this is passed, then exported_tasker_config should be
2696
2813
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
2698
2815
Tasker "Data Backup" XML file instead. Only the info of profiles,
2699
2816
scenes and tasks belonging to the project will be generated. The
2700
2817
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
2717
2834
under the 'Code Description' heading at the end in a markdown code
2718
2835
block.
2719
2836
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
+
2720
2845
Set verbose level to 1 or 2 to get more info when running
2721
2846
tasker_config_utils generate_config_info command.
2722
2847
@@ -2753,10 +2878,10 @@ show_tasker_config_utils_generate_config_info_help_extra () {
2753
2878
2754
2879
##### Examples:
2755
2880
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.
2757
2882
`tasker_config_utils generate_config_info -v -a "config.xml" "config.md"`
2758
2883
2759
- - Generate a markdown project info file of a specific project.
2884
+ - Generate a markdown config info file of a specific project.
2760
2885
`tasker_config_utils generate_config_info -v -p "Foo_Bar.prf.xml" "Foo_Bar-out.prf.md" "Foo Bar"`
2761
2886
TASKER_CONFIG_UTILS_HELP_EOF
2762
2887
0 commit comments