SUICIDE LINUX: BATTLE ROYALE http://slbr.tildeverse.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

71 lines
1.6 KiB

username="$1"
pubkey_path="$2"
slbr_port="1337"
info_port="1338"
log_port="1339"
user_sshd_port="5000"
container_id=""
container_ip=""
host_ip=""
[ -z "$1" ] && echo "please provide a username." && exit
[ -z "$2" ] && echo "please provide a pubkey file." && exit
get_user_sshd_port() {
listening_ports="$(ss -tuln \
| awk '{print $5}' \
| rev \
| cut -f1 -d ":" \
| rev
)"
if echo "$listening_ports" | grep -q "$user_sshd_port"
then
user_sshd_port="$(( user_sshd_port + 1 ))"
get_user_sshd_port
else
echo "$user_sshd_port"
fi
}
get_user_sshd_port
cp "$pubkey_path" image/pubkey
host_ip="$(
ip -br -4 addr \
| grep eth0 \
| awk '{print $3}' \
| cut -f 1 -d '/'
)"
docker build \
-t slbr:$username \
--build-arg USERNAME=$username \
--build-arg HOST_IP=$host_ip \
--build-arg SLBR_PORT=$slbr_port \
--build-arg INFO_PORT=$info_port \
--build-arg LOG_PORT=$log_port \
--build-arg SSHD_PORT=$user_sshd_port \
--label description="SLBR User Container" \
./image
rm image/pubkey
echo "Starting container..."
container_id="$(
docker run \
--cap-drop ALL \
--cap-add AUDIT_WRITE \
--cap-add CHOWN \
--cap-add SETGID \
--cap-add SETPCAP \
--cap-add SETUID \
--cap-add SYS_CHROOT \
-p $user_sshd_port:$user_sshd_port \
-h slbr \
-d "slbr:$username"
)"
container_ip="$(
docker container inspect "$container_id" \
| jq '.[0].NetworkSettings.Networks.bridge.IPAddress'
)"
echo "Done!"
echo "connect using: ssh $username@$host_ip -p $user_sshd_port"