First commit
This commit is contained in:
commit
c063ffb124
|
@ -0,0 +1,41 @@
|
|||
#!/bin/sh
|
||||
|
||||
export tilde_name=""
|
||||
export tilde_username=""
|
||||
export key_file=""
|
||||
|
||||
ssh_command="ssh -i $key_file $tilde_username@$tilde_name"
|
||||
|
||||
check_key_file() {
|
||||
if [ -f "$key_file" ]
|
||||
then
|
||||
while [ -z cat "$key_file" | head -n1 | grep "-----BEGIN .* PRIVATE KEY-----" ]
|
||||
do
|
||||
echo "$key_file does not look like a private key file, try again"
|
||||
bash
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
connection_test() {
|
||||
while ! $ssh_command "true"
|
||||
do
|
||||
echo "There seems to be a problem connecting to the tilde"
|
||||
echo "Use this shell to try and fix any problems, then try connecting again by exiting the shell"
|
||||
bash
|
||||
done
|
||||
}
|
||||
|
||||
configure_user() {
|
||||
mkdir "/home/$tilde_username"
|
||||
useradd "$tilde_username" -d "/home/$tilde_username"
|
||||
chown "$tilde_username:$tilde_username" "/home/$tilde_username"
|
||||
sshfs "$tilde_username@$tilde_name:/home/$tilde_username /home/$tilde_username"
|
||||
touch /usr/bin/sshshell
|
||||
echo "#!/bin/sh" >> /usr/bin/sshshell
|
||||
echo "ssh -i $key_file $tilde_username@$tilde_name" >> /usr/bin/sshshell
|
||||
chmod +x /usr/bin/sshshell
|
||||
echo "/usr/bin/sshshell" >> /etc/shells
|
||||
chsh -s "/usr/bin/sshshell $tilde_username"
|
||||
|
||||
}
|
|
@ -0,0 +1,173 @@
|
|||
#!/bin/sh
|
||||
# This script is to be run on the remote host in order to create a weechat session
|
||||
# NOTE: This script only works with tmux, mosh and screen are not supported
|
||||
# TODO: Cleanup function and robustness
|
||||
|
||||
#. util.sh
|
||||
#weechat_relay_port="9000"
|
||||
#weechat_relay_password="password1234"
|
||||
# these are set when running the script
|
||||
|
||||
|
||||
is_substring() {
|
||||
case $2 in
|
||||
*$1*)
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
create_tmux_session() {
|
||||
new_session_name="weechat"
|
||||
echo "Creating new tmux session..."
|
||||
while tmux list-sessions | grep -q "^$new_session_name"
|
||||
do
|
||||
new_session_name="$new_session_name-"
|
||||
done
|
||||
tmux new-session -d -s "$new_session_name"
|
||||
tmux send -t "$new_session_name":0 'weechat' ENTER
|
||||
}
|
||||
|
||||
attatch_tmux_session() {
|
||||
choice=""
|
||||
tmux_sessions=""
|
||||
session_name=""
|
||||
window_number=""
|
||||
echo "Attatching to existing tmux session..."
|
||||
if [ "$(tmux list-sessions | wc -l)" != "1" ]
|
||||
then
|
||||
tmux_sessions="$(tmux list-sessions \
|
||||
| cut -f 1 -d ' ' \
|
||||
| rev | cut -c 2- | rev)"
|
||||
clear
|
||||
echo "Which tmux session would you like to attach to?"
|
||||
echo "$tmux_sessions"
|
||||
read -r choice
|
||||
if is_substring "$choice" "$tmux_sessions"
|
||||
then
|
||||
session_name="$choice"
|
||||
else
|
||||
echo "\"$choice\" is not recognized as a valid session, please try again"
|
||||
attatch_tmux_session
|
||||
fi
|
||||
else
|
||||
echo "No tmux session appears to be running, a new session will be created"
|
||||
create_tmux_session
|
||||
exit
|
||||
fi
|
||||
window_number="$(( "$(tmux list-sessions | grep "^$session_name" | cut -f 2 -d ' ')" + 1 ))"
|
||||
tmux new-window -t "$session_name:$window_number"
|
||||
tmux send -t "$session_name:$window_number" 'weechat' ENTER
|
||||
echo "Waiting for weechat session..."
|
||||
while ! ps xo 'cmd=' | grep -q '^weechat'
|
||||
do
|
||||
sleep 0.5
|
||||
done
|
||||
}
|
||||
|
||||
create_weechat_relay(){
|
||||
echo "Configuring new WeeChat relay..."
|
||||
if [ -z "$weechat_relay_port" ]
|
||||
then
|
||||
echo "weechat_relay_port is not set! exiting..."
|
||||
exit
|
||||
fi
|
||||
if [ -z "$weechat_relay_password" ]
|
||||
then
|
||||
echo "weechat_relay_password is not set! exiting..."
|
||||
exit
|
||||
fi
|
||||
weechat_pane_name="WeeChat $(weechat -v)"
|
||||
weechat_pane_id="$(tmux list-panes -a -F '#{pane_id} #{pane_title}' \
|
||||
| grep "$weechat_pane_name" \
|
||||
| cut -f 1 -d ' ')"
|
||||
|
||||
if [ "$weechat_pane_id" == " " ]
|
||||
then
|
||||
echo "Failed to find WeeChat session, exiting..."
|
||||
exit
|
||||
fi
|
||||
|
||||
tmux send -t "$weechat_pane_id" '^W'
|
||||
tmux send -t "$weechat_pane_id" "/relay add weechat $weechat_relay_port" ENTER
|
||||
tmux send -t "$weechat_pane_id" "/secure set relay $weechat_relay_password" ENTER
|
||||
tmux send -t "$weechat_pane_id" '/set relay.network.password "${sec.data.relay}"' ENTER
|
||||
tmux send -t "$weechat_pane_id" "/relay start weechat" ENTER
|
||||
sleep 1
|
||||
tmux send -t "$weechat_pane_id" '^Y'
|
||||
echo "WeeChat relay configured!"
|
||||
}
|
||||
|
||||
configure_weechat_session() {
|
||||
choice=""
|
||||
clear
|
||||
echo "=== WeeChat Relay Setup ==="
|
||||
echo "Do you enter a password to start WeeChat? (encrypted config)"
|
||||
echo "1. Yes"
|
||||
echo "2. No"
|
||||
while :
|
||||
do
|
||||
read -r choice
|
||||
case "$choice" in
|
||||
"1")
|
||||
echo "In this case you will need to start WeeChat manually inside tmux or this script will break. Once you have done this press ENTER"
|
||||
read
|
||||
break
|
||||
;;
|
||||
"2")
|
||||
echo "Starting config wizard..."
|
||||
echo
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Please enter a valid option"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if ! ps xo 'cmd=' | grep -q '^weechat'
|
||||
then
|
||||
if ! tmux list-sessions >/dev/null
|
||||
then
|
||||
create_tmux_session
|
||||
else
|
||||
while :
|
||||
do
|
||||
clear
|
||||
echo "Found existing tmux sessions:"
|
||||
echo "$(tmux list-sessions)"
|
||||
echo
|
||||
echo "tmux is already running, what would you like to do?"
|
||||
echo "1. Start WeeChat in a new window in an existing tmux session"
|
||||
echo "2. Start WeeChat in new tmux session"
|
||||
read -r choice
|
||||
case "$choice" in
|
||||
"1")
|
||||
clear
|
||||
attatch_tmux_session
|
||||
create_weechat_relay
|
||||
break
|
||||
;;
|
||||
"2")
|
||||
clear
|
||||
create_tmux_session
|
||||
create_weechat_relay
|
||||
break
|
||||
;;
|
||||
"*")
|
||||
echo "Please enter a valid option"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
else
|
||||
clear
|
||||
echo "A WeeChat process was found, configuring relay..."
|
||||
create_weechat_relay
|
||||
fi
|
||||
}
|
||||
|
||||
configure_weechat_session
|
|
@ -0,0 +1,68 @@
|
|||
#!/bin/sh
|
||||
|
||||
set_relay_config(){
|
||||
weechat_relay_port=""
|
||||
weechat_relay_password=""
|
||||
relay_type="$1"
|
||||
while :
|
||||
do
|
||||
echo "Enter relay port number (leave blank for default 9000)"
|
||||
read -r weechat_relay_port
|
||||
|
||||
if [ -z "$weechat_relay_port" ]
|
||||
then
|
||||
weechat_relay_port="9000"
|
||||
break
|
||||
fi
|
||||
|
||||
if [ "$relay_type" == "new" ] && "$ssh_command grep -w $weechat_relay_port /etc/services"
|
||||
then
|
||||
echo "Port $weechat_relay_port is in use, try another port"
|
||||
else
|
||||
break
|
||||
fi
|
||||
|
||||
if [ "$weechat_relay_port" -gt 1023 ]
|
||||
then
|
||||
break
|
||||
else
|
||||
echo "Please enter a port number > 1023"
|
||||
fi
|
||||
|
||||
done
|
||||
while :
|
||||
do
|
||||
echo "Enter a password for this relay:"
|
||||
stty -echo
|
||||
read -r weechat_relay_password
|
||||
stty echo
|
||||
echo "Re-enter password:"
|
||||
stty -echo
|
||||
read -r weechat_relay_confirm_password
|
||||
stty echo
|
||||
if [ "$weechat_relay_password" == "$weechat_relay_confirm_password" ]
|
||||
then
|
||||
break
|
||||
else
|
||||
echo "Passwords do not match"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
echo "Writing to qWeeChat config..."
|
||||
echo "[relay]" > ./.qweechat.conf
|
||||
echo "lines = 50" > ./.qweechat.conf
|
||||
echo "autoconnect = off" > ./.qweechat.conf
|
||||
echo "password = $weechat_relay_password" > ./.qweechat.conf
|
||||
echo "ssl = off" > ./.qweechat.conf
|
||||
echo "port = $weechat_relay_port" > ./.qweechat.conf
|
||||
echo "server = $tilde_name" > ./.qweechat.conf
|
||||
|
||||
scp -ni "$key_file" ./.qweechat.conf "$tilde_username@$tilde_name:./"
|
||||
|
||||
if [ "$relay_type" == "new" ]
|
||||
then
|
||||
echo "Since you do not have an existing WeeChat relay, a new one will be configured for you"
|
||||
echo "weechat_relay_port=\"$weechat_relay_port\" weechat_relay_password=\"$weechat_relay_password\" $(cat ./util.sh ./configure_weechat_session.sh)" | "$ssh_command -t -t"
|
||||
fi
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
#!/bin/sh
|
||||
|
||||
. util.sh
|
||||
. basics.sh
|
||||
. irc.sh
|
||||
|
||||
tilde_name=""
|
||||
tilde_username=""
|
||||
key_file=""
|
||||
ssh_command="ssh -i $key_file $tilde_username@$tilde_name"
|
||||
|
||||
#configure_tilde
|
||||
#configure_irc
|
||||
|
||||
key_file="$(find /tilde/key | tail -n1)"
|
||||
choice=""
|
||||
|
||||
echo "=== Welcome to Tildelinux! ==="
|
||||
echo "What tilde would you like to connect to? (use the domain name as you would for ssh)"
|
||||
read tilde_name
|
||||
echo "What is your username for $tilde_name?"
|
||||
read tilde_username
|
||||
echo "Now you will need to provide tildelinux with your ssh private key"
|
||||
echo "By whatever means, place your private key in the /tilde/key directory"
|
||||
echo "Here is a shell, once the key is in the proper location, simply type \"exit\" to close the shell and continue"
|
||||
bash
|
||||
echo "Looking for keyfile..."
|
||||
check_key_file || fail
|
||||
echo "Key file located!"
|
||||
echo "Testing connection to the tilde..."
|
||||
connection_test || fail
|
||||
echo "Connection success!"
|
||||
echo "Configuring user..."
|
||||
configure_user || fail
|
||||
echo "User configured!"
|
||||
clear
|
||||
echo "=== IRC Configuration ==="
|
||||
echo "Now we will begin configuring a WeeChat IRC relay"
|
||||
echo "Select the option that applies to you:"
|
||||
echo "1. I have a WeeChat relay configured on my chosen tilde"
|
||||
echo "2. I do not have a WeeChat relay configured on my chosen tilde"
|
||||
read -r choice
|
||||
while :
|
||||
do
|
||||
case "$choice" in
|
||||
"1")
|
||||
clear
|
||||
set_relay_config "existing"
|
||||
;;
|
||||
"2")
|
||||
clear
|
||||
echo "Since no WeeChat relay exists, a new one will be configured"
|
||||
echo "First, provide a port number and password for this relay"
|
||||
set_relay_config "new"
|
||||
;;
|
||||
"*")
|
||||
echo "Please enter a valid option"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
echo "All done! Enjoy using Tildelinux!"
|
||||
#startx
|
Loading…
Reference in New Issue