50 lines
1.5 KiB
Bash
Executable File
50 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
export TMUX_SESSION="app-frpc-$APP_NAME"
|
|
export TMUX_COMMAND="frpc -c $APP_HOME/conf/frpc.toml"
|
|
|
|
case "$2" in
|
|
-h|--help|"")
|
|
echo "commands:"
|
|
echo " exec execute tmux with commands"
|
|
echo " stat show the status"
|
|
echo;
|
|
echo "args:"
|
|
echo " -h, --help show the help documentation"
|
|
echo " -v, --version show the version"
|
|
;;
|
|
-v|--version)
|
|
echo "v0.0.1"
|
|
;;
|
|
stat)
|
|
CURR_TMUX_SESSION=$(tmux list-session 2>&1 | grep "$TMUX_SESSION")
|
|
if [ -z "$CURR_TMUX_SESSION" ]; then
|
|
echo "tmux session [$TMUX_SESSION] not exists."
|
|
else
|
|
echo "tmux session [$TMUX_SESSION] => $CURR_TMUX_SESSION"
|
|
tmux attach -t $TMUX_SESSION
|
|
fi
|
|
;;
|
|
exec)
|
|
CURR_TMUX_SESSION=$(tmux list-session 2>&1 | grep "$TMUX_SESSION")
|
|
if [ -n "$CURR_TMUX_SESSION" ]; then
|
|
echo "tmux session [$TMUX_SESSION] => $CURR_TMUX_SESSION"
|
|
tmux attach -t $TMUX_SESSION
|
|
else
|
|
echo "starting..."
|
|
if [ ! -f "$APP_HOME/conf/frpc.toml" ]; then
|
|
echo "Error: frpc config not exists."
|
|
exit 1
|
|
fi
|
|
tmux new-session -d -s "$TMUX_SESSION"
|
|
sleep 3
|
|
tmux send-keys -t "$TMUX_SESSION" "$TMUX_COMMAND" Enter
|
|
tmux attach -t "$TMUX_SESSION"
|
|
fi
|
|
;;
|
|
*)
|
|
echo "Invalid command: ${@:2}"
|
|
;;
|
|
esac
|
|
|