Skip to content

Commit

Permalink
Debian Image Builder
Browse files Browse the repository at this point in the history
The builder now creates a profile.txt file, which `make config`
will read as your default choices.

`nano profile.txt` and uncomment and edit what applies to you.

Profile: 1.0
Builder: 6.1
Signed-off-by: Patrick Yavitz <pyavitz@xxxxx.com>
  • Loading branch information
Patrick Yavitz committed Nov 21, 2023
1 parent 0ac66f3 commit 1c3e786
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 76 deletions.
97 changes: 34 additions & 63 deletions lib/dialog/config
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#!/bin/bash

# builder version
BUILDER="6.0"
source lib/function/config
# builder and profile versions
BUILDER="6.1"
PROFILE="1.0"

# script
# depends
if [[ `command -v curl` ]]; then :; else sudo apt install curl; fi
if [[ `curl -I https://github.com 2>&1 | grep 'HTTP/2 200'` ]]; then
:;
else
echo -e "The builder requires a internet connection."
exit 0;
exit 0
fi

# dynamic variables
URL="https://kernel.org"
LTS1=$(curl -s $URL | grep -A1 longterm: -n1 | egrep -o '>[^<]+' | egrep -o '[^>]+' | grep -w "5.15")
LTS2=$(curl -s $URL | grep -A1 longterm: -n1 | egrep -o '>[^<]+' | egrep -o '[^>]+' | grep -w "6.1")
Expand All @@ -19,6 +24,7 @@ STABLE=$(curl -s $URL/releases.json | jq '.latest_stable.version' -r)
GCC=`ls -ls /usr/bin/gcc | sed 's/.*\(..\)/\1/' | sed 's/ //g'`
MYNAME=`echo $USER | sed -e "s/\b\(.\)/\u\1/g"`

# userdata dot txt
NAME="$MYNAME"
USERNAME="$USER"
PASSWORD="board"
Expand All @@ -30,12 +36,17 @@ RTL88XXAU="1"
USERACCT="0"
USER_PKGS="htop libsensors-dev"
LOCALE="en_US.UTF-8"
LOCALE_LC_ALL="C.UTF-8"
TIMEZONE="America/New_York"
USER_NAMESERVER1="8.8.8.8"
USER_NAMESERVER2="8.8.4.4"
NAMESERVER1="8.8.8.8"
NAMESERVER2="8.8.4.4"
# profile dot txt
if [[ -f "profile.txt" ]]; then
# source user profile
. profile.txt
if [[ -n "$USER_PROFILE" ]]; then :; else rm -f profile.txt; fi
if [[ "$PROFILE" == "$USER_PROFILE" ]]; then :; else profile_txt; fi
else
profile_txt
fi
HOSTNAME="default"
DISTRO="debian"
Expand All @@ -48,14 +59,13 @@ CUSTOM_DEFCONFIG="0"
MYCONFIG=""
LOGGING="0"
VERBOSE="0"
DEVROOTFS="1"
COMPRESS_IMG="0"
USCRIPTS="0"

# open fd
exec 3>&1

# Store data to $VALUES variable
# store data to $VALUES variable
VALUES=$(dialog --ok-label "Submit" --no-cancel \
--backtitle "DEBIAN IMAGE BUILDER: CONFIG MENU" \
--title "" --form "" 0 40 0 \
Expand Down Expand Up @@ -83,10 +93,9 @@ VALUES=$(dialog --ok-label "Submit" --no-cancel \
" User Options" 22 1 "" 22 14 0 0 \
" Logging:" 23 1 "$LOGGING" 23 11 3 0 \
" Verbosity:" 24 1 "$VERBOSE" 24 13 3 0 \
" Devel Rootfs:" 25 1 "$DEVROOTFS" 25 16 3 0 \
" Compress img:" 26 1 "$COMPRESS_IMG" 26 16 3 0 \
" User scripts:" 27 1 "$USCRIPTS" 27 16 3 0 \
" User service:" 28 1 "$USERACCT" 28 16 3 0 \
" Compress img:" 25 1 "$COMPRESS_IMG" 25 16 3 0 \
" User scripts:" 26 1 "$USCRIPTS" 26 16 3 0 \
" User service:" 27 1 "$USERACCT" 27 16 3 0 \
2>&1 1>&3)

# close fd
Expand All @@ -111,10 +120,10 @@ echo CUSTOM_DEFCONFIG= >> tmp0
echo MYCONFIG='"' >> tmp0
echo LOGGING= >> tmp0
echo VERBOSE= >> tmp0
echo DEVROOTFS= >> tmp0
echo COMPRESS_IMG= >> tmp0
echo USCRIPTS= >> tmp0
echo USERACCT= >> tmp0
echo 'DEVROOTFS="1"' >> tmp0
echo 'EMMC="0"' >> tmp0
echo 'ROOTPASSWD="0"' >> tmp0
echo USER_PKGS='"'${USER_PKGS}'"' >> tmp0
Expand All @@ -124,20 +133,12 @@ echo 'KBUSER="playboy"' >> tmp0
echo 'KBHOST="penguin"' >> tmp0
echo "RTW88=${RTW88}" >> tmp0
echo "RTL88XXAU=${RTL88XXAU}" >> tmp0
echo "set_locales(){" >> tmp0
echo "apt install -y locales" >> tmp0
echo "export LANGUAGE=${LOCALE}" >> tmp0
echo "export LANG=${LOCALE}" >> tmp0
echo "export LC_ALL=C.UTF-8" >> tmp0
echo "locale-gen ${LOCALE}" >> tmp0
echo "}" >> tmp0
echo "set_timezone(){" >> tmp0
echo "ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime" >> tmp0
echo "echo -n '${TIMEZONE}' > /etc/timezone" >> tmp0
echo "}" >> tmp0
echo NAMESERVER1='"'${USER_NAMESERVER1}'"' >> tmp0
echo NAMESERVER2='"'${USER_NAMESERVER2}'"' >> tmp0
echo builder=${BUILDER} >> tmp0
echo LOCALE='"'${LOCALE}'"' >> tmp0
echo LOCALE_LC_ALL='"'${LOCALE_LC_ALL}'"' >> tmp0
echo TIMEZONE='"'${TIMEZONE}'"' >> tmp0
echo NAMESERVER1='"'${NAMESERVER1}'"' >> tmp0
echo NAMESERVER2='"'${NAMESERVER2}'"' >> tmp0
echo BUILDER=${BUILDER} >> tmp0
echo '"' > tmp2
echo '"' >> tmp2
echo '"' >> tmp2
Expand All @@ -164,43 +165,13 @@ sed -i '17i### CUSTOM' userdata.txt
sed -i '29i### COMPILER TUNING' userdata.txt
sed -i '32i### WHOAMI AND HOST' userdata.txt
sed -i '35i### EXTRA WIRELESS' userdata.txt
sed -i '38i### LOCALES' userdata.txt
sed -i '46i### TIMEZONE' userdata.txt
sed -i '51i### NAME SERVER' userdata.txt
sed -i '54i### DO NOT EDIT BELOW THIS LINE' userdata.txt
sed -i '38i### LOCALES TIMEZONE AND NAMESERVERS' userdata.txt
sed -i '44i### DO NOT EDIT BELOW THIS LINE' userdata.txt

# customize your image
custom_txt(){
echo "# Boot Partition: true false" > custom.txt
echo 'ENABLE_VFAT="false"' >> custom.txt
echo "" >> custom.txt
echo "# Root Filesystem Types: ext4 btrfs xfs" >> custom.txt
echo 'FSTYPE="ext4"' >> custom.txt
echo "" >> custom.txt
echo "# UEFI Options: true false" >> custom.txt
echo 'ENABLE_EFI="false"' >> custom.txt
echo "" >> custom.txt
echo "# Petitboot (ODROID): true false" >> custom.txt
echo 'ENABLE_PETITBOOT="false"' >> custom.txt
echo "" >> custom.txt
echo "# Image Size: 3072MB 3584MB 4096MB" >> custom.txt
echo 'IMGSIZE="4096MB"' >> custom.txt
echo "" >> custom.txt
echo "# Shrink Image (EXT4 Only): true false" >> custom.txt
echo 'ENABLE_SHRINK="true"' >> custom.txt
echo "" >> custom.txt
echo "# Compression Types: xz zst" >> custom.txt
echo 'IMG_COMPRESSION="xz"' >> custom.txt
echo "" >> custom.txt
echo "### DO NOT EDIT BELOW THIS LINE" >> custom.txt
echo "# CUSTOM=${BUILDER}" >> custom.txt
}
# custom dot txt
if [[ -f "custom.txt" ]]; then
if [[ `grep -w "CUSTOM=${BUILDER}" "custom.txt"` ]]; then
:;
else
custom_txt
fi
. custom.txt
if [[ "$CUSTOM" == "${BUILDER}" ]]; then :; else custom_txt; fi
else
custom_txt
fi
Expand Down
55 changes: 55 additions & 0 deletions lib/function/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# customize your image
custom_txt (){
cat <<EOF > "custom.txt"
# Boot Partition: true false
ENABLE_VFAT="false"
# Root Filesystem Types: ext4 btrfs xfs
FSTYPE="ext4"
# UEFI Options: true false
ENABLE_EFI="false"
# Petitboot (ODROID): true false
ENABLE_PETITBOOT="false"
# Image Size: 3072MB 3584MB 4096MB
IMGSIZE="4096MB"
# Shrink Image (EXT4 Only): true false
ENABLE_SHRINK="true"
# Compression Types: xz zst
IMG_COMPRESSION="xz"
### DO NOT EDIT BELOW THIS LINE
CUSTOM="$BUILDER"
EOF
}

profile_txt (){
cat <<EOF > "profile.txt"
# User data defaults
#NAME="$MYNAME"
#USERNAME="$USER"
#PASSWORD="board"
#VERSION="$LTS2"
#CCACHE="$CCACHE"
#NETWORKMANAGER="$NETWORKMANAGER"
#RTW88="$RTW88"
#RTL88XXAU="$RTL88XXAU"
#USERACCT="$USERACCT"
#USER_PKGS="$USER_PKGS"
#LOCALE="$LOCALE"
#LOCALE_LC_ALL="$LOCALE_LC_ALL"
#TIMEZONE="$TIMEZONE"
#NAMESERVER1="$NAMESERVER1"
#NAMESERVER2="$NAMESERVER2"
### DO NOT EDIT BELOW THIS LINE
USER_PROFILE="$PROFILE"
EOF
sed -i "s/^#VERSION=.*/#VERSION="'"$LTS2"'"/" profile.txt
}
11 changes: 5 additions & 6 deletions lib/source
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@ HOST_ARCH=`uname -m`

# validate
validation(){
BUILDER=`grep "builder=" "userdata.txt" | sed 's/builder=//g'`
UD="userdata.txt"
if [ -f "$UD" ]; then
BUILDER=`grep "BUILDER=" "userdata.txt" | sed 's/BUILDER=//g'`
if [[ -f "userdata.txt" ]]; then
echo -e ""
else
echo -e ""
echo -e "Create a $UD file"
echo -e "Create a userdata.txt file"
while [ true ]; do
read -t 10 -n 1
if [ $? = 0 ]; then exit 0; fi
done
fi
if [[ "$BUILDER" == "6.0" ]]; then
if [[ "$BUILDER" == "6.1" ]]; then
:;
else
echo -e "The ${WHT}$UD${FIN} file has expired. Please create a new one."
echo -e "The ${WHT}userdata.txt${FIN} file has expired. Please create a new one."
exit 0
fi
}
Expand Down
15 changes: 10 additions & 5 deletions scripts/rootfs-extra
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ fi
apt-get update
apt-get install -y apt-utils

# Locales
set_locales

# Timezone
set_timezone
# locales
apt install -y locales
export LANGUAGE=${LOCALE}
export LANG=${LOCALE}
export LC_ALL=${LOCALE_LC_ALL}
locale-gen ${LOCALE}

# timezone
ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime
echo -n "${TIMEZONE}" > /etc/timezone

apt upgrade -y
apt dist-upgrade -y
Expand Down
9 changes: 7 additions & 2 deletions scripts/stage2
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ apt-get update
apt-get install -y apt-utils

# locales
set_locales
apt install -y locales
export LANGUAGE=${LOCALE}
export LANG=${LOCALE}
export LC_ALL=${LOCALE_LC_ALL}
locale-gen ${LOCALE}

# timezone
set_timezone
ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime
echo -n "${TIMEZONE}" > /etc/timezone

apt upgrade -y
apt dist-upgrade -y
Expand Down

0 comments on commit 1c3e786

Please sign in to comment.