This commit is contained in:
sose 2019-01-26 10:38:39 -08:00
commit b1e3895086
7 changed files with 248 additions and 165 deletions

View File

@ -23,3 +23,11 @@ Part of TildeLinux.
- Equal signs before all yad options
- Move shared functions into separate files
- Error handling for file creation
### ChangeLog
**0.1**
- initial *very* alpha release
**0.2**
- huge refractor

7
debian/changelog vendored
View File

@ -1,3 +1,10 @@
tildemerge (0.2-1) unstable; urgency=medium
* Code cleanup
* Refractor
-- fosslinux <fosslinux@tilde.team> Sun, 20 Jan 2019 16:00:56 +1100
tildemerge (0.1-1) unstable; urgency=medium
* Initial release

53
install.sh Normal file → Executable file
View File

@ -1,31 +1,48 @@
#!/bin/sh
# Copyright (c) 2018-2019 TildeLinux Maintainers
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Email: tildelinux@tildeverse.org
if test -z "$1"
then
install_dir="$HOME/.local/bin"
install_dir="$HOME/.local/bin"
else
install_dir="$1"
install_dir="$1"
fi
install_scripts(){
for f in *.sh
do
if ! echo "$f" | grep -q "install.sh"
then
cp "$f" "$install_dir"
echo "Copied $f to $install_dir/$f"
chmod +x "$install_dir/$f"
echo "Made $install_dir/$f executable"
echo ""
fi
done
install_scripts() {
for f in *.sh
do
if ! printf "%s" "$f" | grep -q "install.sh"
then
full_path="${install_dir}/${f}"
cp "$f" "$install_dir"
printf "Copied %s to %s.\\n" "$f" "$full_path"
chmod +x "$full_path"
printf "Made %s executable.\\n\\n" "$full_path"
fi
done
}
if test -f "$install_dir"
then
install_scripts
install_scripts
else
echo "$install_dir not found, creating..."
mkdir -p "$install_dir"
install_scripts
printf "%s not found, creating...\\n" "$install_dir"
mkdir -p "$install_dir"
install_scripts
fi

View File

@ -1,38 +1,56 @@
#!/bin/sh
# Copyright (c) 2018-2019 TildeLinux Maintainers
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Email: tildelinux@tildeverse.org
ssh_config_file="$HOME/.ssh/config"
get_locations(){
if ! grep -q "SSHFS Mount " "$ssh_config_file"
then
echo "<item label=\"Configure Locations...\">"
echo " <action name=\"Execute\">"
echo " <command>$HOME/.local/bin/sshfs_gui.sh</command>"
echo " </action>"
echo "</item>"
else
while read -r line
do
location_path=""
if echo "$line" | grep -q "SSHFS Mount "
then
location_path=$(echo "$line" | rev | cut -f 1 -d ' ' | rev)
location_name=$(basename "$location_path")
echo "<item label=\"$location_name\">"
echo " <action name=\"Execute\">"
echo " <command>thunar $location_path</command>"
echo " </action>"
echo "</item>"
fi
done < "$ssh_config_file"
fi
get_locations() {
if ! grep -q "SSHFS Mount " "$ssh_config_file"
then
printf "<item label=\"Configure Locations...\">\\n"
printf " <action name=\"Execute\">\\n"
printf " <command>%s/.local/bin/sshfs_gui.sh</command>\\n" "$HOME"
printf " </action>\\n"
printf "</item>\\n"
else
while read -r line
do
location_path=""
if printf "%s" "$line" | grep -q "SSHFS Mount "
then
location_path=$(printf "%s" "$line" | rev | cut -f 1 -d ' ' | rev)
location_name=$(basename "$location_path")
printf "<item label=\"%s\">\\n" "$location_name"
printf " <action name=\"Execute\">\\n"
printf " <command>thunar %s</command>\\n" "$location_path"
printf " </action>\\n"
printf "</item>\\n"
fi
done < "$ssh_config_file"
fi
}
echo "<openbox_pipe_menu>"
echo "<item label=\"File Manager\">"
echo " <action name=\"Execute\">"
echo " <command>thunar</command>"
echo " </action>"
echo "</item>"
echo "<separator label=\"Locations\" />"
get_locations
echo "</openbox_pipe_menu>"
printf "<openbox_pipe_menu>\\n"
printf "<item label=\"File Manager\">\\n"
printf " <action name=\"Execute\">\\n"
printf " <command>thunar</command>\\n"
printf " </action>\\n"
printf "</item>\\n"
printf "<separator label=\"Locations\" />\\n"
get_locations
printf "</openbox_pipe_menu>\\n"

128
setup.sh
View File

@ -1,6 +1,6 @@
#!/bin/sh
# Copyright (C) 2018 oneseveneight
# Copyright (c) 2018-2019 TildeLinux Maintainers
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -15,16 +15,16 @@
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Email: oneseveneight@airmail.cc
#
# Email: tildelinux@tildeverse.org
is_substring(){
is_substring() {
case $2 in
*$1*)
return 0
*$1*)
return 0
;;
*)
return 1
*)
return 1
;;
esac
}
@ -33,18 +33,18 @@ configure_directories() {
server_name="$1"
local_dir=""
remote_dir=""
echo "What would you like to call the local directory? (~/Remote/...)?"
printf "What would you like to call the local directory? (~/Remote/...)?\\n"
read -r answer
local_dir="$HOME/Remote/$answer"
local_dir="${HOME}/Remote/${answer}"
mkdir -p "$local_dir"
echo "Created directory $local_dir."
echo "What directory on \"$server_name\" would you like to link it to? (absolute path)"
printf "Created directory %s.\\n" "$local_dir"
printf "What directory on \"%s\" would you like to link it to? (absolute path)\\n" "$server_name"
read -r answer
remote_dir="$answer"
echo "Linking directory $local_dir to $remote_dir on \"$server_name\"."
sshfs "$server_name:$remote_dir" "$local_dir"
echo "Done, enjoy!"
printf "Linking directory %s to %s on \"%s\".\\n" "$local_dir" "$remote_dir" "$server_name"
sshfs "${server_name}:${remote_dir}" "$local_dir"
printf "Done, enjoy!\\n"
}
attempt_login() {
@ -52,28 +52,27 @@ attempt_login() {
ssh_temp_config="$2"
ssh_config="$3"
echo "Attempting to log in with configuration for \"$server_name\"."
if ssh -qF "$ssh_temp_config" "$server_name" exit
then
echo "Login successful! Writing ssh config..."
printf "Attempting to log in with configuration for \"%s\".\\n" "$server_name"
if ssh -qF "$ssh_temp_config" "$server_name" exit ; then
printf "Login successful! Writing ssh config...\\n"
cp "$ssh_temp_config" "$ssh_config"
echo "Would you like to configure sshfs for this server? (y/n)"
printf "Would you like to configure sshfs for this server? (y/n)\\n"
read -r answer
case "$answer" in
"y")
configure_directories "$server_name"
;;
"n")
echo "All right, you're all done!"
echo "Exiting..."
printf "All right, you're all done!\\n"
printf "Exiting...\\n"
;;
"*")
echo "\"$answer\" was not recognized as an answer, please enter 'y' or 'n'"
printf "\"%s\" was not recognized as an answer, please enter 'y' or 'n'\\n" "$answer"
esac
else
echo "Login failed, what would you like to do?"
echo " 1) Try logging in again."
echo " 2) Re-configure my credentials."
printf "Login failed, what would you like to do?\\n"
printf " 1) Try logging in again.\\n"
printf " 2) Re-configure my credentials.\\n"
read -r answer
case "$answer" in
"1")
@ -94,44 +93,43 @@ setup_keys() {
ssh_dir=""
key_type=""
echo "Configuring \"$server_address\" as \"$server_name\"."
echo "What is your login name for this server?"
printf "Configuring \"%s\" as \"%s\".\\n" "$server_address" "$server_name"
printf "What is your login name for this server?\\n"
read -r login
echo "Where is the private key you use for this account (absolute path)"
printf "Where is the private key you use for this account? (absolute path)\\n"
read -r key_path
if test -r "$key_path"
then
echo "File found, configuring ssh..."
ssh_dir="$HOME/.ssh"
ssh_host_dir="$HOME/.ssh/$server_name"
if test -r "$key_path" ; then
printf "File found, configuring ssh...\\n"
ssh_dir="${HOME}/.ssh"
ssh_host_dir="${HOME}/.ssh/${server_name}"
key_type=$(head -n 1 "$key_path" \
| cut -f 2 -d ' ' \
| tr '[:upper:]' '[:lower:]')
test -d "$ssh_dir" || mkdir "$ssh_dir"
test -d "$ssh_host_dir" || mkdir "$ssh_host_dir"
echo "Key appears to be of type \"$key_type\""
echo "Generating public key..."
ssh-keygen -y -f "$key_path" > "$ssh_host_dir/id_$key_type.pub"
echo "Copying private key..."
cp "$key_path" "$ssh_host_dir/id_$key_type"
echo "Saving configuration..."
test -e "$ssh_dir/config" || touch "$ssh_dir/config"
test -d "$ssh_dir" || mkdir -p "$ssh_dir"
test -d "$ssh_host_dir" || mkdir -p "$ssh_host_dir"
printf "Key appears to be of type \"%s\".\\n" "$key_type"
printf "Generating public key...\\n"
ssh-keygen -y -f "$key_path" > "${ssh_host_dir}/id_${key_type}.pub"
printf "Copying private key...\\n"
cp "$key_path" "${ssh_host_dir}/id_${key_type}"
printf "Saving configuration...\\n"
test -e "${ssh_dir}/config" || touch "${ssh_dir}/config"
cp "$ssh_dir/config" "$ssh_dir/config.tmp"
{
echo "Host $server_name"
echo " HostName $server_address"
echo " port 22"
echo " User $login"
echo " IdentityFile $ssh_host_dir/id_$key_type"
} >> "$ssh_dir/config.tmp"
echo "Right now your configuration looks like this:"
cat "$ssh_dir/config.tmp"
cp "${ssh_dir}/config" "${ssh_dir}/config.tmp"
{
printf "Host %s\\n" "$server_name"
printf " HostName %s\\n" "$server_address"
printf " port 22\\n"
printf " User %s\\n" "$login"
printf " IdentityFile %s/id_%s\\n" "$ssh_host_dir" "$key_type"
} >> "${ssh_dir}/config.tmp"
printf "Right now your configuration looks like this:\\n"
cat "${ssh_dir}/config.tmp"
attempt_login "$server_name" "$ssh_dir/config.tmp" "$ssh_dir/config"
attempt_login "$server_name" "${ssh_dir}/config.tmp" "${ssh_dir}/config"
else
echo "$key_path could not be read."
echo "Either it doesn't exist, or you dont have the correct permissions, please try again."
printf "%s could not be read.\\n" "$key_path"
printf "Either it doesn't exist, or you dont have the correct permissions, please try again.\\n"
setup_keys "$server_address" "$server_name"
fi
}
@ -139,14 +137,14 @@ setup_keys() {
pick_account() {
answers="1 2 3 4"
answer=""
echo "What account would you like to configure?"
echo " 1) tilde.town"
echo " 2) tilde.team"
echo " 3) yourtilde.com"
echo " 4) cosmic.voyage"
echo " 5) tilde.institute"
printf "What account would you like to configure?\\n"
printf " 1) tilde.town\\n"
printf " 2) tilde.team\\n"
printf " 3) yourtilde.com\\n"
printf " 4) cosmic.voyage\\n"
printf " 5) tilde.institute\\n"
read -r answer
if is_substring "$answer" "$answers"
then
case "$answer" in
@ -167,7 +165,7 @@ pick_account() {
;;
esac
else
echo "\"$answer\" is not a valid option."
printf "\"%s\" is not a valid option.\\n" "$answer"
pick_account
fi
}

View File

@ -1,4 +1,22 @@
#!/bin/sh
# Copyright (c) 2018-2019 TildeLinux Maintainers
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Email: tildelinux@tildeverse.org
set -e
eval "$(xdotool getmouselocation --shell)"
@ -12,14 +30,14 @@ ssh_port="22"
ssh_dir="$HOME/.ssh"
priv_key_path=" "
get_field(){
get_field() {
field_num="$1"
info="$2"
echo "$info" | cut -f "$field_num" -d '|'
printf "%s" "$info" | cut -f "$field_num" -d '|'
}
error_box(){
error_box() {
error_text="$1"
yad \
--posx="$mouse_x" \
@ -31,7 +49,7 @@ error_box(){
--button="OK":0
}
succ_box(){
succ_box() {
succ_text="$1"
yad \
--posx="$mouse_x" \
@ -43,7 +61,7 @@ succ_box(){
--button="OK":0
}
dec_box(){
dec_box() {
error_text="$1"
yad \
--posx="$mouse_x" \
@ -57,7 +75,7 @@ dec_box(){
return $?
}
info_box(){
info_box() {
info_text="$1"
yad \
--posx="$mouse_x" \
@ -96,17 +114,17 @@ get_info() {
ssh_port=$(get_field 4 "$info")
ssh_dir=$(get_field 5 "$info")
priv_key_path=$(get_field 6 "$info")
if test -z "$login"
then
error_msg="No login provided!"
error_num=$(( error_num + 1))
error_num=$((error_num + 1))
fi
if test -d "$(echo "$priv_key_path" | sed 's/\/ *$//')"
if test -d "$(printf "%s" "$priv_key_path" | sed 's/\/ *$//')"
then
error_msg="$error_msg\\nNo private key provided!"
error_num=$(( error_num + 1))
error_msg="${error_msg}\\nNo private key provided!"
error_num=$((error_num + 1))
fi
if [ $error_num -gt 0 ]
@ -119,10 +137,10 @@ get_info() {
}
configure_server() {
ssh_current_config="$ssh_dir/config"
ssh_temp_config="$ssh_dir/config.tmp"
ssh_host_dir="$ssh_dir/$server_address"
key_type=$(head -n 1 "$priv_key_path" \
ssh_current_config="${ssh_dir}/config"
ssh_temp_config="${ssh_dir}/config.tmp"
ssh_host_dir="${ssh_dir}/${server_address}"
key_type=$(head -n 1 "${priv_key_path}" \
| cut -f 2 -d ' ' \
| tr '[:upper:]' '[:lower:]')
@ -130,9 +148,9 @@ configure_server() {
|| touch "$ssh_current_config"
cp "$ssh_current_config" "$ssh_temp_config"
if grep -qi "Host $server_name" "$ssh_current_config"
if grep -qi "Host ${server_name}" "$ssh_current_config"
then
dec_box "Host named $server_name already exists, overwrite?" \
dec_box "Host named ${server_name} already exists, overwrite?" \
|| get_info
if ! dec_box "Keep old config in file? (ssh will use the new one)"
@ -141,40 +159,40 @@ configure_server() {
in_old_host_block=0
while read -r line
do
if echo "$line" | grep -q "Host $server_name"
if printf "%s" "$line" | grep -q "Host ${server_name}"
then
in_old_host_block=0
elif echo "$line" | grep -q "Host "
elif printf "%s" "$line" | grep -q "Host "
then
in_old_host_block=1
fi
[ $in_old_host_block -eq 1 ] \
&& echo "$line"
&& printf "%s" "$line"
done < "$ssh_current_config" > "$ssh_temp_config"
fi
fi
mkdir -p "$ssh_host_dir"
cp "$priv_key_path" "$ssh_host_dir/id_$key_type"
cp "$priv_key_path" "${ssh_host_dir}/id_${key_type}"
{
echo "Host $server_name"
echo " HostName $server_address"
echo " Port $ssh_port"
echo " User $login"
echo " IdentityFile $ssh_host_dir/id_$key_type"
{
printf "Host %s\\n" "$server_name"
printf " HostName %s\\n" "$server_address"
printf " Port %s\\n" "$ssh_port"
printf " User %s\\n" "$login"
printf " IdentityFile %s/id_%s\\n" "$ssh_host_dir" "$key_type"
} >> "$ssh_temp_config"
info_box "Attempting to log in with the provided credentials..." &
info_pid=$(( $! + 2 )) # yikes, is this safe?
echo "$ssh_temp_config"
echo "$server_address"
printf "%s\\n" "$ssh_temp_config"
printf "%s\\n" "$server_address"
if ssh -qF "$ssh_temp_config" "$server_name" exit
then
kill $info_pid
succ_box "Login success!\\nAccount for $server_address created!"
succ_box "Login success!\\nAccount for ${server_address} created!"
cp "$ssh_temp_config" "$ssh_current_config"
rm "$ssh_temp_config"
exit # Without this the "Host already exists" box appears, investigate.

View File

@ -1,4 +1,21 @@
#!/bin/sh
# Copyright (c) 2018-2019 TildeLinux Maintainers
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Email: tildelinux@tildeverse.org
setup_script_path="$HOME/.local/bin/setup_gui.sh"
@ -11,17 +28,17 @@ server_name=$(grep -E "[H,h]ost " "$ssh_config_file" \
| cut -f 2 -d ' ' \
| tr '\n' '!' \
| sed 's/!$//') # This only works in posix sh
sshfs_local_path="$HOME/Remote/myfolder"
sshfs_local_path="${HOME}/Remote/myfolder"
sshfs_remote_path="$HOME"
get_field(){
get_field() {
field_num="$1"
info="$2"
echo "$info" | cut -f "$field_num" -d '|'
printf "%s" "$info" | cut -f "$field_num" -d '|'
}
error_box(){
error_box() {
error_text="$1"
yad \
--posx="$mouse_x" \
@ -33,7 +50,7 @@ error_box(){
--button="OK":0
}
succ_box(){
succ_box() {
succ_text="$1"
yad \
--posx="$mouse_x" \
@ -45,7 +62,7 @@ succ_box(){
--button="OK":0
}
dec_box(){
dec_box() {
error_text="$1"
yad \
--posx="$mouse_x" \
@ -59,7 +76,7 @@ dec_box(){
return $?
}
info_box(){
info_box() {
info_text="$1"
yad \
--posx="$mouse_x" \
@ -91,14 +108,14 @@ get_info() {
--button="Continue":0 \
"$ssh_config_file" "$server_name" "$sshfs_local_path" "$sshfs_remote_path")
info_return="$?"
if [ $info_return -eq 1 ]
if [ $info_return -eq 1 ]
then
exit
elif [ $info_return -eq 2 ]
then
if ! "$setup_script_path"
then
error_box "$setup_script_path did not finish successfully"
error_box "${setup_script_path} did not finish successfully!"
get_info
fi
fi
@ -110,13 +127,13 @@ get_info() {
if test -z "$sshfs_local_path"
then
error_msg="No local path provided!"
error_num=$(( error_num + 1))
error_num=$((error_num + 1))
fi
if test -z "$sshfs_remote_path"
then
error_msg="$error_msg\\nNo remote path provided"
error_num=$(( error_num + 1))
error_msg="${error_msg}\\nNo remote path provided!"
error_num=$((error_num + 1))
fi
if [ $error_num -gt 0 ]
@ -135,27 +152,27 @@ configure_mount() {
test -e "$sshfs_local_path" \
|| mkdir -p "$sshfs_local_path"
if ! ssh "$server_name" "test -d $sshfs_remote_path"
if ! ssh "$server_name" "test -d \${sshfs_remote_path}"
then
if dec_box "Directory $sshfs_remote_path does not exist on remote host, create?"
then
if ! error_msg=$(ssh "$server_name" "mkdir $sshfs_remote_path" 2>&1)
if ! error_msg=$(ssh "$server_name" "mkdir \${sshfs_remote_path}" 2>&1)
then
error_box "Failed to create remote directory $error_msg"
error_box "Failed to create remote directory. ${error_msg}"
fi
fi
fi
if error_msg=$(sshfs \
"$server_name:$sshfs_remote_path" \
"${server_name}:${sshfs_remote_path}" \
"$sshfs_local_path" \
-oauto_cache,reconnect,Compression=no 2>&1)
then
kill $info_pid
succ_box "Successfuly linked $sshfs_local_path to $sshfs_remote_path on $server_name"
succ_box "Successfuly linked ${sshfs_local_path} to ${sshfs_remote_path} on ${server_name}"
else
kill $info_pid
error_box "Failed to link $sshfs_local_path to $sshfs_remote_path on $server_name\\n$error_msg"
error_box "Failed to link ${sshfs_local_path} to ${sshfs_remote_path} on ${server_name}\\n${error_msg}"
fi
}