mirror of
https://github.com/kevinveenbirkenbach/raspberry-pi-tools.git
synced 2024-11-22 18:11:03 +01:00
Optimized code structure
This commit is contained in:
parent
555d9ecfe5
commit
ae60d9ae75
11
README.md
11
README.md
@ -12,10 +12,13 @@ To install a Linux distribution manually on a SD card type in:
|
|||||||
To pase the configuration to the program use this syntax:
|
To pase the configuration to the program use this syntax:
|
||||||
```bash
|
```bash
|
||||||
(
|
(
|
||||||
echo "$USER" #The username
|
echo "$USER" #The username
|
||||||
echo "mmcblk1" #The device
|
echo "mmcblk1" #The device
|
||||||
echo "3" #The raspberry pi number
|
echo "3" #The raspberry pi number
|
||||||
echo "arch" #The operation system
|
echo "arch" #The operation system
|
||||||
|
echo "user_password" #The user password
|
||||||
|
echo "root_password" #The root password
|
||||||
|
echo "y" #Copy wifi configurations to target system
|
||||||
)| sudo bash ./sd_setup.sh
|
)| sudo bash ./sd_setup.sh
|
||||||
```
|
```
|
||||||
## Backup
|
## Backup
|
||||||
|
27
sd_setup.sh
27
sd_setup.sh
@ -13,8 +13,21 @@ echo "Define variables..."
|
|||||||
working_folder="/tmp/raspberry-pi-tools-$(date +%s)/";
|
working_folder="/tmp/raspberry-pi-tools-$(date +%s)/";
|
||||||
|
|
||||||
echo "Define functions..."
|
echo "Define functions..."
|
||||||
|
|
||||||
|
warning(){
|
||||||
|
echo "WARNING: $1";
|
||||||
|
}
|
||||||
|
|
||||||
|
destructor(){
|
||||||
|
echo "Cleaning up..."
|
||||||
|
umount -v "$root_mount_path" "$boot_mount_path" || warning "Umounting $root_mount_path and/or $boot_mount_path failed!"
|
||||||
|
rm -vr "$working_folder" || warning "Removing $working_folder failed!"
|
||||||
|
}
|
||||||
|
|
||||||
error(){
|
error(){
|
||||||
echo "ERROR: $1. Leaving program." && exit 1;
|
echo "ERROR: $1 Leaving program."
|
||||||
|
destructor
|
||||||
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Create temporary working folder in $working_folder";
|
echo "Create temporary working folder in $working_folder";
|
||||||
@ -137,7 +150,7 @@ if [[ -v image_checksum ]]
|
|||||||
then
|
then
|
||||||
echo "$image_checksum $image_path"| md5sum -c -|| error "Verification failed."
|
echo "$image_checksum $image_path"| md5sum -c -|| error "Verification failed."
|
||||||
else
|
else
|
||||||
echo "WARNING: Verification is not possible. No checksum is define."
|
warning "Verification is not possible. No checksum is define."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Preparing mount paths..."
|
echo "Preparing mount paths..."
|
||||||
@ -225,7 +238,7 @@ target_user_home_folder_path="$target_home_path$target_username/";
|
|||||||
|
|
||||||
echo "Copy ssh key to target..."
|
echo "Copy ssh key to target..."
|
||||||
target_user_ssh_folder_path="$target_user_home_folder_path"".ssh/"
|
target_user_ssh_folder_path="$target_user_home_folder_path"".ssh/"
|
||||||
target_authorized_keys="$target_user_ssh_folder_path/authorized_keys"
|
target_authorized_keys="$target_user_ssh_folder_path""authorized_keys"
|
||||||
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
|
||||||
@ -240,10 +253,10 @@ if [ -f "$origin_user_rsa_pub" ]
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Change password of user \"$target_username\"..."
|
echo "Change password of user \"$target_username\"..."
|
||||||
chroot "$root_mount_path" /bin/passwd "$target_username"
|
(chroot "$root_mount_path" /bin/passwd "$target_username") || error "Password change for \"$target_username\" wasn't possible."
|
||||||
|
|
||||||
echo "Change password of root user..."
|
echo "Change password of root user..."
|
||||||
chroot "$root_mount_path" /bin/passwd root
|
(chroot "$root_mount_path" /bin/passwd root) || error "Password change for \"root\" wasn't possible."
|
||||||
|
|
||||||
echo "Do you want to copy all Wifi passwords to the sd-card?(y/n)"
|
echo "Do you want to copy all Wifi passwords to the sd-card?(y/n)"
|
||||||
read -r copy_wifi
|
read -r copy_wifi
|
||||||
@ -256,7 +269,5 @@ fi
|
|||||||
echo "The first level folder structure on $root_mount_path is now:" && tree -laL 1 "$root_mount_path"
|
echo "The first level folder structure on $root_mount_path is now:" && tree -laL 1 "$root_mount_path"
|
||||||
echo "The first level folder structure on $boot_mount_path is now:" && tree -laL 1 "$boot_mount_path"
|
echo "The first level folder structure on $boot_mount_path is now:" && tree -laL 1 "$boot_mount_path"
|
||||||
|
|
||||||
echo "Cleaning up..."
|
destructor
|
||||||
umount -v "$root_mount_path" "$boot_mount_path" || error "Umounting $root_mount_path and/or $boot_mount_path failed!."
|
|
||||||
rm -vr "$working_folder"
|
|
||||||
echo "Setup successfull :)" && exit 0
|
echo "Setup successfull :)" && exit 0
|
||||||
|
Loading…
Reference in New Issue
Block a user