Merge branch 'master' of github.com:kevinveenbirkenbach/core-system into master

This commit is contained in:
Kevin Veen-Birkenbach 2020-09-24 18:58:49 +02:00
commit f10d637785
12 changed files with 280 additions and 117 deletions

View File

@ -84,20 +84,21 @@ To pase the configuration to the program use this syntax:
```bash ```bash
( (
echo "$USER" # | The username echo "$USER" # | The username
echo "sdX" # | The device echo "mmcblk1" # | The device
echo "64_bit" # | The architecture type; arm or 64_bit echo "arm" # | The architecture type; arm or 64_bit
echo "manjaro" # | The operation system echo "arch" # | The operation system
echo "gnome" # | The version echo "3" # | The version
#echo "n" # ├── If arch: Should a encrypted setup be used? (y/n) #echo "n" # ├── If arch: Should a encrypted setup be used? (y/n)
echo "n" # | Should the image download be forced?(y/n) echo "n" # | Should the image download be forced?(y/n)
echo "y" # | Should the image be transfered to $device_path?(y/n) echo "n" # | Should the image be transfered to $device_path?(y/n)
echo "n" # ├── Overwrite device before copying? (y/n) #echo "n" # ├── Overwrite device before copying? (y/n)
echo "n" # | Should the ssh-key be copied to the image?(y/N) echo "n" # | Should the password be changed?(y/N)
#echo "test12345" # ├── The user password_1 #echo "test12345" # ├── The user password_1
#echo "test12345" # ├── The user password_2 #echo "test12345" # ├── The user password_2
echo "n" # | Should the ssh-key be copied to the image?(y/N) echo "n" # | Should the ssh-key be copied to the image?(y/N)
echo "n" # |Should the hostname be changed?(y/N) echo "n" # |Should the hostname be changed?(y/N)
#echo "example-host" # | The hostname #echo "example-host" # | The hostname
echo "y" # Should the image system be updated?(y/N)
#echo "y" # | Setup Wifi on target system - Not implemented yet #echo "y" # | Setup Wifi on target system - Not implemented yet
)| sudo bash ./scripts/image/setup.sh | tee log.txt )| sudo bash ./scripts/image/setup.sh | tee log.txt
``` ```

View File

@ -85,3 +85,6 @@ ansible
# entertainment software # entertainment software
rhythmbox rhythmbox
# cloud
nextcloud-client

View File

@ -8,5 +8,5 @@ libpurple-carbons
eclipse-java eclipse-java
# language server # language server
ccls ccls
# guest user support # office
systemd-guest-user ttf-ms-fonts

View File

@ -3,3 +3,4 @@ nano
tree tree
htop htop
git git
sudo

View File

@ -0,0 +1,8 @@
# Packages to install LUKS on servers
rsync
base-devel
uboot-tools
dropbear
mkinitcpio-utils
mkinitcpio-netconf
mkinitcpio-dropbear

View File

@ -3,8 +3,11 @@
# This script contains the global program variables and functions # This script contains the global program variables and functions
# #
# shellcheck disable=SC2034 #Deactivate checking of unused variables # shellcheck disable=SC2034 #Deactivate checking of unused variables
# shellcheck disable=SC2003 #Deactivate "expr is antiquated"
REPOSITORY_PATH=$(readlink -f "$(dirname "$(readlink -f "${0}")")/../../") # Propably this can be optimized # shellcheck disable=SC2015 #Deactivate bool hint
# shellcheck disable=SC2005 #Remove useless echo hint
# shellcheck disable=SC2010 #Deactivate ls | grep hint
REPOSITORY_PATH="$(readlink -f "${0}" | sed -e 's/\/scripts\/.*//g')"
CONFIGURATION_PATH="$REPOSITORY_PATH""/configuration/" CONFIGURATION_PATH="$REPOSITORY_PATH""/configuration/"
PACKAGE_PATH="$CONFIGURATION_PATH""packages/" PACKAGE_PATH="$CONFIGURATION_PATH""packages/"
TEMPLATE_PATH="$CONFIGURATION_PATH""templates/"; TEMPLATE_PATH="$CONFIGURATION_PATH""templates/";
@ -76,7 +79,7 @@ set_device_path(){
error "$device_path is not valid device." error "$device_path is not valid device."
fi fi
# @see https://www.heise.de/ct/hotline/Optimale-Blockgroesse-fuer-dd-2056768.html # @see https://www.heise.de/ct/hotline/Optimale-Blockgroesse-fuer-dd-2056768.html
OPTIMAL_BLOCKSIZE=$(expr 64 \* "$(sudo cat /sys/block/$device/queue/physical_block_size)") && OPTIMAL_BLOCKSIZE=$(expr 64 \* "$(sudo cat /sys/block/"$device"/queue/physical_block_size)") &&
info "Device path set to: $device_path" && info "Device path set to: $device_path" &&
info "Optimal blocksize set to: $OPTIMAL_BLOCKSIZE" || info "Optimal blocksize set to: $OPTIMAL_BLOCKSIZE" ||
error error
@ -93,6 +96,15 @@ overwritte_device_with_zeros(){
fi fi
} }
get_packages(){
for package_collection in "$@"
do
package_collection_path="$PACKAGE_PATH""$package_collection.txt" &&
echo "$(sed -e "/^#/d" -e "s/#.*//" "$package_collection_path" | tr '\n' ' ')" ||
error
done
}
HEADER(){ HEADER(){
echo echo
echo "${COLOR_YELLOW}The" echo "${COLOR_YELLOW}The"

View File

@ -6,13 +6,6 @@
# shellcheck disable=SC2086 # Deactivating escaping warning, because it's wrong concerning pacman_packages # shellcheck disable=SC2086 # Deactivating escaping warning, because it's wrong concerning pacman_packages
source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh failed." && exit 1) source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh failed." && exit 1)
get_packages(){
for package_collection in "$@"
do
echo "$(sed -e "/^#/d" -e "s/#.*//" "$PACKAGE_PATH""$package_collection.txt" | tr '\n' ' ')" || error "Loading package wasn't possible."
done
}
install_yay_packages_if_needed(){ install_yay_packages_if_needed(){
info "Checking yay packages [ $1 ]..." info "Checking yay packages [ $1 ]..."
for package in $1; do for package in $1; do
@ -159,7 +152,7 @@ install_gnome_extension(){
if [ "$DESKTOP_SESSION" == "gnome" ]; then if [ "$DESKTOP_SESSION" == "gnome" ]; then
info "Synchronizing gnome tools..." && info "Synchronizing gnome tools..." &&
sudo pacman -S $(get_packages "client/pacman/gnome") || error "Syncronisation failed." sudo pacman -S "$(get_packages 'client/pacman/gnome')" || error "Syncronisation failed."
info "Setting up gnome dash favourites..." && info "Setting up gnome dash favourites..." &&
gsettings set org.gnome.shell favorite-apps "['org.gnome.Nautilus.desktop', gsettings set org.gnome.shell favorite-apps "['org.gnome.Nautilus.desktop',
'org.gnome.Terminal.desktop', 'org.gnome.Terminal.desktop',
@ -178,6 +171,7 @@ if [ "$DESKTOP_SESSION" == "gnome" ]; then
info "Install GNOME extensions..." && info "Install GNOME extensions..." &&
install_gnome_extension "nasa_apod@elinvention.ovh" "https://github.com/Elinvention/gnome-shell-extension-nasa-apod.git" install_gnome_extension "nasa_apod@elinvention.ovh" "https://github.com/Elinvention/gnome-shell-extension-nasa-apod.git"
install_gnome_extension "dash-to-panel@jderose9.github.com" "https://github.com/home-sweet-gnome/dash-to-panel" install_gnome_extension "dash-to-panel@jderose9.github.com" "https://github.com/home-sweet-gnome/dash-to-panel"
install_gnome_extension "caffeine@patapon.info" "https://github.com/eonpatapon/gnome-shell-extension-caffeine.git"
info "Deactivating \"Dash to Dock\"..." && info "Deactivating \"Dash to Dock\"..." &&
gnome-extensions disable dash-to-dock@micxgx.gmail.com || error gnome-extensions disable dash-to-dock@micxgx.gmail.com || error

View File

@ -2,10 +2,11 @@
# Executes the import script in reverse mode # Executes the import script in reverse mode
# @author Kevin Veen-Birkenbach [aka. Frantz] # @author Kevin Veen-Birkenbach [aka. Frantz]
# shellcheck source=/dev/null # Deactivate SC1090 # shellcheck source=/dev/null # Deactivate SC1090
# shellcheck disable=SC2015 # Deactivating bool hint
source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh failed." && exit 1) source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh failed." && exit 1)
bash "$SCRIPT_PATH""data/import-from-system.sh" reverse bash "$SCRIPT_PATH""data/import-from-system.sh" reverse
info "Setting right permissions for importet files..." info "Setting right permissions for importet files..." &&
chown -R $USER:$USER ~ chmod -R 700 ~/.ssh &&
chmod -R 700 ~/.ssh chmod 600 ~/.ssh/id_rsa &&
chmod 600 ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa.pub || error "Failed to set correct ssh permissions"
chmod 600 ~/.ssh/id_rsa.pub chown -R "$USER":"$USER" ~ || warning "Not all files could be owned by user \"$USER\"..."

View File

@ -11,12 +11,14 @@ source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh
declare -a BACKUP_LIST=("$HOME/.ssh/" \ declare -a BACKUP_LIST=("$HOME/.ssh/" \
"$HOME/.gitconfig" \ "$HOME/.gitconfig" \
"$HOME/.atom/config.cson" \ "$HOME/.atom/config.cson" \
"$HOME/.projectlibre/projectlibre.conf" \
"$HOME/.local/share/rhythmbox/rhythmdb.xml" \ "$HOME/.local/share/rhythmbox/rhythmdb.xml" \
"$HOME/.config/keepassxc/keepassxc.ini" \ "$HOME/.config/keepassxc/keepassxc.ini" \
"$HOME/Documents/certificates/" \ "$HOME/Documents/certificates/" \
"$HOME/Documents/recovery_codes/" \ "$HOME/Documents/recovery_codes/" \
"$HOME/Documents/identity/" \ "$HOME/Documents/identity/" \
"$HOME/Documents/passwords/" \ "$HOME/Documents/passwords/" \
"$HOME/Documents/health/" \
"$HOME/Documents/licenses/"); "$HOME/Documents/licenses/");
if [ -z "$(mount | grep "$DECRYPTED_PATH")" ] if [ -z "$(mount | grep "$DECRYPTED_PATH")" ]

View File

@ -6,6 +6,7 @@
# shellcheck disable=SC2010 # ls | grep allowed # shellcheck disable=SC2010 # ls | grep allowed
# shellcheck source=/dev/null # Deactivate SC1090 # shellcheck source=/dev/null # Deactivate SC1090
# shellcheck disable=SC2015 # Deactivate bools hints # shellcheck disable=SC2015 # Deactivate bools hints
# shellcheck disable=SC2154 # Deactivate referenced but not assigned hints
source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh failed." && exit 1) source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh failed." && exit 1)
# Writes the full partition name # Writes the full partition name
@ -22,8 +23,9 @@ echo_partition_name(){
set_partition_paths(){ set_partition_paths(){
info "Setting partition paths..." info "Setting partition paths..."
root_partition_path=$(echo_partition_name "2")
boot_partition_path=$(echo_partition_name "1") boot_partition_path=$(echo_partition_name "1")
root_partition_path=$(echo_partition_name "2")
encrypted_partition_path=$(echo_partition_name "3")
} }
make_mount_folders(){ make_mount_folders(){
@ -44,22 +46,50 @@ make_working_folder(){
mount_partitions(){ mount_partitions(){
info "Mount boot and root partition..." && info "Mount boot and root partition..." &&
mount "$boot_partition_path" "$boot_mount_path" && mount -v "$boot_partition_path" "$boot_mount_path" &&
mount "$root_partition_path" "$root_mount_path" && mount -v "$root_partition_path" "$root_mount_path" &&
info "The following mounts refering this setup exist:" && mount | grep "$working_folder_path" || info "The following mounts refering this setup exist:" && mount | grep "$working_folder_path" ||
error error
} }
mount_binds(){ destructor(){
info "Cleaning up..."
info "Unmounting everything..."
umount -lv "$chroot_dev_pts_mount_path" || warning "Umounting $chroot_dev_pts_mount_path failed!"
umount -lv "$chroot_dev_mount_path" || warning "Umounting $chroot_dev_mount_path failed!"
umount -v "$chroot_proc_mount_path" || warning "Umounting $chroot_proc_mount_path failed!"
umount -v "$chroot_sys_mount_path" || warning "Umounting $chroot_sys_mount_path failed!"
umount -v "$root_mount_path""boot/" || warning "Umounting $root_mount_path""boot/ failed!"
umount -v "$root_mount_path" || warning "Umounting $root_mount_path failed!"
umount -v "$boot_mount_path" || warning "Umounting $boot_mount_path failed!"
info "Deleting mount folders..."
rmdir -v "$root_mount_path" || warning "Removing $root_mount_path failed!"
rmdir -v "$boot_mount_path" || warning "Removing $boot_mount_path failed!"
rmdir -v "$working_folder_path" || warning "Removing $working_folder_path failed!"
}
mount_chroot_binds(){
info "Mount chroot environments..." && info "Mount chroot environments..." &&
chroot_sys_mount_path="$root_mount_path""sys/" && chroot_sys_mount_path="$root_mount_path""sys/" &&
chroot_proc_mount_path="$root_mount_path""proc/" && chroot_proc_mount_path="$root_mount_path""proc/" &&
chroot_dev_mount_path="$root_mount_path""dev/" && chroot_dev_mount_path="$root_mount_path""dev/" &&
chroot_dev_pts_mount_path="$root_mount_path""dev/pts" && chroot_dev_pts_mount_path="$root_mount_path""dev/pts" &&
mount --bind "$boot_mount_path" "$root_mount_path""/boot" && mount --bind "$boot_mount_path" "$root_mount_path""boot" &&
mount --bind /dev "$chroot_dev_mount_path" && mount --bind /dev "$chroot_dev_mount_path" &&
mount --bind /sys "$chroot_sys_mount_path" && mount --bind /sys "$chroot_sys_mount_path" &&
mount --bind /proc "$chroot_proc_mount_path" && mount --bind /proc "$chroot_proc_mount_path" &&
mount --bind /dev/pts "$chroot_dev_pts_mount_path" || mount --bind /dev/pts "$chroot_dev_pts_mount_path" ||
error error
} }
copy_qemu(){
info "Copy qemu binary..." &&
cp -v /usr/bin/qemu-arm-static "$root_mount_path""usr/bin/" ||
error
}
copy_resolve_conf(){
info "Copy resolve.conf..." &&
cp --remove-destination -v /etc/resolv.conf "$root_mount_path""etc/" ||
warning "Failed. Propably there is no internet connection available."
}

View File

@ -16,32 +16,14 @@ set_partition_paths
mount_partitions mount_partitions
mount_binds mount_chroot_binds
info "ld.so.preload fix" && copy_qemu
sed -i 's/^/#CHROOT /g' "$root_mount_path""etc/ld.so.preload" ||
warning "Failed."
info "Copy qemu binary..." && copy_resolve_conf
cp -v /usr/bin/qemu-arm-static "$root_mount_path""usr/bin/" ||
error
info "Copy resolve.conf..." info "Bash shell starts..." &&
cp -v /etc/resolv.conf "$root_mount_path""etc/" &&
warning "Failed. Propably there is no internet connection available."
info "You will be transferred to the bash shell now." &&
info "Issue 'exit' when you are done." &&
info "Issue 'su pi' if you need to work as the user pi." &&
info "chroot to raspbian" &&
chroot "$root_mount_path" /bin/bash || chroot "$root_mount_path" /bin/bash ||
error error
info "Clean up" && destructor
info "revert ld.so.preload fix" &&
sed -i 's/^#CHROOT //g' "$root_mount_path""etc/ld.so.preload" ||
warning "Failed."
info "unmount everything" &&
umount "$root_mount_path"/{dev/pts,dev,sys,proc,boot,} ||
error

View File

@ -8,22 +8,6 @@ source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh fa
info "Setupscript for images started..." info "Setupscript for images started..."
info "Define functions..."
destructor(){
info "Cleaning up..."
sed -i 's/^#CHROOT //g' "$root_mount_path""etc/ld.so.preload" || warning "sed failed."
umount -v "$chroot_dev_pts_mount_path" || warning "Umounting $chroot_dev_pts_mount_path failed!"
umount -v "$chroot_dev_mount_path" || warning "Umounting $chroot_dev_mount_path failed!"
umount -v "$chroot_proc_mount_path" || warning "Umounting $chroot_proc_mount_path failed!"
umount -v "$chroot_sys_mount_path" || warning "Umounting $chroot_sys_mount_path failed!"
umount -v "$root_mount_path""boot/" || warning "Umounting $root_mount_path""boot/ failed!"
umount -v "$root_mount_path" || warning "Umounting $root_mount_path failed!"
umount -v "$boot_mount_path" || warning "Umounting $boot_mount_path failed!"
rmdir -v "$root_mount_path" || warning "Removing $root_mount_path failed!"
rmdir -v "$boot_mount_path" || warning "Removing $boot_mount_path failed!"
rmdir -v "$working_folder_path" || warning "Removing $working_folder_path failed!"
}
info "Checking if root..." info "Checking if root..."
if [ "$(id -u)" != "0" ];then if [ "$(id -u)" != "0" ];then
error "This script must be executed as root!" error "This script must be executed as root!"
@ -106,14 +90,18 @@ os_does_not_support_raspberry_version_error () {
case "$os" in case "$os" in
"arch") "arch")
question "Should the system be encrypted?(y/N)" && read -r encrypt_system
base_download_url="http://os.archlinuxarm.org/os/"; base_download_url="http://os.archlinuxarm.org/os/";
case "$version" in case "$version" in
"1") "1")
imagename="ArchLinuxARM-rpi-latest.tar.gz" imagename="ArchLinuxARM-rpi-latest.tar.gz"
;; ;;
"2" | "3") "2")
imagename="ArchLinuxARM-rpi-2-latest.tar.gz" imagename="ArchLinuxARM-rpi-2-latest.tar.gz"
;; ;;
"3")
imagename="ArchLinuxARM-rpi-3-latest.tar.gz"
;;
"4") "4")
imagename="ArchLinuxARM-rpi-4-latest.tar.gz" imagename="ArchLinuxARM-rpi-4-latest.tar.gz"
;; ;;
@ -200,8 +188,8 @@ fi
info "Verifying image..." info "Verifying image..."
if [[ -v image_checksum ]] if [[ -v image_checksum ]]
then then
info "Checking md5 checksum..." && echo "$image_checksum $image_path"| md5sum -c -|| (info "Checking md5 checksum..." && echo "$image_checksum $image_path"| md5sum -c -) ||
info "Checking sha1 checksum..." && echo "$image_checksum $image_path"| sha1sum -c -|| (info "Checking sha1 checksum..." && echo "$image_checksum $image_path"| sha1sum -c -) ||
error "Verification failed. HINT: Force the download of the image." error "Verification failed. HINT: Force the download of the image."
else else
warning "Verification is not possible. No checksum is defined." warning "Verification is not possible. No checksum is defined."
@ -211,7 +199,7 @@ make_mount_folders
set_partition_paths set_partition_paths
question "Should the image be transfered to $device_path?(y/n)" && read -r transfer_image question "Should the image be transfered to $device_path?(y/N)" && read -r transfer_image
if [ "$transfer_image" = "y" ] if [ "$transfer_image" = "y" ]
then then
@ -220,29 +208,57 @@ if [ "$transfer_image" = "y" ]
info "Starting image transfer..." info "Starting image transfer..."
if [ "$os" = "arch" ] if [ "$os" = "arch" ]
then then
info "Execute fdisk..." info "Deleting partition tables..." &&
wipefs -a "$device_path" || error
if [ "$encrypt_system" == "y" ]
then
info "Creating partitions for encrypted system..." &&
( echo "o" #Type o. This will clear out any partitions on the drive. ( 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 "p" #Type p to list partitions. There should be no partitions left
echo "n" #Type n, echo "n" #Type n,
echo "p" #then p for primary, echo "p" #then p for primary,
echo "1" #1 for the first partition on the drive, echo "1" #1 for the first partition on the drive,
echo "" #press ENTER to accept the default first sector, echo "" #press ENTER to accept the default first sector,
echo "+300M" #then type +100M 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 "+3G" #Endsector
echo "n" #Type n,
echo "p" #then p for primary,
echo "3" #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
else
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 "+100M" #then type +100M for the last sector. echo "+100M" #then type +100M for the last sector.
echo "t" #Type t, echo "t" #Type t,
echo "c" #then c to set the first partition to type W95 FAT32 (LBA). echo "c" #then c to set the first partition to type W95 FAT32 (LBA).
echo "n" #Type n, echo "n" #Type n,
echo "p" #then p for primary, echo "p" #then p for primary,
echo "2" #2 for the second partition on the drive, echo "2" #2 for the second partition on the drive,
echo "" #and then press ENTER twice to accept the default first and last sector. echo "" #Default start sector
echo "" echo "" #Default end sector
echo "w" #Write the partition table and exit by typing w. echo "w" #Write the partition table and exit by typing w.
)| fdisk "$device_path" || error "Creating partitions failed. Try to execute this script with the overwritting parameter." )| fdisk "$device_path" || error
fi
info "Format boot partition..." && info "Format boot partition..." &&
mkfs.vfat "$boot_partition_path" || error "Format boot is not possible." mkfs.vfat "$boot_partition_path" || error
info "Format root partition..." && info "Format root partition..." &&
mkfs.ext4 "$root_partition_path" || error "Format root is not possible." mkfs.ext4 "$root_partition_path" || error
mount_partitions; mount_partitions;
@ -252,7 +268,7 @@ if [ "$transfer_image" = "y" ]
error error
info "Boot files will be transfered to device..." && info "Boot files will be transfered to device..." &&
mv -v "$root_mount_path/boot/"* "$boot_mount_path" || mv -v "$root_mount_path""boot/"* "$boot_mount_path" ||
error error
elif [ "${image_path: -4}" = ".zip" ] elif [ "${image_path: -4}" = ".zip" ]
then then
@ -280,11 +296,16 @@ if [ "$transfer_image" = "y" ]
fi fi
info "Start regular mounting procedure..." info "Start regular mounting procedure..."
if mount | grep -q "$boot_mount_path" && mount | grep -q "$root_mount_path" if mount | grep -q "$boot_partition_path"
then then
info "Everything allready mounted. Skipping..." info "$boot_partition_path is allready mounted..."
else
if mount | grep -q "$root_partition_path"
then
info "$root_partition_path is allready mounted..."
else else
mount_partitions mount_partitions
fi
fi fi
info "Define target paths..." info "Define target paths..."
@ -301,7 +322,7 @@ if [ "$copy_ssh_key" == "y" ]
origin_user_rsa_pub="$origin_user_home"".ssh/id_rsa.pub"; origin_user_rsa_pub="$origin_user_home"".ssh/id_rsa.pub";
if [ -f "$origin_user_rsa_pub" ] if [ -f "$origin_user_rsa_pub" ]
then then
mkdir -v "$target_user_ssh_folder_path" && mkdir -v "$target_user_ssh_folder_path" || warning "Folder \"$target_user_ssh_folder_path\" exists. Can't be created."
cat "$origin_user_rsa_pub" > "$target_authorized_keys" && cat "$origin_user_rsa_pub" > "$target_authorized_keys" &&
target_authorized_keys_content=$(cat "$target_authorized_keys") && target_authorized_keys_content=$(cat "$target_authorized_keys") &&
info "$target_authorized_keys contains the following: $target_authorized_keys_content" && info "$target_authorized_keys contains the following: $target_authorized_keys_content" &&
@ -315,14 +336,16 @@ if [ "$copy_ssh_key" == "y" ]
else else
info "Skipped SSH-key copying.." info "Skipped SSH-key copying.."
fi fi
info "Start chroot procedures..." info "Start chroot procedures..."
mount_binds mount_chroot_binds
sed -i 's/^/#CHROOT /g' "$root_mount_path""etc/ld.so.preload" || warning "sed failed." copy_qemu
cp -v /usr/bin/qemu-arm-static "$root_mount_path""/usr/bin/" || error "Copy qemu-arm-static failed. The following packages are neccessary: qemu qemu-user-static binfmt-support."
question "Should the image password of the standart user \"$target_username\" be changed?(y/N)" && read -r change_password copy_resolve_conf
question "Should the password of the standart user \"$target_username\" be changed?(y/N)" && read -r change_password
if [ "$change_password" == "y" ] if [ "$change_password" == "y" ]
then then
info "Changing passwords on target system..." info "Changing passwords on target system..."
@ -339,35 +362,141 @@ if [ "$change_password" == "y" ]
echo '$password_1' echo '$password_1'
echo '$password_1' echo '$password_1'
) | passwd" ) | passwd"
) | chroot "$root_mount_path" /bin/bash || error "Password change failed." ) | chroot "$root_mount_path" /bin/bash || error
else else
error "Passwords didn't match." error "Passwords didn't match."
fi fi
else else
info "Skipped password change..." info "Skipped password change..."
fi fi
# @todo add to chroot
#pacman-key --init hostname_path="$root_mount_path""etc/hostname"
#pacman-key --populate archlinuxarm
#pacman -Syyu
question "Should the hostname be changed?(y/N)" && read -r change_hostname question "Should the hostname be changed?(y/N)" && read -r change_hostname
if [ "$change_hostname" == "y" ] if [ "$change_hostname" == "y" ]
then then
question "Type in the hostname:" && read -r hostname; question "Type in the hostname:" && read -r target_hostname;
echo "$hostname" > "$root_mount_path""etc/hostname" || error "Changing hostname failed." echo "$target_hostname" > "$hostname_path" || error
else else
target_hostname=$(cat "$hostname_path")
info "Skipped hostname change..." info "Skipped hostname change..."
fi fi
# question "Do you want to copy all Wifi passwords to the device?(y/n)" && read -r copy_wifi info "Used hostname is: $target_hostname"
# if [ "$copy_wifi" = "y" ]
# then
# origin_wifi_config_path="/etc/NetworkManager/system-connections/"
# target_wifi_config_path="$root_mount_path$origin_wifi_config_path"
# rsync -av "$origin_wifi_config_path" "$target_wifi_config_path"
# fi
info "The first level folder structure on $root_mount_path is:" && tree -laL 1 "$root_mount_path" question "Should the system be updated?(y/N)" && read -r update_system
info "The first level folder structure on $boot_mount_path is:" && tree -laL 1 "$boot_mount_path" if [ "$update_system" == "y" ]
then
info "Updating system..."
case "$os" in
"arch"|"manjaro")
(
echo "yes | pacman-key --init"
echo "yes | pacman-key --populate archlinuxarm"
echo "pacman --noconfirm -Syyu"
) | 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
fi
if [ "$encrypt_system" == "y" ]
then
# @see https://gist.github.com/gea0/4fc2be0cb7a74d0e7cc4322aed710d38
rescue_suffix=".$(date +%s).rescue"
search_hooks="HOOKS=(base udev autodetect modconf block filesystems keyboard fsck)"
replace_hooks="HOOKS=(base udev autodetect modconf block sleep netconf dropbear encryptssh filesystems keyboard fsck)"
mkinitcpio_path="/etc/mkinitcpio.conf"
mkinitcpio_rescue_path="$mkinitcpio_path$rescue_suffix"
search_modules="MODULES=()"
replace_modules="MODULES=(g_cdc usb_f_acm usb_f_ecm smsc95xx g_ether)"
standart_luks_password="luks_password"
root_mapper_path="/dev/mapper/root"
fstab_path="/mnt/etc/fstab"
fstab_rescue_path="$fstab_path$rescue_suffix"
crypttab_path="/mnt/etc/crypttab"
crypttab_rescue_path="$crypttab_path$rescue_suffix"
boot_txt_path="/boot/boot.txt"
boot_txt_rescue_path="/boot/boot.txt$rescue_suffix"
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=$encrypted_partition_path:root root=$root_mapper_path rw rootwait smsc95xx.macaddr=\"\${usbethaddr}\""| sed -e 's/[\/&]/\\&/g')
info "Setup encryption..." &&
(
echo "pacman --noconfirm -S --needed $(get_packages "server/luks")"
echo "cp -v /home/$target_username/.ssh/authorized_keys /etc/dropbear/root_key"
echo "cp -v $mkinitcpio_path $mkinitcpio_rescue_path"
echo "sed -i 's/$search_modules/$replace_modules/g' $mkinitcpio_path"
echo "sed -i 's/$search_hooks/$replace_hooks/g' $mkinitcpio_path"
echo "mkinitcpio -P"
echo "( echo 'YES'
echo '$standart_luks_password'
echo '$standart_luks_password'
)|sudo cryptsetup luksFormat -c aes-xts-plain64 -s 512 -h sha512 --use-random -i 1000 $encrypted_partition_path"
echo "echo $standart_luks_password | sudo cryptsetup luksOpen $encrypted_partition_path root"
echo "mkfs.ext4 $root_mapper_path"
echo "mount $root_mapper_path /mnt"
echo "rsync --info=progress2 -axHAX / /mnt/"
echo "cp -v $fstab_path $fstab_rescue_path"
echo "echo '$root_mapper_path / ext4 defaults,noatime 0 1' >> $fstab_path"
echo "echo \"$fstab_path:\" && cat \"$fstab_path\""
echo "cp -v $crypttab_path $crypttab_rescue_path"
echo "echo 'root $encrypted_partition_path none luks' >> $crypttab_path"
echo "echo \"$crypttab_path:\" && cat \"$crypttab_path\""
echo "cp -v $boot_txt_path $boot_txt_rescue_path"
echo "sed -i 's/$boot_txt_delete_line//g' $boot_txt_path" #@todo doesn't work yet
echo "sed -i 's/$boot_txt_setenv_origin/$boot_txt_setenv_replace/g' $boot_txt_path" #@todo doesn't work yet
echo "echo \"$boot_txt_path:\" && cat \"$boot_txt_path\""
echo "cd /boot/ && ./mkscr"
echo "umount $root_mapper_path"
echo "exit"
) | chroot "$root_mount_path" /bin/bash || error
fi
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")
wifi_file="$boot_mount_path""wifikeyfile.txt"
echo "ssid=\"$ssid\"" > "$wifi_file"
echo "psk=\"$psk\"" >> "$wifi_file"
;;
*)
warning "Wifi setting for operation system \"$os\" is not supported yet. Skipped."
;;
esac
fi
info "Running system specific procedures..."
if [ "$os" = "retropie" ]
then
question "Should the roms be copied to the system?(y/N)" && read -r copy_roms
if [ "$copy_roms" == "y" ]
then
target_roms_path="$target_user_home_folder_path""/RetroPie/roms/" &&
source_roms_path="$origin_user_home""Games/roms/" &&
info "Copy roms from $source_roms_path to $target_roms_path..."
cp -v "$source_roms_path" "$target_roms_path" &&
chown -vR 1000 "$target_roms_path" || error
fi
question "Should the RetroFlag specific procedures be executed?(y/N)" && read -r setup_retroflag
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
destructor destructor
success "Setup successfull :)" && exit 0 success "Setup successfull :)" && exit 0