From fe1b7bbf577a0828eb32be237eae118c11909c10 Mon Sep 17 00:00:00 2001 From: ljf Date: Sun, 15 Dec 2019 00:26:56 +0100 Subject: [PATCH 1/6] [wip] Install on eemc --- install-sd.sh | 90 ++++++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/install-sd.sh b/install-sd.sh index 3e98b6c..7e3a5dc 100755 --- a/install-sd.sh +++ b/install-sd.sh @@ -3,6 +3,8 @@ # LaBriqueInternet SD Card Installer # Copyright (C) 2015-2016 Julien Vaubourg # Copyright (C) 2015-2016 Emile Morel +# Copyright (C) 2019 Aleks +# Copyright (C) 2019 ljf # Contribute at https://github.com/labriqueinternet/labriqueinter.net # # This program is free software: you can redistribute it and/or modify @@ -258,19 +260,13 @@ function check_args() { fi if [[ "${opt_imgpath}" =~ lime2 ]]; then - if ! $opt_lime2; then - info "Option -2 automatically set, based on the filename given to -f" - opt_lime2=true - fi - elif $opt_lime2; then + info "Option -2 automatically set, based on the filename given to -f" + opt_hardware="lime2" + elif [ $opt_hardware == "lime2" ]; then exit_usage "Filename given to -f does not contain lime2 in its name, but -2 was set" fi fi - if [ -z "${opt_lime2}" ]; then - info "No option -2 specified, installing for LIME by default" - opt_lime2=false - fi } @@ -403,43 +399,55 @@ function find_cubes() { } function autodetect_sdcardpath() { - echo -n "1. Please, remove the target SD card from your computer if present, then press Enter" - read -s && echo - sleep 1 - - local blocks1=$(ls -1 /sys/block/) - - debug "Block devices found: $(echo $blocks1)" - - echo -n "2. Please, plug the target SD card into your computer (and don't touch to other devices), then press Enter" - read -s && echo - sleep 2 - - local blocks2=$(ls -1 /sys/block/) local foundblock=; local confirm=no; - debug "Block devices found: $(echo $blocks2)" + if $opt_eemc; then + debug "Search for eemc" + root_uuid=$(sed -e 's/^.*root=//' -e 's/ .*$//' < /proc/cmdline) + root_partition=$(blkid | tr -d '":' | grep ${root_uuid} | awk '{print $1}') + root_partition_device="${root_partition::-2}" - for i in $blocks2; do - if ! (echo ' '${blocks1}' ' | grep -q " ${i} ") && [ -b "/dev/${i}" ]; then - if [ ! -z "${foundblock}" ]; then - debug "Block devices ${foundblock} and ${i} was found" - exit_error "Assisted Block Device Detection failed: more than 1 new block device found" - fi + foundblock=$(ls -d -1 /dev/mmcblk* | grep -w 'mmcblk[0-9]' | grep -v "$root_partition_device"); - foundblock="${i}" - fi - done + else + + echo -n "1. Please, remove the target SD card from your computer if present, then press Enter" + read -s && echo + sleep 1 + + local blocks1=$(ls -1 /sys/block/) + + debug "Block devices found: $(echo $blocks1)" + + echo -n "2. Please, plug the target SD card into your computer (and don't touch to other devices), then press Enter" + read -s && echo + sleep 2 + + local blocks2=$(ls -1 /sys/block/) + + debug "Block devices found: $(echo $blocks2)" + + for i in $blocks2; do + if ! (echo ' '${blocks1}' ' | grep -q " ${i} ") && [ -b "/dev/${i}" ]; then + if [ ! -z "${foundblock}" ]; then + debug "Block devices ${foundblock} and ${i} was found" + exit_error "Assisted Block Device Detection failed: more than 1 new block device found" + fi + + foundblock="/dev/${i}" + fi + done + fi if [ -z "${foundblock}" ]; then exit_error "Assisted Block Device Detection failed: no new block device found" else - echo -en "\nBlock device /dev/${foundblock} found. Use it as your SD card block device? (yes/no) " + echo -en "\nBlock device ${foundblock} found. Use it as your SD card block device? (yes/no) " read confirm if [ "${confirm}" == yes ]; then - opt_sdcardpath="/dev/${foundblock}" + opt_sdcardpath="${foundblock}" else exit_error "Aborted" fi @@ -480,7 +488,7 @@ function download_file() { } function download_img() { - $opt_lime2 && local urlpart_lime2=2 + [ $opt_hardware == "lime2" ] && local urlpart_lime2=2 $opt_encryptedfs && local urlpart_encryptedfs=-encryptedfs local tar_name="internetcube-${deb_version}-latest-lime${urlpart_lime2}${urlpart_encryptedfs}.img.tar.xz" @@ -562,8 +570,8 @@ function install_encrypted() { mkdir -p "${files_path}" "${olinux_mountpoint}" - $opt_lime2 && board+=2 - $opt_lime2 && uboot+=2 + [ $opt_hardware == "lime2" ] && board+=2 + [ $opt_hardware == "lime2" ] && uboot+=2 local sunxispl_path="${olinux_mountpoint}/usr/lib/u-boot/${uboot}/u-boot-sunxi-with-spl.bin" @@ -729,7 +737,7 @@ deb_version=stretch opt_encryptedfs=false opt_findcubes=false opt_debug=false -opt_lime2=false +opt_hardware="lime1" tmp_dir=$(mktemp -dp . .install-sd.sh_tmpXXXXXX) olinux_mountpoint="${tmp_dir}/olinux_mountpoint" files_path="${tmp_dir}/files" @@ -744,7 +752,7 @@ loopdev= trap cleaning_exit EXIT ERR trap cleaning_ctrlc INT -while getopts "s:f:g:mc:y:w:e2ldh" opt; do +while getopts "s:mf:g:c:y:w:em2pldh" opt; do case $opt in s) opt_sdcardpath=$OPTARG ;; f) opt_imgpath=$OPTARG ;; @@ -752,8 +760,10 @@ while getopts "s:f:g:mc:y:w:e2ldh" opt; do y) opt_hypercubepath=$OPTARG ;; w) opt_hypercubeshpath=$OPTARG ;; c) opt_customscriptpath=$OPTARG ;; + m) opt_emmc=true ;; e) opt_encryptedfs=true ;; - 2) opt_lime2=true ;; + 2) opt_hardware="lime2" ;; + p) opt_hardware="pcplus" ;; l) opt_findcubes=true ;; d) opt_debug=true ;; h) exit_usage ;; From cf3f97e4610b1a1289d673321039a4ae0c37c2b5 Mon Sep 17 00:00:00 2001 From: ljf Date: Sun, 15 Dec 2019 00:27:58 +0100 Subject: [PATCH 2/6] [fix] Typo --- install-sd.sh | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/install-sd.sh b/install-sd.sh index 7e3a5dc..e37da93 100755 --- a/install-sd.sh +++ b/install-sd.sh @@ -402,8 +402,8 @@ function autodetect_sdcardpath() { local foundblock=; local confirm=no; - if $opt_eemc; then - debug "Search for eemc" + if $opt_emmc; then + debug "Search for emmc" root_uuid=$(sed -e 's/^.*root=//' -e 's/ .*$//' < /proc/cmdline) root_partition=$(blkid | tr -d '":' | grep ${root_uuid} | awk '{print $1}') root_partition_device="${root_partition::-2}" @@ -694,6 +694,39 @@ function install_clear() { sudo mount "${partition1}" "${olinux_mountpoint}" } +function update_boot_and_fstab() { + local targetuuid=$emmcuuid + local choosen_fs="ext4" + local root_uuid=$(sed -e 's/^.*root=//' -e 's/ .*$//' < /proc/cmdline) + mkdir -p ${olinux_mountpoint}/etc ${olinux_mountpoint}/media/mmcboot ${olinux_mountpoint}/media/mmcroot + + # Update fstab + echo "# " > ${olinux_mountpoint}/etc/fstab + echo "tmpfs /tmp tmpfs defaults,nosuid 0 0" >> ${olinux_mountpoint}/etc/fstab + echo "$targetuuid / $choosen_fs defaults,noatime,nodiratime,commit=600,errors=remount-ro,x-gvfs-hide 0 1" >> ${olinux_mountpoint}/etc/fstab + + # Update boot + cp -R /boot ${olinux_mountpoint} + # old boot scripts + sed -e 's,root='"$root_uuid"',root='"$targetuuid"',g' -i ${olinux_mountpoint}/boot/boot.cmd + # new boot scripts + if [[ -f ${olinux_mountpoint}/boot/armbianEnv.txt ]]; then + sed -e 's,rootdev=.*,rootdev='"$targetuuid"',g' -i ${olinux_mountpoint}/boot/armbianEnv.txt + else + sed -e 's,setenv rootdev.*,setenv rootdev '"$targetuuid"',g' -i ${olinux_mountpoint}/boot/boot.cmd + [[ -f ${olinux_mountpoint}/boot/boot.ini ]] && sed -e 's,^setenv rootdev.*$,setenv rootdev "'"$targetuuid"'",' -i ${olinux_mountpoint}/boot/boot.ini + [[ -f ${olinux_mountpoint}/boot/boot.ini ]] && sed -e 's,^setenv rootdev.*$,setenv rootdev "'"$targetuuid"'",' -i ${olinux_mountpoint}/boot/boot.ini + fi + mkimage -C none -A arm -T script -d ${olinux_mountpoint}/boot/boot.cmd ${olinux_mountpoint}/boot/boot.scr >/dev/null 2>&1 || (echo "Error"; exit 0) + + [[ -f /usr/lib/u-boot/platform_install.sh ]] && source /usr/lib/u-boot/platform_install.sh + if [[ $(type -t write_uboot_platform) != function ]]; then + echo "Error: no u-boot package found, exiting" + exit -1 + fi + write_uboot_platform "$DIR" "$opt_sdcardpath" +} + function copy_hypercube() { debug "Copying ${hypercube_path} to ${olinux_mountpoint}/root/" sudo cp "${hypercube_path}" "${olinux_mountpoint}/root/install.hypercube" @@ -834,6 +867,10 @@ if $opt_encryptedfs; then else info "Installing SD card (this could take a few minutes)" install_clear + + if $opt_emmc; then + update_boot_and_fstab + fi fi patch_servicesyml From 2deb6939441b49d4a7889e2c1592cfdbdf889e9b Mon Sep 17 00:00:00 2001 From: ljf Date: Sun, 15 Dec 2019 01:00:40 +0100 Subject: [PATCH 3/6] [wip] Convert yunohost image into internetcube --- install-sd.sh | 90 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 14 deletions(-) diff --git a/install-sd.sh b/install-sd.sh index e37da93..f3d9a3a 100755 --- a/install-sd.sh +++ b/install-sd.sh @@ -491,7 +491,7 @@ function download_img() { [ $opt_hardware == "lime2" ] && local urlpart_lime2=2 $opt_encryptedfs && local urlpart_encryptedfs=-encryptedfs - local tar_name="internetcube-${deb_version}-latest-lime${urlpart_lime2}${urlpart_encryptedfs}.img.tar.xz" + local tar_name="yunohost-${deb_version}-latest-${opt_hardware}${urlpart_encryptedfs}.img.zip" info "Image file: ${tar_name}" @@ -534,10 +534,10 @@ function check_gpg() { fi } -function untar_img() { +function uncompress_img() { debug "Decompressing ${img_path}" - tar xf "${img_path}" -C "${tmp_dir}" + unzip "${img_path}" -d "${tmp_dir}" # Should not have more than 1 line, but, you know... img_path=$(find "${tmp_dir}" -name '*.img' | head -n1) @@ -549,6 +549,63 @@ function untar_img() { fi } +function convert_img() { + debug "Converting ${img_path}" + local TARGET_DIR=./build-img +* local REP=$(dirname $0) + local APT='DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes' + local IMAGE=$(echo ${img_path} | sed 's/yunohost/internetcube/') + if [ -f $IMAGE ]; then + return + fi + cp ${img_path} $IMAGE + mkdir -p $TARGET_DIR + umount $TARGET_DIR || true + mount -o loop,offset=4194304 $IMAGE $TARGET_DIR + + + echo '. /etc/bash_completion' >> $TARGET_DIR/root/.bashrc + + # Use dhcp on boot + cat < $TARGET_DIR/etc/network/interfaces +source /etc/network/interfaces.d/* + +auto lo +iface lo inet loopback + +auto usb0 +allow-hotplug usb0 +iface usb0 inet dhcp +EOT + + # Debootstrap optimisations from igorpecovnik + # change default I/O scheduler, noop for flash media, deadline for SSD, cfq for mechanical drive + cat <> $TARGET_DIR/etc/sysfs.conf +block/mmcblk0/queue/scheduler = noop +#block/sda/queue/scheduler = cfq +EOT + + # Add firstrun and secondrun init script + local build_repo="https://raw.githubusercontent.com/labriqueinternet/build.labriqueinter.net/master/script/" + pushd $(basename ${hypercubesh_path}) + curl -#fOA $TARGET_DIR/usr/local/bin/resize2fs-reboot $build_repo/resize2fs-reboot + curl -#fOA $TARGET_DIR/usr/local/bin/hypercube.sh $build_repo/hypercube/hypercube.sh + curl -#fOA $TARGET_DIR/etc/systemd/system/resize2fs-reboot.service $build_repo/resize2fs-reboot.service + curl -#fOA $TARGET_DIR/etc/systemd/system/hypercube.service $build_repo/hypercube/hypercube.service + chmod 755 $TARGET_DIR/usr/local/bin/resize2fs-reboot $TARGET_DIR/usr/local/bin/hypercube.sh + chmod 444 $TARGET_DIR/etc/systemd/system/resize2fs-reboot.service $TARGET_DIR/etc/systemd/system/hypercube.service + + ln -f -s '/etc/systemd/system/resize2fs-reboot.service' $TARGET_DIR/etc/systemd/system/multi-user.target.wants/resize2fs-reboot.service + ln -f -s '/etc/systemd/system/hypercube.service' $TARGET_DIR/etc/systemd/system/multi-user.target.wants/hypercube.service + + # Add hypercube scripts + mkdir -p $TARGET_DIR/var/log/hypercube + curl -#fOA $TARGET_DIR/var/log/hypercube/install.html $build_repo/script/hypercube/install.html + chmod 444 $TARGET_DIR/var/log/hypercube/install.html + umount $TARGET_DIR || true + img_path=$IMAGE +} + function copy_custom_script() { debug "Copying ${custom_script_path} to ${olinux_mountpoint}/usr/local/bin/hypercube_custom.sh" sudo install -m 755 -o root -g root "${custom_script_path}" "${olinux_mountpoint}/usr/local/bin/hypercube_custom.sh" @@ -763,7 +820,7 @@ function patch_servicesyml() { ### GLOBAL VARIABLES ### ######################## -url_base=https://repo.labriqueinter.net/ +url_base=https://build.yunohost.org/ gpg_key=0xCD8F4D648AC0ECC1 gpg_server=keyserver.ubuntu.com deb_version=stretch @@ -841,24 +898,29 @@ if [ -z "${img_path}" ]; then info "Downloading Debian/YunoHost image (HTTPS)" download_img - if [ -z "${gpg_path}" ]; then - info "Downloading GPG signature (HTTPS)" - download_gpg - fi + #if [ -z "${gpg_path}" ]; then + # info "Downloading GPG signature (HTTPS)" + # download_gpg + #fi fi -if [ ! -z "${gpg_path}" ]; then - info "Checking GPG signature" - check_gpg -fi +#if [ ! -z "${gpg_path}" ]; then +# info "Checking GPG signature" +# check_gpg +#fi if [ -z "${gpg_path}" ]; then warn "Not checking image integrity" fi -if [[ "${img_path}" =~ .img.tar.xz$ ]]; then +if [[ "${img_path}" =~ .img.zip$ ]]; then info "Decompressing Debian/YunoHost image" - untar_img + uncompress_img +fi + +if [[ "${img_path}" =~ ^yunohost ]]; then + info "Converting yunohost image into internetcube image" + convert_img fi if $opt_encryptedfs; then From 39af1e4937cf396de17a69822c5f3b57e4545e75 Mon Sep 17 00:00:00 2001 From: ljf Date: Sun, 15 Dec 2019 11:43:58 +0100 Subject: [PATCH 4/6] [enh] Update usage --- install-sd.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/install-sd.sh b/install-sd.sh index f3d9a3a..1030712 100755 --- a/install-sd.sh +++ b/install-sd.sh @@ -65,6 +65,8 @@ function show_usage() { echo -e " HyperCube file" >&2 echo -e " \e[1m-c\e[0m \e[4mpath\e[0m" >&2 echo -e " Include custom script to be executed at the end of system installation" >&2 + echo -e " \e[1m-m\e[0m" >&2 + echo -e " Install on emmc (need to be run from an armbian on the sdcard)" >&2 echo -e " \e[1m-e\e[0m" >&2 echo -e " Install an encrypted file system" >&2 echo -e " \e[2mCan be automatically enabled, based on the image filename\e[0m" >&2 @@ -73,6 +75,9 @@ function show_usage() { echo -e " Install an image for LIME2" >&2 echo -e " \e[2mCan be automatically enabled, based on the image filename\e[0m" >&2 echo -e " \e[2mDefault: LIME\e[0m" >&2 + echo -e " \e[1m-p\e[0m" >&2 + echo -e " Install an image for Orange Pi PC Plus" >&2 + echo -e " \e[2mDefault: LIME\e[0m" >&2 echo -e " \e[1m-l\e[0m" >&2 echo -e " Just scan network for finding local IPv4s corresponding to Internet Cubes" >&2 echo -e " \e[1m-d\e[0m" >&2 @@ -853,7 +858,7 @@ while getopts "s:mf:g:c:y:w:em2pldh" opt; do m) opt_emmc=true ;; e) opt_encryptedfs=true ;; 2) opt_hardware="lime2" ;; - p) opt_hardware="pcplus" ;; + p) opt_hardware="orangepipcplus" ;; l) opt_findcubes=true ;; d) opt_debug=true ;; h) exit_usage ;; From a3cc579cd2e6fa828775b569a177c4a6c444ff7b Mon Sep 17 00:00:00 2001 From: ljf Date: Sun, 15 Dec 2019 12:08:27 +0100 Subject: [PATCH 5/6] [fix] Emmc always set --- install-sd.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install-sd.sh b/install-sd.sh index 1030712..8c3793e 100755 --- a/install-sd.sh +++ b/install-sd.sh @@ -831,6 +831,7 @@ gpg_server=keyserver.ubuntu.com deb_version=stretch opt_encryptedfs=false opt_findcubes=false +opt_emmc=false opt_debug=false opt_hardware="lime1" tmp_dir=$(mktemp -dp . .install-sd.sh_tmpXXXXXX) From 670a9cc8cd011b267e57b884eacf21c27aa4976b Mon Sep 17 00:00:00 2001 From: ljf Date: Thu, 19 Dec 2019 01:21:38 +0100 Subject: [PATCH 6/6] [fix] Be able to convert img --- install-sd.sh | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/install-sd.sh b/install-sd.sh index 8c3793e..bb91f8e 100755 --- a/install-sd.sh +++ b/install-sd.sh @@ -496,7 +496,7 @@ function download_img() { [ $opt_hardware == "lime2" ] && local urlpart_lime2=2 $opt_encryptedfs && local urlpart_encryptedfs=-encryptedfs - local tar_name="yunohost-${deb_version}-latest-${opt_hardware}${urlpart_encryptedfs}.img.zip" + local tar_name="yunohost-${deb_version}-latest-${opt_hardware}-stable${urlpart_encryptedfs}.img.zip" info "Image file: ${tar_name}" @@ -556,23 +556,23 @@ function uncompress_img() { function convert_img() { debug "Converting ${img_path}" - local TARGET_DIR=./build-img -* local REP=$(dirname $0) + local TARGET_DIR="${tmp_dir}/build-img" local APT='DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes' local IMAGE=$(echo ${img_path} | sed 's/yunohost/internetcube/') if [ -f $IMAGE ]; then return fi + debug "into ${IMAGE}" cp ${img_path} $IMAGE mkdir -p $TARGET_DIR - umount $TARGET_DIR || true - mount -o loop,offset=4194304 $IMAGE $TARGET_DIR + sudo umount $TARGET_DIR || true + sudo mount -o loop,offset=4194304 $IMAGE $TARGET_DIR - echo '. /etc/bash_completion' >> $TARGET_DIR/root/.bashrc + echo '. /etc/bash_completion' | sudo tee -a $TARGET_DIR/root/.bashrc # Use dhcp on boot - cat < $TARGET_DIR/etc/network/interfaces + cat <> $TARGET_DIR/etc/sysfs.conf + cat <