-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to run record firstboot scripts with script(1)
- Loading branch information
Showing
6 changed files
with
104 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env sh | ||
|
||
## This is an example script that: | ||
# 1. Installs Tor | ||
# 2. Sets up a stealth Tor Hidden Service for ssh access | ||
# 3. Copies `hostname` to `/boot/` (necessary to access) | ||
# 4. Halts RBP when done (unless `/boot/nohalt` exists) | ||
|
||
set -e | ||
|
||
RET_COUNT=20 | ||
|
||
retry() { | ||
delay=${RET_DELAY:-10} # seconds | ||
count=${RET_COUNT:-3} | ||
|
||
_s=s | ||
until $*; do | ||
>&2 printf "'%s' failed (exit=%s)" "$1" "$?" | ||
if [ $((count-=1)) = 0 ]; then | ||
>&2 printf "\n" | ||
return 1 | ||
fi | ||
|
||
[ "$count" = 1 ] && _s= | ||
>&2 printf ", retry in %ss (%s more time%s)…\n\n" "$delay" "$count" "$_s" | ||
sleep "$delay" | ||
done | ||
} | ||
|
||
do_tor() { | ||
retry apt-get install -y tor | ||
|
||
retry test -f /etc/tor/torrc || exit 1 | ||
|
||
cat << EOF >> /etc/tor/torrc | ||
HiddenServiceDir /var/lib/tor/ssh/ | ||
HiddenServiceVersion 2 | ||
HiddenServicePort 22 127.0.0.1:22 | ||
HiddenServiceAuthorizeClient stealth ssh | ||
EOF | ||
|
||
retry systemctl restart tor | ||
retry systemctl restart tor@default | ||
|
||
RET_COUNT=10 retry cp /var/lib/tor/ssh/hostname /boot/ | ||
} | ||
|
||
retry apt-get update | ||
|
||
do_tor | ||
|
||
RET_COUNT=100 RET_DELAY=5 retry test -f /boot/nohalt || halt | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[Unit] | ||
Description=FirstBoot | ||
After=network.target | ||
Before=rc-local.service | ||
ConditionFileNotEmpty=/boot/firstboot-script.sh | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/usr/bin/script --command=/boot/firstboot-script.sh --return --flush --timing=/boot/firstboot-script-log.tm /boot/firstboot-script-log.out | ||
ExecStartPost=/bin/mv /boot/firstboot-script.sh /boot/firstboot-script.sh.done | ||
RemainAfterExit=no | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters