Skip to content

Instantly share code, notes, and snippets.

@Marcocanc
Last active December 31, 2021 11:48
Show Gist options
  • Save Marcocanc/8b0a1c11c18a86939e9000ba00468825 to your computer and use it in GitHub Desktop.
Save Marcocanc/8b0a1c11c18a86939e9000ba00468825 to your computer and use it in GitHub Desktop.
Create a scaleway instance, put rclone and its config on it, sync drives and then terminate the the server
#!/bin/bash
set -e
SCALEWAY='scw --region="ams1"'
ARCH=X64
COMM_TYPE=$ARCH-2GB
IMAGE=xenial
TRANSFERS=7
TG_TOKEN=<BOT_TOKEN>
TG_CHAT_ID=<CHAT_ID>
send_telegram_msg () {
curl -sG "https://api.telegram.org/bot${TG_TOKEN}/sendMessage?chat_id=${TG_CHAT_ID}" --data-urlencode text="$1"> /dev/null
}
echo "[+] Creating Server from image"
send_telegram_msg "Spinning up a Server for ya"
SERVER=$($SCALEWAY run -d --ipv6 --commercial-type=${COMM_TYPE} ${IMAGE})
echo "[+] Server created with id: ${SERVER}"
echo "[+] Waiting for server to start"
SERVER_VERSION=$($SCALEWAY exec -w "${SERVER}" "uname -v")
echo "[+] Booted ${SERVER_VERSION}"
function cleanup {
echo "[+] Stopping and terminaing the server"
send_telegram_msg "Terminating server"
$SCALEWAY stop -t "${SERVER}" >/dev/null
}
trap cleanup EXIT
echo "[+] Installing unzip"
$SCALEWAY exec "${SERVER}" "apt-get -qq update && apt-get -y -qq install unzip"
echo "[+] Installing rclone"
case "$ARCH" in
X64)
RCLONE_ARCH=amd64
;;
ARM64)
RCLONE_ARCH=arm64
;;
esac
$SCALEWAY exec "${SERVER}" "curl -sO https://downloads.rclone.org/rclone-current-linux-${RCLONE_ARCH}.zip && \
unzip -q rclone-current-linux-${RCLONE_ARCH}.zip && \
cd rclone-*-linux-${RCLONE_ARCH} && \
cp rclone /usr/bin/ &&\
chown root:root /usr/bin/rclone && \
chmod 755 /usr/bin/rclone"
echo "[+] Copying rclone config"
$SCALEWAY exec "${SERVER}" "mkdir -p /root/.config/rclone"
$SCALEWAY cp /root/.config/rclone/rclone.conf "${SERVER}":/root/.config/rclone/
echo "[+] Syncing drives"
$SCALEWAY exec "${SERVER}" "rclone sync --transfers ${TRANSFERS} --verbose gdrive-crypt:/ acd-crypt:/"
echo "[+] Finished syncing drives"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment