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