Skip to content

Commit

Permalink
Ensure run.sh is present in the container by copying it if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
ysdragon committed Dec 27, 2024
1 parent 5e7ab58 commit 9df8760
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions helper.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
#!/bin/bash

ensure_run_script_exists() {
# Check if run.sh exists in the container, if not copy it again
if [ ! -f "$HOME/run.sh" ]; then
cp /run.sh "$HOME/run.sh"
chmod +x "$HOME/run.sh"
fi
}

# Parse port configuration
parse_ports() {
local config_file="$HOME/vps.config"
local port_args=""

while read -r line; do
case "$line" in
internalip=*) ;;
port[0-9]*=*)
port=${line#*=}
if [ -n "$port" ]; then port_args=" -p $port:$port$port_args"; fi
;;
port=*)
port=${line#*=}
if [ -n "$port" ]; then port_args=" -p $port:$port$port_args"; fi
;;
esac
done <"$config_file"
# Check if config file exists
if [ ! -f "$config_file" ]; then
return
fi

while IFS='=' read -r key value; do
[[ -z "$key" || "$key" =~ ^[[:space:]]*# ]] && continue

key=$(echo "$key" | tr -d '[:space:]')
value=$(echo "$value" | tr -d '[:space:]')

[ "$key" = "internalip" ] && continue

if [[ "$key" =~ ^port[0-9]*$ ]] && [ -n "$value" ]; then
if [[ "$value" =~ ^[0-9]+$ ]] && [ "$value" -ge 1 ] && [ "$value" -le 65535 ]; then
port_args="$port_args -p $value:$value"
fi
fi
done < "$config_file"

echo "$port_args"
}

# Execute PRoot environment
Expand All @@ -33,4 +49,6 @@ exec_proot() {
/bin/sh "/run.sh"
}

ensure_run_script_exists

exec_proot

0 comments on commit 9df8760

Please sign in to comment.