Bash script performing text file replacement

#!/usr/bin/env bash

# This will be executed as the following
# history -c && echo "BASE64STRING==" | /path/to/script.sh

# Without this the script might report a success
# if something fails in the script.
set -o pipefail -e

IFS= read -r params
json=$(echo "$params" | base64 -d)

# There is no built int JSON parser.
# In order to parse JSON, a tool like jq or fx is required.
$( echo "$json" | jq -r 'keys[] as $k | "export \($k)=\(.[$k])"' )

# Requires htpasswd from apache2-utils (Ubuntu) or httpd-tools (CentOS)
# Note: -c option creates new file but if file already exists it overwrites and truncates
htpasswd -b ~/path/to/pwdfile $user $newPassword

Last updated