This repository has been archived on 2024-03-13. You can view files and clone it, but cannot push or open issues or pull requests.

37 lines
1.6 KiB
Executable File

# Day 0 - Create script
# Requires linode-cli to be installed (`pip3 install linode-cli`)
# require ROOT_PASS
if [ -z "$ROOT_PASS" ]
echo "Define a root password for this linode, example: ROOT_PASS=password1234 $0"
exit 1
# default to current user's SSH key as authorized key
if [ -z "$AUTHORIZED_KEYS" ]
AUTHORIZED_KEYS=$(cat ~/.ssh/
JSON=$(linode-cli linodes create --root_pass "$ROOT_PASS" \
--authorized_keys "$AUTHORIZED_KEYS" \
--label "UpskillChallengeNode" \
# Example output:
#[{"id": 34627775, "label": "linode34627775", "group": "", "status": "provisioning", "created": "2022-02-09T01:02:39", "updated": "2022-02-09T01:02:39", "type": "g6-nanode-1", "ipv4": [""], "ipv6": "2600:3c02::f03c:93ff:fe98:b296/128", "image": "linode/debian11", "region": "us-southeast", "specs": {"disk": 25600, "memory": 1024, "vcpus": 1, "transfer": 1000}, "alerts": {"cpu": 90, "network_in": 10, "network_out": 10, "transfer_quota": 80, "io": 10000}, "backups": {"enabled": false, "schedule": {"day": null, "window": null}, "last_successful": null}, "hypervisor": "kvm", "watchdog_enabled": true, "tags": []}]
# Ugly one-line of Python to parse the JSON from linode-cli. Folly?
python -c "import json; j=json.loads('$JSON')[0]; print(f'''IP Address: {j['ipv4']}\nStatus: {j['status']}\nCreated: {j['created']}\n''')"
# Sleep to wait for provisioning - this isn't long enough and it isn't a good practice.
# sleep 5.0
# show pretty table of info to prove changes
linode-cli linodes list --format 'label,status,ipv4'