Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- guest_name=""
- guest_id=""
- guest_config=""
- domain=""
- if [ ! $1 ]; then
- echo "Must specify a hostname or container ID!"
- exit 1
- elif [[ $1 =~ ^[0-9]{3}$ ]]; then
- guest_id=$1
- guest_config="/etc/pve/lxc/$guest_id.conf"
- if [[ ! -f $guest_config ]]; then
- echo "Guest config does not exist!"
- exit 1
- fi
- guest_name=$(cat $guest_config | grep -m 1 hostname | cut -d' ' -f2)
- if [ ! $guest_name ]; then
- echo "No guest found with that ID!"
- exit 1
- fi
- echo "Found guest named $guest_name with that ID."
- else
- guest_name=$1
- guest_id=$(grep -l "hostname: $guest_name" /etc/pve/lxc/*.conf | egrep -o [0-9]{3})
- guest_config="/etc/pve/lxc/$guest_id.conf"
- if [ ! $guest_id ]; then
- echo "No guest found with that name!"
- exit 1
- fi
- echo "Found guest with ID $guest_id matching that name."
- fi
- if [ $(egrep '^\[.*\]$' $guest_config) ]; then
- echo "Cannot add mounts to container with snapshots!"
- exit 1
- fi
- /root/.acme.sh/acme.sh --issue --dns dns_cf -d $guest_name.$domain
- if [ $? -eq 0 ]; then
- echo "Certificate creation succeeded! Adding mount point to container..."
- else
- echo "Certificate creation failed!"
- exit 1
- fi
- mount_list=$(egrep -o 'mp([0-9]{1,}): /' $guest_config)
- mount_target=0
- for mount in $mount_list; do
- m_num=$(echo $mount | egrep -o '[0-9]{1,}')
- if [[ $m_num -ge $mount_target ]]; then
- mount_target=$(($m_num+1))
- fi
- done
- mount_point="mp$mount_target: /root/.acme.sh/$guest_name.$domain/,mp=/certs"
- echo $mount_point >> $guest_config
- echo "Added mount point to $guest_config:"
- echo $mount_point
- echo "Restart the container and you should see the new certificate and key in /certs"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement