pinebook_install_to_SD.sh
#1
Brick 
Greetings,  

  The purpose of this post is to make the Pine Installer script available (on the forum) for Pinebook users who want to create SD cards on their Pinebook using the SD card slot, which will allow making SD cards directly on the Pinebook from the network;  this script is similar to the pin64_install_to_emm.sh , as well the rock64_install_to_SD.sh.

  The script does require the  curl  package,  as well the  jq  package.

(  This script allows you to burn Pinebook images from the network, to the SD card while booted from eMMC  )

pinebook_install_to_SD.sh

Code:
#!/bin/bash

set -eo pipefail

if [[ "$(id -u)" -ne "0" ]]; then
    echo "This script requires root."
    exit 1
fi

echo "Pine A64/Pinebook release installer!"
echo "(C) 2017. Kamil Trzciński (https://ayufan.eu)."
echo ""

usage() {
   echo "Usage:"
   echo "$ $0 <system> [version]"
   echo ""
   echo "Systems:"
   echo " - xenial-minimal (https://github.com/ayufan-pine64/linux-build/releases)"
   echo " - xenial-mate (https://github.com/ayufan-pine64/linux-build/releases)"
   echo " - xenial-i3 (https://github.com/ayufan-pine64/linux-build/releases)"
   echo " - android-7.0 (https://github.com/ayufan-pine64/android-7.0/releases)"
   echo " - android-7.1 (https://github.com/ayufan-pine64/android-7.1/releases)"
   echo ""
   echo "Version:"
   echo " - latest will be used if version is not defined"
   exit 1
}

if [[ $# -ne 1 ]] && [[ $# -ne 2 ]]; then
   usage
fi

#if [[ ! -d /sys/devices/soc.0/1c10000.sdmmc/mmc_host/mmc1 ]]; then
#    echo "You should boot from SD card"
#    exit 1
#fi

#if [[ ! -e /dev/mmcblk1 ]]; then
#    echo "You should boot from SD card"
#    exit 1
#fi

case "$1" in
   xenial-minimal|xenial-mate|xenial-i3)
       REPO="ayufan-pine64/linux-build"
       PREFIX="$1-$(cat /etc/pine64_model)-bspkernel-"
       SUFFIX="-[0-9]*.img.xz"
       ARCHIVER="xz -d"
       ;;

   android-7.0|android-7.1)
       REPO="ayufan-pine64/$1"
       if [[ "$(cat /etc/pine64_model)" == "pinebook" ]]; then
           PREFIX="$1-pine-a64-pinebook-v"
       elif [[ "$(cat /etc/pine64_model)" == "sopine" ]]; then
           PREFIX="$1-pine-a64-sopine-v"
       else
           PREFIX="$1-pine-a64-v"
       fi
       SUFFIX="-r[0-9]*.img.gz"
       ARCHIVER="gzip -d"
       ;;

   *)
       echo "Unknown system: $1"
       echo ""
       usage
       ;;
esac

VERSION="$2"

if [[ -z "$VERSION" ]]; then
    VERSION=$(curl -f -sS https://api.github.com/repos/$REPO/releases/latest | jq -r ".tag_name")
    if [ -z "$VERSION" ]; then
        echo "Latest release was not for $1."
       echo "Please go to: https://github.com/$REPO/releases/latest"
       exit 1
    fi

    echo "Using latest release: $VERSION from https://github.com/$REPO/releases."
fi

NAME="$PREFIX$VERSION$SUFFIX"
NAME_SAFE="${NAME//./\\.}"
VERSION_SAFE="${VERSION//./\\.}"

echo "Looking for download URL..."
DOWNLOAD_URL=$(curl -f -sS https://api.github.com/repos/$REPO/releases | \
   jq -r ".[].assets | .[].browser_download_url" | \
   ( grep -o "https://github\.com/$REPO/releases/download/$VERSION_SAFE/$NAME_SAFE" || true))

if [[ -z "$DOWNLOAD_URL" ]]; then
   echo "The download URL for $NAME not found".
   echo "Look at https://github.com/$REPO/releases for correct versions."
   exit 1
fi

echo "Doing this will overwrite all data stored on eMMC."

while true; do
   echo "Type YES to continue or Ctrl-C to abort."
   read CONFIRM
   if [[ "$CONFIRM" == "YES" ]]; then
       break
   fi
done

echo ""
echo "Using $DOWNLOAD_URL..."
echo "Umounting..."
umount -f /dev/mmcblk1* || true
echo ""

echo "Downloading and writing to /dev/mmcblk1..."
curl -L -f "$DOWNLOAD_URL" | $ARCHIVER | dd bs=30M of=/dev/mmcblk1
sync
echo ""
echo "You may want to run now pine64_remove_boot0.sh to make the current device unbootable."
echo ""

echo "Done."
Notes:
Place the script in the normal place    /usr/local/sbin/pinebook_install_to_SD.sh
make the script executable with :
sudo  chmod  0775  /usr/local/sbin/pinebook_install_to_SD.sh
sudo  chown  root  /usr/local/sbin/pinebook_install_to_SD.sh
sudo  chgrp  root  /usr/local/sbin/pinebook_install_to_SD.sh
To run the script and get usage:
sudo  /usr/local/sbin/pinebook_install_to_SD.sh
To run the script and load xenial-i3 :
sudo  /usr/local/sbin/pinebook_install_to_SD.sh   xenial-i3

If you do not specify a version then the script will pull the most recent (non pre release) from the repos.

(  This script allows you to burn Pinebook images from the network, to the SD card while booted from eMMC  )
Rolleyes

Updated Instructions.
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )


Messages In This Thread
pinebook_install_to_SD.sh - by MarkHaysHarris777 - 08-23-2017, 04:26 PM
RE: pinebook_install_to_SD.sh - by tlaswell - 08-28-2017, 12:30 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)