| |
| |
| |
| |
| |
| |
| |
| |
| export LC_ALL=C |
| |
| |
| __check_reqd_binaries() { |
| local BIN __binaries=("egrep" "sort" "sha256sum" "sed") |
| for BIN in $__binaries; do |
| if ! type -P $BIN >/dev/null 2>&1; then |
| echo "Binary $BIN not found. Please install." |
| exit 1 |
| fi |
| done |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| calc_sha() { |
| __check_reqd_binaries |
| |
| if [ "$1" == "" ]; then |
| echo "Please pass in a storage variable." |
| return 1 |
| fi |
| |
| local __resultvar=$1 |
| __retval=1 |
| shift |
| |
| local __file=$1 |
| local cmnt=${2:-#} |
| |
| if [ -f "$__file" ]; then |
| local __shasum=$(egrep -v ^"$cmnt" "$__file" | egrep -v ^$ | sort -u | sha256sum -t | cut -d" " -f1) |
| eval $__resultvar="'$__shasum'" |
| __retval=0 |
| fi |
| return $__retval |
| } |
| |
| |
| |
| |
| |
| |
| retr_sha() { |
| __check_reqd_binaries |
| |
| if [ "$1" == "" ]; then |
| echo "Please pass in a storage variable." |
| return 1 |
| fi |
| |
| local __resultvar=$1 |
| __retval=1 |
| shift |
| |
| local __file=$1 |
| local cmnt=${2:-#} |
| |
| if [ -f "$__file" ]; then |
| if grep -q "$cmnt -\*- cfg-sha:" "$__file"; then |
| local __shasum=$(grep "$cmnt -\*- cfg-sha:" "$__file" | sed -e "s@$cmnt -\*- cfg-sha: @@" | cut -d" " -f1) |
| eval $__resultvar="'$__shasum'" |
| __retval=0 |
| fi |
| fi |
| return $__retval |
| } |
| |
| |
| |
| |
| |
| |
| |
| set_conf() { |
| c="$1/.config" |
| shift |
| |
| if grep -q "$1" "$c"; then |
| sed -i "s:^$1=.*$:$1=$2:g" $c |
| else |
| echo $1=$2 >> "$c" |
| fi |
| } |
| |