Browse Source

split repo to ovhcli

volixer 5 tháng trước cách đây
mục cha
commit
45c6b43822

+ 2 - 86
scripts/bash/README.md

@@ -1,87 +1,3 @@
-# OVH-BASH
+# split repo
+You should find everything into https://git.linuxforward.com/byom/ovhcli
 
-This is a simple **OVH API wrapper** in BASH
-
-All API specifications is here : [OVH API](https://eu.api.ovh.com/console/?section=%2FallDom&branch=v1)
-
-It use the same configuration file as for the [go-ovh](https://github.com/ovh/go-ovh?tab=readme-ov-file#application-keyapplication-secret) wrapper
-
-## Token creation
-
-You need to follow : [createApp](https://www.ovh.com/auth/api/createApp)
-And add the Application_key,secret_key and consumer_key to the [ovh.conf](/../golang/ovh.conf)
-
-## How to use
-
-**Examples**
-1. Get all VPS
-```bash
-./ovhcli get vps
-
-[
-  "vps-3e2da6b4.vps.ovh.net",
-  "vps-556c9180.vps.ovh.net",
-  "vps-59e2e922.vps.ovh.net",
-  "vps-76fdb68a.vps.ovh.net",
-  "vps-89819518.vps.ovh.net",
-  "vps-b280dcff.vps.ovh.net",
-  "vps-f31d3392.vps.ovh.net"
-]
-```
-2. Get all records for a DNS Zone "linuxforward.com"
-```bash
-./ovhcli get domain/zone/linuxforward.com/record/
-[
-  5344790631,
-  5344790632,
-  5344790633,
-  5344790634,
-  5344790635,
-  5344790636,
-  5344790637,
-  [...]
-  5344790668,
-  5344790669,
-  5344790670,
-  5344790671
-]
-```
-
-3. Get info from a specific DNS Zone record
-
-```bash
-./ovhcli get domain/zone/linuxforward.com/record/5344790650
-{
-  "fieldType": "A",
-  "id": 5344790650,
-  "subDomain": "demodev",
-  "target": "51.91.101.38",
-  "ttl": 0,
-  "zone": "linuxforward.com"
-}
-
-```
-
-4. List all details from all VPS
-```bash
-./ovhcli get vps | jq -r '.[]' | while read vps;  do ./ovhcli get vps/${vps} | jq  '[.name, .model.name, .model.version, .model.disk, .model.memory]|@tsv' ; done | column -t
-vps-3e2da6b4.vps.ovh.net  vps-value-1-2-40    2019v1  40  2048
-vps-556c9180.vps.ovh.net  vps-value-1-2-40    2019v1  40  2048
-vps-59e2e922.vps.ovh.net  vps-value-1-2-40    2019v1  40  2048
-vps-76fdb68a.vps.ovh.net  vps-starter-1-2-20  2019v1  20  2048
-vps-89819518.vps.ovh.net  vps-value-1-2-40    2019v1  40  2048
-vps-b280dcff.vps.ovh.net  vps-value-1-2-40    2019v1  40  2048
-vps-f31d3392.vps.ovh.net  vps-starter-1-2-20  2019v1  20  2048
-```
-
-5. If credentials are revoked
-
-```bash
-./ovhcli get vps
-{
-  "class": "Client::Forbidden",
-  "message": "This credential is not valid",
-  "httpCode": "403 Forbidden",
-  "errorCode": "INVALID_CREDENTIAL"
-}
-```

+ 0 - 18
scripts/bash/delDNSName

@@ -1,18 +0,0 @@
-#!/bin/bash
-
-SUB_DOMAIN="${1:?Need customer subdomain code}"
-ZONE="linuxforward.com"
-
-
-# get subdomain record id
-record_id=$( ./ovhcli get "domain/zone/${ZONE}/record?fieldType=A&subDomain=${SUB_DOMAIN}" | jq -r '.[]' )
-
-if [ -n "${record_id}" ]; then
-  ./ovhcli delete "domain/zone/${ZONE}/record/${record_id}" | jq -r 'select(. != null)'
-  sleep 2
-  ./ovhcli post "domain/zone/${ZONE}/refresh" | jq -r 'select(. != null)'
-else
-  echo "Could not find any RecordID for ${SUB_DOMAIN}"
-fi
-
-exit $?

+ 0 - 7
scripts/bash/delSSHKey

@@ -1,7 +0,0 @@
-#!/bin/bash
-
-KEY_NAME="${1:?need a SSHKey name from /me}"
-
-./ovhcli delete "me/sshKey/${KEY_NAME}" | jq -r 'select(. != null)'
-
-exit $?

+ 0 - 7
scripts/bash/getImageDetails

@@ -1,7 +0,0 @@
-#!/bin/bash
-
-SRV="${1:?Need a fqdn}"
-
-./ovhcli get "vps/${SRV}/images/current" | jq -r '.'
-
-exit $?

+ 0 - 7
scripts/bash/getSSHKeys

@@ -1,7 +0,0 @@
-#!/bin/bash
-
-KEY_NAME="${1:?need a SSHKey name from /me}"
-
-./ovhcli get "me/sshKey/${KEY_NAME}"
-
-exit $?

+ 0 - 10
scripts/bash/getSecret

@@ -1,10 +0,0 @@
-#!/bin/bash
-
-# get Email Secret ID :
-last_id=$( ./ovhcli get me/notification/email/history | jq 'last(.[])' )
-secret_id=$( ./ovhcli 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
-./ovhcli post secret/retrieve '{ "id": "'"${secret_id}"'" }' | jq -r '.secret'
-
-exit $?

+ 0 - 36
scripts/bash/newSSHKey

@@ -1,36 +0,0 @@
-#!/bin/bash
-
-KEY_NAME="${1:?need a SSHKey name from /me}"
-KEY_DIR="${HOME}/.ssh/keys.d"
-
-# check if sshkey exists locally
-if [ -e "${KEY_DIR}/${KEY_NAME}" ] ; then
-  echo "SSH Key ${KEY_DIR}/${KEY_NAME} already exists locally"
-else
-  echo "SSH Key ${KEY_DIR}/${KEY_NAME} not found locally"
-  echo ">>> Creating it ..."
-  ssh-keygen -t ed25519 -f "${KEY_DIR}/${KEY_NAME}" -C "OVH_${KEY_NAME}" -q -N ""
-  ./delSSHKey "${KEY_NAME}"
-fi
-PUBKEY="$( cat "${KEY_DIR}/${KEY_NAME}.pub" )"
-
-# check if KEY_NAME exists into OVH User Account /me
-# remote_keyname = "string or empty"
-remote_keyname=$( ./ovhcli get "me/sshKey" | jq --arg v "${KEY_NAME}" -r '.|to_entries[]|select(.value == $v ).value' )
-
-# if remote_keyname exists check if pubkey is matching.
-remote_pubkey=$( ./ovhcli get "me/sshKey/${KEY_NAME}" | jq -r '.key' )
-  
-# if remote_keyname does not match KEY_NAME = this KEY_NAME is not already uploaded into OVH Account
-if [ -z "${remote_keyname}" ] || [ "${remote_pubkey}" != "${PUBKEY}" ] ; then
-  echo "SSH Keys does not exists remotely"
-  echo ">>> Uploading ${KEY_DIR}/${KEY_NAME} to OVH account"
-  HTTP_PAYLOAD='{ "key": "'${PUBKEY}'", "keyName": "'${KEY_NAME}'" }'
-
-  ./ovhcli post "me/sshKey" "${HTTP_PAYLOAD}" | jq -r 'select(. != null)'
-
-else
-  echo "SSH Keys are up-to-date"
-fi
-
-exit $?

+ 0 - 46
scripts/bash/ovhcli

@@ -1,46 +0,0 @@
-#!/bin/bash
-# shellcheck disable=SC1090 # https://www.shellcheck.net/wiki/SC1090
-# shellcheck disable=SC2154 # https://www.shellcheck.net/wiki/SC2154
-# shellcheck disable=SC2016 # https://www.shellcheck.net/wiki/SC2016
-
-# main variables
-# using same config file than for Golang script
-OVH_CONF="${OVH_CONF:-../golang/ovh.conf}"
-OVH_API_VERSION="1.0"
-#OUTPUT="${OUTPUT:-json}"
-
-# source all ovh keys
-source <( grep '=' "${OVH_CONF}" )
-
-# Create ENDPOINT
-case "${endpoint}" in
-  ovh-eu) ENDPOINT="https://eu.api.ovh.com/${OVH_API_VERSION}" ;;
-  ovh-us) ENDPOINT="https://us.api.ovh.com/${OVH_API_VERSION}" ;;
-  ovh-ca) ENDPOINT="https://ca.api.ovh.com/${OVH_API_VERSION}" ;;
-  *) echo "${endpoint} is not yet supported" ; exit ;;
-esac
-
-# Signing process
-# @"method" "url" "post_data" "timestamp"
-TIME=$( curl -s "${ENDPOINT}/auth/time" )
-
-# Method
-# ovhcli get vps
-HTTP_METHOD="${1:?need a http method}"
-HTTP_QUERY="${ENDPOINT}/${2:?need a query}"
-HTTP_PAYLOAD="${3}"
-
-CLEAR_SIGN="${application_secret}+${consumer_key}+${HTTP_METHOD^^}+${HTTP_QUERY}+${HTTP_PAYLOAD}+${TIME}"
-SIG='$1$'$( echo -n "${CLEAR_SIGN}" | sha1sum - | cut -d' ' -f1 )
-
-# curl call
-curl -sL -X "${HTTP_METHOD^^}" \
-	-H "Content-Type:application/json;charset=utf-8" \
-	-H "X-Ovh-Application:${application_key}" \
-	-H "X-Ovh-Timestamp:${TIME}" \
-	-H "X-Ovh-Signature:${SIG}" \
-	-H "X-Ovh-Consumer:${consumer_key}" \
-	--data "${HTTP_PAYLOAD}" "${HTTP_QUERY}" \
-	| jq '.'
-
-exit $?

+ 0 - 17
scripts/bash/setDNSName

@@ -1,17 +0,0 @@
-#!/bin/bash
-
-SRV="${1:?Need a current server fqdn}"
-ZONE="linuxforward.com"
-TTL=0
-
-SRV_IP=$( host "${SRV}" | awk '!/:/ { print $NF }' )
-SUB_DOMAIN_1="$( awk '$0 ~ /^\w{5}$/ { print tolower($1) }' /usr/share/dict/words | sort -n | uniq | shuf -n 1 )"
-SUB_DOMAIN_2="$( awk '$0 ~ /^\w{5}$/ { print tolower($1) }' /usr/share/dict/words | sort -n | uniq | shuf -n 1 )"
-
-HTTP_PAYLOAD='{ "fieldType": "A", "subDomain": "'${SUB_DOMAIN_1}-${SUB_DOMAIN_2}'", "target": "'${SRV_IP}'", "ttl": '${TTL}' }'
-
-./ovhcli post "domain/zone/${ZONE}/record" "${HTTP_PAYLOAD}"
-sleep 2
-./ovhcli post "domain/zone/${ZONE}/refresh" | jq -r 'select(. != null)'
-
-exit $?

+ 0 - 9
scripts/bash/setNewName

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

+ 0 - 14
scripts/bash/vpsReinstall

@@ -1,14 +0,0 @@
-#!/bin/bash
-
-SRV="${1:?Need a fqdn}"
-SSHKEY_NAME="${2:-vpsbot}"
-
-sshpubkey=$( ./getSSHKeys "${SSHKEY_NAME}" | jq -r '.key' )
-current_image_id=$( ./getImageDetails "${SRV}" | jq -r '.id' )
-
-IMAGE_ID="${3:-${current_image_id}}"
-HTTP_PAYLOAD='{ "doNotSendPassword": true, "publicSshKey": "'${sshpubkey}'", "imageId": "'${IMAGE_ID}'" }'
-
-./ovhcli post "vps/${SRV}/rebuild" "${HTTP_PAYLOAD}"
-
-exit $?

+ 0 - 4
scripts/bash/vps_postinstall

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