diff --git a/functions/core.sh b/functions/core.sh index 4ea6470..ce6c676 100644 --- a/functions/core.sh +++ b/functions/core.sh @@ -31,11 +31,36 @@ function unmount() { sudo umount $ROOTFS_DIR } -function flash() { +function flash_adb() { adb push $IMAGE_DIR/rootfs.img /data/ adb push $IMAGE_DIR/system.img /data/ } +function flash_rsync() { + TARGET_ARCH=$(adb shell uname -m) + + # Download prebuilt rsync + echo "[install] Installing rsync on the device ..." + ! [ -f $IMAGE_DIR/rsync.bin ] && wget -O $IMAGE_DIR/rsync.bin --continue -q "https://github.com/JBBgameich/rsync-static/releases/download/continuous/rsync-$TARGET_ARCH" + ! [ -f $IMAGE_DIR/rsyncd.conf ] && wget -O $IMAGE_DIR/rsyncd.conf --continue -q "https://raw.githubusercontent.com/JBBgameich/rsync-static/master/rsyncd.conf" + + # Push rsync + adb push $IMAGE_DIR/rsync.bin /data/rsync >/dev/null + adb push $IMAGE_DIR/rsyncd.conf /data/rsyncd.conf >/dev/null + adb shell chmod +x /data/rsync + + # Start rsync daemon on the device + adb shell '/data/rsync --daemon --config=/data/rsyncd.conf &' + adb forward tcp:6010 tcp:1873 + + echo "[install] Transferring files ..." + rsync -avz --progress $IMAGE_DIR/rootfs.img rsync://localhost:6010/root/data/rootfs.img + rsync -avz --progress $IMAGE_DIR/system.img rsync://localhost:6010/root/data/system.img + + # Kill running rsync instances + adb shell killall rsync +} + function clean() { # Delete created files from last install sudo rm $ROOTFS_DIR $IMAGE_DIR -rf diff --git a/functions/misc.sh b/functions/misc.sh index 17d46ef..72c28c0 100755 --- a/functions/misc.sh +++ b/functions/misc.sh @@ -56,3 +56,15 @@ function usage() { defaults : none EOF } + +function flash_error() { + echo "Error: Couldn't copy the files to the device, is it connected?" +} + +function debug_variables() { + echo "[debug] rootfs: $ROOTFS_TAR" + echo "[debug] android image: $AND_IMAGE" + echo "[debug] release: $ROOTFS_RELEASE" + echo "[debug] install method: $FLASH_METHOD" + echo +} diff --git a/halium-install b/halium-install index 183ff93..8ff077d 100755 --- a/halium-install +++ b/halium-install @@ -50,12 +50,14 @@ export AND_IMAGE=$2 export ROOTFS_DIR=$(mktemp -d .halium-install-rootfs.XXXXX) export IMAGE_DIR=$(mktemp -d .halium-install-imgs.XXXXX) -# Start installer -echo "Debug: Chosen rootfs is $ROOTFS_TAR" -echo "Debug: Chosen android image is $AND_IMAGE" -echo "Debug: Chosen release is $ROOTFS_RELEASE" -echo +# Set defaults +export ${FLASH_METHOD:="rsync"} +export ${DEBUG:="true"} + +# Print out useful debugging information +[ $DEBUG == "true" ] && debug_variables +# Start installer echo "I: Writing rootfs into mountable image" convert_rootfs $IMAGE_SIZE &>/dev/null & spinner $! @@ -74,9 +76,11 @@ spinner $! echo "I: Shrinking images" shrink_images -echo "I: Pushing rootfs and android image to /data via ADB" -if ! flash $ROOTFS_RELEASE; then - echo "Error: Couldn't copy the files to the device, is it connected?" +echo "I: Pushing rootfs and android image to /data" +if [ $FLASH_METHOD == "adb" ]; then + flash_adb || flash_error +elif [ $FLASH_METHOD == "rsync" ]; then + flash_rsync || flash_error fi echo "I: Cleaning up host"