image_builder: add echo_stamp to other files

This commit is contained in:
Artem Smirnov
2018-08-20 19:06:41 +03:00
parent a008f6b57c
commit 3fc266a061
7 changed files with 211 additions and 57 deletions

View File

@@ -1,11 +1,33 @@
#!/bin/bash
set -e
##################################################################################################################################
# Image initialisation
##################################################################################################################################
set -e
echo_stamp() {
# STATIC FUNCTION
# TEMPLATE: echo_stamp <TEXT> <TYPE>
# TYPE: SUCCESS, ERROR, INFO
# More info there https://www.shellhacks.com/ru/bash-colors/
TEXT="$(date) | $1"
TEXT="\e[1m$TEXT\e[0m" # BOLD
case "$2" in
SUCCESS)
TEXT="\e[32m${TEXT}\e[0m";; # GREEN
ERROR)
TEXT="\e[31m${TEXT}\e[0m";; # RED
*)
TEXT="\e[34m${TEXT}\e[0m";; # BLUE
esac
echo -e ${TEXT}
}
# Add apt key to allow local mirror usage during image build
#wget -O - ftp://192.168.0.10/coex-mirror.gpg | apt-key add -
# Generate a backup of the original source.list
@@ -13,7 +35,7 @@ set -e
# Add the local mirror as the first priority repository
#wget -O - ftp://192.168.0.10/coex-mirror.list 2>/dev/null | cat - /etc/apt/sources.list > /var/sources.list && mv /var/sources.list /etc/apt/sources.list
echo -e "\033[0;31m\033[1m$(date) | #1 apt cache update\033[0m\033[0m"
echo_stamp "#1 apt cache update"
# Clean repostory cache
apt-get clean -qq > /dev/null
@@ -21,15 +43,15 @@ apt-get clean -qq > /dev/null
apt-get update -qq > /dev/null
# && apt upgrade -y
echo -e "\033[0;31m\033[1m$(date) | #2 Write clever information\033[0m\033[0m"
echo_stamp "#2 Write clever information"
# Clever image version
echo "$1" >> /etc/clever_version
# Origin image file name
echo "${2%.*}" >> /etc/clever_origin
echo -e "\033[0;31m\033[1m$(date) | #1 Write magic script to /etc/rc.local\033[0m\033[0m"
echo_stamp "#3 Write magic script to /etc/rc.local"
MAGIC_SCRIPT="sudo /root/init_rpi.sh && sudo sed -i '/sudo \\\/root\\\/init_rpi.sh/d' /etc/rc.local && sudo reboot"
sed -i "19a${MAGIC_SCRIPT}" /etc/rc.local
echo -e "\033[0;31m\033[1m$(date) | #3 End initialisation of image\033[0m\033[0m"
echo_stamp "#4 End initialisation of image"