-
Notifications
You must be signed in to change notification settings - Fork 1
/
dropbear_init
executable file
·111 lines (91 loc) · 4.62 KB
/
dropbear_init
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
#!/usr/bin/env bash
# ┌┌────────────────────────────────────────────────────────────────────────┐┐ #
# ││ Dependencies: ││ #
# ││ ./scripts/run/dropbear_init ││ #
# ││ └─ dropbear ││ #
# ││ └─ ./scripts/run/dropbear_settings ││ #
# ││ └─ ./scripts/run/print_functions ││ #
# ││ └─ ./scripts/run/ssh_entrypoint ││ #
# ││ └─ ./scripts/run/ssh_key_check ││ #
# ││ └─ ./scripts/run/ssh_key_setup ││ #
# └└────────────────────────────────────────────────────────────────────────┘┘ #
# =========================== > Environment File < =========================== #
# ┌┌────────────────────────────────────────────────────────────────────────┐┐ #
# ││ This will check for an environment file and source it if it is there ││ #
# └└────────────────────────────────────────────────────────────────────────┘┘ #
if [ -f ${HOME}/.env ]; then
source "${HOME}/.env" &&
{
echo "source'd \${HOME}/.env"
} ||
printf "%s\n" "source ${HOME}/.env failed"
elif [ -f /.env ]; then
source /.env &&
{
echo "source'd /.env"
} ||
printf "%s\n" "source /.env failed"
fi
# ────────────────────────────────── <end> ─────────────────────────────────── #
source "${DEV_CONTAINER_DIR}/run/dropbear_settings"
source "${DEV_CONTAINER_DIR}/run/print_functions"
# Enter folder
mkdir -p "${DROPBEAR_FOLDER}"
cd ${DROPBEAR_FOLDER}
# Delete existing host keys
rm -rf ./host_key_*
# Read host keys from files in ${SSH_KEY_FOLDER}
source "${DEV_CONTAINER_DIR}/run/ssh_key_setup" "insert"
# Add section to .bashrc that automatically execudes code
bashrc_path="$HOME/.bashrc"
begin_delim="# >>>>>>>>>>>>>>>>>>>> dev-container shell setup >>>>>>>>>>>>>>>>>>>> "
end_delim="# <<<<<<<<<<<<<<<<<<<< dev-container shell setup <<<<<<<<<<<<<<<<<<<< "
# Remove the `dev-container shell setup` section from .bashrc if it is already there
if grep -iq "${begin_delim}" "${bashrc_path}"; then
perl -p0i -e "s/${begin_delim}.*${end_delim}//gms" "${bashrc_path}"
fi
# Add `dev-container shell setup` section to .bashrc
cat \
>>${bashrc_path} <<EOF
${begin_delim}
export DEV_CONTAINER_DIR="${DEV_CONTAINER_DIR}"
export PATH="${PATH}:\${PATH}"
export PATH="\$("${DEV_CONTAINER_DIR}/run/make_unique" "\${PATH}" ":")";
if [[ "\${TERM_PROGRAM}" == "vscode" ]]; then
export __ssh_entrypoint_run__=
fi
source /.ssh_entrypoint
${end_delim}
EOF
# Initialize VScode server folders
source "${DEV_CONTAINER_DIR}/run/vscode-server_init"
# Check if keys have been changed in comparison to those
# publicly available on git
${DEV_CONTAINER_DIR}/run/ssh_key_check || {
# Store cursor position
tput_store_cursor
printf "%s\n" "Do you wish to proceed $(tput_red "with unsafe keys")? (yes / no)"
read -n 255 -t 30 answer
if (echo "${answer}" | grep "^\s*[Yy]\([Ee][Ss]\)\{1,1\}\s*$"); then
# Restore cursor position and clear everything afterwards
tput_restore_and_clear
echo "OK, $(tput_red "proceeding with unsafe keys")"
else
exit 1
fi
}
if [ -n "${HOST}" ]; then
SSH_HOSTNAME="$HOST"
elif [ -n "${HOSTNAME}" ]; then
SSH_HOSTNAME="$HOSTNAME"
else
err "\$HOST and \$HOSTNAME are both empty!"
exit 1
fi
echo "$SSH_HOSTNAME" > "${DEV_CONTAINER_DIR}/ssh_hostname.txt"
echo "----------------------------------------------------"
printf "Running on %s, port %s\n" \
"$SSH_HOSTNAME" \
"${dropbear_port}"
echo "----------------------------------------------------"
/usr/local/sbin/dropbear -F -E -s -p ${dropbear_port}