From 9d458cc88a6b9539525adc2547c10b7147a04f69 Mon Sep 17 00:00:00 2001 From: Sylvain303 Date: Tue, 15 Dec 2015 05:39:31 +0100 Subject: [PATCH 01/21] correct log location in README /var/log/yunohost-installation.log from installv2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 46271ec..f806189 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Execute the script: $ bash install_yunohostv2 -If something goes wrong, you can check the installation logs saved in ```/var/log/yunohost.log``` +If something goes wrong, you can check the installation logs saved in ```/var/log/yunohost-installation.log``` ## Advanced usage From 5580fd41330c30c37cc934feda179687356da0d1 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 15 Dec 2015 10:08:04 +0100 Subject: [PATCH 02/21] add build_arm_image tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit firstboot is copied form previous ARM image verbatim, initial import. --- build_arm_image/README.md | 7 +++++ build_arm_image/etc/init.d/yunohost-firstboot | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 build_arm_image/README.md create mode 100755 build_arm_image/etc/init.d/yunohost-firstboot diff --git a/build_arm_image/README.md b/build_arm_image/README.md new file mode 100644 index 0000000..87beb64 --- /dev/null +++ b/build_arm_image/README.md @@ -0,0 +1,7 @@ +This folder contains helper script to build arm image for raspberry and derivative arm plateform. + +the folder structure maps debian OS folders. + +files are copied to the /root when finished. + +See also: https://yunohost.org/#/build_arm_image diff --git a/build_arm_image/etc/init.d/yunohost-firstboot b/build_arm_image/etc/init.d/yunohost-firstboot new file mode 100755 index 0000000..c90d35e --- /dev/null +++ b/build_arm_image/etc/init.d/yunohost-firstboot @@ -0,0 +1,27 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: expand rootfs and Generates new ssh host keys on first boot +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: +# Short-Description: Generates new ssh host keys on first boot +# Description: Generatesapt-get --purge clean new ssh host keys on $ +### END INIT INFO +echo "Expanding rootfs ..." +raspi-config --expand-rootfs +echo "Generating new ssh keys ..." +# Delete SSH keys +rm -f /etc/ssh/ssh_host_* +yes | ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa +yes | ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa +yes | ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa -b 521 +echo "Deleting logs ..." +find /var/log -type f -exec echo > {} \; +echo "Purging apt ..." +apt-get --purge clean +echo "Removing myself ..." +echo > /etc/udev/rules.d/70-persistent-net.rules +update-rc.d -f yunohost-firstboot remove >/dev/null 2>&1 +echo "Rebooting ..." +reboot From 9f04bd1db8c2931c8028437b9b5e01c2b57eb0a2 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 15 Dec 2015 14:58:14 +0000 Subject: [PATCH 03/21] add script for firstboot updated yunohost-firstboot and installer --- build_arm_image/etc/init.d/yunohost-firstboot | 4 ++-- build_arm_image/intsall_arm.sh | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100755 build_arm_image/intsall_arm.sh diff --git a/build_arm_image/etc/init.d/yunohost-firstboot b/build_arm_image/etc/init.d/yunohost-firstboot index c90d35e..78c9ac3 100755 --- a/build_arm_image/etc/init.d/yunohost-firstboot +++ b/build_arm_image/etc/init.d/yunohost-firstboot @@ -21,7 +21,7 @@ find /var/log -type f -exec echo > {} \; echo "Purging apt ..." apt-get --purge clean echo "Removing myself ..." -echo > /etc/udev/rules.d/70-persistent-net.rules -update-rc.d -f yunohost-firstboot remove >/dev/null 2>&1 +insserv -r /etc/init.d/yunohost-firstboot +rm -f /etc/init.d/yunohost-firstboot echo "Rebooting ..." reboot diff --git a/build_arm_image/intsall_arm.sh b/build_arm_image/intsall_arm.sh new file mode 100755 index 0000000..4c05d26 --- /dev/null +++ b/build_arm_image/intsall_arm.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# complete install with some specific ARM (raspberry) scripts. +# +# to be run for building an SD card image. +# + +cp etc/init.d/yunohost-firstboot /etc/init.d/ +chmod a+x /etc/init.d/yunohost-firstboot +insserv /etc/init.d/yunohost-firstboot From df49b0d1680187e75e7746e491261b0ce5d733d2 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 15 Dec 2015 16:15:25 +0100 Subject: [PATCH 04/21] add autosizer initial import --- build_arm_image/autosizer.sh | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 build_arm_image/autosizer.sh diff --git a/build_arm_image/autosizer.sh b/build_arm_image/autosizer.sh new file mode 100755 index 0000000..6f36138 --- /dev/null +++ b/build_arm_image/autosizer.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Automatic Image file resizer +# Written by SirLagz +strImgFile=$1 + +if [[ ! $(whoami) =~ "root" ]]; then + echo "" + echo "**********************************" + echo "*** This should be run as root ***" + echo "**********************************" + echo "" + exit +fi + +if [[ -z $1 ]]; then + echo "Usage: ./autosizer.sh " + exit +fi + +if [[ ! -e $1 || ! $(file $1) =~ "x86" ]]; then + echo "Error : Not an image file, or file doesn't exist" + exit +fi + +partinfo=`parted -m $1 unit B print` +partnumber=`echo "$partinfo" | grep ext4 | awk -F: ' { print $1 } '` +partstart=`echo "$partinfo" | grep ext4 | awk -F: ' { print substr($2,0,length($2)-1) } '` +loopback=`losetup -f --show -o $partstart $1` +e2fsck -f $loopback +minsize=`resize2fs -P $loopback | awk -F': ' ' { print $2 } '` +minsize=`echo $minsize+1000 | bc` +resize2fs -p $loopback $minsize +sleep 1 +losetup -d $loopback +partnewsize=`echo "$minsize * 4096" | bc` +newpartend=`echo "$partstart + $partnewsize" | bc` +part1=`parted $1 rm 2` +part2=`parted $1 unit B mkpart primary $partstart $newpartend` +endresult=`parted -m $1 unit B print free | tail -1 | awk -F: ' { print substr($2,0,length($2)-1) } '` +truncate -s $endresult $1 From c65b9daf1fd087cd41ec0c093bebba21535f8da1 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 15 Dec 2015 17:54:43 +0100 Subject: [PATCH 05/21] add autosizer source, modified README --- build_arm_image/README.md | 19 +++++++++++++++---- build_arm_image/autosizer.sh | 22 +++++++++++++--------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/build_arm_image/README.md b/build_arm_image/README.md index 87beb64..96f2c74 100644 --- a/build_arm_image/README.md +++ b/build_arm_image/README.md @@ -1,7 +1,18 @@ -This folder contains helper script to build arm image for raspberry and derivative arm plateform. +This folder contains helper scripts to build an arm image for raspberry. +The files here are for builder. They are not needed to install yunohost. -the folder structure maps debian OS folders. +The folder structure maps debian OS folders, shell script here are helpers. -files are copied to the /root when finished. +The files are copied on the sdcard when installation is finished. -See also: https://yunohost.org/#/build_arm_image +See also: https://yunohost.org/#/build_arm_image for previous step. + +run the following script before shuting down your rasbian. + +~~~ +./intsall_arm.sh +~~~ + + +autosizer.sh is used on your PC to compact the dd image you will copy back. +this script requier root privilege to run and modify the sdcard image. diff --git a/build_arm_image/autosizer.sh b/build_arm_image/autosizer.sh index 6f36138..af21b23 100755 --- a/build_arm_image/autosizer.sh +++ b/build_arm_image/autosizer.sh @@ -1,6 +1,9 @@ #!/bin/bash # Automatic Image file resizer # Written by SirLagz +# +# got from: http://sirlagz.net/2013/03/10/script-automatic-rpi-image-downsizer/ + strImgFile=$1 if [[ ! $(whoami) =~ "root" ]]; then @@ -12,20 +15,20 @@ if [[ ! $(whoami) =~ "root" ]]; then exit fi -if [[ -z $1 ]]; then +if [[ -z $strImgFile ]]; then echo "Usage: ./autosizer.sh " exit fi -if [[ ! -e $1 || ! $(file $1) =~ "x86" ]]; then +if [[ ! -e $strImgFile || ! $(file $strImgFile) =~ "x86" ]]; then echo "Error : Not an image file, or file doesn't exist" exit fi -partinfo=`parted -m $1 unit B print` -partnumber=`echo "$partinfo" | grep ext4 | awk -F: ' { print $1 } '` +partinfo=`parted -m $strImgFile unit B print` +partnumber=`echo "$partinfo" | grep ext4 | awk -F: ' { print $strImgFile } '` partstart=`echo "$partinfo" | grep ext4 | awk -F: ' { print substr($2,0,length($2)-1) } '` -loopback=`losetup -f --show -o $partstart $1` +loopback=`losetup -f --show -o $partstart $strImgFile` e2fsck -f $loopback minsize=`resize2fs -P $loopback | awk -F': ' ' { print $2 } '` minsize=`echo $minsize+1000 | bc` @@ -34,7 +37,8 @@ sleep 1 losetup -d $loopback partnewsize=`echo "$minsize * 4096" | bc` newpartend=`echo "$partstart + $partnewsize" | bc` -part1=`parted $1 rm 2` -part2=`parted $1 unit B mkpart primary $partstart $newpartend` -endresult=`parted -m $1 unit B print free | tail -1 | awk -F: ' { print substr($2,0,length($2)-1) } '` -truncate -s $endresult $1 +# TODO: 2 is probably $partnumber +part1=`parted $strImgFile rm 2` +part2=`parted $strImgFile unit B mkpart primary $partstart $newpartend` +endresult=`parted -m $strImgFile unit B print free | tail -1 | awk -F: ' { print substr($2,0,length($2)-1) } '` +truncate -s $endresult $strImgFile From d7367f3b11afcb5f141c8d116c3876d3c9de30d7 Mon Sep 17 00:00:00 2001 From: Sylvain303 Date: Thu, 17 Dec 2015 06:13:19 +0100 Subject: [PATCH 06/21] add link to yunohost forum --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f806189..02f8968 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # YunoHost installation scripts +Forked version: some discussion available [here](https://forum.yunohost.org/t/building-a-new-image-for-raspberry-debian-jessie-fr-en/1101) + ## Context The scripts in this repository will install [YunoHost](https://yunohost.org/) on a Debian system. From 95259a44f098a53093e7b28e2a6ba5951dd08e15 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Sat, 19 Dec 2015 11:29:38 +0100 Subject: [PATCH 07/21] add first version of 01_create_sdcard.sh helper to rebuild sdcard in reproducible steps add .gitignore for cache step folder --- build_arm_image/.gitignore | 1 + build_arm_image/01_create_sdcard.sh | 162 ++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 build_arm_image/.gitignore create mode 100755 build_arm_image/01_create_sdcard.sh diff --git a/build_arm_image/.gitignore b/build_arm_image/.gitignore new file mode 100644 index 0000000..e7e4f39 --- /dev/null +++ b/build_arm_image/.gitignore @@ -0,0 +1 @@ +_build_arm_steps diff --git a/build_arm_image/01_create_sdcard.sh b/build_arm_image/01_create_sdcard.sh new file mode 100755 index 0000000..a1ff6ba --- /dev/null +++ b/build_arm_image/01_create_sdcard.sh @@ -0,0 +1,162 @@ +#!/bin/bash +# +# Create the sdcard on your PC with the latest debian. +# +# Usage: +# ./01_create_sdcard.sh downloaded_debian_image.zip /dev/sdcard_device +# +# Licence: GPLv3 +# Author: sylvain303@github + +# informations about Raspbian image: +# Raspbian Jessie Lite Version: November 2015 Release date: 2015-11-21 +# version: SHA-1 of the .zip: 97888fcd9bfbbae2a359b0f1d199850852bf0104 +# Kernel version: 4.1 +# http://downloads.raspberrypi.org/raspbian/release_notes.txt + +DOWNLOAD_URL=https://www.raspberrypi.org/downloads/raspbian/ +SHA_DEBIAN_IMG_ZIP=97888fcd9bfbbae2a359b0f1d199850852bf0104 + +die() { + echo "$*" + exit 1 +} + +# helper, test if a shell program exists in PATH +test_tool() { + local cmd=$1 + if type $cmd > /dev/null + then + # OK + return 0 + else + die "tool missing: $cmd" + 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 +} + + +sha_verify_zip() { + local zip=$DEBIAN_IMG_ZIP + local out=_build_arm_steps/sha_verify_zip + skip_if $out && return 2 + sha1sum $zip > $out + # read only sha check hash + local sha="$(sed -e 's/\(^[a-f0-9]\+\).*/\1/' $out)" + if [[ "$sha" != "$SHA_DEBIAN_IMG_ZIP" ]] + then + echo "NOK: '$sha' != '$SHA_DEBIAN_IMG_ZIP'" + exit 1 + fi +} + +# unzip raspbian image in the cache folder +unzip_img() { + if ! skip_if _build_arm_steps/*.img + then + unzip -o $DEBIAN_IMG_ZIP -d _build_arm_steps + fi + # get extrated image filename from zip file + DEBIAN_IMG=$(ls _build_arm_steps/ | grep \\.img$) +} + +# helper try to guess top device name +# /dev/sdp2 => /dev/sdp +# /dev/mmcblk0p1 => /dev/mmcblk0 +# just some regexp no smart thing +get_top_device() { + local device="$1" + local regexp1='^/dev/sd[a-z]' + local regexp2='^/dev/mmcblk[0-9]' + + if [[ "$device" =~ $regexp1 ]] + then + #echo sd + device="${device/[0-9]/}" + elif [[ "$device" =~ $regexp2 ]] + then + #echo mmcblk + device="${device/p[0-9]/}" + fi + + echo "$device" +} + +umount_all_partition() { + local p + # search and replace all occurence of / by . + local pattern=${SDCARD////.} + pattern=${pattern/p[0-9]/} + for p in $(df | awk "/^$pattern/ { print \$1 }") + do + echo sudo umount $p + done + echo "done device for sdcard=${pattern//.//}" +} + +dd_to_sdcard() { + # ensure + echo dd bs=16M if=_build_arm_steps/$DEBIAN_IMG of=$SDCARD +} + +test_all_tools() { + for t in $* + do + test_tool $t + done +} + +# 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. +STEPS=" +sha_verify_zip +unzip_img +umount_all_partition +dd_to_sdcard" + +# main wrapper, so the script can be sourced for debuging purpose or unittesting +main() { + # positional argument must be script argument. + # init + if [[ -z "$1" ]] + then + echo "argument 1 error: expecting raspbian image file.zip" + echo "can be downloaded here: $DOWNLOAD_URL" + exit 1 + fi + + # reading script argument + DEBIAN_IMG_ZIP=$1 + [[ -f "$DEBIAN_IMG_ZIP" ]] || die "error raspbian image not found: '$DEBIAN_IMG_ZIP'" + SDCARD=$(get_top_device "$2") + [[ -z "$SDCARD" ]] && die "argument 2 error: expecting sdcard_device" + + test_all_tools dd sync sudo + mkdir -p _build_arm_steps + + # actions loop + for s in $STEPS + do + echo -n "$s: " + eval $s + done +} + +# sourcing code detection, if code is sourced for debug purpose, main is not executed. +[[ $0 != "$BASH_SOURCE" ]] && sourced=1 || sourced=0 +if [[ $sourced -eq 0 ]] +then + # pass positional argument as is + main "$@" +fi From 26a441d573e89786f9afb62a3c9ea68b955093aa Mon Sep 17 00:00:00 2001 From: Sylvain Date: Sat, 19 Dec 2015 21:30:19 +0100 Subject: [PATCH 08/21] update documentation add ssh key pair --- build_arm_image/.gitignore | 1 + build_arm_image/README.md | 42 +++++++++++++++++++++++++++++------ build_arm_image/nopasskey | 27 ++++++++++++++++++++++ build_arm_image/nopasskey.pub | 1 + 4 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 build_arm_image/nopasskey create mode 100644 build_arm_image/nopasskey.pub diff --git a/build_arm_image/.gitignore b/build_arm_image/.gitignore index e7e4f39..1bdecb0 100644 --- a/build_arm_image/.gitignore +++ b/build_arm_image/.gitignore @@ -1 +1,2 @@ _build_arm_steps +.*.swp diff --git a/build_arm_image/README.md b/build_arm_image/README.md index 96f2c74..3c0753f 100644 --- a/build_arm_image/README.md +++ b/build_arm_image/README.md @@ -1,18 +1,46 @@ += Build your own yunohost image for Raspberry Pi = + This folder contains helper scripts to build an arm image for raspberry. The files here are for builder. They are not needed to install yunohost. The folder structure maps debian OS folders, shell script here are helpers. - The files are copied on the sdcard when installation is finished. -See also: https://yunohost.org/#/build_arm_image for previous step. +== See also == +* https://yunohost.org/#/build_arm_image for buildini step explanations +* https://forum.yunohost.org/t/building-a-new-image-for-raspberry-debian-jessie-fr-en/1101/13 - discussion about building an new image for Raspberry Pi. -run the following script before shuting down your rasbian. +== Files == + +Descriptions of the files available here. + +=== Run on PC === + +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. +this script requier root privilege to run and modify the sdcard image. + +==== 01_create_sdcard.sh ==== + +Create a bootable image for raspbian. You have to download the .zip of the image. +it embeds sudo call for using dd to copy the raw image to the sdcard. + +Usage: + +~~~ +./01_create_sdcard.sh image_rasbian.zip /dev/device_to_sdcard +~~~ + +it takes some minutes to perform all the steps. Be patient. + + +=== Run on Raspberry === + +run the following script before shuting down your raspbian. ~~~ ./intsall_arm.sh ~~~ - - -autosizer.sh is used on your PC to compact the dd image you will copy back. -this script requier root privilege to run and modify the sdcard image. diff --git a/build_arm_image/nopasskey b/build_arm_image/nopasskey new file mode 100644 index 0000000..6c3ddbf --- /dev/null +++ b/build_arm_image/nopasskey @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEArQtaSUb9ge79E/bNfAoH3jaPbWtG5O7+y/7m+Bi8I5KY+DHI +cUfc0Agf4HxpioJFHUP5U5xcchHwMXcoQ5qGTdTsgnvWs9xHdrwAWsG8HaaYvMVw +YMgiwEdUawGWmsLC7b/lgo3GLVbSFYes+xaOQh5e6hnCPFQtqdiRk0bYM19Mgqh8 +7UPToVBUalhDr53f53UYwT0hfGVF8887NxthRCXIp0HrGbsA/7LKYj1xE9k+cJ04 ++6xzyofLHxcloIWTdSekcV7nGD9k7+noDMwtbYNKm8V7JZjVPqt9tIYUdAA+xhF9 +fPA42sV3gEXNakSsZrvd+uZ9Q3C6SaHKYH/1UwIDAQABAoIBAQCSV4eDcQXzXKmq +uI4O2GzPAFVLs+3Arl3NJ0Uti72QV+oF/BQHuT6EsFpE/vJCsOjCVzoD+7gyv/jh +3GOwyH3MVMWvlAt/EEtfnp6uIil06e9BtbfUIW1CLxC1biJvv0Yayq7OOhffQA1r +J9KihfDI+eZLFH2vh4EWopB6fO9agVk+Gmsb/2kPXa8wumBdD8EedQRNWWExdQJr +a6v5Q+z54XCUNQMu/mjkJVGblsKaNROTmSmLavLh0aSom2DR6KSQN8etATKYDDiq +OxbMD/1euXN1kjihbyg6ERRO744jfLXFg9bxoghXjtetLReQpWW/H8kqHxE6Fya6 +IlNiTLwBAoGBAN1y7QPdEGE/ZHUAjtkB6owx5oXdpUKov8YL/88viYyhRR3SJtVg +8gmvl7nTvaZ7kbOQevada18Bt3EUUnCkLr2NoGh1Boy9RRds/iUjL+BZn0tb67KR +HP1PlMOe1OPLTCJCa89qrTB3bHChF8hXPZlK4aH1yCmsrpJecWMdNm/VAoGBAMgL +DzyB0LBkjPzoaY855Nm0H9q2Oj32uMU5e1wxB5ppKqt4s4M6QXcnPuGM1azOtePQ +jiu7kq2OjrIpN1xjds5AYGYWnRWoI1DOp3hiod/H9fIGecq00TsRtNAbliez4v89 +BoJej+tynMynlSqgo8sbPFbf+yuQqOCYq+gg2QyHAoGAK2V5MxegPR56Jj+cvsQU +XbLttPARkbWWF06Eq+pp7ygvbj+fopMj+2fwuNbYxIZUsDaxEiEZSH4Cn+NWoIJc +MoNNmwrL5Mq2fne6ejaiDDoj8FWsI8syPiXZRlia6aUOX2xaykPieqv8kTnQek82 +YBL/koii2B/h+gcN+1lfMJ0CgYAV0w8QfOE1vWKcXQbXN2u+TKaFCAiGpho2ejT5 +M+gucnbTSlHbaUmnJEL5/JF7TvoNJr28C7TO9pSe31xI2hkmG2Po/2KX8EYaFNG0 +kp4yefBdPVOgR+Xj2eSuJ7RUFI4ZZqEFLCfreg+dTFM72VbFW+1TVRBkCl5CUqW+ +p4bGlQKBgQCf3ixc746gIn33CC93fIRw+1k9wpXYDvBZSMTcmabjHdvqOo/9OZdy +I2Hf+QqWfUsu5oPiVzLQl7QLwaZfZ2i+FLl6QfMZ6JlB+nHlWOFainnwnujLGulj +yJef4liZcrBB8DSNbUTZO8aEME7SDNRYN1qdwn5ddtq1b6F15Cyv6A== +-----END RSA PRIVATE KEY----- diff --git a/build_arm_image/nopasskey.pub b/build_arm_image/nopasskey.pub new file mode 100644 index 0000000..818d709 --- /dev/null +++ b/build_arm_image/nopasskey.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCtC1pJRv2B7v0T9s18CgfeNo9ta0bk7v7L/ub4GLwjkpj4MchxR9zQCB/gfGmKgkUdQ/lTnFxyEfAxdyhDmoZN1OyCe9az3Ed2vABawbwdppi8xXBgyCLAR1RrAZaawsLtv+WCjcYtVtIVh6z7Fo5CHl7qGcI8VC2p2JGTRtgzX0yCqHztQ9OhUFRqWEOvnd/ndRjBPSF8ZUXzzzs3G2FEJcinQesZuwD/sspiPXET2T5wnTj7rHPKh8sfFyWghZN1J6RxXucYP2Tv6egMzC1tg0qbxXslmNU+q320hhR0AD7GEX188DjaxXeARc1qRKxmu9365n1DcLpJocpgf/VT sylvain@sylvain-laptop From fd57e4103dcd9be590329d5af02950199ae72b0a Mon Sep 17 00:00:00 2001 From: Sylvain Date: Sat, 19 Dec 2015 21:36:11 +0100 Subject: [PATCH 09/21] remove nopasskey, not used. Will be generated on the fly --- build_arm_image/nopasskey | 27 --------------------------- build_arm_image/nopasskey.pub | 1 - 2 files changed, 28 deletions(-) delete mode 100644 build_arm_image/nopasskey delete mode 100644 build_arm_image/nopasskey.pub diff --git a/build_arm_image/nopasskey b/build_arm_image/nopasskey deleted file mode 100644 index 6c3ddbf..0000000 --- a/build_arm_image/nopasskey +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEArQtaSUb9ge79E/bNfAoH3jaPbWtG5O7+y/7m+Bi8I5KY+DHI -cUfc0Agf4HxpioJFHUP5U5xcchHwMXcoQ5qGTdTsgnvWs9xHdrwAWsG8HaaYvMVw -YMgiwEdUawGWmsLC7b/lgo3GLVbSFYes+xaOQh5e6hnCPFQtqdiRk0bYM19Mgqh8 -7UPToVBUalhDr53f53UYwT0hfGVF8887NxthRCXIp0HrGbsA/7LKYj1xE9k+cJ04 -+6xzyofLHxcloIWTdSekcV7nGD9k7+noDMwtbYNKm8V7JZjVPqt9tIYUdAA+xhF9 -fPA42sV3gEXNakSsZrvd+uZ9Q3C6SaHKYH/1UwIDAQABAoIBAQCSV4eDcQXzXKmq -uI4O2GzPAFVLs+3Arl3NJ0Uti72QV+oF/BQHuT6EsFpE/vJCsOjCVzoD+7gyv/jh -3GOwyH3MVMWvlAt/EEtfnp6uIil06e9BtbfUIW1CLxC1biJvv0Yayq7OOhffQA1r -J9KihfDI+eZLFH2vh4EWopB6fO9agVk+Gmsb/2kPXa8wumBdD8EedQRNWWExdQJr -a6v5Q+z54XCUNQMu/mjkJVGblsKaNROTmSmLavLh0aSom2DR6KSQN8etATKYDDiq -OxbMD/1euXN1kjihbyg6ERRO744jfLXFg9bxoghXjtetLReQpWW/H8kqHxE6Fya6 -IlNiTLwBAoGBAN1y7QPdEGE/ZHUAjtkB6owx5oXdpUKov8YL/88viYyhRR3SJtVg -8gmvl7nTvaZ7kbOQevada18Bt3EUUnCkLr2NoGh1Boy9RRds/iUjL+BZn0tb67KR -HP1PlMOe1OPLTCJCa89qrTB3bHChF8hXPZlK4aH1yCmsrpJecWMdNm/VAoGBAMgL -DzyB0LBkjPzoaY855Nm0H9q2Oj32uMU5e1wxB5ppKqt4s4M6QXcnPuGM1azOtePQ -jiu7kq2OjrIpN1xjds5AYGYWnRWoI1DOp3hiod/H9fIGecq00TsRtNAbliez4v89 -BoJej+tynMynlSqgo8sbPFbf+yuQqOCYq+gg2QyHAoGAK2V5MxegPR56Jj+cvsQU -XbLttPARkbWWF06Eq+pp7ygvbj+fopMj+2fwuNbYxIZUsDaxEiEZSH4Cn+NWoIJc -MoNNmwrL5Mq2fne6ejaiDDoj8FWsI8syPiXZRlia6aUOX2xaykPieqv8kTnQek82 -YBL/koii2B/h+gcN+1lfMJ0CgYAV0w8QfOE1vWKcXQbXN2u+TKaFCAiGpho2ejT5 -M+gucnbTSlHbaUmnJEL5/JF7TvoNJr28C7TO9pSe31xI2hkmG2Po/2KX8EYaFNG0 -kp4yefBdPVOgR+Xj2eSuJ7RUFI4ZZqEFLCfreg+dTFM72VbFW+1TVRBkCl5CUqW+ -p4bGlQKBgQCf3ixc746gIn33CC93fIRw+1k9wpXYDvBZSMTcmabjHdvqOo/9OZdy -I2Hf+QqWfUsu5oPiVzLQl7QLwaZfZ2i+FLl6QfMZ6JlB+nHlWOFainnwnujLGulj -yJef4liZcrBB8DSNbUTZO8aEME7SDNRYN1qdwn5ddtq1b6F15Cyv6A== ------END RSA PRIVATE KEY----- diff --git a/build_arm_image/nopasskey.pub b/build_arm_image/nopasskey.pub deleted file mode 100644 index 818d709..0000000 --- a/build_arm_image/nopasskey.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCtC1pJRv2B7v0T9s18CgfeNo9ta0bk7v7L/ub4GLwjkpj4MchxR9zQCB/gfGmKgkUdQ/lTnFxyEfAxdyhDmoZN1OyCe9az3Ed2vABawbwdppi8xXBgyCLAR1RrAZaawsLtv+WCjcYtVtIVh6z7Fo5CHl7qGcI8VC2p2JGTRtgzX0yCqHztQ9OhUFRqWEOvnd/ndRjBPSF8ZUXzzzs3G2FEJcinQesZuwD/sspiPXET2T5wnTj7rHPKh8sfFyWghZN1J6RxXucYP2Tv6egMzC1tg0qbxXslmNU+q320hhR0AD7GEX188DjaxXeARc1qRKxmu9365n1DcLpJocpgf/VT sylvain@sylvain-laptop From 8937c2ae46de1897ff067284478e5ba83f4c0a77 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Sat, 19 Dec 2015 21:55:32 +0100 Subject: [PATCH 10/21] add action with sudo for using sdcard img add ssh key to pi accound manipulate mounting the image with losetup some real actions with dd not tested on sdcard yet --- build_arm_image/01_create_sdcard.sh | 56 +++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/build_arm_image/01_create_sdcard.sh b/build_arm_image/01_create_sdcard.sh index a1ff6ba..687ba3f 100755 --- a/build_arm_image/01_create_sdcard.sh +++ b/build_arm_image/01_create_sdcard.sh @@ -93,21 +93,24 @@ get_top_device() { echo "$device" } -umount_all_partition() { +umount_sdcard_partition() { + [[ -z "$SDCARD" ]] && { echo '$SDCARD is empty refusing to run'; return; } local p # search and replace all occurence of / by . local pattern=${SDCARD////.} pattern=${pattern/p[0-9]/} for p in $(df | awk "/^$pattern/ { print \$1 }") do - echo sudo umount $p + sudo umount $p done echo "done device for sdcard=${pattern//.//}" } dd_to_sdcard() { - # ensure - echo dd bs=16M if=_build_arm_steps/$DEBIAN_IMG of=$SDCARD + [[ -z "$SDCARD" ]] && { echo '$SDCARD is empty refusing to run'; return; } + # ensure that sdcard partitions are unmounted with umount_sdcard_partition + sudo dd bs=16M if=_build_arm_steps/$DEBIAN_IMG of=$SDCARD + sudo sync } test_all_tools() { @@ -117,12 +120,51 @@ test_all_tools() { done } +mount_loopback_img() { + [[ -z "$DEBIAN_IMG" ]] && { echo '$DEBIAN_IMG is empty refusing to run'; return; } + mkdir -p _build_arm_steps/mnt + local dev_loop0=$(sudo losetup -f --show _build_arm_steps/$DEBIAN_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/$DEBIAN_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 +} + +# copy a local key for ssh without password later +add_ssh_key_to_img() { + mount_loopback_img + cd _build_arm_steps/mnt/home/pi/ + mkdir .ssh + local ssh_key=$OLDPWD/_build_arm_steps/nopasskey + # silently generate an ssh-key pair + yes | ssh-keygen -q -t rsa -C "nopasskey-install" -N "" -f $ssh_key > /dev/null + cp ${ssh_key}.pub .ssh/authorized_keys + # remove some permissions + chmod -R go= .ssh/ + # give to pi user id + sudo chown -R --reference . .ssh + cd - > /dev/null + umount_loopback_img +} + # 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. STEPS=" sha_verify_zip unzip_img -umount_all_partition +add_ssh_key_to_img +umount_sdcard_partition dd_to_sdcard" # main wrapper, so the script can be sourced for debuging purpose or unittesting @@ -142,7 +184,7 @@ main() { SDCARD=$(get_top_device "$2") [[ -z "$SDCARD" ]] && die "argument 2 error: expecting sdcard_device" - test_all_tools dd sync sudo + test_all_tools dd sync sudo losetup ssh-keygen mkdir -p _build_arm_steps # actions loop @@ -159,4 +201,6 @@ if [[ $sourced -eq 0 ]] then # pass positional argument as is main "$@" +else + echo $STEPS fi From fe34552be349217f610637e8dc1419edca0c4dd2 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Sun, 20 Dec 2015 10:50:56 +0100 Subject: [PATCH 11/21] update README add step 02, step 01 tested See README.md and read the code in 02_install_yunohost.sh Not working yet. Step 01 seems to work well. Bug #4 is present for me. --- build_arm_image/02_install_yunohost.sh | 199 +++++++++++++++++++++++++ build_arm_image/README.md | 48 +++++- 2 files changed, 239 insertions(+), 8 deletions(-) create mode 100755 build_arm_image/02_install_yunohost.sh diff --git a/build_arm_image/02_install_yunohost.sh b/build_arm_image/02_install_yunohost.sh new file mode 100755 index 0000000..e13928a --- /dev/null +++ b/build_arm_image/02_install_yunohost.sh @@ -0,0 +1,199 @@ +#!/bin/bash +# +# Usage: ./02_install_yunohost.sh DHCP_IP_ADDRESS_OF_RASPBERRYPI +# +# apply this doc: https://github.com/Sylvain304/doc/blob/master/build_arm_image.md +# +# Status: draft +# Licence: GPLv3 +# Author: sylvain303@github + +# usefull wrapper to use ssh with our nopasskey +sshpi() { + ssh -i _build_arm_steps/nopasskey pi@$PI_IP "$@" +} + +# harcoded test IP +PI_IP=192.168.1.50 +YUNOHOST_INSTALL=../install_yunohostv2 +YUNOHOST_REMOTE_DIR=/tmp/install_yunohost + +ask_root_pass() { + echo "HINT: very good program to generate strong memorisable passwords: pwqgen" + echo "HINT: sudo apt-get install passwdqc" + echo -n "Enter a new root password for raspberrypi: " + read PASSROOT +} + +# helper to "scp" a local script to the raspberrypi +# Usage: scp_yunohost local_filename +scp_yunohost() { + if [[ -z "$1" ]] + then + echo "scp_yunohost: expect a local filename" + return 1 + fi + + if [[ ! -f "$1" ]] + then + echo "scp_yunohost: filename not found: '$1'" + return 1 + fi + + if [[ -z "$YUNOHOST_REMOTE_DIR" ]] + then + echo "scp_yunohost: error \$YUNOHOST_REMOTE_DIR is empty" + return 1 + fi + + local script=$1 + local scriptb=$(basename $script) + + cat "$script" | \ + sshpi "mkdir -p $YUNOHOST_REMOTE_DIR && \ + cat > $YUNOHOST_REMOTE_DIR/$scriptb && \ + chmod a+x $YUNOHOST_REMOTE_DIR/$scriptb + " +} + +# helper, compute common remote_step script name so they can be skiped by do_step +make_step_file() { + local step_name="$1" + local step_file=yuno_step_${step_name}.sh + echo $step_file +} + +# helper will create a local script and upload it to raspberrypi in $YUNOHOST_REMOTE_DIR +# Usage: create_remote_script $FUNCNAME "shell commands…" +create_remote_script() { + local step_file=$(make_step_file "$1") + local actions="$2" + + echo '#!/bin/bash' > _build_arm_steps/$step_file + echo "$actions" >> _build_arm_steps/$step_file + scp_yunohost _build_arm_steps/$step_file + + echo $YUNOHOST_REMOTE_DIR/$step_file +} + +init_sdcard_and_reboot() { + local actions=" +# fix locale warning +sudo sed -i -e '/\(en_US\|fr_FR\)\.UTF-8/ s/^# //' /etc/locale.gen +sudo locale-gen +# enlarge filesystem, we need more space to install yunohost +sudo raspi-config --expand-rootfs +sudo reboot +" + create_remote_script $FUNCNAME "$actions" +} + +install_yunohostv2_on_sdcard() { + local actions=" +# change root password +echo 'root:$PASSROOT' | sudo chpasswd +sudo apt-get -y install git +# so you can hack your local copy of install_yunohost over and over… +# run yunohost installer unattended (scp previously with scp_yunohost_installer) +cat << ENDMSG +Launching unattended install_yunohostv2 which will take some time to run… +You can watch using a new ssh connection to the raspberrypi. +By example issuing those commands: + cd $PWD + source 02_install_yunohost.sh + sshpi + tail -f /var/log/yunohost-installation.log +ENDMSG +cd /tmp/install_yunohost && sudo ./install_yunohostv2 -a +" + create_remote_script $FUNCNAME "$actions" +} + +finalize_yunohost() { + local actions=" +cd / +tar xzf $YUNOHOST_REMOTE_DIR/etc.tzg +chmod a+x /etc/init.d/yunohost-firstboot +insserv /etc/init.d/yunohost-firstboot +cat << ENDMSG +We are going to shutdown the raspberrypi now. +When it's done, the yunohost image is ready to be copied back on your comupter. +* Unplug raspberrypi +* remove the sdcard +* Go to next step +ENDMSG +shutdown +" + create_remote_script $FUNCNAME "$actions" +} + +reboot_pi() { + echo "${FUNCNAME}…" + sshpi "sudo reboot" +} + +# helper simply visualy wait for raspberrypi to come up for ssh +wait_raspberrypi() { + local max=30 + local n=1 + local up=false + while [[ $n -le $max ]] + do + sleep 1 + output=$(timeout 2 ssh -i _build_arm_steps/nopasskey pi@$PI_IP 'echo up' 2> /dev/null) + echo -n . + if [[ "$output" == 'up' ]] + then + up=true + break + fi + n=$(($n + 1)) + done + + if $up + then + echo up + return 0 + else + echo too_long + echo "something goes wrong for your raspberrypi or the timeout it too short" + echo "please retry" + return 1 + fi +} + +do_step() { + local step=$1 + local step_file=$(make_step_file $step) + local remote_step + echo -n "$step: " + if [[ -e "_build_arm_steps/$step_file" ]] + then + echo "SKIPED" + else + echo "RUNING" + remote_step=$(eval $step) + sshpi $remote_step + fi +} + +main() { + do_step init_sdcard_and_reboot + + wait_raspberrypi || return 1 + + do_step install_yunohostv2_on_sdcard + + # copy the installation.log on the PC + sshpi "cat /var/log/yunohost-installation.log" > \ + _build_arm_steps/yunohost-installation.log + + reboot_pi + + wait_raspberrypi || return 1 + + # was ./intsall_arm.sh + tar czf _build_arm_steps/etc.tgz etc + scp_yunohost _build_arm_steps/etc.tgz + do_step finalize_yunohost +} diff --git a/build_arm_image/README.md b/build_arm_image/README.md index 3c0753f..999ea42 100644 --- a/build_arm_image/README.md +++ b/build_arm_image/README.md @@ -1,14 +1,18 @@ = Build your own yunohost image for Raspberry Pi = This folder contains helper scripts to build an arm image for raspberry. -The files here are for builder. They are not needed to install yunohost. +The files here are for builder. They are not needed to install your yunohost. The folder structure maps debian OS folders, shell script here are helpers. -The files are copied on the sdcard when installation is finished. +Files in subfolders will be copied on the sdcard when installation is finished. + +== License == + +All the content here is distributed under [GPLv3](http://www.gnu.org/licenses/gpl-3.0.txt). == See also == -* https://yunohost.org/#/build_arm_image for buildini step explanations -* https://forum.yunohost.org/t/building-a-new-image-for-raspberry-debian-jessie-fr-en/1101/13 - discussion about building an new image for Raspberry Pi. +* 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. == Files == @@ -20,13 +24,14 @@ Scripts are prefixed by a number which is an hint of the order they should be ra ==== autosizer.sh ==== -Used on your PC to compact the dd image you will copy back. -this script requier root privilege to run and modify the sdcard image. +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 ==== Create a bootable image for raspbian. You have to download the .zip of the image. -it embeds sudo call for using dd to copy the raw image to the sdcard. +It 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 remonved at the end. The key-pair in generated only for you. Usage: @@ -34,8 +39,35 @@ Usage: ./01_create_sdcard.sh image_rasbian.zip /dev/device_to_sdcard ~~~ -it takes some minutes to perform all the steps. Be patient. +It takes some minutes to perform all the steps. 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. + +==== 02_install_yunohost.sh ==== + +Should I say you have to plug the new sdcard freshly created and boot the Raspberry PI pluged on the same network as your PC? + +The Raspberry has hopefully booted and is displaying a console's prompt: + +~~~ +Raspbian GNU/Linux 8 raspberrypi tty1 + +raspberrypi login: +~~~ + +If DHCP has done its job well, you also have an IP address on the Raspberry PI console screen: + +~~~ +My IP address is 192.168.1.123 +~~~ + +Or what ever your DHCP is giving… + +Run: + +~~~ +./02_install_yunohost.sh 192.168.1.123 +~~~ === Run on Raspberry === From da9ae9453a9049453b5647cc9a4dcee03b9f0918 Mon Sep 17 00:00:00 2001 From: Sylvain303 Date: Sun, 20 Dec 2015 11:00:25 +0100 Subject: [PATCH 12/21] format headings with markdown format --- build_arm_image/README.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/build_arm_image/README.md b/build_arm_image/README.md index 999ea42..995ff14 100644 --- a/build_arm_image/README.md +++ b/build_arm_image/README.md @@ -1,4 +1,4 @@ -= Build your own yunohost image for Raspberry Pi = +# Build your own yunohost image for Raspberry Pi This folder contains helper scripts to build an arm image for raspberry. The files here are for builder. They are not needed to install your yunohost. @@ -6,28 +6,27 @@ The files here are for builder. They are not needed to install your yunohost. The folder structure maps debian OS folders, shell script here are helpers. Files in subfolders will be copied on the sdcard when installation is finished. -== License == - +## License 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. -== Files == +## Files Descriptions of the files available here. -=== Run on PC === +### Run on PC Scripts are prefixed by a number which is an hint of the order they should be ran. -==== autosizer.sh ==== +#### 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 image. It embeds sudo call for using dd to copy the raw image to the sdcard. @@ -43,7 +42,7 @@ It takes some minutes to perform all the steps. 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. -==== 02_install_yunohost.sh ==== +#### 02_install_yunohost.sh Should I say you have to plug the new sdcard freshly created and boot the Raspberry PI pluged on the same network as your PC? @@ -69,7 +68,9 @@ Run: ./02_install_yunohost.sh 192.168.1.123 ~~~ -=== Run on Raspberry === +### Run on Raspberry + +Will be handled by [02_install_yunohost.sh](https://github.com/Sylvain303/install_script/blob/master/build_arm_image/02_install_yunohost.sh) run the following script before shuting down your raspbian. From 2d17872fb255ab6cd9b29dbe035f027834162acb Mon Sep 17 00:00:00 2001 From: Sylvain303 Date: Sun, 20 Dec 2015 11:03:35 +0100 Subject: [PATCH 13/21] typos --- build_arm_image/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_arm_image/README.md b/build_arm_image/README.md index 995ff14..31b1ffa 100644 --- a/build_arm_image/README.md +++ b/build_arm_image/README.md @@ -30,7 +30,7 @@ This script requier root privilege to run and modify the local sdcard image. Create a bootable image for raspbian. You have to download the .zip of the image. It 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 remonved at the end. The key-pair in 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 remonved at the end. The key-pair is generated only for you. Usage: @@ -40,7 +40,7 @@ Usage: It takes some minutes to perform all the steps. 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 partion if any. It also guess the disk's name if you give an partition's name instead of entire disk device's name. #### 02_install_yunohost.sh From 972965ba6147e399977b0e64257be0277ccd389c Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 21 Dec 2015 08:56:24 +0100 Subject: [PATCH 14/21] retest full step 01 + 02 OK. Miss argument IP reading for 02_install_yunohost.sh README updated --- build_arm_image/01_create_sdcard.sh | 11 ++- build_arm_image/02_install_yunohost.sh | 99 ++++++++++++++++++++------ build_arm_image/README.md | 25 +++++-- 3 files changed, 104 insertions(+), 31 deletions(-) diff --git a/build_arm_image/01_create_sdcard.sh b/build_arm_image/01_create_sdcard.sh index 687ba3f..513f43e 100755 --- a/build_arm_image/01_create_sdcard.sh +++ b/build_arm_image/01_create_sdcard.sh @@ -5,6 +5,8 @@ # Usage: # ./01_create_sdcard.sh downloaded_debian_image.zip /dev/sdcard_device # +# +# Status: functional # Licence: GPLv3 # Author: sylvain303@github @@ -46,7 +48,6 @@ skip_if() { return 1 } - sha_verify_zip() { local zip=$DEBIAN_IMG_ZIP local out=_build_arm_steps/sha_verify_zip @@ -71,10 +72,10 @@ unzip_img() { DEBIAN_IMG=$(ls _build_arm_steps/ | grep \\.img$) } -# helper try to guess top device name +# helper, try to guess top device name # /dev/sdp2 => /dev/sdp # /dev/mmcblk0p1 => /dev/mmcblk0 -# just some regexp no smart thing +# just some regexp, no smart thing get_top_device() { local device="$1" local regexp1='^/dev/sd[a-z]' @@ -93,6 +94,7 @@ get_top_device() { echo "$device" } +# helper, umount the sdcard partition if any umount_sdcard_partition() { [[ -z "$SDCARD" ]] && { echo '$SDCARD is empty refusing to run'; return; } local p @@ -120,6 +122,7 @@ test_all_tools() { done } +# mount the .img so we can write on it before copying on the sdcard mount_loopback_img() { [[ -z "$DEBIAN_IMG" ]] && { echo '$DEBIAN_IMG is empty refusing to run'; return; } mkdir -p _build_arm_steps/mnt @@ -142,6 +145,7 @@ umount_loopback_img() { } # copy a local key for ssh without password later +# having an ssh-key pair to remote connect on the raspi will be used by the next step add_ssh_key_to_img() { mount_loopback_img cd _build_arm_steps/mnt/home/pi/ @@ -202,5 +206,6 @@ then # pass positional argument as is main "$@" else + # just print STEPS so I can copy/paste to call them interactivly echo $STEPS fi diff --git a/build_arm_image/02_install_yunohost.sh b/build_arm_image/02_install_yunohost.sh index e13928a..ef587c9 100755 --- a/build_arm_image/02_install_yunohost.sh +++ b/build_arm_image/02_install_yunohost.sh @@ -2,21 +2,40 @@ # # Usage: ./02_install_yunohost.sh DHCP_IP_ADDRESS_OF_RASPBERRYPI # -# apply this doc: https://github.com/Sylvain304/doc/blob/master/build_arm_image.md +# This script apply this doc:  +# https://yunohost.org/#/build_arm_image +# +# Doc: See README.md +# +# STEPS: +# 1. enlarge filesystem with raspi-config --expand-rootfs and reboot +# 2. run install_yunohostv2 on the raspi +# 3. install an yunohost-firstboot script and shutdown # # Status: draft # Licence: GPLv3 # Author: sylvain303@github -# usefull wrapper to use ssh with our nopasskey +# wrapper to use ssh with our nopasskey +# Usage: sshpi "some remote commands" sshpi() { ssh -i _build_arm_steps/nopasskey pi@$PI_IP "$@" } # harcoded test IP -PI_IP=192.168.1.50 +PI_IP=192.168.1.2 +# the installer script is used localy, no git clone else where. YUNOHOST_INSTALL=../install_yunohostv2 +# the folder on the raspberrypi, where script are uploaded YUNOHOST_REMOTE_DIR=/tmp/install_yunohost +# dummy password +PASSROOT='Free_money?yunomakeit' + +# wrapper to init with positional parameters +init_param() { + PI_IP=$1 + ask_root_pass +} ask_root_pass() { echo "HINT: very good program to generate strong memorisable passwords: pwqgen" @@ -46,9 +65,10 @@ scp_yunohost() { return 1 fi - local script=$1 - local scriptb=$(basename $script) + local script="$1" + local scriptb="$(basename $script)" + # no real scp, just wrap with sshpi cat "$script" | \ sshpi "mkdir -p $YUNOHOST_REMOTE_DIR && \ cat > $YUNOHOST_REMOTE_DIR/$scriptb && \ @@ -59,7 +79,7 @@ scp_yunohost() { # helper, compute common remote_step script name so they can be skiped by do_step make_step_file() { local step_name="$1" - local step_file=yuno_step_${step_name}.sh + local step_file="yuno_step_${step_name}.sh" echo $step_file } @@ -68,14 +88,19 @@ make_step_file() { create_remote_script() { local step_file=$(make_step_file "$1") local actions="$2" + local dst="_build_arm_steps/$step_file" - echo '#!/bin/bash' > _build_arm_steps/$step_file - echo "$actions" >> _build_arm_steps/$step_file - scp_yunohost _build_arm_steps/$step_file + echo '#!/bin/bash' > $dst + echo "# $1" >> $dst + echo "$actions" >> $dst + scp_yunohost $dst + # the remote file on the raspi echo $YUNOHOST_REMOTE_DIR/$step_file } +# ======================= ACTIONS - remote actions steps to be performed on the raspberrypi. + init_sdcard_and_reboot() { local actions=" # fix locale warning @@ -83,6 +108,7 @@ sudo sed -i -e '/\(en_US\|fr_FR\)\.UTF-8/ s/^# //' /etc/locale.gen sudo locale-gen # enlarge filesystem, we need more space to install yunohost sudo raspi-config --expand-rootfs +echo 'rebooting raspberrypi…' sudo reboot " create_remote_script $FUNCNAME "$actions" @@ -92,10 +118,10 @@ install_yunohostv2_on_sdcard() { local actions=" # change root password echo 'root:$PASSROOT' | sudo chpasswd +# some packages sudo apt-get -y install git -# so you can hack your local copy of install_yunohost over and over… -# run yunohost installer unattended (scp previously with scp_yunohost_installer) cat << ENDMSG +!!!!!!!!!!!!!!!!!!!!!!! sdcard builder !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Launching unattended install_yunohostv2 which will take some time to run… You can watch using a new ssh connection to the raspberrypi. By example issuing those commands: @@ -103,7 +129,9 @@ By example issuing those commands: source 02_install_yunohost.sh sshpi tail -f /var/log/yunohost-installation.log +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ENDMSG +# run yunohost installer unattended (scp previously with scp_yunohost) cd /tmp/install_yunohost && sudo ./install_yunohostv2 -a " create_remote_script $FUNCNAME "$actions" @@ -111,18 +139,25 @@ cd /tmp/install_yunohost && sudo ./install_yunohostv2 -a finalize_yunohost() { local actions=" +# uploaded modified or new config files to the raspberrypi cd / -tar xzf $YUNOHOST_REMOTE_DIR/etc.tzg -chmod a+x /etc/init.d/yunohost-firstboot -insserv /etc/init.d/yunohost-firstboot +sudo tar xzf $YUNOHOST_REMOTE_DIR/etc.tgz +# yunohost-firstboot is an helper to cleanup and resizefs with srinked sdcard +# image +sudo chmod a+x /etc/init.d/yunohost-firstboot +sudo insserv /etc/init.d/yunohost-firstboot cat << ENDMSG +================================================================================= We are going to shutdown the raspberrypi now. When it's done, the yunohost image is ready to be copied back on your comupter. * Unplug raspberrypi * remove the sdcard -* Go to next step +* Go to next step! +================================================================================= ENDMSG -shutdown +# remove pi user, we will not be able to ssh connect anymore +# sudo userdel pi +sudo shutdown -h now " create_remote_script $FUNCNAME "$actions" } @@ -132,7 +167,10 @@ reboot_pi() { sshpi "sudo reboot" } -# helper simply visualy wait for raspberrypi to come up for ssh +# ======================= END ACTIONS + +# helper, simply visualy wait for raspberrypi to come up for ssh +# Usage: wait_raspberrypi || some_fail command wait_raspberrypi() { local max=30 local n=1 @@ -140,7 +178,9 @@ wait_raspberrypi() { while [[ $n -le $max ]] do sleep 1 - output=$(timeout 2 ssh -i _build_arm_steps/nopasskey pi@$PI_IP 'echo up' 2> /dev/null) + # remove redirect to /dev/null to debug + output=$(timeout 2 ssh -o "StrictHostKeyChecking=no" \ + -i _build_arm_steps/nopasskey pi@$PI_IP 'echo up' 2> /dev/null) echo -n . if [[ "$output" == 'up' ]] then @@ -162,33 +202,42 @@ wait_raspberrypi() { fi } +# wrapper, execute a step script on the raspberrypi or skip it +# Status: draft do_step() { local step=$1 local step_file=$(make_step_file $step) local remote_step echo -n "$step: " + # skip if script already there if [[ -e "_build_arm_steps/$step_file" ]] then echo "SKIPED" + return 1 else echo "RUNING" remote_step=$(eval $step) sshpi $remote_step + return 0 fi } +# main script code, wrapped inside a function, so the whole script can also be +# sourced as a lib, for debug or unittesting purpose. main() { do_step init_sdcard_and_reboot wait_raspberrypi || return 1 - do_step install_yunohostv2_on_sdcard + scp_yunohost $YUNOHOST_INSTALL + NEED_REBOOT=false + do_step install_yunohostv2_on_sdcard && { NEED_REBOOT=true; } - # copy the installation.log on the PC + # backup the installation.log on the PC sshpi "cat /var/log/yunohost-installation.log" > \ _build_arm_steps/yunohost-installation.log - reboot_pi + $NEED_REBOOT && reboot_pi wait_raspberrypi || return 1 @@ -197,3 +246,11 @@ main() { scp_yunohost _build_arm_steps/etc.tgz do_step finalize_yunohost } + +# sourcing code detection, if code is sourced for debug purpose, main is not executed. +[[ $0 != "$BASH_SOURCE" ]] && sourced=1 || sourced=0 +if [[ $sourced -eq 0 ]] +then + # pass positional argument as is + main "$@" +fi diff --git a/build_arm_image/README.md b/build_arm_image/README.md index 31b1ffa..3872c88 100644 --- a/build_arm_image/README.md +++ b/build_arm_image/README.md @@ -1,10 +1,10 @@ # Build your own yunohost image for Raspberry Pi -This folder contains helper scripts to build an arm image for raspberry. +This folder contains helper scripts to build an arm image of yunohost for raspberry. The files here are for builder. They are not needed to install your yunohost. -The folder structure maps debian OS folders, shell script here are helpers. -Files in subfolders will be copied on the sdcard when installation is finished. +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. ## License All the content here is distributed under [GPLv3](http://www.gnu.org/licenses/gpl-3.0.txt). @@ -15,7 +15,18 @@ All the content here is distributed under [GPLv3](http://www.gnu.org/licenses/gp ## Files -Descriptions 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 script are designed to run in this folder: + +~~~ +git clone this_repos +cd path_to/build_arm_image/ +~~~ + +then run steps scripts in order. ### Run on PC @@ -28,9 +39,9 @@ This script requier root privilege to run and modify the local sdcard image. #### 01_create_sdcard.sh -Create a bootable image for raspbian. You have to download the .zip of the 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. -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 remonved at the end. The 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. The ssh key-pair is generated only for you. Usage: @@ -38,7 +49,7 @@ Usage: ./01_create_sdcard.sh image_rasbian.zip /dev/device_to_sdcard ~~~ -It takes some minutes to perform all the steps. 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. From 22279473dc6524a07b37794de327b9606b8d9987 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 22 Dec 2015 06:40:18 +0100 Subject: [PATCH 15/21] add step 03, copy back sdcard and shrink image. prototype, derivated from 01_create_sdcard.sh Seems working. --- build_arm_image/03_copy_sdcard_to_img.sh | 188 +++++++++++++++++++++++ build_arm_image/autosizer.sh | 2 + 2 files changed, 190 insertions(+) create mode 100755 build_arm_image/03_copy_sdcard_to_img.sh diff --git a/build_arm_image/03_copy_sdcard_to_img.sh b/build_arm_image/03_copy_sdcard_to_img.sh new file mode 100755 index 0000000..5988e8a --- /dev/null +++ b/build_arm_image/03_copy_sdcard_to_img.sh @@ -0,0 +1,188 @@ +#!/bin/bash +# +# Create the image file from the sdcard +# +# Usage: +# ./03_copy_sdcard_to_img.sh /dev/sdcard_device +# +# the resulting image will be stored in _build_arm_steps +# +# Status: prototype +# Licence: GPLv3 +# Author: sylvain303@github + +die() { + echo "$*" + exit 1 +} + +# helper, test if a shell program exists in PATH +test_tool() { + local cmd=$1 + if type $cmd > /dev/null + then + # OK + return 0 + else + die "tool missing: $cmd" + 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 +# /dev/sdp2 => /dev/sdp +# /dev/mmcblk0p1 => /dev/mmcblk0 +# just some regexp, no smart thing +get_top_device() { + local device="$1" + local regexp1='^/dev/sd[a-z]' + local regexp2='^/dev/mmcblk[0-9]' + + if [[ "$device" =~ $regexp1 ]] + then + #echo sd + device="${device/[0-9]/}" + elif [[ "$device" =~ $regexp2 ]] + then + #echo mmcblk + device="${device/p[0-9]/}" + fi + + echo "$device" +} + +# helper, umount the sdcard partition if any +umount_sdcard_partition() { + [[ -z "$SDCARD" ]] && { echo '$SDCARD is empty refusing to run'; return; } + local p + # search and replace all occurence of / by . + local pattern=${SDCARD////.} + pattern=${pattern/p[0-9]/} + for p in $(df | awk "/^$pattern/ { print \$1 }") + do + sudo umount $p + done + echo "done device for sdcard=${pattern//.//}" +} + +dd_from_sdcard() { + [[ -z "$SDCARD" ]] && { echo '$SDCARD is empty refusing to run'; return; } + [[ -z "$OUTPUT_IMG" ]] && { echo '$OUTPUT_IMG is empty refusing to run'; return; } + local count + if [[ ! -z "$1" ]] + then + count="count=$1" + fi + # ensure that sdcard partitions are unmounted with umount_sdcard_partition + sudo dd bs=16M if=$SDCARD of=_build_arm_steps/$OUTPUT_IMG $count +} + +test_all_tools() { + for t in $* + do + test_tool $t + done +} + +# mount the .img so we can write on it before copying on the sdcard +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() { + local part_data=2 + [[ ! -d _build_arm_steps/sdcard ]] && mkdir _build_arm_steps/sdcard + sudo mount ${SDCARD}p2 _build_arm_steps/sdcard +} + +get_used_partition_size() { + 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 }') + + echo "start_offset=$start_offset" + echo "used =$used" + + local count=$(($start_offset + $used)) + echo "count =$count" + local div=$(($count / (16 * 1048576) )) + echo "16M =$(($count / (16 * 1048576) ))" + echo "verif =$(( ($div + 1) * (16 * 1048576) ))" +} + +shrink_img() { + echo "shrinking _build_arm_steps/$OUTPUT_IMG" + sudo ./autosizer.sh _build_arm_steps/$OUTPUT_IMG +} + +# 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. +STEPS=" +umount_sdcard_partition +dd_from_sdcard +shrink_img" + +# main wrapper, so the script can be sourced for debuging purpose or unittesting +main() { + # positional argument must be script argument. + # init + if [[ -z "$1" ]] + then + echo "argument 1 error: expecting sdcard_device" + exit 1 + fi + + test_all_tools dd sync sudo losetup + if [[ ! -d _build_arm_steps ]] + then + die "cannot find _build_arm_steps/ folder are you following build step?" + fi + # reading script argument + SDCARD=$(get_top_device "$1") + OUTPUT_IMG="$(date "+%Y-%m-%d")_yunohost_rasbian-jessie.img" + + # actions loop + for s in $STEPS + do + echo -n "$s: " + eval $s + done +} + +# sourcing code detection, if code is sourced for debug purpose, main is not executed. +[[ $0 != "$BASH_SOURCE" ]] && sourced=1 || sourced=0 +if [[ $sourced -eq 0 ]] +then + # pass positional argument as is + main "$@" +else + # just print STEPS so I can copy/paste to call them interactivly + echo $STEPS +fi diff --git a/build_arm_image/autosizer.sh b/build_arm_image/autosizer.sh index af21b23..1816a88 100755 --- a/build_arm_image/autosizer.sh +++ b/build_arm_image/autosizer.sh @@ -3,6 +3,8 @@ # Written by SirLagz # # got from: http://sirlagz.net/2013/03/10/script-automatic-rpi-image-downsizer/ +# +# Usage: sudo autosizer.sh sdcard.img strImgFile=$1 From 89a7ca3cc6289d6f9cfd1762cf909a018ba6cd88 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 22 Dec 2015 08:24:10 +0100 Subject: [PATCH 16/21] updated Doc and steps. Commit push before retest. --- build_arm_image/01_create_sdcard.sh | 42 +++++++++++---- build_arm_image/02_install_yunohost.sh | 18 +++---- build_arm_image/03_copy_sdcard_to_img.sh | 39 ++------------ build_arm_image/README.md | 69 ++++++++++++++++-------- 4 files changed, 90 insertions(+), 78 deletions(-) diff --git a/build_arm_image/01_create_sdcard.sh b/build_arm_image/01_create_sdcard.sh index 513f43e..f164833 100755 --- a/build_arm_image/01_create_sdcard.sh +++ b/build_arm_image/01_create_sdcard.sh @@ -4,6 +4,7 @@ # # Usage: # ./01_create_sdcard.sh downloaded_debian_image.zip /dev/sdcard_device +# ./01_create_sdcard.sh generated_yunohost.img /dev/sdcard_device # # # Status: functional @@ -50,6 +51,9 @@ skip_if() { sha_verify_zip() { local zip=$DEBIAN_IMG_ZIP + + [[ -z "$zip" ]] && { echo "no zip refuse to run"; return 3; } + local out=_build_arm_steps/sha_verify_zip skip_if $out && return 2 sha1sum $zip > $out @@ -57,19 +61,20 @@ sha_verify_zip() { local sha="$(sed -e 's/\(^[a-f0-9]\+\).*/\1/' $out)" if [[ "$sha" != "$SHA_DEBIAN_IMG_ZIP" ]] then - echo "NOK: '$sha' != '$SHA_DEBIAN_IMG_ZIP'" - exit 1 + die "NOK: '$sha' != '$SHA_DEBIAN_IMG_ZIP'" fi } # unzip raspbian image in the cache folder 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 unzip -o $DEBIAN_IMG_ZIP -d _build_arm_steps fi + # 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 @@ -111,7 +116,8 @@ umount_sdcard_partition() { dd_to_sdcard() { [[ -z "$SDCARD" ]] && { echo '$SDCARD is empty refusing to run'; return; } # 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 } @@ -126,10 +132,10 @@ test_all_tools() { mount_loopback_img() { [[ -z "$DEBIAN_IMG" ]] && { echo '$DEBIAN_IMG is empty refusing to run'; return; } 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 }') # 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/ } @@ -158,14 +164,17 @@ add_ssh_key_to_img() { chmod -R go= .ssh/ # give to pi user id sudo chown -R --reference . .ssh + # return to working folder cd - > /dev/null umount_loopback_img + echo "ssh-key added" } # 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. +# STEPS is modifiy in main() if argument1 is an .img and not a .zip STEPS=" -sha_verify_zip +sha_verify_zip unzip_img add_ssh_key_to_img umount_sdcard_partition @@ -177,14 +186,27 @@ main() { # init if [[ -z "$1" ]] 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" exit 1 fi + local regexp='\.img$' + # reading script argument DEBIAN_IMG_ZIP=$1 - [[ -f "$DEBIAN_IMG_ZIP" ]] || die "error raspbian image not found: '$DEBIAN_IMG_ZIP'" + 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'" + fi + SDCARD=$(get_top_device "$2") [[ -z "$SDCARD" ]] && die "argument 2 error: expecting sdcard_device" diff --git a/build_arm_image/02_install_yunohost.sh b/build_arm_image/02_install_yunohost.sh index ef587c9..a441215 100755 --- a/build_arm_image/02_install_yunohost.sh +++ b/build_arm_image/02_install_yunohost.sh @@ -2,9 +2,6 @@ # # 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 # # STEPS: @@ -12,7 +9,7 @@ # 2. run install_yunohostv2 on the raspi # 3. install an yunohost-firstboot script and shutdown # -# Status: draft +# Status: functional # Licence: GPLv3 # Author: sylvain303@github @@ -22,7 +19,7 @@ sshpi() { 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 # the installer script is used localy, no git clone else where. YUNOHOST_INSTALL=../install_yunohostv2 @@ -31,12 +28,7 @@ YUNOHOST_REMOTE_DIR=/tmp/install_yunohost # dummy password PASSROOT='Free_money?yunomakeit' -# wrapper to init with positional parameters -init_param() { - PI_IP=$1 - ask_root_pass -} - +# used by main() See at the end. ask_root_pass() { echo "HINT: very good program to generate strong memorisable passwords: pwqgen" 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 # sourced as a lib, for debug or unittesting purpose. 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 wait_raspberrypi || return 1 diff --git a/build_arm_image/03_copy_sdcard_to_img.sh b/build_arm_image/03_copy_sdcard_to_img.sh index 5988e8a..760fc61 100755 --- a/build_arm_image/03_copy_sdcard_to_img.sh +++ b/build_arm_image/03_copy_sdcard_to_img.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash # # Create the image file from the sdcard # @@ -28,18 +28,6 @@ test_tool() { 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 # /dev/sdp2 => /dev/sdp # /dev/mmcblk0p1 => /dev/mmcblk0 @@ -95,34 +83,15 @@ test_all_tools() { done } -# mount the .img so we can write on it before copying on the sdcard -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 -} - +# debug, not used mount_sdcard_data_partition() { local part_data=2 [[ ! -d _build_arm_steps/sdcard ]] && mkdir _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() { 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 }') diff --git a/build_arm_image/README.md b/build_arm_image/README.md index 3872c88..d3019b4 100644 --- a/build_arm_image/README.md +++ b/build_arm_image/README.md @@ -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. 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 All the content here is distributed under [GPLv3](http://www.gnu.org/licenses/gpl-3.0.txt). ## 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. ## Files 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 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 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. +Scripts are prefixed by a number which is the order they must be ran. #### 01_create_sdcard.sh 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. -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. +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 (See #4). The ssh key-pair is generated only for you. Usage: @@ -51,7 +50,9 @@ Usage: 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 @@ -75,16 +76,40 @@ Or what ever your DHCP is giving… Run: -~~~ +~~~bash ./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) - -run the following script before shuting down your raspbian. +When the build is finished the Raspberry will shutdown. Unplug and insert the sdcard back in the computer. +~~~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. From 0ea3d0c8c12e62c3fa3639ae071898433681cf1e Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 22 Dec 2015 09:22:15 +0100 Subject: [PATCH 17/21] procedure restested OK add hint to fix ssh host indentification failure. --- build_arm_image/README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/build_arm_image/README.md b/build_arm_image/README.md index d3019b4..1e739ca 100644 --- a/build_arm_image/README.md +++ b/build_arm_image/README.md @@ -50,9 +50,9 @@ Usage: 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 partition if any. It also guesses 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 gave a partition's name instead of entire disk device's name. -Be carefull not to wipe the wrong device! +BE CAREFULL not to wipe the wrong device! #### 02_install_yunohost.sh @@ -80,6 +80,16 @@ Run: ./02_install_yunohost.sh 192.168.1.123 ~~~ +This step is quite long. It took ~24min on my Raspberry. Be patient, A message will be displayed on the screen to explain how you can watch it if you want. + +If you got ssh `Host key verification failed.`, fix it then: + +~~~bash +rm _build_arm_steps/yuno_step* +# retry +./02_install_yunohost.sh 192.168.1.123 +~~~ + #### 03_copy_sdcard_to_img.sh When the build is finished the Raspberry will shutdown. Unplug and insert the sdcard back in the computer. From 181462d1eea84df941ec59c9c46d75179d56e89f Mon Sep 17 00:00:00 2001 From: Sylvain Date: Fri, 6 May 2016 07:14:26 +0200 Subject: [PATCH 18/21] rebuild with new raspbian doc more precise. --- build_arm_image/01_create_sdcard.sh | 17 ++++++++-- build_arm_image/README.md | 49 +++++++++++++++++++++-------- build_arm_image/intsall_arm.sh | 9 ------ 3 files changed, 50 insertions(+), 25 deletions(-) delete mode 100755 build_arm_image/intsall_arm.sh diff --git a/build_arm_image/01_create_sdcard.sh b/build_arm_image/01_create_sdcard.sh index f164833..0d29b6d 100755 --- a/build_arm_image/01_create_sdcard.sh +++ b/build_arm_image/01_create_sdcard.sh @@ -1,15 +1,23 @@ #!/bin/bash # -# Create the sdcard on your PC with the latest debian. +# Create the sdcard on your PC with the latest debian raspbian. # # Usage: -# ./01_create_sdcard.sh downloaded_debian_image.zip /dev/sdcard_device +# ./01_create_sdcad.sh downloaded_debian_image.zip /dev/sdcard_device # ./01_create_sdcard.sh generated_yunohost.img /dev/sdcard_device # +# HowTo: +# find your sdcard device: +# mount it first graphicaly +# next issue a df -h look for something "/dev/mmcblk0p1" +# create a totally new image: +# delete _build_arm_steps/ which is the cache folder. +# follows steps in README.md # # Status: functional # Licence: GPLv3 # Author: sylvain303@github +# SeeAlso: # informations about Raspbian image: # Raspbian Jessie Lite Version: November 2015 Release date: 2015-11-21 @@ -17,8 +25,11 @@ # Kernel version: 4.1 # http://downloads.raspberrypi.org/raspbian/release_notes.txt + +# DOWNLOAD_URL used only for echo a message +# SHA_DEBIAN_IMG_ZIP need to be updated to match your image DOWNLOAD_URL=https://www.raspberrypi.org/downloads/raspbian/ -SHA_DEBIAN_IMG_ZIP=97888fcd9bfbbae2a359b0f1d199850852bf0104 +SHA_DEBIAN_IMG_ZIP="b78bb50bdac5ec8c108f34104f788e214ac23635" die() { echo "$*" diff --git a/build_arm_image/README.md b/build_arm_image/README.md index 1e739ca..583768e 100644 --- a/build_arm_image/README.md +++ b/build_arm_image/README.md @@ -1,18 +1,34 @@ # Build your own yunohost image for Raspberry Pi This folder contains helper scripts to build an arm image of yunohost for raspberry. -The files here are for builder. They are not needed to install your yunohost. +The files here are for builder. They are not needed to install your yunohost, the purpose is to reproduce the .img. +Of course you can try the step exlained here, and you will get a fresh yunohost at the end. 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. Those scripts are following the steps provided here: https://yunohost.org/#/build_arm_image +### Notes: + +`01_create_sdcard.sh` can be used to copy raspbian image to a sdcard and stop here, without yunohost. +An ssh key is added to remote access pi@raspbian account without passphrase. + +Ex: +``` +ssh -i _build_arm_steps/nopasskey pi@DHCP_IP +``` + +Don't forget to at first: `sudo raspbi-config` + enlarge file-system to have full size sdcard for your raspberry. +(also accomplished by: `sudo raspi-config --expand-rootfs`) +Enjoy. + ## License All the content here is distributed under [GPLv3](http://www.gnu.org/licenses/gpl-3.0.txt). ## See also * 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. +* http://build.yunohost.org/ - some build here ## Files @@ -20,7 +36,7 @@ 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 scripts are designed to run in this folder: +All step scripts are designed to run in this folder on your PC: ~~~bash git clone this_repos @@ -39,8 +55,11 @@ Scripts are prefixed by a number which is the order they must be ran. #### 01_create_sdcard.sh Create a bootable image for raspbian. You have to download the .zip of the raspbian image. -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 (See #4). The ssh key-pair is generated only for you. +([See:](https://www.raspberrypi.org/downloads/raspbian/) + +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 order to connect later to continue automated installation (See `02_install_yunohost.sh`) +The pi user will be removed at the end (Not yet, See #4). The ssh key-pair is generated only for you, in `_build_arm_steps/` Usage: @@ -50,15 +69,17 @@ Usage: 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 partition if any. It also guesses the disk's name if you gave a partition's name instead of entire disk device's name. +Use commend like `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 gave a partition's name instead of entire disk device's name. i +(ex: /dev/mmcblk0p2 --> /dev/mmcblk0) BE CAREFULL not to wipe the wrong device! #### 02_install_yunohost.sh -Should I say you have to plug the new sdcard freshly created and boot the Raspberry PI pluged on the same network as your PC? +Should I say: you have to plug the new sdcard freshly created and boot the Raspberry PI pluged on the same network as your PC? -The Raspberry has hopefully booted and is displaying a console's prompt: +The Raspberry has hopefully booted and is displaying a console's prompt, which looks like: ~~~ Raspbian GNU/Linux 8 raspberrypi tty1 @@ -74,15 +95,16 @@ My IP address is 192.168.1.123 Or what ever your DHCP is giving… -Run: +Run (on the PC, not the raspberry): ~~~bash ./02_install_yunohost.sh 192.168.1.123 ~~~ -This step is quite long. It took ~24min on my Raspberry. Be patient, A message will be displayed on the screen to explain how you can watch it if you want. +This step is quite long. It took ~24min on my Raspberry. Be patient. +A message will be displayed on the screen to explain how you can watch it if you want. -If you got ssh `Host key verification failed.`, fix it then: +If you got ssh `Host key verification failed.`, to fix it then: ~~~bash rm _build_arm_steps/yuno_step* @@ -92,20 +114,21 @@ rm _build_arm_steps/yuno_step* #### 03_copy_sdcard_to_img.sh -When the build is finished the Raspberry will shutdown. Unplug and insert the sdcard back in the computer. +When the build is finished, the Raspberry will shutdown. Unplug and insert the sdcard back in the computer. ~~~bash ./03_copy_sdcard_to_img.sh /dev/sdcard_device ~~~ -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. +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`. +You can test the resutling image back again with `01_create_sdcard.sh`. ~~~bash ./01_create_sdcard.sh _build_arm_steps/newly_created_image.img /dev/sdcard_device diff --git a/build_arm_image/intsall_arm.sh b/build_arm_image/intsall_arm.sh deleted file mode 100755 index 4c05d26..0000000 --- a/build_arm_image/intsall_arm.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -# complete install with some specific ARM (raspberry) scripts. -# -# to be run for building an SD card image. -# - -cp etc/init.d/yunohost-firstboot /etc/init.d/ -chmod a+x /etc/init.d/yunohost-firstboot -insserv /etc/init.d/yunohost-firstboot From 30f69b669c9132f739a49067b44dcd8c46e2545a Mon Sep 17 00:00:00 2001 From: Sylvain Date: Fri, 6 May 2016 14:34:11 +0200 Subject: [PATCH 19/21] =?UTF-8?q?change=20file=20type=20check=20on=20xubun?= =?UTF-8?q?tu=2016.04=C2=A0for=20.img?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit file _build_arm_steps/2016-05-06_yunohost_rasbian-jessie.img _build_arm_steps/2016-05-06_yunohost_rasbian-jessie.img: DOS/MBR boot sector; partition 1 : ID=0xc, start-CHS (0x0,130,3), end-CHS (0x8,40,32), startsector 8192, 122880 sectors; partition 2 : ID=0x83, start-CHS (0x8,40,33), end-CHS (0x15,194,6), startsector 131072, 4074121 sectors may be file command changed output for img file. --- build_arm_image/autosizer.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_arm_image/autosizer.sh b/build_arm_image/autosizer.sh index 1816a88..f7726bc 100755 --- a/build_arm_image/autosizer.sh +++ b/build_arm_image/autosizer.sh @@ -22,7 +22,7 @@ if [[ -z $strImgFile ]]; then exit fi -if [[ ! -e $strImgFile || ! $(file $strImgFile) =~ "x86" ]]; then +if [[ ! -e $strImgFile || ! $(file $strImgFile) =~ "DOS/MBR boot sector" ]]; then echo "Error : Not an image file, or file doesn't exist" exit fi From ee8020f76738f031037967c71b70ac58ca697858 Mon Sep 17 00:00:00 2001 From: Sylvain303 Date: Mon, 13 Mar 2017 10:20:57 +0100 Subject: [PATCH 20/21] add link --- build_arm_image/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build_arm_image/README.md b/build_arm_image/README.md index 583768e..f5ac192 100644 --- a/build_arm_image/README.md +++ b/build_arm_image/README.md @@ -146,3 +146,7 @@ Enjoy! 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. + + +## See also +* https://github.com/likeitneverwentaway/rpi_buildbot From 4da5e22d697cc26b090ae747916ffa545660a7ab Mon Sep 17 00:00:00 2001 From: Sylvain Viart Date: Sat, 22 Apr 2017 07:45:15 +0200 Subject: [PATCH 21/21] update debian signature --- build_arm_image/01_create_sdcard.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_arm_image/01_create_sdcard.sh b/build_arm_image/01_create_sdcard.sh index 0d29b6d..c975b34 100755 --- a/build_arm_image/01_create_sdcard.sh +++ b/build_arm_image/01_create_sdcard.sh @@ -3,7 +3,7 @@ # Create the sdcard on your PC with the latest debian raspbian. # # Usage: -# ./01_create_sdcad.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 # # HowTo: @@ -29,7 +29,7 @@ # DOWNLOAD_URL used only for echo a message # SHA_DEBIAN_IMG_ZIP need to be updated to match your image DOWNLOAD_URL=https://www.raspberrypi.org/downloads/raspbian/ -SHA_DEBIAN_IMG_ZIP="b78bb50bdac5ec8c108f34104f788e214ac23635" +SHA_DEBIAN_IMG_ZIP="6741a30d674d39246302a791f1b7b2b0c50ef9b7" die() { echo "$*"