Przeglądaj źródła

update scripts and check them through shellcheck

Virgil Ollivier 5 miesięcy temu
rodzic
commit
af5150a02c

+ 1 - 4
scripts/bash/getImageDetails

@@ -1,10 +1,7 @@
 #!/bin/bash
 
 SRV="${1:?Need a fqdn}"
-request=$( ./ovh-bash get vps/${SRV}/images/current | jq '.' )
-#image_id=$( echo "${request}" | jq -r '.id' )
-#image_name=$( echo "${request}" | jq -r '.id' )
 
-echo "${request}"
+./ovh-bash get "vps/${SRV}/images/current" | jq -r '.'
 
 exit $?

+ 3 - 5
scripts/bash/getSecret

@@ -2,11 +2,9 @@
 
 # get Email Secret ID :
 last_id=$( ./ovh-bash get me/notification/email/history | jq 'last(.[])' )
-secret_id=$( ./ovh-bash get me/notification/email/history/${last_id}  | jq -r '.body' | awk '/secret/ { split($NF,a,"=") ; print a[2] }' )
+secret_id=$( ./ovh-bash get "me/notification/email/history/${last_id}"  | jq -r '.body' | awk '/secret/ { split($NF,a,"=") ; print a[2] }' )
 
 # retrieve or set Password from email link
-vps_password=$( ./ovh-bash post secret/retrieve '{ "id": "'${secret_id}'" }' | jq -r '.secret' )
+./ovh-bash post secret/retrieve '{ "id": "'"${secret_id}"'" }' | jq -r '.secret'
 
-echo "${vps_password}"
-
-exit $?
+exit $?

+ 9 - 0
scripts/bash/setNewName

@@ -0,0 +1,9 @@
+#!/bin/bash
+
+SRV=${1:?need a fqdn}
+NEWDISPLAY_NAME=${2:?new display name, a human readable one}
+HTTP_PAYLOAD='{ "displayName": "'${NEWDISPLAY_NAME}'" }'
+
+./ovh-bash put "vps/${SRV}" "${HTTP_PAYLOAD}" | jq -r 'select(. != null)'
+
+exit $?

+ 5 - 4
scripts/bash/vpsReinstall

@@ -1,12 +1,13 @@
 #!/bin/bash
 
 SRV="${1:?Need a fqdn}"
-SSHKEY_NAME="lfwdbot"
-#HTTP_PAYLOAD='{ "doNotSendPassword": false, "language": "fr", "publicSshKey": "", "softwareId": [0], "sshKey": [ "'${SSHKEY_NAME}'" ], "templateId": 0 }'
+SSHKEY_NAME="${2:-vpsbot}"
 
 sshpubkey=$( ./getSSHKeys "${SSHKEY_NAME}" | jq -r '.key' )
-image_id=$( ./getImageDetails "${SRV}" | jq -r '.id' )
-HTTP_PAYLOAD='{ "doNotSendPassword": true, "publicSshKey": "'${sshpubkey}'", "imageId": "'${image_id}'" }'
+current_image_id=$( ./getImageDetails "${SRV}" | jq -r '.id' )
+
+IMAGE_ID="${3:-${current_image_id}}"
+HTTP_PAYLOAD='{ "doNotSendPassword": true, "publicSshKey": "'${sshpubkey}'", "imageId": "'${IMAGE_ID}'" }'
 
 ./ovh-bash post "vps/${SRV}/rebuild" "${HTTP_PAYLOAD}"
 

+ 4 - 0
scripts/bash/vps_postinstall

@@ -0,0 +1,4 @@
+#!/bin/bash
+
+sudo apt update
+sudo apt -y install htop