mirror of
				https://github.com/kevinveenbirkenbach/linux-image-manager.git
				synced 2025-11-04 01:18:10 +00:00 
			
		
		
		
	Optimized chroot procedures
This commit is contained in:
		
							
								
								
									
										12
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								README.md
									
									
									
									
									
								
							@@ -84,15 +84,15 @@ To pase the configuration to the program use this syntax:
 | 
			
		||||
```bash
 | 
			
		||||
(
 | 
			
		||||
  echo "$USER"              # | The username
 | 
			
		||||
  echo "sdX"                # | The device
 | 
			
		||||
  echo "64_bit"             # | The architecture type; arm or 64_bit
 | 
			
		||||
  echo "manjaro"            # | The operation system
 | 
			
		||||
  echo "gnome"          # | The version
 | 
			
		||||
  echo "mmcblk1"                # | The device
 | 
			
		||||
  echo "arm"             # | The architecture type; arm or 64_bit
 | 
			
		||||
  echo "arch"            # | The operation system
 | 
			
		||||
  echo "3"          # | The version
 | 
			
		||||
  #echo "n"                 # ├── If arch: Should a encrypted setup be used? (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"                  # | 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_2
 | 
			
		||||
  echo "n"                 # | Should the ssh-key be copied to the image?(y/N)
 | 
			
		||||
 
 | 
			
		||||
@@ -50,7 +50,7 @@ mount_partitions(){
 | 
			
		||||
  error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
mount_binds(){
 | 
			
		||||
mount_chroot_binds(){
 | 
			
		||||
  info "Mount chroot environments..." &&
 | 
			
		||||
  chroot_sys_mount_path="$root_mount_path""sys/" &&
 | 
			
		||||
  chroot_proc_mount_path="$root_mount_path""proc/" &&
 | 
			
		||||
@@ -63,3 +63,15 @@ mount_binds(){
 | 
			
		||||
  mount --bind /dev/pts "$chroot_dev_pts_mount_path" ||
 | 
			
		||||
  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 -v /etc/resolv.conf "$root_mount_path""etc/" ||
 | 
			
		||||
  warning "Failed. Propably there is no internet connection available."
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -16,32 +16,16 @@ set_partition_paths
 | 
			
		||||
 | 
			
		||||
mount_partitions
 | 
			
		||||
 | 
			
		||||
mount_binds
 | 
			
		||||
mount_chroot_binds
 | 
			
		||||
 | 
			
		||||
info "ld.so.preload fix" &&
 | 
			
		||||
sed -i 's/^/#CHROOT /g' "$root_mount_path""etc/ld.so.preload" ||
 | 
			
		||||
warning "Failed."
 | 
			
		||||
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 -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" &&
 | 
			
		||||
info "Bash shell starts..." &&
 | 
			
		||||
chroot "$root_mount_path" /bin/bash ||
 | 
			
		||||
error
 | 
			
		||||
 | 
			
		||||
info "Clean up" &&
 | 
			
		||||
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
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,6 @@ 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!"
 | 
			
		||||
@@ -110,9 +109,12 @@ case "$os" in
 | 
			
		||||
      "1")
 | 
			
		||||
        imagename="ArchLinuxARM-rpi-latest.tar.gz"
 | 
			
		||||
        ;;
 | 
			
		||||
      "2" | "3")
 | 
			
		||||
      "2")
 | 
			
		||||
        imagename="ArchLinuxARM-rpi-2-latest.tar.gz"
 | 
			
		||||
        ;;
 | 
			
		||||
      "3")
 | 
			
		||||
        imagename="ArchLinuxARM-rpi-3-latest.tar.gz"
 | 
			
		||||
        ;;
 | 
			
		||||
      "4")
 | 
			
		||||
        imagename="ArchLinuxARM-rpi-4-latest.tar.gz"
 | 
			
		||||
        ;;
 | 
			
		||||
@@ -314,12 +316,14 @@ if [ "$copy_ssh_key" == "y" ]
 | 
			
		||||
  else
 | 
			
		||||
    info "Skipped SSH-key copying.."
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
info "Start chroot procedures..."
 | 
			
		||||
 | 
			
		||||
mount_binds
 | 
			
		||||
mount_chroot_binds
 | 
			
		||||
 | 
			
		||||
sed -i 's/^/#CHROOT /g' "$root_mount_path""etc/ld.so.preload" || warning "sed failed."
 | 
			
		||||
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."
 | 
			
		||||
copy_qemu
 | 
			
		||||
 | 
			
		||||
copy_resolve_conf
 | 
			
		||||
 | 
			
		||||
question "Should the image password of the standart user \"$target_username\" be changed?(y/N)" && read -r change_password
 | 
			
		||||
if [ "$change_password" == "y" ]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user