-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathldm
executable file
·135 lines (115 loc) · 4.17 KB
/
ldm
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/sh
set -eu
#this will run things that need root, so just check here for root
if [ -n "$(command -v id 2> /dev/null)" ]; then
USERID="$(id -u 2> /dev/null)"
fi
if [ -z "${USERID}" ] && [ -n "$(id -ru)" ]; then
USERID="$(id -ru)"
fi
if [ -n "${USERID}" ] && [ "${USERID}" != "0" ]; then
printf "Run it as root\n" ; exit 1;
elif [ -z "${USERID}" ]; then
printf "Unable to determine user id, permission errors may occur.\n"
fi
if [ ! -x /usr/bin/arping ] && [ ! -x /usr/sbin/arping ] && [ ! -x /bin/arping ]; then
printf "No arping is installed, pick one and install it\n"
exit 1
fi
if [ ! -x "$(command -v screen 2>&1)" ]; then
printf "Please install screen\n"
exit 1
fi
if [ ! -x "$(command -v dhcpcd 2>&1)" ]; then
printf "Please install dhcpcd\n"
exit 1
fi
system_checks() {
if [ -r "/sys/devices/virtual/dmi/id/board_vendor" ] && [ "$(cat /sys/devices/virtual/dmi/id/board_vendor)" = 'Amazon EC2' ]; then
# Don't start the services in the virtual environment
return 0
fi
# Or in docker
[ -f '/.dockerenv' ] && return 0
#truthfully, I have no idea if this matters for wifi. but it doesn't hurt
#disable limit (default 16MB) on memory used for usb transfer
if [ -w "/sys/module/usbcore/parameters/usbfs_memory_mb" ]; then
echo 0 > /sys/module/usbcore/parameters/usbfs_memory_mb
fi
if [ -x /etc/init.d/ntp ]; then
/etc/init.d/ntp status > /dev/null 2>&1 || /etc/init.d/ntp start
# shellcheck disable=SC2181
if [ "$?" != "0" ]; then
printf "ntp failed to start, but we really want it.\n"
#we may not have internet, fail gracefully
#exit 1
fi
fi
if [ -x /etc/init.d/thermald ]; then
/etc/init.d/thermald status > /dev/null 2>&1 || /etc/init.d/thermald start
# shellcheck disable=SC2181
if [ "$?" != "0" ]; then
printf "thermald failed to start, but we really want it.\n"
fi
else
printf "Please 'emerge thermald' before running this script or we may cook ourselves.\n"
fi
#this *will* fail horribly without significant entropy for wpa_supplicant, on most systems that seems to require rng-tools installed
if [ -x /etc/init.d/rngd ]; then
/etc/init.d/rngd status > /dev/null 2>&1 || /etc/init.d/rngd start
# shellcheck disable=SC2181
if [ "$?" != "0" ]; then
printf "rngd failed to start, but we really need it.\n"
printf "Most likely this can be solved by specifying a device manually in /etc/conf.d/rngd\n"
printf "Run 'ls /dev/hw_random* /dev/hwrandom* /dev/i810_rng /dev/hwrng* /dev/urandom'\n"
printf "Then add the first hit from ls to DEVICE= in /etc/conf.d/rngd\n"
exit 1
fi
else
printf "Please 'emerge rng-tools' before running this script or wpa_supplicant will fail.\n"
fi
if [ -x /usr/sbin/watchdog ]; then
if [ -r /etc/watchdog.conf ]; then
if grep -q '#watchdog-device = /dev/watchdog' /etc/watchdog.conf && [ -f /dev/watchdog ]; then
if [ -w /etc/watchdog.conf ]; then
sed -i 's/^#watchdog-device/watchdog-device/' /etc/watchdog.conf
else
printf "Unable to write to watchdog.conf\n"
fi
fi
if grep -q '^watchdog-device' /etc/watchdog.conf; then
/etc/init.d/watchdog status > /dev/null 2>&1 || /etc/init.d/watchdog start
fi
fi
fi
}
system_checks
#setup screen
screen -wipe || true # exits 1 when no old sessions are found to wipe
if [ -d '/tmp/screen' ] && [ -f '/.dockerenv' ]; then
#sometimes screen expects 777, sometimes 775, I don't know why
rm -rf '/tmp/screen'
fi
ssn="LeelooDallasMultipass"
screen -d -m -S "${ssn}"
screen -S "${ssn}" -X hardstatus string "[%f%n%?:%t%?]%h"
window=0
#right before starting everything, remove status files
mkdir -p /run/rfctf_status
#rm -rf "/run/rfctf_status/*_{attempt,active,seen,meta}"
#start everything
while IFS="" read -r command || [ -n "${command}" ]
do
printf '%s' "${command}" | grep -q '^#' && continue
if [ "${window}" = 0 ]; then
screen -p "${window}" -S "${ssn}" -X title "${command}"
else
screen -S "${ssn}" -X screen -t "${command}"
sleep 1
fi
screen -p "${window}" -S "${ssn}" -X stuff "sh -c \"${command}\""'\n'
: $((window=window+1))
sleep 2
done < ldm.conf
#attach
#screen -xr "${ssn}"