Skip to content

Instantly share code, notes, and snippets.

@wopfel
Last active November 17, 2018 17:53
Show Gist options
  • Select an option

  • Save wopfel/f0224b611c769ae4fd59f52bf1a3ac84 to your computer and use it in GitHub Desktop.

Select an option

Save wopfel/f0224b611c769ae4fd59f52bf1a3ac84 to your computer and use it in GitHub Desktop.

Revisions

  1. wopfel revised this gist Nov 17, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions prepare-sd-card.sh
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,8 @@
    exit 99


    # This script also copies a public key to the SSH authorized_keys file for the root user (ansible, here)

    set -e

    if [[ -z $1 ]] ; then
  2. wopfel created this gist Nov 17, 2018.
    69 changes: 69 additions & 0 deletions prepare-sd-card.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    #!/bin/bash

    # Call: ./prepare-sd-card.sh /dev/sdX
    # Danger! May wipe the wrong data...
    exit 99


    set -e

    if [[ -z $1 ]] ; then
    echo "Parameter (sdcard /dev/sdx) missing"
    exit 1
    fi

    if [[ ! -b $1 ]] ; then
    echo "$1 is no block device"
    exit 1
    fi

    # Gives only sdb
    BASENAME=$( basename $1 )
    OUTPUT=$( lsblk -do name,tran,rm $1 | tail -n 1 )
    echo $OUTPUT
    REGEX="^$BASENAME usb 1$"
    if [[ ! $OUTPUT =~ $REGEX ]] ; then
    echo Not a usb device / removable
    exit 1
    fi

    FDISK_CMDS='
    o
    p
    n
    p
    1
    +100M
    t
    c
    n
    p
    2
    w
    q
    '

    echo "$FDISK_CMDS" | fdisk $1

    mkfs.vfat ${1}1
    yes | mkfs.ext4 ${1}2

    mount ${1}1 /root/pi-boot
    mount ${1}2 /root/pi-root

    df -Th /root/pi-*

    bsdtar -xpf ArchLinuxARM-rpi-2-latest.tar.gz -C /root/pi-root
    mv /root/pi-root/boot/* /root/pi-boot

    df -Th /root/pi-*

    mkdir /root/pi-root/root/.ssh/ && cat ansible-ssh-pubkey >> /root/pi-root/root/.ssh/authorized_keys

    sync

    umount /root/pi-boot /root/pi-root
    sync