Skip to content

Instantly share code, notes, and snippets.

@kristijorgji
Last active June 17, 2021 11:55
Show Gist options
  • Save kristijorgji/d869f337f0692fc1616839911a6266b0 to your computer and use it in GitHub Desktop.
Save kristijorgji/d869f337f0692fc1616839911a6266b0 to your computer and use it in GitHub Desktop.
letencrypt-copy-live.sh
#!/usr/bin/env bash
# @kristijorgji
# This script copies all the live certbot/letsencrypt certificates to the dest you specify as first argument
# Example:
# bash letsencrypt-copy-live /home/ubuntu/certificates
DEST=$1
cd /etc/letsencrypt/live;
pwd=$(pwd);
for dir in ./*/ # list directories in the form "/tmp/dirname/"
do
dir=${dir%*/} # remove the trailing "/"
#currentDomain=$(basename $pwd);
currentDomain=$(echo "${dir##*/}");
mkdir -p $DEST/$currentDomain;
echo "Current domain $currentDomain"
for filename in ./$currentDomain/*; do
name=$(basename $filename);
realPath=$(readlink -f $filename);
fileDest="$DEST/$currentDomain/$name";
echo "Will copy $name to $fileDest";
cp $realPath $fileDest;
done
done
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment