Advertisement
Uno-Dan

Untitled

Jun 14th, 2019
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.94 KB | None | 0 0
  1. #!/bin/bash
  2. # File: install.sh
  3. #
  4. # Starts the install, you must copy your public ssh key to the target host before you run this script.
  5. #
  6. # ******** IMPORTANT MAKE SURE YOU HAVE THE CORRECT DEVICE. ALL DATA ON DEVICE WILL BE DELETED *******
  7.  
  8. echo
  9. echo "Starting LFS build process."
  10. echo
  11.  
  12. # Set some constants.
  13. USR=lfs
  14. HOST=$1 # The target host.
  15. DEVICE=sda # Device that will be used for the target system.
  16. SCRIPT=install.sh # Name of this script.
  17. LOGS=./$HOST-logs # The path to the log files.
  18. TIME_LOGS=$LOGS/build-time.log # The time logs file.
  19.  
  20. echo -e "Executing Script: $SCRIPT, Time: $(date)\n" | tee $INFO_LOGS
  21.  
  22. # Save start time, for timing script run time.
  23. start=`date +%s`
  24. source ./lfs-functions.sh &&
  25.  
  26. rm -rf $LOGS
  27.  
  28. # Create the logging directory and time log file.
  29. mkdir -p $LOGS && touch $TIME_LOGS
  30.  
  31. # Copy source bash scripts to target host.
  32. echo -e "Copying source files to target host \"$HOST\"\n"
  33. scp lfs-* root@$HOST:~ &&
  34. echo -e "\nFiles copied to target host \"$HOST\" successfully.\n"
  35.  
  36. # Login to remote host and run distribution prep script.
  37. echo -e "Logging into target host \"$HOST\" as root user.\n"
  38. ssh root@$HOST . ~/lfs-fedora.sh $USR $HOST $DEVICE &&
  39.  
  40. # The distribution prep script on remote host has finished wait for host to come back online .
  41. echo
  42. echo -e "\nRebooting remote host: $HOST\n"
  43. echo -n "Waiting for host, $HOST to come back online: "
  44.  
  45. # Display dots indicating time passing, well waiting for target host to come back online.
  46. for i in {1..5}; do sleep 1; echo -n "."; done
  47. while ! ping -c 1 -n -w 1 $HOST &> /dev/null; do echo -n "*"; done
  48. for i in {1..5}; do sleep 1; echo -n "."; done
  49. echo
  50.  
  51. # Login to target host, the login will trigger the stage 1 prep script to execute.
  52. ssh root@$HOST &&
  53.  
  54. end=`date +%s`
  55. echo -e "Finished Script: $SCRIPT, Time: $(date)\n" | tee $INFO_LOGS
  56. echo "S:$start E:$end T:$(format_time $[end-start]) S:$SCRIPT" >> $TIME_LOGS
  57. echo Build completed.
  58.  
  59. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement