HUGE refractor
This commit is contained in:
parent
dae9fcb783
commit
55be991490
|
@ -23,3 +23,7 @@ Part of TildeLinux.
|
|||
- Equal signs before all yad options
|
||||
- Move shared functions into separate files
|
||||
- Error handling for file creation
|
||||
|
||||
### Changelog
|
||||
|
||||
version
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
tildemerge (0.2-1) unstable; urgency=medium
|
||||
|
||||
* Code cleanup
|
||||
* Refractor
|
||||
|
||||
-- ***REMOVED*** <fosslinux@tilde.team> Sun, 20 Jan 2019 16:00:56 +1100
|
||||
|
||||
tildemerge (0.1-1) unstable; urgency=medium
|
||||
|
||||
* Initial release
|
||||
|
|
|
@ -10,13 +10,14 @@ fi
|
|||
install_scripts() {
|
||||
for f in *.sh
|
||||
do
|
||||
if ! echo "$f" | grep -q "install.sh"
|
||||
if ! printf "%s" "$f" | grep -q "install.sh"
|
||||
then
|
||||
full_path="${install_dir}/${f}"
|
||||
cp "$f" "$install_dir"
|
||||
echo "Copied $f to $install_dir/$f"
|
||||
chmod +x "$install_dir/$f"
|
||||
echo "Made $install_dir/$f executable"
|
||||
echo ""
|
||||
printf "Copied %s to %s.\\n" "$f" "$full_path"
|
||||
chmod +x "%s" "$full_path"
|
||||
printf "Made %s executable.\\n" "$full_path"
|
||||
printf ""
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
@ -25,7 +26,7 @@ if test -f "$install_dir"
|
|||
then
|
||||
install_scripts
|
||||
else
|
||||
echo "$install_dir not found, creating..."
|
||||
printf "%s not found, creating...\\n" "$install_dir"
|
||||
mkdir -p "$install_dir"
|
||||
install_scripts
|
||||
fi
|
||||
|
|
|
@ -4,35 +4,35 @@ 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>"
|
||||
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 echo "$line" | grep -q "SSHFS Mount "
|
||||
if printf "%s" "$line" | grep -q "SSHFS Mount "
|
||||
then
|
||||
location_path=$(echo "$line" | rev | cut -f 1 -d ' ' | rev)
|
||||
location_path=$(printf "%s" "$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>"
|
||||
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\" />"
|
||||
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
|
||||
echo "</openbox_pipe_menu>"
|
||||
printf "</openbox_pipe_menu>\\n"
|
||||
|
|
106
setup.sh
106
setup.sh
|
@ -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
|
||||
|
@ -16,7 +16,7 @@
|
|||
# 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() {
|
||||
case $2 in
|
||||
|
@ -34,17 +34,17 @@ configure_directories() {
|
|||
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"
|
||||
printf "Key appears to be of type \"%s\"." "$key_type\\n"
|
||||
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"
|
||||
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"
|
||||
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,12 +137,12 @@ 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"
|
||||
|
@ -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
|
||||
}
|
||||
|
|
42
setup_gui.sh
42
setup_gui.sh
|
@ -16,7 +16,7 @@ get_field(){
|
|||
field_num="$1"
|
||||
info="$2"
|
||||
|
||||
echo "$info" | cut -f "$field_num" -d '|'
|
||||
printf "%s" "$info" | cut -f "$field_num" -d '|'
|
||||
}
|
||||
|
||||
error_box() {
|
||||
|
@ -103,9 +103,9 @@ get_info() {
|
|||
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_msg="${error_msg}\\nNo private key provided!"
|
||||
error_num=$((error_num + 1))
|
||||
fi
|
||||
|
||||
|
@ -119,10 +119,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 +130,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 +141,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.
|
||||
|
|
20
sshfs_gui.sh
20
sshfs_gui.sh
|
@ -11,14 +11,14 @@ 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() {
|
||||
field_num="$1"
|
||||
info="$2"
|
||||
|
||||
echo "$info" | cut -f "$field_num" -d '|'
|
||||
printf "%s" "$info" | cut -f "$field_num" -d '|'
|
||||
}
|
||||
|
||||
error_box() {
|
||||
|
@ -98,7 +98,7 @@ get_info() {
|
|||
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
|
||||
|
@ -115,7 +115,7 @@ get_info() {
|
|||
|
||||
if test -z "$sshfs_remote_path"
|
||||
then
|
||||
error_msg="$error_msg\\nNo remote path provided"
|
||||
error_msg="${error_msg}\\nNo remote path provided!"
|
||||
error_num=$((error_num + 1))
|
||||
fi
|
||||
|
||||
|
@ -135,27 +135,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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue