general crud baseline for secondary user

This commit is contained in:
2026-09-20 20:31:50 -07:00
parent 48ed9eabde
commit 6f393077d1
3 changed files with 169 additions and 1 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
.env
linodes.log
+143
View File
@@ -0,0 +1,143 @@
#!/bin/bash
# For my use, debian for the little one, ubuntu for the big ones
# From .env, following values:
# LINODE_API_KEY (used for all Linode API calls below, via curl)
# WHICH_DOMAIN
# ROOT_PASS
source .env
# All Linode API requests use the API key sourced from .env above:
# curl -H "Authorization: Bearer $LINODE_API_KEY" https://api.linode.com/v4/...
#ROOT_PASS=$(for w in {1..3}; do echo -n $(cat /usr/share/dict/words | grep -v "'" | sed -n $(echo "$(cat /usr/share/dict/words | grep -v "'" | wc -l) * $RANDOM / 32768 + 1" | bc)p); done)
#ROOT_PASS="StartRootPass5678"
SCRIPT_ACTION=$1
LINODE_LABEL=$2
# ni7ne 1997630
# oily 2111036
WHICH_DOMAIN="2111036"
LOGFILE="./linodes.log"
if [[ "$SCRIPT_ACTION" == "" || "$SCRIPT_ACTION" == "--help" || "$SCRIPT_ACTION" == "-?" ]]; then
echo "Linode helper script: create-linode.sh <action> <label> [args]"
echo "Create: create-linode.sh c <new label>"
echo " (fixed size: 8GB shared, newest Debian image)"
echo "Destroy: create-linode.sh d <label>"
echo "Connect: create-linode.sh x <label>"
echo " create-linode.sh x <label> get <remote source> <local dest>"
echo " create-linode.sh x <label> put <local source> <remote dest>"
echo "Update record: create-linode.sh a <label> <subdomain>"
echo "List: create-linode.sh l"
echo " (lists all Linodes, no label needed)"
fi
# Create
if [[ "$SCRIPT_ACTION" == "c" ]]; then
# Fixed size: 8GB shared, newest Debian image
INSTANCE_SIZE="g6-standard-4"
INSTANCE_IMAGE="linode/debian13"
curl -s -H "Content-Type: application/json" \
-H "Authorization: Bearer $LINODE_API_KEY" \
-X POST -d '{
"label": "'$LINODE_LABEL'",
"region": "us-central",
"type": "'$INSTANCE_SIZE'",
"image": "'$INSTANCE_IMAGE'",
"root_pass": "'$ROOT_PASS'",
"authorized_users": ["ni7ne_midpriv"]
}' \
https://api.linode.com/v4/linode/instances | jq .
sleep 60
INSTANCE_IP=$(curl -s -H "Authorization: Bearer $LINODE_API_KEY" https://api.linode.com/v4/linode/instances | jq '.data[] | select(.label == "'$LINODE_LABEL'") | .ipv4[]' | sed -e "s/\"//g")
INSTANCE_ID=$(curl -s -H "Authorization: Bearer $LINODE_API_KEY" https://api.linode.com/v4/linode/instances | jq '.data[] | select(.label == "'$LINODE_LABEL'") | .id' | sed -e "s/\"//g")
echo "Instance IP: $INSTANCE_IP"
echo "Instance ID: $INSTANCE_ID"
# SSH CONFIG BLOCK
#ssh -o "StrictHostKeyChecking no" root@$INSTANCE_IP "apt update && apt install -y jq"
# END SSH CONFIG BLOCK
echo "$(date -Iminutes) --- Id:$INSTANCE_ID --- IP:$INSTANCE_IP Summoned $LINODE_LABEL." >>$LOGFILE
echo "Started with root pass $ROOT_PASS"
fi
# List
if [[ "$SCRIPT_ACTION" == "l" ]]; then
curl -s -H "Authorization: Bearer $LINODE_API_KEY" \
https://api.linode.com/v4/linode/instances | jq .
fi
# Destroy
if [[ "$SCRIPT_ACTION" == "d" ]]; then
INSTANCE_IP=$(curl -s -H "Authorization: Bearer $LINODE_API_KEY" https://api.linode.com/v4/linode/instances | jq '.data[] | select(.label == "'$LINODE_LABEL'") | .ipv4[]' | sed -e "s/\"//g")
INSTANCE_ID=$(curl -s -H "Authorization: Bearer $LINODE_API_KEY" https://api.linode.com/v4/linode/instances | jq '.data[] | select(.label == "'$LINODE_LABEL'") | .id' | sed -e "s/\"//g")
echo "Destroying ID:$INSTANCE_ID Hit Ctrl-C in the next 10 seconds to cancel."
sleep 15
curl -s -H "Authorization: Bearer $LINODE_API_KEY" \
-X DELETE https://api.linode.com/v4/linode/instances/$INSTANCE_ID
echo "$(date -Iminutes) --- Id:$INSTANCE_ID --- IP:$INSTANCE_IP Destroyed $LINODE_LABEL." >>$LOGFILE
fi
# Connect
if [[ "$SCRIPT_ACTION" == "x" ]]; then
REMOTE_ACTION=$3
SCP_SOURCE=$4
SCP_DEST=$5
INSTANCE_IP=$(curl -s -H "Authorization: Bearer $LINODE_API_KEY" https://api.linode.com/v4/linode/instances | jq '.data[] | select(.label == "'$LINODE_LABEL'") | .ipv4[]' | sed -e "s/\"//g")
if [[ "$REMOTE_ACTION" == "get" ]]; then
echo "get </~/source> <localdest>"
scp $INSTANCE_IP:/home/finn/$SCP_SOURCE $SCP_DEST
fi
if [[ "$REMOTE_ACTION" == "put" ]]; then
echo "put <localsource> </~/dest>"
scp $SCP_SOURCE $INSTANCE_IP:/home/finn/$SCP_DEST
fi
if [[ "$REMOTE_ACTION" == "" ]]; then
echo "Connecting: $INSTANCE_IP"
ssh root@$INSTANCE_IP
fi
fi
# Update record
if [[ "$SCRIPT_ACTION" == "a" ]]; then
INSTANCE_IP=$(curl -s -H "Authorization: Bearer $LINODE_API_KEY" https://api.linode.com/v4/linode/instances | jq '.data[] | select(.label == "'$LINODE_LABEL'") | .ipv4[]' | sed -e "s/\"//g")
NI_SUBDOMAIN=$3
echo "Previous value ni7ne:"
curl -s -H "Authorization: Bearer $LINODE_API_KEY" \
https://api.linode.com/v4/domains/$WHICH_DOMAIN/records | jq .
sleep 3
echo "Updating records with ip $INSTANCE_IP..."
#ni7ne:
curl -s -H "Content-Type: application/json" \
-H "Authorization: Bearer $LINODE_API_KEY" \
-X POST -d '{
"type": "A",
"name": "'$NI_SUBDOMAIN'",
"target": "'$INSTANCE_IP'",
"priority": 0,
"weight": 0,
"port": 0,
"service": null,
"protocol": null,
"ttl_sec": 14400,
"tag": null
}' \
https://api.linode.com/v4/domains/$WHICH_DOMAIN/records | jq .
echo "Update complete."
fi
+25
View File
@@ -0,0 +1,25 @@
Volume Configuration
To get started with a new volume, youll want to create a filesystem on it:
Create a Filesystem
mkfs.ext4 "/dev/disk/by-id/scsi-0Linode_Volume_ValVol202609"
THIS STEP HAS BEEN COMPLETED
Once the volume has a filesystem, you can create a mountpoint for it:
Create a Mountpoint
mkdir "/mnt/ValVol202609"
THIS HAS BEEN VERIFIED WORKING
Then you can mount the new volume:
Mount Volume
mount "/dev/disk/by-id/scsi-0Linode_Volume_ValVol202609" "/mnt/ValVol202609"
THIS HAS BEEN VERIFIED WORKING
If you want the volume to automatically mount every time your Linode boots, youll want to add a line like the following to your /etc/fstab file:
Mount every time your Linode boots
/dev/disk/by-id/scsi-0Linode_Volume_ValVol202609 /mnt/ValVol202609 ext4 defaults,noatime,nofail 0 2