2020-05-02 11:46:39 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# shellcheck disable=SC2010 # ls | grep allowed
|
2020-05-15 10:41:44 +02:00
|
|
|
# shellcheck source=/dev/null # Deactivate SC1090
|
2020-05-19 11:10:06 +02:00
|
|
|
# shellcheck disable=SC2015 # Deactivate bools hints
|
|
|
|
# shellcheck disable=SC2154 # Deactivate not referenced link
|
2020-09-24 18:58:30 +02:00
|
|
|
# @see https://wiki.polaire.nl/doku.php?id=archlinux-raspberry-encrypted
|
2020-05-15 12:00:03 +02:00
|
|
|
source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1)
|
2020-05-02 11:46:39 +02:00
|
|
|
|
2020-05-15 10:19:58 +02:00
|
|
|
info "Setupscript for images started..."
|
2020-05-02 11:46:39 +02:00
|
|
|
|
|
|
|
info "Checking if root..."
|
|
|
|
if [ "$(id -u)" != "0" ];then
|
|
|
|
error "This script must be executed as root!"
|
|
|
|
fi
|
|
|
|
|
2020-05-15 14:10:24 +02:00
|
|
|
make_working_folder
|
2020-05-15 12:23:07 +02:00
|
|
|
|
2020-05-18 12:45:48 +02:00
|
|
|
info "Configure user..." &&
|
|
|
|
question "Please type in a valid working username:" && read -r origin_username &&
|
|
|
|
getent passwd "$origin_username" > /dev/null 2 || error "User $origin_username doesn't exist."
|
|
|
|
origin_user_home="/home/$origin_username/"
|
2020-05-02 11:46:39 +02:00
|
|
|
|
|
|
|
info "Image routine starts..."
|
|
|
|
image_folder="$origin_user_home""Images/";
|
|
|
|
info "The images will be stored in \"$image_folder\"."
|
|
|
|
if [ ! -d "$image_folder" ]; then
|
2020-05-18 12:45:48 +02:00
|
|
|
info "Folder \"$image_folder\" doesn't exist. It will be created now." &&
|
|
|
|
mkdir -v "$image_folder" ||
|
|
|
|
error
|
2020-05-02 11:46:39 +02:00
|
|
|
fi
|
|
|
|
|
2020-05-15 12:23:07 +02:00
|
|
|
set_device_path
|
2020-05-02 11:46:39 +02:00
|
|
|
|
2020-05-15 12:23:07 +02:00
|
|
|
if mount | grep -q "$device_path"
|
2020-05-02 11:46:39 +02:00
|
|
|
then
|
2020-05-15 12:23:07 +02:00
|
|
|
error "Device $device_path is allready mounted. Umount with \"umount $device_path*\"."
|
2020-05-02 11:46:39 +02:00
|
|
|
fi
|
|
|
|
|
2020-05-18 12:45:48 +02:00
|
|
|
info "Select which architecture type should be used..." &&
|
|
|
|
echo "1) arm " &&
|
|
|
|
echo "2) 64_bit" &&
|
|
|
|
question "Please type in the architecture type:" &&
|
|
|
|
read -r architecture ||
|
|
|
|
error
|
2020-05-02 11:46:39 +02:00
|
|
|
|
2020-05-18 12:45:48 +02:00
|
|
|
|
|
|
|
info "Select which operating system should be used..."
|
2020-05-02 11:46:39 +02:00
|
|
|
info "Available systems:"
|
2020-05-18 12:45:48 +02:00
|
|
|
if [ "$architecture" = "arm" ]
|
|
|
|
then
|
|
|
|
echo "1) arch"
|
|
|
|
echo "2) moode"
|
|
|
|
echo "3) retropie"
|
|
|
|
fi
|
|
|
|
if [ "$architecture" = "64_bit" ]
|
|
|
|
then
|
|
|
|
echo "1) manjaro"
|
|
|
|
fi
|
2020-05-02 11:46:39 +02:00
|
|
|
question "Please type in the os:" && read -r os
|
|
|
|
|
2020-05-18 12:45:48 +02:00
|
|
|
info "Select which version should be used..."
|
|
|
|
case "$architecture" in
|
|
|
|
"arm")
|
|
|
|
echo "Version for Raspberry Pi modell:"
|
|
|
|
echo "1) 1"
|
|
|
|
echo "2) 2"
|
|
|
|
echo "3) 3"
|
|
|
|
echo "4) 4"
|
|
|
|
;;
|
|
|
|
"64_bit")
|
|
|
|
case "$os" in
|
2020-05-18 21:01:18 +02:00
|
|
|
"manjaro")
|
2020-05-18 12:45:48 +02:00
|
|
|
echo "1) architect"
|
2020-05-19 10:31:18 +02:00
|
|
|
echo "1) gnome"
|
2020-05-18 12:45:48 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
error "The os system \"$os\" is not supported yet for 64bit!"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
error "The architecture \"$architecture\" is not supported yet!"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
question "Please type in the version:" && read -r version
|
|
|
|
|
2020-05-02 11:46:39 +02:00
|
|
|
os_does_not_support_raspberry_version_error () {
|
|
|
|
error "$os for Raspberry Pi Version $version is not supported!";
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$os" in
|
|
|
|
"arch")
|
2020-06-11 16:58:15 +02:00
|
|
|
question "Should the system be encrypted?(y/N)" && read -r encrypt_system
|
2020-05-02 11:46:39 +02:00
|
|
|
base_download_url="http://os.archlinuxarm.org/os/";
|
|
|
|
case "$version" in
|
|
|
|
"1")
|
|
|
|
imagename="ArchLinuxARM-rpi-latest.tar.gz"
|
|
|
|
;;
|
2020-05-21 19:22:14 +02:00
|
|
|
"2")
|
2020-05-02 11:46:39 +02:00
|
|
|
imagename="ArchLinuxARM-rpi-2-latest.tar.gz"
|
|
|
|
;;
|
2020-05-21 19:22:14 +02:00
|
|
|
"3")
|
|
|
|
imagename="ArchLinuxARM-rpi-3-latest.tar.gz"
|
|
|
|
;;
|
2020-05-02 11:46:39 +02:00
|
|
|
"4")
|
|
|
|
imagename="ArchLinuxARM-rpi-4-latest.tar.gz"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
os_does_not_support_raspberry_version_error
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2020-05-18 12:45:48 +02:00
|
|
|
"manjaro")
|
|
|
|
case "$version" in
|
|
|
|
"architect")
|
2020-05-18 12:47:33 +02:00
|
|
|
image_checksum="6b1c2fce12f244c1e32212767a9d3af2cf8263b2"
|
2020-05-18 21:01:18 +02:00
|
|
|
base_download_url="https://osdn.net/frs/redir.php?m=dotsrc&f=%2Fstorage%2Fg%2Fm%2Fma%2Fmanjaro%2Farchitect%2F20.0%2F";
|
2020-05-18 12:45:48 +02:00
|
|
|
imagename="manjaro-architect-20.0-200426-linux56.iso"
|
2020-05-19 10:31:18 +02:00
|
|
|
;;
|
|
|
|
"gnome")
|
|
|
|
image_checksum="d16118207c546c18201703d80b6356b1522b47d0"
|
|
|
|
base_download_url="https://osdn.net/frs/redir.php?m=dotsrc&f=/storage/g/m/ma/manjaro/gnome/20.0.1/";
|
|
|
|
imagename="manjaro-gnome-20.0.1-200511-linux56.iso"
|
2020-05-18 12:45:48 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
os_does_not_support_raspberry_version_error
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2020-05-02 11:46:39 +02:00
|
|
|
"moode")
|
|
|
|
image_checksum="185cbc9a4994534bb7a4bc2744c78197"
|
|
|
|
base_download_url="https://github.com/moode-player/moode/releases/download/r651prod/"
|
|
|
|
imagename="moode-r651-iso.zip";
|
|
|
|
;;
|
|
|
|
"retropie")
|
|
|
|
base_download_url="https://github.com/RetroPie/RetroPie-Setup/releases/download/4.6/";
|
|
|
|
case "$version" in
|
|
|
|
"1")
|
|
|
|
image_checksum="98b4205ad0248d378c6776e20c54e487"
|
|
|
|
imagename="retropie-buster-4.6-rpi1_zero.img.gz"
|
|
|
|
;;
|
|
|
|
|
|
|
|
"2" | "3")
|
|
|
|
image_checksum="2e082ef5fc2d7cf7d910494cf0f7185b"
|
|
|
|
imagename="retropie-buster-4.6-rpi2_rpi3.img.gz"
|
|
|
|
;;
|
|
|
|
|
|
|
|
"4")
|
|
|
|
image_checksum="9154d998cba5219ddf23de46d8845f6c"
|
|
|
|
imagename="retropie-buster-4.6-rpi4.img.gz"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
os_does_not_support_raspberry_version_error
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
error "The operation system \"$os\" is not supported yet!"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
info "Generating os-image..."
|
|
|
|
download_url="$base_download_url$imagename"
|
|
|
|
image_path="$image_folder$imagename"
|
|
|
|
|
2020-05-19 11:10:06 +02:00
|
|
|
question "Should the image download be forced?(y/N)" && read -r force_image_download
|
2020-05-02 11:46:39 +02:00
|
|
|
if [ "$force_image_download" = "y" ]
|
|
|
|
then
|
|
|
|
if [ -f "$image_path" ]
|
|
|
|
then
|
2020-05-18 21:01:18 +02:00
|
|
|
info "Removing image $image_path." &&
|
2020-05-02 11:46:39 +02:00
|
|
|
rm "$image_path" || error "Removing image \"$image_path\" failed."
|
|
|
|
else
|
|
|
|
info "Forcing download wasn't neccessary. File $image_path doesn't exist."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
info "Start Download procedure..."
|
|
|
|
if [ -f "$image_path" ]
|
|
|
|
then
|
|
|
|
info "Image exist local. Download skipped."
|
|
|
|
else
|
|
|
|
info "Image \"$imagename\" doesn't exist under local path \"$image_path\"."
|
|
|
|
info "Image \"$imagename\" gets downloaded from \"$download_url\"..."
|
2020-05-18 21:01:18 +02:00
|
|
|
wget "$download_url" -O "$image_path" || error "Download from \"$download_url\" failed."
|
2020-05-02 11:46:39 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
info "Verifying image..."
|
|
|
|
if [[ -v image_checksum ]]
|
|
|
|
then
|
2020-05-25 14:46:52 +02:00
|
|
|
(info "Checking md5 checksum..." && echo "$image_checksum $image_path"| md5sum -c -) ||
|
|
|
|
(info "Checking sha1 checksum..." && echo "$image_checksum $image_path"| sha1sum -c -) ||
|
2020-05-18 12:45:48 +02:00
|
|
|
error "Verification failed. HINT: Force the download of the image."
|
2020-05-02 11:46:39 +02:00
|
|
|
else
|
|
|
|
warning "Verification is not possible. No checksum is defined."
|
|
|
|
fi
|
|
|
|
|
2020-05-15 14:10:24 +02:00
|
|
|
make_mount_folders
|
2020-05-02 11:46:39 +02:00
|
|
|
|
2020-05-15 13:37:14 +02:00
|
|
|
set_partition_paths
|
2020-05-02 11:46:39 +02:00
|
|
|
|
2020-05-25 14:46:52 +02:00
|
|
|
question "Should the image be transfered to $device_path?(y/N)" && read -r transfer_image
|
2020-05-02 11:46:39 +02:00
|
|
|
if [ "$transfer_image" = "y" ]
|
|
|
|
then
|
|
|
|
|
2020-09-26 17:12:13 +02:00
|
|
|
question "Should the partition table of $device_path be deleted?(y/N)" && read -r delete_partition_table
|
|
|
|
if [ "$delete_partition_table" = "y" ]
|
|
|
|
then
|
|
|
|
info "Deleting..." &&
|
|
|
|
wipefs -a "$device_path" || error
|
|
|
|
else
|
|
|
|
info "Skipping partition table deletion..."
|
|
|
|
fi
|
|
|
|
|
2020-05-20 12:47:30 +02:00
|
|
|
overwritte_device_with_zeros
|
2020-05-02 11:46:39 +02:00
|
|
|
|
|
|
|
info "Starting image transfer..."
|
2020-05-18 12:45:48 +02:00
|
|
|
if [ "$os" = "arch" ]
|
|
|
|
then
|
2020-06-11 16:58:15 +02:00
|
|
|
info "Deleting partition tables..." &&
|
2020-10-01 17:42:35 +02:00
|
|
|
wipefs -a "$device_path" &&
|
|
|
|
info "Creating partitions..." &&
|
|
|
|
( echo "o" #Type o. This will clear out any partitions on the drive.
|
|
|
|
echo "p" #Type p to list partitions. There should be no partitions left
|
|
|
|
echo "n" #Type n,
|
|
|
|
echo "p" #then p for primary,
|
|
|
|
echo "1" #1 for the first partition on the drive,
|
|
|
|
echo "" #Default start sector
|
|
|
|
echo "+300M" #then type +300M for the last sector.
|
|
|
|
echo "t" #Type t,
|
|
|
|
echo "c" #then c to set the first partition to type W95 FAT32 (LBA).
|
|
|
|
echo "n" #Type n,
|
|
|
|
echo "p" #then p for primary,
|
|
|
|
echo "2" #2 for the second partition on the drive,
|
|
|
|
echo "" #Default start sector
|
|
|
|
echo "" #Default end sector
|
|
|
|
echo "w" #Write the partition table and exit by typing w.
|
|
|
|
)| fdisk "$device_path" || error
|
2020-05-02 11:46:39 +02:00
|
|
|
|
2020-05-18 12:45:48 +02:00
|
|
|
info "Format boot partition..." &&
|
2020-06-11 16:58:15 +02:00
|
|
|
mkfs.vfat "$boot_partition_path" || error
|
2020-05-02 11:46:39 +02:00
|
|
|
|
2020-10-01 17:42:35 +02:00
|
|
|
if [ "$encrypt_system" == "y" ]
|
|
|
|
then
|
|
|
|
info "Formating $root_partition_path with LUKS..." &&
|
2020-10-01 21:01:06 +02:00
|
|
|
sudo cryptsetup -v luksFormat -c aes-xts-plain64 -s 512 -h sha512 --use-random -i 1000 "$root_partition_path" &&
|
2020-10-01 21:16:08 +02:00
|
|
|
decrypt_root || error
|
2020-10-01 17:42:35 +02:00
|
|
|
fi
|
2020-05-02 11:46:39 +02:00
|
|
|
|
2020-10-01 17:42:35 +02:00
|
|
|
info "Format root partition..." &&
|
|
|
|
mkfs.ext4 "$root_mapper_path" || error
|
2020-05-02 11:46:39 +02:00
|
|
|
mount_partitions;
|
|
|
|
|
2020-05-18 12:45:48 +02:00
|
|
|
info "Root files will be transfered to device..." &&
|
|
|
|
bsdtar -xpf "$image_path" -C "$root_mount_path" &&
|
|
|
|
sync ||
|
|
|
|
error
|
|
|
|
|
|
|
|
info "Boot files will be transfered to device..." &&
|
2020-06-08 17:45:11 +02:00
|
|
|
mv -v "$root_mount_path""boot/"* "$boot_mount_path" ||
|
2020-05-18 12:45:48 +02:00
|
|
|
error
|
2020-05-18 21:01:18 +02:00
|
|
|
elif [ "${image_path: -4}" = ".zip" ]
|
2020-05-18 12:45:48 +02:00
|
|
|
then
|
2020-05-18 21:01:18 +02:00
|
|
|
info "Transfering .zip file..." &&
|
2020-05-20 10:35:37 +02:00
|
|
|
unzip -p "$image_path" | sudo dd of="$device_path" bs="$OPTIMAL_BLOCKSIZE" conv=fsync status=progress || error "DD $image_path to $device_path failed." &&
|
2020-05-18 12:45:48 +02:00
|
|
|
sync ||
|
|
|
|
error
|
2020-05-18 21:01:18 +02:00
|
|
|
elif [ "${image_path: -3}" = ".gz" ]
|
2020-05-18 12:45:48 +02:00
|
|
|
then
|
2020-05-18 21:01:18 +02:00
|
|
|
info "Transfering .gz file..." &&
|
2020-05-20 10:35:37 +02:00
|
|
|
gunzip -c "$image_path" | sudo dd of="$device_path" bs="$OPTIMAL_BLOCKSIZE" conv=fsync status=progress &&
|
2020-05-18 12:45:48 +02:00
|
|
|
sync ||
|
|
|
|
error
|
2020-05-18 21:01:18 +02:00
|
|
|
elif [ "${image_path: -4}" = ".iso" ]
|
2020-05-18 12:45:48 +02:00
|
|
|
then
|
2020-05-18 21:01:18 +02:00
|
|
|
info "Transfering .iso file..." &&
|
2020-05-20 10:35:37 +02:00
|
|
|
sudo dd if="$image_path" of="$device_path" bs="$OPTIMAL_BLOCKSIZE" conv=fsync status=progress &&
|
2020-05-18 12:45:48 +02:00
|
|
|
sync ||
|
|
|
|
error
|
|
|
|
else
|
2020-05-02 11:46:39 +02:00
|
|
|
error "Image transfer for operation system \"$os\" is not supported yet!";
|
2020-05-18 12:45:48 +02:00
|
|
|
fi
|
2020-05-02 11:46:39 +02:00
|
|
|
else
|
|
|
|
info "Skipping image transfer..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
info "Start regular mounting procedure..."
|
2020-06-11 21:22:10 +02:00
|
|
|
if mount | grep -q "$boot_partition_path"
|
2020-05-02 11:46:39 +02:00
|
|
|
then
|
2020-06-11 21:22:10 +02:00
|
|
|
info "$boot_partition_path is allready mounted..."
|
2020-05-02 11:46:39 +02:00
|
|
|
else
|
2020-10-01 17:42:35 +02:00
|
|
|
if mount | grep -q "$root_mapper_path"
|
2020-06-08 17:45:11 +02:00
|
|
|
then
|
2020-10-01 17:42:35 +02:00
|
|
|
info "$root_mapper_path is allready mounted..."
|
2020-06-08 17:45:11 +02:00
|
|
|
else
|
2020-10-01 21:16:08 +02:00
|
|
|
decrypt_root
|
2020-06-08 17:45:11 +02:00
|
|
|
mount_partitions
|
|
|
|
fi
|
2020-05-02 11:46:39 +02:00
|
|
|
fi
|
|
|
|
|
2020-10-02 15:30:47 +02:00
|
|
|
info "Define target paths..." &&
|
|
|
|
target_home_path="$root_mount_path""home/" &&
|
|
|
|
target_username=$(ls "$target_home_path") &&
|
|
|
|
target_user_home_folder_path="$target_home_path$target_username/" &&
|
|
|
|
|
|
|
|
target_user_ssh_folder_path="$target_user_home_folder_path"".ssh/" &&
|
|
|
|
target_authorized_keys="$target_user_ssh_folder_path""authorized_keys" &&
|
|
|
|
question "Should the ssh-key be copied to the image?(y/N)" && read -r copy_ssh_key || error
|
2020-05-18 12:45:48 +02:00
|
|
|
if [ "$copy_ssh_key" == "y" ]
|
2020-05-02 11:46:39 +02:00
|
|
|
then
|
2020-10-02 15:30:47 +02:00
|
|
|
info "Copy ssh key to target..." &&
|
|
|
|
origin_user_rsa_pub="$origin_user_home"".ssh/id_rsa.pub" || error
|
2020-05-18 12:45:48 +02:00
|
|
|
if [ -f "$origin_user_rsa_pub" ]
|
|
|
|
then
|
2020-05-25 14:46:52 +02:00
|
|
|
mkdir -v "$target_user_ssh_folder_path" || warning "Folder \"$target_user_ssh_folder_path\" exists. Can't be created."
|
2020-05-18 12:45:48 +02:00
|
|
|
cat "$origin_user_rsa_pub" > "$target_authorized_keys" &&
|
|
|
|
target_authorized_keys_content=$(cat "$target_authorized_keys") &&
|
|
|
|
info "$target_authorized_keys contains the following: $target_authorized_keys_content" &&
|
|
|
|
chown -vR 1000 "$target_user_ssh_folder_path" &&
|
|
|
|
chmod -v 700 "$target_user_ssh_folder_path" &&
|
2020-10-02 15:30:47 +02:00
|
|
|
chmod -v 600 "$target_authorized_keys" || error
|
2020-05-18 12:45:48 +02:00
|
|
|
else
|
|
|
|
warning "The ssh key \"$origin_user_rsa_pub\" can't be copied to \"$target_authorized_keys\" because it doesn't exist."
|
|
|
|
fi
|
2020-05-02 11:46:39 +02:00
|
|
|
else
|
2020-05-18 12:45:48 +02:00
|
|
|
info "Skipped SSH-key copying.."
|
2020-05-02 11:46:39 +02:00
|
|
|
fi
|
2020-05-21 19:22:14 +02:00
|
|
|
|
2020-05-02 11:46:39 +02:00
|
|
|
info "Start chroot procedures..."
|
2020-05-15 14:10:24 +02:00
|
|
|
|
2020-05-21 19:22:14 +02:00
|
|
|
mount_chroot_binds
|
2020-05-02 11:46:39 +02:00
|
|
|
|
2020-05-21 19:22:14 +02:00
|
|
|
copy_qemu
|
2020-05-02 11:46:39 +02:00
|
|
|
|
2020-05-21 19:22:14 +02:00
|
|
|
copy_resolve_conf
|
2020-05-02 11:46:39 +02:00
|
|
|
|
2020-05-25 14:18:34 +02:00
|
|
|
question "Should the password of the standart user \"$target_username\" be changed?(y/N)" && read -r change_password
|
2020-05-18 12:45:48 +02:00
|
|
|
if [ "$change_password" == "y" ]
|
2020-05-02 11:46:39 +02:00
|
|
|
then
|
2020-05-18 12:45:48 +02:00
|
|
|
info "Changing passwords on target system..."
|
|
|
|
question "Type in new password: " && read -r password_1
|
|
|
|
question "Repeat new password\"$target_username\"" && read -r password_2
|
|
|
|
if [ "$password_1" = "$password_2" ]
|
|
|
|
then
|
|
|
|
(
|
|
|
|
echo "(
|
|
|
|
echo '$password_1'
|
|
|
|
echo '$password_1'
|
|
|
|
) | passwd $target_username"
|
|
|
|
echo "(
|
|
|
|
echo '$password_1'
|
|
|
|
echo '$password_1'
|
|
|
|
) | passwd"
|
2020-05-21 20:01:32 +02:00
|
|
|
) | chroot "$root_mount_path" /bin/bash || error
|
2020-05-18 12:45:48 +02:00
|
|
|
else
|
|
|
|
error "Passwords didn't match."
|
|
|
|
fi
|
2020-05-02 11:46:39 +02:00
|
|
|
else
|
2020-05-18 12:45:48 +02:00
|
|
|
info "Skipped password change..."
|
2020-05-02 11:46:39 +02:00
|
|
|
fi
|
2020-05-21 19:42:29 +02:00
|
|
|
|
2020-06-12 09:38:13 +02:00
|
|
|
hostname_path="$root_mount_path""etc/hostname"
|
2020-05-18 12:45:48 +02:00
|
|
|
question "Should the hostname be changed?(y/N)" && read -r change_hostname
|
|
|
|
if [ "$change_hostname" == "y" ]
|
|
|
|
then
|
2020-06-12 09:38:13 +02:00
|
|
|
question "Type in the hostname:" && read -r target_hostname;
|
|
|
|
echo "$target_hostname" > "$hostname_path" || error
|
2020-05-18 12:45:48 +02:00
|
|
|
else
|
2020-06-12 09:38:13 +02:00
|
|
|
target_hostname=$(cat "$hostname_path")
|
2020-05-18 12:45:48 +02:00
|
|
|
info "Skipped hostname change..."
|
|
|
|
fi
|
2020-06-12 09:38:13 +02:00
|
|
|
info "Used hostname is: $target_hostname"
|
2020-05-21 19:42:29 +02:00
|
|
|
|
2020-10-01 22:35:38 +02:00
|
|
|
case "$os" in
|
|
|
|
"arch"|"manjaro")
|
|
|
|
info "Populating keys..." &&
|
|
|
|
(
|
|
|
|
echo "yes | pacman-key --init"
|
|
|
|
echo "yes | pacman-key --populate archlinuxarm"
|
|
|
|
) | chroot "$root_mount_path" /bin/bash || error
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-05-21 20:01:32 +02:00
|
|
|
question "Should the system be updated?(y/N)" && read -r update_system
|
2020-05-21 19:42:29 +02:00
|
|
|
if [ "$update_system" == "y" ]
|
|
|
|
then
|
2020-05-25 14:18:34 +02:00
|
|
|
info "Updating system..."
|
|
|
|
case "$os" in
|
|
|
|
"arch"|"manjaro")
|
|
|
|
(
|
2020-06-11 15:36:27 +02:00
|
|
|
echo "pacman --noconfirm -Syyu"
|
2020-05-25 14:18:34 +02:00
|
|
|
) | chroot "$root_mount_path" /bin/bash || error
|
|
|
|
;;
|
|
|
|
"moode"|"retropie")
|
|
|
|
(
|
|
|
|
echo "yes | apt update"
|
|
|
|
echo "yes | apt upgrade"
|
|
|
|
) | chroot "$root_mount_path" /bin/bash || error
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
warning "System update for operation system \"$os\" is not supported yet. Skipped."
|
|
|
|
;;
|
|
|
|
esac
|
2020-05-21 19:42:29 +02:00
|
|
|
fi
|
2020-05-21 20:01:32 +02:00
|
|
|
|
2020-05-25 13:40:03 +02:00
|
|
|
if [ "$encrypt_system" == "y" ]
|
|
|
|
then
|
2020-10-01 12:46:54 +02:00
|
|
|
# Adapted this instruction for setting up encrypted systems @see https://gist.github.com/gea0/4fc2be0cb7a74d0e7cc4322aed710d38
|
2020-10-02 12:55:13 +02:00
|
|
|
info "Setup encryption..." &&
|
2020-10-02 13:54:43 +02:00
|
|
|
|
|
|
|
info "Installing neccessary software..." &&
|
|
|
|
echo "pacman --noconfirm -S --needed $(get_packages "server/luks")" | chroot "$root_mount_path" /bin/bash &&
|
|
|
|
|
|
|
|
dropbear_root_key_path="$root_mount_path""etc/dropbear/root_key" &&
|
2020-10-02 13:58:04 +02:00
|
|
|
info "Adding $target_authorized_keys to dropbear..." &&
|
2020-10-02 13:54:43 +02:00
|
|
|
cp -v "$target_authorized_keys" "$dropbear_root_key_path" &&
|
|
|
|
|
2020-10-02 12:55:13 +02:00
|
|
|
#Concerning mkinitcpio warning @see https://gist.github.com/imrvelj/c65cd5ca7f5505a65e59204f5a3f7a6d
|
2020-10-02 13:54:43 +02:00
|
|
|
mkinitcpio_path="$root_mount_path""etc/mkinitcpio.conf" &&
|
2020-10-02 12:55:13 +02:00
|
|
|
info "Configuring $mkinitcpio_path..." &&
|
2020-10-01 19:35:01 +02:00
|
|
|
mkinitcpio_search_modules="MODULES=()" &&
|
|
|
|
mkinitcpio_replace_modules="MODULES=(g_cdc usb_f_acm usb_f_ecm smsc95xx g_ether)" &&
|
|
|
|
mkinitcpio_search_binaries="BINARIES=()" &&
|
|
|
|
mkinitcpio_replace_binaries=$(echo "BINARIES=(/usr/lib/libgcc_s.so.1)"| sed -e 's/[\/&]/\\&/g') &&
|
|
|
|
mkinitcpio_search_hooks="HOOKS=(base udev autodetect modconf block filesystems keyboard fsck)" &&
|
|
|
|
mkinitcpio_replace_hooks="HOOKS=(base udev autodetect modconf block sleep netconf dropbear encryptssh filesystems keyboard fsck)" &&
|
2020-10-02 13:58:04 +02:00
|
|
|
sed -i "s/$mkinitcpio_search_modules/$mkinitcpio_replace_modules/g" "$mkinitcpio_path" &&
|
|
|
|
sed -i "s/$mkinitcpio_search_binaries/$mkinitcpio_replace_binaries/g" "$mkinitcpio_path" &&
|
|
|
|
sed -i "s/$mkinitcpio_search_hooks/$mkinitcpio_replace_hooks/g" "$mkinitcpio_path" &&
|
2020-10-02 14:27:39 +02:00
|
|
|
info "Content of $mkinitcpio_path:$(cat "$mkinitcpio_path")" &&
|
2020-10-02 13:54:43 +02:00
|
|
|
info "Generating mkinitcpio..." &&
|
|
|
|
echo "mkinitcpio -vP || exit 1" | chroot "$root_mount_path" /bin/bash &&
|
|
|
|
|
|
|
|
fstab_path="$root_mount_path""etc/fstab" &&
|
2020-10-02 15:17:06 +02:00
|
|
|
fstab_insert_line="UUID=$root_partition_uuid / ext4 defaults,noatime 0 1" &&
|
|
|
|
info "Configuring $fstab_path..." || error
|
|
|
|
if grep -q "$fstab_insert_line" "$fstab_path"
|
|
|
|
then
|
|
|
|
warning "$fstab_path contains allready $fstab_insert_line - Skipped."
|
|
|
|
else
|
|
|
|
echo "$fstab_insert_line" >> "$fstab_path" || error
|
|
|
|
fi
|
2020-10-02 14:27:39 +02:00
|
|
|
info "Content of $fstab_path:$(cat "$fstab_path")" &&
|
2020-10-02 13:54:43 +02:00
|
|
|
|
|
|
|
crypttab_path="$root_mount_path""etc/crypttab" &&
|
2020-10-02 15:17:06 +02:00
|
|
|
crypttab_insert_line="$root_mapper_name UUID=$root_partition_uuid none luks" &&
|
|
|
|
info "Configuring $crypttab_path..." || error
|
|
|
|
if grep -q "$crypttab_insert_line" "$crypttab_path"
|
|
|
|
then
|
|
|
|
warning "$crypttab_path contains allready $crypttab_insert_line - Skipped."
|
|
|
|
else
|
|
|
|
echo "$crypttab_insert_line" >> "$crypttab_path" || error
|
|
|
|
fi
|
2020-10-02 14:27:39 +02:00
|
|
|
info "Content of $crypttab_path:$(cat "$crypttab_path")" &&
|
|
|
|
|
|
|
|
boot_txt_path="$boot_mount_path""boot.txt" &&
|
2020-10-02 14:59:50 +02:00
|
|
|
cryptdevice_configuration="cryptdevice=UUID=$root_partition_uuid:$root_mapper_name root=$root_mapper_path" || error
|
2020-10-02 14:27:39 +02:00
|
|
|
if [ -f "$boot_txt_path" ];
|
|
|
|
then
|
|
|
|
info "Configuring $boot_txt_path..." &&
|
|
|
|
boot_txt_delete_line=$(echo "part uuid \${devtype} \${devnum}:2 uuid" | sed -e 's/[]\/$*.^[]/\\&/g') &&
|
|
|
|
boot_txt_setenv_origin=$(echo "setenv bootargs console=ttyS1,115200 console=tty0 root=PARTUUID=\${uuid} rw rootwait smsc95xx.macaddr=\"\${usbethaddr}\"" | sed -e 's/[]\/$*.^[]/\\&/g') &&
|
|
|
|
boot_txt_setenv_replace=$(echo "setenv bootargs console=ttyS1,115200 console=tty0 ip=::::$target_hostname:eth0:dhcp $cryptdevice_configuration rw rootwait smsc95xx.macaddr=\"\${usbethaddr}\""| sed -e 's/[\/&]/\\&/g') &&
|
|
|
|
sed -i "s/$boot_txt_delete_line//g" "$boot_txt_path" &&
|
|
|
|
sed -i "s/$boot_txt_setenv_origin/$boot_txt_setenv_replace/g" "$boot_txt_path" &&
|
2020-10-02 15:17:06 +02:00
|
|
|
info "Content of $boot_txt_path:$(cat "$boot_txt_path")" &&
|
2020-10-02 14:27:39 +02:00
|
|
|
info "Generating..." &&
|
|
|
|
echo "cd /boot/ && ./mkscr || exit 1" | chroot "$root_mount_path" /bin/bash || error
|
|
|
|
else
|
|
|
|
cmdline_txt_path="$boot_mount_path""cmdline.txt" &&
|
|
|
|
info "Configuring $cmdline_txt_path..." &&
|
|
|
|
cmdline_search_string=$(echo "root=/dev/mmcblk0p2" | sed -e 's/[\/&]/\\&/g') &&
|
2020-10-02 14:59:50 +02:00
|
|
|
cmdline_replace_string=$(echo "$cryptdevice_configuration rootfstype=ext4"| sed -e 's/[\/&]/\\&/g') &&
|
|
|
|
sed -i "s/$cmdline_search_string/$cmdline_replace_string/g" "$cmdline_txt_path" &&
|
2020-10-02 16:11:05 +02:00
|
|
|
info "Content of $cmdline_txt_path:$(cat "$cmdline_txt_path")" || error
|
2020-10-02 14:27:39 +02:00
|
|
|
fi
|
2020-05-25 13:40:03 +02:00
|
|
|
fi
|
|
|
|
|
2020-05-26 14:07:29 +02:00
|
|
|
question "Do you want to setup Wifi on the device?(y/N)" && read -r setup_wifi
|
|
|
|
if [ "$setup_wifi" = "y" ]
|
|
|
|
then
|
|
|
|
question "Please type in the ssid:" && read -r ssid
|
|
|
|
question "Please type in the psk:" && read -r psk
|
|
|
|
case "$os" in
|
|
|
|
"retropie")
|
2020-10-02 14:59:50 +02:00
|
|
|
wifi_file="$boot_mount_path""wifikeyfile.txt" &&
|
|
|
|
echo "ssid=\"$ssid\"" > "$wifi_file" &&
|
|
|
|
echo "psk=\"$psk\"" >> "$wifi_file" || error
|
2020-05-26 14:07:29 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
warning "Wifi setting for operation system \"$os\" is not supported yet. Skipped."
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2020-05-02 11:46:39 +02:00
|
|
|
|
2020-05-25 14:18:34 +02:00
|
|
|
info "Running system specific procedures..."
|
|
|
|
if [ "$os" = "retropie" ]
|
|
|
|
then
|
2020-05-25 14:46:52 +02:00
|
|
|
question "Should the roms be copied to the system?(y/N)" && read -r copy_roms
|
2020-05-25 14:18:34 +02:00
|
|
|
if [ "$copy_roms" == "y" ]
|
|
|
|
then
|
|
|
|
target_roms_path="$target_user_home_folder_path""/RetroPie/roms/" &&
|
|
|
|
source_roms_path="$origin_user_home""Games/roms/" &&
|
2020-10-02 14:59:50 +02:00
|
|
|
info "Copy roms from $source_roms_path to $target_roms_path..." &&
|
2020-05-25 14:18:34 +02:00
|
|
|
cp -v "$source_roms_path" "$target_roms_path" &&
|
|
|
|
chown -vR 1000 "$target_roms_path" || error
|
|
|
|
fi
|
2020-05-25 14:46:52 +02:00
|
|
|
question "Should the RetroFlag specific procedures be executed?(y/N)" && read -r setup_retroflag
|
2020-05-25 14:18:34 +02:00
|
|
|
if [ "$setup_retroflag" == "y" ]
|
|
|
|
then
|
|
|
|
info "Executing RetroFlag specific procedures..." &&
|
|
|
|
(
|
|
|
|
echo 'wget -O - "https://raw.githubusercontent.com/RetroFlag/retroflag-picase/master/install_gpi.sh" | bash'
|
|
|
|
) | chroot "$root_mount_path" /bin/bash || error
|
|
|
|
fi
|
|
|
|
fi
|
2020-05-02 11:46:39 +02:00
|
|
|
|
|
|
|
destructor
|
|
|
|
success "Setup successfull :)" && exit 0
|