-
Notifications
You must be signed in to change notification settings - Fork 43
/
copyRootToUSB.sh
executable file
·76 lines (70 loc) · 2.28 KB
/
copyRootToUSB.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Copyright (c) 2016-21 Jetsonhacks
# MIT License
# Copy the root directory to the given volume
DESTINATION_TARGET=""
VOLUME_LABEL=""
function usage
{
echo "usage: ./copyRootToUSB.sh [OPTION]"
echo "-d | --directory <directory> Directory path to parent of kernel)"
echo "-p | --path <path> e.g. /dev/sda1"
echo "-v | --volume_label Name of the volume label"
echo "-h | --help This message"
}
# Iterate through command line inputs
while [ "$1" != "" ]; do
case $1 in
-d | --directory ) shift
DESTINATION_TARGET=$1
;;
-v | --volume_label ) shift
VOLUME_LABEL=$1
;;
-p | --path ) shift
DEVICE_PATH=$1
;;
-h | --help ) usage
exit
;;
* ) usage
exit
;;
esac
shift
done
if [ "$DEVICE_PATH" != "" ] ; then
echo "Device Path: "$DEVICE_PATH
DESTINATION_TARGET=$(findmnt -rno TARGET "$DEVICE_PATH")
if [ "$DESTINATION_TARGET" = "" ] ; then
echo "Unable to find the mount point of: ""$DEVICE_PATH"
exit 1
fi
else
if [ "$DESTINATION_TARGET" = "" ] ; then
if [ "$VOLUME_LABEL" = "" ] ; then
# No destination path, no volume label
usage
exit 1
else
DEVICE_PATH=$(findfs LABEL="$VOLUME_LABEL")
if [ "$DEVICE_PATH" = "" ] ; then
echo "Unable to find mounted volume: ""$VOLUME_LABEL"
exit 1
else
echo "Device Path: "$DEVICE_PATH
DESTINATION_TARGET=$(findmnt -rno TARGET "$DEVICE_PATH")
echo "Destination Target: "$DESTINATION_TARGET
if [ "$DESTINATION_TARGET" = "" ] ; then
echo "Unable to find the mount point of: ""$VOLUME_LABEL"
exit 1
fi
fi
fi
fi
fi
echo "Target: "$DESTINATION_TARGET
# apt-get update should make rsync available on a new system
sudo apt-get update
sudo apt-get install rsync -y
sudo rsync -axHAWX --numeric-ids --info=progress2 --exclude=/proc / "$DESTINATION_TARGET"