updated Doc and steps.

Commit push before retest.
This commit is contained in:
Sylvain 2015-12-22 08:24:10 +01:00
parent 22279473dc
commit 89a7ca3cc6
4 changed files with 90 additions and 78 deletions

View file

@ -4,6 +4,7 @@
# #
# Usage: # Usage:
# ./01_create_sdcard.sh downloaded_debian_image.zip /dev/sdcard_device # ./01_create_sdcard.sh downloaded_debian_image.zip /dev/sdcard_device
# ./01_create_sdcard.sh generated_yunohost.img /dev/sdcard_device
# #
# #
# Status: functional # Status: functional
@ -50,6 +51,9 @@ skip_if() {
sha_verify_zip() { sha_verify_zip() {
local zip=$DEBIAN_IMG_ZIP local zip=$DEBIAN_IMG_ZIP
[[ -z "$zip" ]] && { echo "no zip refuse to run"; return 3; }
local out=_build_arm_steps/sha_verify_zip local out=_build_arm_steps/sha_verify_zip
skip_if $out && return 2 skip_if $out && return 2
sha1sum $zip > $out sha1sum $zip > $out
@ -57,19 +61,20 @@ sha_verify_zip() {
local sha="$(sed -e 's/\(^[a-f0-9]\+\).*/\1/' $out)" local sha="$(sed -e 's/\(^[a-f0-9]\+\).*/\1/' $out)"
if [[ "$sha" != "$SHA_DEBIAN_IMG_ZIP" ]] if [[ "$sha" != "$SHA_DEBIAN_IMG_ZIP" ]]
then then
echo "NOK: '$sha' != '$SHA_DEBIAN_IMG_ZIP'" die "NOK: '$sha' != '$SHA_DEBIAN_IMG_ZIP'"
exit 1
fi fi
} }
# unzip raspbian image in the cache folder # unzip raspbian image in the cache folder
unzip_img() { unzip_img() {
if ! skip_if _build_arm_steps/*.img local img_filename=$(unzip -l $DEBIAN_IMG_ZIP | awk '/\.img$/ { print $4 }')
if ! skip_if _build_arm_steps/$img_filename
then then
unzip -o $DEBIAN_IMG_ZIP -d _build_arm_steps unzip -o $DEBIAN_IMG_ZIP -d _build_arm_steps
fi fi
# get extrated image filename from zip file # get extrated image filename from zip file
DEBIAN_IMG=$(ls _build_arm_steps/ | grep \\.img$) DEBIAN_IMG="_build_arm_steps/$img_filename"
} }
# helper, try to guess top device name # helper, try to guess top device name
@ -111,7 +116,8 @@ umount_sdcard_partition() {
dd_to_sdcard() { dd_to_sdcard() {
[[ -z "$SDCARD" ]] && { echo '$SDCARD is empty refusing to run'; return; } [[ -z "$SDCARD" ]] && { echo '$SDCARD is empty refusing to run'; return; }
# ensure that sdcard partitions are unmounted with umount_sdcard_partition # ensure that sdcard partitions are unmounted with umount_sdcard_partition
sudo dd bs=16M if=_build_arm_steps/$DEBIAN_IMG of=$SDCARD echo "starting dd it will take some times…"
sudo dd bs=16M if="$DEBIAN_IMG" of=$SDCARD
sudo sync sudo sync
} }
@ -126,10 +132,10 @@ test_all_tools() {
mount_loopback_img() { mount_loopback_img() {
[[ -z "$DEBIAN_IMG" ]] && { echo '$DEBIAN_IMG is empty refusing to run'; return; } [[ -z "$DEBIAN_IMG" ]] && { echo '$DEBIAN_IMG is empty refusing to run'; return; }
mkdir -p _build_arm_steps/mnt mkdir -p _build_arm_steps/mnt
local dev_loop0=$(sudo losetup -f --show _build_arm_steps/$DEBIAN_IMG) local dev_loop0=$(sudo losetup -f --show "$DEBIAN_IMG")
local part_offset=$(sudo fdisk -l $dev_loop0 | awk '/Linux/ { print $2 }') local part_offset=$(sudo fdisk -l $dev_loop0 | awk '/Linux/ { print $2 }')
# mount the ext4 partition at computed offset # mount the ext4 partition at computed offset
local dev_loop1=$(sudo losetup -f --show -o $((512 * $part_offset)) _build_arm_steps/$DEBIAN_IMG) local dev_loop1=$(sudo losetup -f --show -o $((512 * $part_offset)) "$DEBIAN_IMG")
sudo mount $dev_loop1 _build_arm_steps/mnt/ sudo mount $dev_loop1 _build_arm_steps/mnt/
} }
@ -158,12 +164,15 @@ add_ssh_key_to_img() {
chmod -R go= .ssh/ chmod -R go= .ssh/
# give to pi user id # give to pi user id
sudo chown -R --reference . .ssh sudo chown -R --reference . .ssh
# return to working folder
cd - > /dev/null cd - > /dev/null
umount_loopback_img umount_loopback_img
echo "ssh-key added"
} }
# functions call in that order, edit remove a long running step if already done or if # functions call in that order, edit remove a long running step if already done or if
# you want to skip it, step states are saved in folder _build_arm_steps and skipped automatically. # you want to skip it, step states are saved in folder _build_arm_steps and skipped automatically.
# STEPS is modifiy in main() if argument1 is an .img and not a .zip
STEPS=" STEPS="
sha_verify_zip sha_verify_zip
unzip_img unzip_img
@ -177,14 +186,27 @@ main() {
# init # init
if [[ -z "$1" ]] if [[ -z "$1" ]]
then then
echo "argument 1 error: expecting raspbian image file.zip" echo "argument 1 error: expecting raspbian image file.zip or an img"
echo "can be downloaded here: $DOWNLOAD_URL" echo "can be downloaded here: $DOWNLOAD_URL"
exit 1 exit 1
fi fi
local regexp='\.img$'
# reading script argument # reading script argument
DEBIAN_IMG_ZIP=$1 DEBIAN_IMG_ZIP=$1
if [[ "$1" =~ $regexp ]]
then
DEBIAN_IMG="$1"
DEBIAN_IMG_ZIP=""
# write image verbatim without modification
STEPS="
umount_sdcard_partition
dd_to_sdcard"
else
[[ -f "$DEBIAN_IMG_ZIP" ]] || die "error raspbian image not found: '$DEBIAN_IMG_ZIP'" [[ -f "$DEBIAN_IMG_ZIP" ]] || die "error raspbian image not found: '$DEBIAN_IMG_ZIP'"
fi
SDCARD=$(get_top_device "$2") SDCARD=$(get_top_device "$2")
[[ -z "$SDCARD" ]] && die "argument 2 error: expecting sdcard_device" [[ -z "$SDCARD" ]] && die "argument 2 error: expecting sdcard_device"

View file

@ -2,9 +2,6 @@
# #
# Usage: ./02_install_yunohost.sh DHCP_IP_ADDRESS_OF_RASPBERRYPI # Usage: ./02_install_yunohost.sh DHCP_IP_ADDRESS_OF_RASPBERRYPI
# #
# This script apply this doc: 
# https://yunohost.org/#/build_arm_image
#
# Doc: See README.md # Doc: See README.md
# #
# STEPS: # STEPS:
@ -12,7 +9,7 @@
# 2. run install_yunohostv2 on the raspi # 2. run install_yunohostv2 on the raspi
# 3. install an yunohost-firstboot script and shutdown # 3. install an yunohost-firstboot script and shutdown
# #
# Status: draft # Status: functional
# Licence: GPLv3 # Licence: GPLv3
# Author: sylvain303@github # Author: sylvain303@github
@ -22,7 +19,7 @@ sshpi() {
ssh -i _build_arm_steps/nopasskey pi@$PI_IP "$@" ssh -i _build_arm_steps/nopasskey pi@$PI_IP "$@"
} }
# harcoded test IP # harcoded test IP, you can change for yours for debuging. See main()
PI_IP=192.168.1.2 PI_IP=192.168.1.2
# the installer script is used localy, no git clone else where. # the installer script is used localy, no git clone else where.
YUNOHOST_INSTALL=../install_yunohostv2 YUNOHOST_INSTALL=../install_yunohostv2
@ -31,12 +28,7 @@ YUNOHOST_REMOTE_DIR=/tmp/install_yunohost
# dummy password # dummy password
PASSROOT='Free_money?yunomakeit' PASSROOT='Free_money?yunomakeit'
# wrapper to init with positional parameters # used by main() See at the end.
init_param() {
PI_IP=$1
ask_root_pass
}
ask_root_pass() { ask_root_pass() {
echo "HINT: very good program to generate strong memorisable passwords: pwqgen" echo "HINT: very good program to generate strong memorisable passwords: pwqgen"
echo "HINT: sudo apt-get install passwdqc" echo "HINT: sudo apt-get install passwdqc"
@ -225,6 +217,10 @@ do_step() {
# main script code, wrapped inside a function, so the whole script can also be # main script code, wrapped inside a function, so the whole script can also be
# sourced as a lib, for debug or unittesting purpose. # sourced as a lib, for debug or unittesting purpose.
main() { main() {
# you can comment the 2 lines, for debuging. Fix PI_IP with your dhcp IP.
PI_IP=$1
ask_root_pass
do_step init_sdcard_and_reboot do_step init_sdcard_and_reboot
wait_raspberrypi || return 1 wait_raspberrypi || return 1

View file

@ -28,18 +28,6 @@ test_tool() {
fi fi
} }
# skip if the file exists.
# usage: skip_if _build_arm_steps/somefile && return 2
skip_if() {
if [[ -e "$1" ]]
then
echo "cached"
return 0
fi
# echo -n "continue for $1"
return 1
}
# helper, try to guess top device name # helper, try to guess top device name
# /dev/sdp2 => /dev/sdp # /dev/sdp2 => /dev/sdp
# /dev/mmcblk0p1 => /dev/mmcblk0 # /dev/mmcblk0p1 => /dev/mmcblk0
@ -95,34 +83,15 @@ test_all_tools() {
done done
} }
# mount the .img so we can write on it before copying on the sdcard # debug, not used
mount_loopback_img() {
[[ -z "$OUTPUT_IMG" ]] && { echo '$OUTPUT_IMG is empty refusing to run'; return; }
[[ ! -d _build_arm_steps/mnt ]] && mkdir _build_arm_steps/mnt
local dev_loop0=$(sudo losetup -f --show _build_arm_steps/$OUTPUT_IMG)
local part_offset=$(sudo fdisk -l $dev_loop0 | awk '/Linux/ { print $2 }')
# mount the ext4 partition at computed offset
local dev_loop1=$(sudo losetup -f --show -o $((512 * $part_offset)) _build_arm_steps/$OUTPUT_IMG)
sudo mount $dev_loop1 _build_arm_steps/mnt/
}
umount_loopback_img() {
# find mounted loopback
local dev_loop1=$(mount | awk '/_build_arm_steps/ { print $1 }')
# compute loop n-1
local n=${dev_loop1#/dev/loop}
local dev_loop0="/dev/loop$(($n - 1))"
sudo umount _build_arm_steps/mnt
sudo losetup -d $dev_loop1
sudo losetup -d $dev_loop0
}
mount_sdcard_data_partition() { mount_sdcard_data_partition() {
local part_data=2 local part_data=2
[[ ! -d _build_arm_steps/sdcard ]] && mkdir _build_arm_steps/sdcard [[ ! -d _build_arm_steps/sdcard ]] && mkdir _build_arm_steps/sdcard
sudo mount ${SDCARD}p2 _build_arm_steps/sdcard sudo mount ${SDCARD}p2 _build_arm_steps/sdcard
} }
# prototype, not used. Wanna test if I can d.d only used part of the partion, and fix it back on the PC
# not working yet, may be not achieved anyway…
get_used_partition_size() { get_used_partition_size() {
local start_offset=$(sudo fdisk -l /dev/mmcblk0 | awk '/Linux/ { print $2 * 512 }') local start_offset=$(sudo fdisk -l /dev/mmcblk0 | awk '/Linux/ { print $2 * 512 }')
local used=$(df -B1 _build_arm_steps/sdcard | awk '/dev.mmcblk0p2/ { print $3 }') local used=$(df -B1 _build_arm_steps/sdcard | awk '/dev.mmcblk0p2/ { print $3 }')

View file

@ -6,42 +6,41 @@ The files here are for builder. They are not needed to install your yunohost.
The folder etc/ structure maps debian OS folders, shell script here are helpers. The folder etc/ structure maps debian OS folders, shell script here are helpers.
Files in etc/ subfolders will be copied on the sdcard when installation is finished. Files in etc/ subfolders will be copied on the sdcard when installation is finished.
Those scripts are following the steps provided here: https://yunohost.org/#/build_arm_image
## License ## License
All the content here is distributed under [GPLv3](http://www.gnu.org/licenses/gpl-3.0.txt). All the content here is distributed under [GPLv3](http://www.gnu.org/licenses/gpl-3.0.txt).
## See also ## See also
* https://yunohost.org/#/build_arm_image for building steps explanations
* https://forum.yunohost.org/t/building-a-new-image-for-raspberry-debian-jessie-fr-en/1101/13 - discussion about building a new image for Raspberry Pi. * https://forum.yunohost.org/t/building-a-new-image-for-raspberry-debian-jessie-fr-en/1101/13 - discussion about building a new image for Raspberry Pi.
## Files ## Files
Description of the files available here. Description of the files available here.
All step stripts are using your PC to store some files in the folder _build_arm_steps/. This folder will be created by 01_create_sdcard.sh. You can wipe it, or remove selected script data form it, to redo a step. All step stripts are using your PC to store some files in the folder `_build_arm_steps/`. This folder will be created by `01_create_sdcard.sh`. You can wipe it, or remove selected script data form it, to redo a step.
All step script are designed to run in this folder: All step scripts are designed to run in this folder:
~~~ ~~~bash
git clone this_repos git clone this_repos
cd path_to/build_arm_image/ cd path_to/build_arm_image/
./01_create_sdcard.sh raspbian-jessie.zip /dev/mmcblk0
# plug and boot raspberrypi
./02_install_yunohost.sh 192.168.1.200
# unplug raspberrypi and connect the sdcard back to the PC
./03_copy_sdcard_to_img.sh /dev/mmcblk0
~~~ ~~~
then run steps scripts in order. ### Steps
### Run on PC Scripts are prefixed by a number which is the order they must be ran.
Scripts are prefixed by a number which is an hint of the order they should be ran.
#### autosizer.sh
Used on your PC to compact the dd image you will copy back after the rapsbian has been built.
This script requier root privilege to run and modify the local sdcard image.
#### 01_create_sdcard.sh #### 01_create_sdcard.sh
Create a bootable image for raspbian. You have to download the .zip of the raspbian image. Create a bootable image for raspbian. You have to download the .zip of the raspbian image.
It embeds sudo call for using dd to copy the raw image to the sdcard. This script embeds sudo call for using dd to copy the raw image to the sdcard.
It will add an ssh key to pi default rasbian user in oder to connect later to continue automated installation. The pi user will be removed at the end. The ssh key-pair is generated only for you. It will add an ssh key to pi default rasbian user in oder to connect later to continue automated installation. The pi user will be removed at the end (See #4). The ssh key-pair is generated only for you.
Usage: Usage:
@ -51,7 +50,9 @@ Usage:
It takes some minutes to perform all the steps (~ 2m3.867s at last run). Be patient. It takes some minutes to perform all the steps (~ 2m3.867s at last run). Be patient.
Use `df` or `lsblk` to find the name of your sdcard device. The script is taking care of umonting the partion if any. It also guess the disk's name if you give an partition's name instead of entire disk device's name. Use `df` or `lsblk` to find the name of your sdcard device. The script is taking care of umonting the partition if any. It also guesses the disk's name if you give an partition's name instead of entire disk device's name.
Be carefull not to wipe the wrong device!
#### 02_install_yunohost.sh #### 02_install_yunohost.sh
@ -75,16 +76,40 @@ Or what ever your DHCP is giving…
Run: Run:
~~~ ~~~bash
./02_install_yunohost.sh 192.168.1.123 ./02_install_yunohost.sh 192.168.1.123
~~~ ~~~
### Run on Raspberry #### 03_copy_sdcard_to_img.sh
Will be handled by [02_install_yunohost.sh](https://github.com/Sylvain303/install_script/blob/master/build_arm_image/02_install_yunohost.sh) When the build is finished the Raspberry will shutdown. Unplug and insert the sdcard back in the computer.
run the following script before shuting down your raspbian.
~~~bash
./03_copy_sdcard_to_img.sh /dev/sdcard_device
~~~ ~~~
./intsall_arm.sh
This will ask your sudo password and dd the resulting img from the sdcard back to your PC. Stored in `_build_arm_steps/` folder. It takes arround 6min on my PC to copy an sdcard of 8G.
The image will be automaticly shrinked to its minimal size using autosizer.sh.
#### test the image back
You can test the resutling image back with `01_create_sdcard.sh`.
~~~bash
./01_create_sdcard.sh _build_arm_steps/newly_created_image.img /dev/sdcard_device
~~~ ~~~
#### share
You can zip, bzip2, or…, and share your freshly created yunohost image on the [forum](https://forum.yunohost.org).
Enjoy!
### Helper
#### autosizer.sh
Used on your PC to compact the dd image you will copy back after the rapsbian has been built.
This script requier root privilege to run and modify the local sdcard image.