forked from piffall/PXESetupWizard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·83 lines (69 loc) · 1.86 KB
/
setup.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
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
# ...
echo "+------------------------------------+"
echo "| PXE SETUP WIZARD |"
echo "+------------------------------------+"
echo ""
apt-get -y install git tftpd-hpa unzip wget curl p7zip-full xzip xz-utils cpio
cd $(dirname "$0")
export TFTP_PATH=$(pwd)
export SCRIPT_PATH=$TFTP_PATH/scripts/exec
# Assume yes to all questions
ASSUME_YES=${1:-false}
# Parse IPs, set default and calc length
IPS=($(ip addr | grep 'inet ' | cut -d' ' -f6 | cut -d '/' -f1))
DEF_IP_INDEX=1
IPS_LEN=${#IPS[*]}
# Header of IP choice
echo "Select an IP address to bind TFTP service"
echo "-----------------------------------------"
echo ""
for (( i=0; i<=$(( $IPS_LEN -1 )); i++ ))
do
if [ $i -eq $DEF_IP_INDEX ]; then
echo -n " * "
else
echo -n " "
fi
echo "$i. ${IPS[$i]}"
done
# Ask user to choose one of the IP addresses
if [ "$ASSUME_YES" == false ]; then
echo ""
echo -n "Press enter to keep the current choice[*], or type selection number: "
read IP_INDEX
fi
if [ "x$IP_INDEX" == "x" ]; then
IP=${IPS[$DEF_IP_INDEX]}
else
IP=${IPS[$IP_INDEX]}
fi
# Inject IP address
cd conf
BLD_PATH=$(pwd)
for FILE in $(ls src/)
do
echo "Building file $FILE..."
cat $BLD_PATH/src/$FILE | sed -s 's/{ip}/'$IP'/g' > $BLD_PATH/available/$FILE
done
# Create all symlinks
. $TFTP_PATH/scripts/enable-all.sh
# Ask to run scripts
DOWNLOAD="y"
if [ "$ASSUME_YES" == false ]; then
echo -n "Do you want to run scripts? [Y/n]: "
read DOWNLOAD
DOWNLOAD=$(echo $DOWNLOAD | tr '[:upper:]' '[:lower:]')
echo ""
fi
# Enter path and run each installation script
cd $TFTP_PATH
if [ "$DOWNLOAD" = "y" ]; then
for SCRIPT in $(find $SCRIPT_PATH -executable -type f | sort)
do
echo -e "\x1b[30;01m""Running script "$SCRIPT"\x1b[39;49;00m"
$SCRIPT
done
fi
# Fix bad vesamenu files
. ./fix_vesamenu.sh