From aa55c7920568233e1829fc41249d71ad6af55670 Mon Sep 17 00:00:00 2001 From: James Swineson Date: Tue, 9 Apr 2019 16:59:41 +0800 Subject: [PATCH] try to get rootfs url automatically --- README.md | 34 ++++++++++++++++++++++++++++++++++ menhera.sh | 13 ++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..33978e0 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# menhera.sh + +Start a RAM Linux system (Debian for now) without requiring physical access to your server. + +With menhera.sh you can: + * format your system disk or create RAID + * install a new distro + * do important maintenance or backup with nobody writing to your root filesystem + * ... + +with only SSH! + +"menhera" is short for "mental healer". + +## Dependencies + + * Linux kernel: overlayfs and tmpfs support + * systemd + * squashfs-tools + * wget + +## Usage + +Just download and run. + +## Known issues + + * Cannot auto detect rootfs URL + +## Thanks + + * This project is inspired by [marcan/takeover.sh](https://github.com/marcan/takeover.sh) + * The major code came from [a maintenance writeup on my blog](https://blog.swineson.me/debian-9-csm-online-convert-root-partition-to-raid/) (in Simp. Chinese) + * [xTom.com](https://xtom.com/) donated a VPS for my testing \ No newline at end of file diff --git a/menhera.sh b/menhera.sh index e997eb0..047dfce 100755 --- a/menhera.sh +++ b/menhera.sh @@ -3,7 +3,7 @@ set -Eeuo pipefail # config WORKDIR="/tmp/menhera" -ROOTFS="https://images.linuxcontainers.org/images/debian/stretch/amd64/default/20190409_05:24/rootfs.squashfs" +ROOTFS="" # internal global variables OLDROOT="/" @@ -23,6 +23,16 @@ confirm() { esac } +get_rootfs() { + if [ -z ${ROOTFS+x} ]; then + echo "Getting rootfs URL..." + ROOTFS_TIME=$(curl "https://uk.images.linuxcontainers.org/images/debian/stretch/amd64/default/?C=M;O=D" | grep "folder.gif" | head -n 1 | cut -d'>' -f7 | cut -d'/' -f1) + ROOTFS="https://images.linuxcontainers.org/images/debian/stretch/amd64/default/${ROOTFS_TIME}/rootfs.squashfs" + else + echo "\$ROOTFS is set to '$ROOTFS'" + fi +} + sync_filesystem() { echo "Syncing..." sync @@ -135,6 +145,7 @@ echo -e "\tYou have closed all programs you can, and backed up all important dat echo -e "\tYou can SSH into your system as root user" confirm || exit -1 +get_rootfs sync_filesystem prepare_environment