From f96c231ec6adc243218b8b3032e629d7abf0f7b5 Mon Sep 17 00:00:00 2001 From: Huan Truong Date: Sat, 24 Feb 2018 19:45:29 -0500 Subject: [PATCH] [import] Initial import with changes from ezpi4me --- make-crankshaft.sh | 210 +++++++++++++++++++++++++ precompiled/autoapp.service | 13 ++ precompiled/autoapp_brightness.service | 13 ++ precompiled/brightness_max.sh | 5 + precompiled/openauto.rules | 1 + scripts/customize-image-pi.sh | 63 ++++++++ 6 files changed, 305 insertions(+) create mode 100755 make-crankshaft.sh create mode 100644 precompiled/autoapp.service create mode 100644 precompiled/autoapp_brightness.service create mode 100755 precompiled/brightness_max.sh create mode 100644 precompiled/openauto.rules create mode 100755 scripts/customize-image-pi.sh diff --git a/make-crankshaft.sh b/make-crankshaft.sh new file mode 100755 index 00000000..c7d2a246 --- /dev/null +++ b/make-crankshaft.sh @@ -0,0 +1,210 @@ +#!/bin/bash + +# ezpi4me - Raspberry Pi ME Cleaner image creation script +# Written by Huan Truong , 2018 +# This script is licensed under GNU Public License v3 + +IMAGE_FILE=2017-11-29-raspbian-stretch-lite.zip +IMAGE_FILE_UNZIPPED=2017-11-29-raspbian-stretch-lite.img +TODAY_EXT=$(date +"%Y-%m-%d") +IMAGE_FILE_CUSTOMIZED=crankshaft-${TODAY_EXT}.img +IMAGE_URL=http://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2017-12-01/2017-11-29-raspbian-stretch-lite.zip +IMAGE_SIZE_RAW=1858076672 +IMAGE_ROOTPART_START=94208 +TEMP_CHROOT_DIR=/mnt/raspbian-temp + + +######################################################### +# Support functions +######################################################### + +bail_and_cleanup() { + kpartx -d $1 + # rm $2 +} + +check_command_ok() { + if ! [ -x "$(command -v $1)" ]; then + echo 'Error: $1 is not installed. Please install it.' >&2 + exit 1 + fi +} + +check_root() { + # make sure we're root + if [ "$EUID" -ne 0 ]; then + echo "Please run this script as using sudo/as root, otherwise it can't continue." + exit + fi +} + +check_dependencies() { + check_command_ok kpartx + # check_command_ok parted + check_command_ok qemu-arm-static + check_command_ok chroot +} + +get_unzip_image() { + #get raspberry image + if [ -f ${IMAGE_FILE} ]; then + echo "Image file ${IMAGE_FILE} is already here, skip download. To re-download, please remove it." + else + wget -O${IMAGE_FILE} ${IMAGE_URL} + fi + if ! [ -f ${IMAGE_FILE_UNZIPPED} ]; then + unzip ${IMAGE_FILE} + fi + if ! [ -f ${IMAGE_FILE_CUSTOMIZED} ]; then + echo "Copying a big file..." + cp ${IMAGE_FILE_UNZIPPED} ${IMAGE_FILE_CUSTOMIZED} + else + echo "Skipping creation of ${IMAGE_FILE_CUSTOMIZED}, it's already there. To re-create, delete it." + fi +} + +resize_raw_image() { + IMAGE_SIZE_ACTUAL=$(wc -c < "${IMAGE_FILE_CUSTOMIZED}") + if [ ${IMAGE_SIZE_ACTUAL} -gt ${IMAGE_SIZE_RAW} ]; then + echo "Image seems already resized, or something is wrong." + echo "If the image doesn't work, try removing the .img and try again." + return + fi + echo "Resizing image" + + #resize image + dd if=/dev/zero bs=1M count=512 >> ${IMAGE_FILE_CUSTOMIZED} + + PART_NUM=2 + + fdisk ${IMAGE_FILE_CUSTOMIZED} < /sys/class/backlight/rpi_backlight/brightness + +exit 0 diff --git a/precompiled/openauto.rules b/precompiled/openauto.rules new file mode 100644 index 00000000..3c27e9ad --- /dev/null +++ b/precompiled/openauto.rules @@ -0,0 +1 @@ +SUBSYSTEM=="usb", ATTR{idVendor}=="*", ATTR{idProduct}=="*", MODE="0660", GROUP="plugdev" diff --git a/scripts/customize-image-pi.sh b/scripts/customize-image-pi.sh new file mode 100755 index 00000000..7e7556b4 --- /dev/null +++ b/scripts/customize-image-pi.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# crankshaft + +# adapted from Raspberry Pi ME Cleaner image customization script +# Written by Huan Truong , 2018 +# This script is licensed under GNU Public License v3 + +############################################################################### + +print_banner() { + echo "---- WELCOME TO THE RASPBERRY PI IMAGE CUSTOMIZER --------------" + sleep 1 + echo " Congratulations, we have gone a long way." + sleep 1 + echo " I will prepare some software for you, sit tight." + sleep 1 + echo "" + echo "" + echo "" +} + +get_deps() { + apt update + #apt upgrade + apt install -y libprotobuf10 libpulse0 libboost-log1.62.0 libboost-test1.62.0 libboost-thread1.62.0 libboost-date-time1.62.0 libboost-chrono1.62.0 libboost-atomic1.62.0 libpulse-mainloop-glib0 libfontconfig1 pulseaudio + #update raspi firmware + SKIP_WARNING=1 rpi-update +} + +mark_script_run() { + touch /etc/customizer_done +} + +house_keeping() { + # make sure everything has the right owner + chown -R root:staff /usr/local/ + chown root:staff /etc/systemd/system/autoapp.service + chown root:staff /etc/systemd/system/autoapp_brightness.service + chown root:staff /etc/udev/rules.d/openauto.rules + + # enable the startup actions + systemctl enable autoapp.service + systemctl enable autoapp_brightness.service +} + + +############################################################################### + +if [ -f /etc/customizer_done ]; then + echo "This script has been run before. Nothing to do." + exit 0 +fi + +cd /root/ + +print_banner + +get_deps + +house_keeping + +mark_script_run