Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display the address of the server in the ui #7

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ echo 1 >/tmp/stay_awake
SERVICE_NAME="sftpgo"
HUMAN_READABLE_NAME="SFTPGo Server"
LAUNCHES_SCRIPT="false"
NETWORK_PORT=21

service_off() {
killall "$SERVICE_NAME"
Expand Down Expand Up @@ -113,6 +114,40 @@ wait_for_service_to_stop() {
done
}

get_ip_address() {
if [ -z "$NETWORK_PORT" ]; then
return
fi

enabled="$(cat /sys/class/net/wlan0/operstate)"
if [ "$enabled" != "up" ]; then
echo "Not connected to WiFi"
return
fi
ip_address=""

count=0
while true; do
count=$((count + 1))
if [ "$count" -gt 5 ]; then
break
fi

ip_address="$(ip addr show wlan0 | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1)"
if [ -n "$ip_address" ]; then
break
fi
sleep 1
done

if [ -z "$ip_address" ]; then
echo "Not connected to WiFi"
return
fi

echo "http://$ip_address:$NETWORK_PORT"
}

main_screen() {
minui_list_file="/tmp/minui-list"
rm -f "$minui_list_file"
Expand All @@ -129,8 +164,12 @@ main_screen() {

if is_service_running; then
service_pid="$(pgrep "$SERVICE_NAME" 2>/dev/null | sort | head -n 1 || true)"
ip_address="$(get_ip_address)"
echo "Enabled: true (pid: $service_pid)" >"$minui_list_file"
echo "Start on boot: $start_on_boot" >>"$minui_list_file"
if [ -n "$ip_address" ]; then
echo "Address: $ip_address" >>"$minui_list_file"
fi
echo "Disable" >>"$minui_list_file"
fi

Expand All @@ -141,7 +180,7 @@ main_screen() {
fi

killall sdl2imgshow >/dev/null 2>&1 || true
"$progdir/bin/minui-list-$PLATFORM" --file "$minui_list_file" --format text --header "$HUMAN_READABLE_NAME Configuration"
"$progdir/bin/minui-list-$PLATFORM" --file "$minui_list_file" --format text --header "$HUMAN_READABLE_NAME"
}

main() {
Expand Down