diff --git a/CHANGELOG.md b/CHANGELOG.md index 711f63a..30d76e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2023.8.0 +- Improved ssh key generation to make sure a new one is generated if a new username is inputted. + ## 2023.7.4 - Changed default backup time to 1 week interval diff --git a/config.yaml b/config.yaml index e0ef1e8..5bb9397 100644 --- a/config.yaml +++ b/config.yaml @@ -1,6 +1,6 @@ name: "m-connect" description: "Wireguard client for reverse proxy in cloud setup" -version: "2023.7.4" +version: "2023.8.0" slug: "m_connect" init: false url: https://github.com/kjetilmjos/m-connect diff --git a/rootfs/etc/s6-overlay/scripts/startupbackupscript b/rootfs/etc/s6-overlay/scripts/startupbackupscript index 860674f..2dbc458 100755 --- a/rootfs/etc/s6-overlay/scripts/startupbackupscript +++ b/rootfs/etc/s6-overlay/scripts/startupbackupscript @@ -4,47 +4,40 @@ # Creates the backup configuration # ============================================================================== declare username -#backup_enable=true - -# Get config input from addon UI -#if bashio::config.has_value "server.enable_backup"; then -# backup_enable=$(bashio::config "server.enable_backup") -#fi -#bashio::exit.die_if_false $backup_enable "Backup is disabled. Backup startup script will stop" -#if [[ $backup_enable = false ]]; then -# bashio::log.warning -# bashio::log.warning "Backup is disabled. Backup startup script will exit" -# bashio::log.warning -# bashio::exit.ok -#fi if bashio::config.has_value "server.username"; then username=$(bashio::config "server.username") fi -# If private key is already existing, don't create a new one -#if bashio::fs.file_exists "/backup_cred/${username}.pub"; then -# bashio::log.info "An existing ssh key was found. A new one will not be generated" -# bashio::exit.ok -#fi - # Wireguard configuration directory if bashio::fs.directory_exists '/data/backup_cred'; then - bashio::log.info "An existing ssh key was found. A new one will not be generated" + bashio::log.info "An existing directory was found. A new one will not be generated" + if bashio::fs.file_exists "/data/backup_cred/$username.pub"; then + bashio::log.info "An existing ssh identity was found. A new one will not be generated" + pubkey=$(cat "/data/backup_cred/$username.pub") + bashio::log.info "The ssh public key is: $pubkey" + bashio::exit.ok + else + ssh-keygen -t ed25519 -C "$username" -f /data/backup_cred/$username -P "" + eval "$(ssh-agent -s)" + ssh-add /data/backup_cred/$username + + #Print the SSH public key pubkey=$(cat "/data/backup_cred/$username.pub") bashio::log.info "The ssh public key is: $pubkey" bashio::exit.ok -fi + fi +else + mkdir -p /data/backup_cred + # Creating required folder for ssh-copy-id + #mkdir -p ~/.ssh + ssh-keygen -t ed25519 -C "$username" -f /data/backup_cred/$username -P "" + # Use command permitted i authorized key fila: https://www.ssh.com/academy/ssh/authorized-keys-file + eval "$(ssh-agent -s)" + ssh-add /data/backup_cred/$username -mkdir -p /data/backup_cred -# Creating required folder for ssh-copy-id -mkdir -p ~/.ssh -ssh-keygen -t ed25519 -C "$username" -f /data/backup_cred/$username -P "" -# Bruk command permitted i authorized key fila: https://www.ssh.com/academy/ssh/authorized-keys-file -eval "$(ssh-agent -s)" -ssh-add /data/backup_cred/$username -#sshpass -p "$password" ssh-copy-id -o "StrictHostKeyChecking no" -i /data/backup_cred/$username $username@$host + #Print the SSH public key + pubkey=$(cat "/data/backup_cred/$username.pub") + bashio::log.info "The ssh public key is: $pubkey" +fi -#Print the SSH public key -pubkey=$(cat "/data/backup_cred/$username.pub") -bashio::log.info "The ssh public key is: $pubkey" \ No newline at end of file