first scripts
This commit is contained in:
		
							parent
							
								
									db50f44221
								
							
						
					
					
						commit
						5ad4393d9b
					
				
							
								
								
									
										12
									
								
								create.sh
									
									
									
									
									
										Executable file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										12
									
								
								create.sh
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,12 @@ | ||||
| #!/bin/bash | ||||
| cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" | ||||
| source creator_exports.sh | ||||
| source creator_functions.sh | ||||
| rm -rf "$ROOT" 2>/dev/null | ||||
| mkdir -p build "$ROOT" "${ROOT}/usr/bin/" | ||||
| cd build | ||||
| 
 | ||||
| echo_blue "Starting installation at $ROOT." | ||||
| 
 | ||||
| install_busybox || exit 1 | ||||
| create_archive | ||||
							
								
								
									
										6
									
								
								creator_exports.sh
									
									
									
									
									
										Executable file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										6
									
								
								creator_exports.sh
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,6 @@ | ||||
| #!/bin/bash | ||||
| script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||||
| 
 | ||||
| # root of the initrd, that will be used to create the cpio archive | ||||
| export ROOT="${script_dir}/build/initrd_root" | ||||
| export BUSYBOX_PATH="/usr/lib/initcpio/busybox" | ||||
							
								
								
									
										63
									
								
								creator_functions.sh
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										63
									
								
								creator_functions.sh
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,63 @@ | ||||
| #!/bin/bash | ||||
| 
 | ||||
| echo_blue() { | ||||
|   echo -e "\033[34m$1\033[0m" | ||||
| } | ||||
| 
 | ||||
| echo_red() { | ||||
|   echo -e "\033[0;31m$1\033[0m" | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| # Installs a library. Expects absolute path. | ||||
| install_lib() { | ||||
|   local lib="$1" | ||||
|   [[ -f "$lib" ]] || { | ||||
|     echo "Did not find library at path: $lib" | ||||
|     return 1 | ||||
|   } | ||||
| 
 | ||||
|   mkdir -p $(dirname "${ROOT}${lib}") | ||||
|   echo_blue "Adding library to root: $lib" | ||||
|   cp "$lib" "${ROOT}${lib}" | ||||
| } | ||||
| 
 | ||||
| # Expects to receive the absolute path as the full argument. | ||||
| # Use `which binary_name` if it's in your path. | ||||
| # Installs to /usr/bin | ||||
| install_binary() { | ||||
|   local binary="$1" lib='' | ||||
|   [[ -f "$binary" ]] || { | ||||
|     echo_red "Did not find binary at path: $binary" | ||||
|     return 1 | ||||
|   } | ||||
| 
 | ||||
|   echo_blue "Adding binary to root: $binary" | ||||
|   cp "$binary" "${ROOT}/usr/bin/" | ||||
| 
 | ||||
|   ldd_deps="$(ldd "$binary")" | ||||
|   if [[ $ldd_deps == *"not a dynamic executable"* ]]; then | ||||
|     return 0 | ||||
|   fi | ||||
| 
 | ||||
|   while read -r lib; do | ||||
|     install_lib "$lib" | ||||
|   done <<< "$( echo "$ldd_deps" | grep -F ' => ' | awk '{ print $3 }' )" | ||||
| } | ||||
| 
 | ||||
| install_busybox() { | ||||
|   echo_blue "Installing busybox..." | ||||
|   [[ -f "$BUSYBOX_PATH" ]] || { | ||||
|     echo_red "Did not find busybox at $BUSYBOX_PATH" | ||||
|     echo_red "Please compile or download busybox. You can also change the path." | ||||
|     return 1 | ||||
|   } | ||||
|   install_binary "$BUSYBOX_PATH" | ||||
|   for applet in $(/usr/lib/initcpio/busybox --list); do | ||||
|       ln -s busybox "${ROOT}/usr/bin/$applet"  | ||||
|   done | ||||
| } | ||||
| 
 | ||||
| create_archive() { | ||||
|   find . | cpio -o -H newc | gzip > detee-$(hostnamectl hostname)-$(uname -r).cpio.gz | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user