Last active
February 22, 2018 22:10
-
-
Save StalkingKillah/0c3daa04dbf7c6564e23b7877c6006f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -z "$1" ]; then | |
echo "Input device (ex. /dev/sda1)" | |
exit | |
fi | |
TARGET="${1}" | |
MOUNT_POINT="/mnt/$(basename $TARGET)" | |
echo "Make sure the partition on $TARGET is safe for deletion" | |
read -p "Do you wish to continue [yN]? " answer; | |
if echo "$answer" | grep -iq "^y"; then | |
echo "Updating opkg package list" | |
opkg -V0 update | |
echo "Creating ext4 partition on $TARGET" | |
opkg -V0 install e2fsprogs -d ram | |
export PATH=$PATH:/tmp/bin:/tmp/sbin:/tmp/usr/bin:/tmp/usr/sbin | |
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/tmp/lib:/tmp/usr/lib | |
mkfs.ext4 $TARGET | |
echo "Mounting $TARGET to $MOUNT_POINT" | |
mkdir -p $MOUNT_POINT | |
mount $TARGET $MOUNT_POINT | |
mkdir -p /tmp/cproot | |
mount --bind / /tmp/cproot | |
tar -C /tmp/cproot -cvf - . | tar -C $MOUNT_POINT -xf - | |
umount /tmp/cproot | |
umount $MOUNT_POINT | |
echo "Setting up fstab" | |
# block detect > /etc/config/fstab | |
/etc/init.d/fstab enable | |
uci batch << EOF | |
set fstab.@mount[0].uuid=$(block detect | grep uuid | awk '{ print $3 }') | |
set fstab.@mount[0].target='/' | |
set fstab.@mount[0].fstype='ext4' | |
set fstab.@mount[0].option='rw,sync' | |
set fstab.@mount[0].enabled='1' | |
set fstab.@mount[0].enabled_fsck='0' | |
commit fstab | |
EOF | |
read -p "Press enter to restart the router" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment