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.
This commit is contained in:
Sylvain 2015-12-20 10:50:56 +01:00
parent 8937c2ae46
commit fe34552be3
2 changed files with 239 additions and 8 deletions

View file

@ -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
}

View file

@ -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 ===