Skip to content

Instantly share code, notes, and snippets.

@eyedeekay
Last active January 20, 2016 17:36
Show Gist options
  • Save eyedeekay/24d409321df4984577e5 to your computer and use it in GitHub Desktop.
Save eyedeekay/24d409321df4984577e5 to your computer and use it in GitHub Desktop.
xombrero-update-certs
#! /bin/sh
if [ -f /usr/bin/srm ]; then
alias rm=/usr/bin/srm
fi
if [ -f "$1" ]; then
TEMP=$(cat "$1" | grep "work_dir")
TEMP=$(echo "$TEMP" | tr -d " ")
export $(echo "$TEMP" | tr -d "\t")
TEMP=$(cat "$1" | grep "ssl_ca_file")
TEMP=$(echo "$TEMP" | tr -d " ")
export $(echo "$TEMP" | tr -d "\t")
if [ -z "$ssl_ca_file" ]; then
TEMP=$(echo $TEMP | tr -d " " )
export $(echo $TEMP | tr -d "\t" )
mv -v "$ssl_ca_file" "$ssl_ca_file.old" 2> /dev/null
else
mv -v "$work_dir/cert.pem" "$work_dir/cert.pem.old" 2> /dev/null
fi
else
TEMP=$(cat "$HOME/.xombrero.conf" | grep "work_dir")
TEMP=$(echo "$TEMP" | tr -d " ")
export $(echo "$TEMP" | tr -d "\t")
if [ -z "$work_dir" ]; then
work_dir="$HOME/.xombrero/"
fi
if [ -d "$work_dir" ]; then
TEMP=$(cat "$HOME/.xombrero.conf" | grep "ssl_ca_file")
TEMP=$(echo $TEMP | tr -d " " )
export $(echo $TEMP | tr -d "\t" )
if [ -z "$ssl_ca_file" ]; then
mv -v "$ssl_ca_file" "$ssl_ca_file.old" 2> /dev/null
else
mv -v "$work_dir/cert.pem" "$work_dir/cert.pem.old" 2> /dev/null
fi
fi
fi
mkdir $work_dir -p
SYSTEM_CERTS=$(find /etc/ssl/certs -name *.pem 2> /dev/null)
for pem in $SYSTEM_CERTS; do
if [ "$1" != "q" ]; then
echo "libssl provided a certificate, $pem."
read -p "Should I add this to your certificates(Y/N)?" REPLY
if [ "$1" = "v" ]; then
cat "$pem"
echo "Review Certificate and press Enter to continue, or ctrl-c to cancel."
if [ $REPLY = "Y" ] || [ $REPLY = "y" ]; then
cat "$pem" >> "$work_dir/cert.pem"
fi
else
if [ $REPLY = "Y" ] || [ $REPLY = "y" ]; then
cat "$pem" >> "$work_dir/cert.pem"
fi
fi
else
cat "$pem" >> "$work_dir/cert.pem"
fi
done
TOR_CERT=$(find / -name torproject.pem 2> /dev/null)
TOR_CERT_CAT=$(echo "$TOR_CERT" | grep -v "$HOME/Projects")
if [ "$1" != "q" ]; then
echo "Possible Tor Project Certificate found in $TOR_CERT_CAT."
echo "Should I add this to your certificates?"
if [ "$1" = "v" ]; then
cat "$TOR_CERT_CAT"
echo "Review Certificate and press Enter to continue"
if [ $ANSWER = "yes" ]; then
cat "$TOR_CERT_CAT" >> "$work_dir/cert.pem"
fi
else
cat "$TOR_CERT_CAT" >> "$work_dir/cert.pem"
fi
else
cat "$TOR_CERT_CAT" >> "$work_dir/cert.pem"
fi
cache(){
if [ "$1" = "v" ] || [ "$1" = "q" ]; then
echo -n " "
elif [ "$1" = "c" ]; then
DATE=$(date +%Y%m%d)
if [ -f "$2" ]; then
TEMP=$(cat "$2" | grep "work_dir")
TEMP=$(echo "$TEMP" | tr -d " " )
export $(echo "$TEMP" | tr -d "\t" )
mv -v "$work_dir/cert.pem.old" "$work_dir/cert_cache/cert$DATE.pem" 2> /dev/null
elif [ -d "$work_dir" ]; then
mv -v "$work_dir/cert.pem.old" "$work_dir/cert_cache/cert$DATE.pem" 2> /dev/null
fi
else
echo -n " "
fi
}
custom_file(){
if [ -f "$1" ]; then
TEMP=$(cat "$1" | grep "ssl_ca_file")
TEMP=$(echo $TEMP | tr -d " " )
export $(echo $TEMP | tr -d "\t" )
if [ -z "$ssl_ca_file" ]; then
TEMP=$(cat "$1" | grep "work_dir")
TEMP=$(echo "$TEMP" | tr -d " " )
export $(echo "$TEMP" | tr -d "\t" )
if [ -f "$ssl_ca_file" ]; then
echo "ssl_ca_file = $ssl_ca_file" >> "$1.conf"
else
if [ -d "$work_dir" ]; then
echo "ssl_ca_file = $work_dir/cert.pem" >> "$1.conf"
fi
fi
cache "$2" "$1"
clear_cache "$2" "$1"
fi
fi
}
clear_cache(){
if [ "$1" = "cc" ]; then
if [ -f "$2" ]; then
TEMP=$(cat "$2" | grep "work_dir")
TEMP=$(echo "$TEMP" | tr -d " " )
export $(echo "$TEMP" | tr -d "\t" )
fi
if [ -d "$work_dir/cert_cache" ]; then
rm -v "$work_dir/cert_cache/*" 2> /dev/null
fi
fi
}
FILE_LIST="$HOME/.xombrero.conf
$HOME/.insecure.conf
$1
$2
$3 "
for f in $FILE_LIST; do
if [ -z "$1" ]; then
custom_file "$f" "$1"
elif [ -z "$2" ]; then
custom_file "$f" "$2"
elif [ -z "$3" ]; then
custom_file "$f" "$3"
fi
done
rm -v "$work_dir/cert.pem.old" 2> /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment