Added language support flag, set language in image, improvement to the help system.

This commit is contained in:
Storm Dragon 2020-12-12 14:56:20 -05:00
parent 7c0c71ab2c
commit 50959e458a

View File

@ -38,7 +38,7 @@ help() {
echo -e "Usage:\n"
echo "With no arguments, build with default parameters."
for i in "${!command[@]}" ; do
echo "-${i}: ${command[${i}]}"
echo "-${i/:/ <parameter>}: ${command[${i}]}"
done | sort
exit 0
}
@ -46,9 +46,10 @@ help() {
# Array of command line arguments
declare -A command=(
[h]="This help screen."
[n]="Image name, default is stormux-pi<3|4>-<yyyy-mm-dd>.img"
[s]="image size in GB, default is 4."
[v]="Version of the Raspberry Pi for which you are building. (3|4 default)"
[l:]="Language default is en_US."
[n:]="Image name, default is stormux-pi<3|4>-<yyyy-mm-dd>.img"
[s:]="image size in GB, default is 4."
[v:]="Version of the Raspberry Pi for which you are building. (3|4 default)"
)
# Convert the keys of the associative array to a format usable by getopts
@ -56,31 +57,31 @@ args="${!command[*]}"
args="${args//[[:space:]]/}"
while getopts "${args}" i ; do
case "$i" in
n)
shift
imageName="$1"
shift
;;
h) help;;
l)
imageLanguage="${OPTARG}.UTF-8"
;;
n)
imageName="${OPTARG}"
;;
s)
shift
if [[ "$1" =~ ^[[:digit:]]+$ ]]; then
imageSize="${1}G"
if [[ "${OPTARG}" =~ ^[[:digit:]]+$ ]]; then
imageSize="${OPTARG}G"
else
echo "Image size must be numeric."
exit 1
fi
shift
;;
v)
shift
if [[ "$1" =~ ^[34]$ ]]; then
imageVersion="$1"
if [[ "${OPTARG}" =~ ^[34]$ ]]; then
imageVersion="${OPTARG}"
else
echo "Image version must be 3 for the Raspberry Pi 3, or 4 for the Raspberry Pi 4 (default)."
exit 1
fi
shift
;;
*)
exit 1
;;
esac
done
@ -89,6 +90,7 @@ done
export imageVersion="${imageVersion:-4}"
export imageSize="${imageSize:-4G}"
export imageName="${imageName:-stormux-pi${imageVersion}-$(date '+%Y-%m-%d').img}"
export imageLanguage="${imageLanguage:-en_US.UTF-8}"
# Make sure the image file doesn't exist.
if [[ -e "$imageName" ]]; then
@ -118,7 +120,8 @@ done
# Url for the image to be downloaded.
url[3]="http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-aarch64-latest.tar.gz"
#url[3]="http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-aarch64-latest.tar.gz"
url[3]="http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz"
#url[4]="http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-aarch64-latest.tar.gz"
url[4]="http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-4-latest.tar.gz"
@ -138,6 +141,10 @@ arch-chroot /mnt << EOF
pacman-key --init
pacman-key --populate archlinuxarm
pacman -Syu --needed --noconfirm base base-devel bash-completion cronie espeak-ng git
# set the language
sed -i "s/#$imageLanguage/$imageLanguage/" /etc/locale.gen
echo "LANG=$imageLanguage" > /etc/locale.conf
locale-gen
# Set the distribution name.
echo 'Stormux \r (\l)' > /etc/issue
echo >> /etc/issue
@ -145,6 +152,8 @@ echo >> /etc/issue
usermod -a -g users -G wheel,audio,video -m -d /home/stormux -l stormux alarm
# Grant sudo privileges to the stormux user for package installation.
echo 'stormux ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/wheel
# Set the password for the root user
echo -e "root\nroot" | passwd "root"
# Set the password for the stormux user
echo -e "stormux\nstormux" | passwd "stormux"
# Change to the stormux user and install some packages