2021-07-16 03:44:18 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Installer script for qq2clone
|
|
|
|
|
2021-07-16 01:56:36 +00:00
|
|
|
#------------------------------------------------------------------------#
|
|
|
|
# Copyright 2021, Jesse Gardner #
|
|
|
|
#------------------------------------------------------------------------#
|
|
|
|
# This file is part of qq2clone. #
|
|
|
|
# #
|
|
|
|
# qq2clone 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. #
|
|
|
|
# #
|
|
|
|
# qq2clone 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 qq2clone. If not, see <https://www.gnu.org/licenses/>. #
|
|
|
|
#------------------------------------------------------------------------#
|
|
|
|
|
2021-07-16 03:44:18 +00:00
|
|
|
# base64 encoded tgz archive will be added by gen_all.bash in archive below
|
|
|
|
|
|
|
|
#REPLACE WITH ARCHIVE#
|
2021-07-14 05:41:59 +00:00
|
|
|
|
|
|
|
[[ -z "$HOME" ]] &&
|
|
|
|
{ echo '$HOME must be defined'; exit 1; }
|
|
|
|
|
|
|
|
temp_dir="$(mktemp -d)" ||
|
|
|
|
{ echo "Failed to create temp directory"; exit 1; }
|
2021-07-14 19:17:33 +00:00
|
|
|
trap "rm -rf \"${temp_dir:?}\" &>/dev/null" EXIT
|
2021-07-14 05:41:59 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
cd "$temp_dir" &&
|
2021-07-14 19:17:33 +00:00
|
|
|
echo "$archive" | base64 -d > archive.tgz &&
|
|
|
|
tar -xzf archive.tgz &&
|
|
|
|
rm archive.tgz
|
2021-07-14 05:41:59 +00:00
|
|
|
} || { echo "Problem unpacking data to $temp_dir"; exit 1; }
|
|
|
|
|
|
|
|
declare input="" location="${HOME}/storage-qq2clone"
|
|
|
|
while [[ ! "$input" =~ ^(y|n|Y|N)$ ]]; do
|
2021-07-14 19:25:18 +00:00
|
|
|
echo "[y/n] Use default storage directory '$location' ?"
|
2021-07-14 19:17:33 +00:00
|
|
|
read -rn1 input; echo
|
2021-07-14 05:41:59 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
while [[ ! "$input" =~ (y|Y) ]]; do
|
|
|
|
echo "Type in new location"
|
2021-07-14 20:04:32 +00:00
|
|
|
read -r location; input=""
|
2021-07-14 05:41:59 +00:00
|
|
|
while [[ ! "$input" =~ ^(y|n|Y|N)$ ]]; do
|
2021-07-14 20:04:32 +00:00
|
|
|
echo "[y/n] Accept location '$location' ?"
|
2021-07-14 19:17:33 +00:00
|
|
|
read -rn 1 input; echo
|
2021-07-14 05:41:59 +00:00
|
|
|
done
|
|
|
|
done
|
2021-07-14 19:17:33 +00:00
|
|
|
echo
|
2021-07-14 05:41:59 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
mkdir -p "${HOME}/.config" &&
|
|
|
|
echo "$location" > "${HOME}/.config/qq2clone"
|
2021-07-14 19:17:33 +00:00
|
|
|
} || { echo "Failed to write to ${HOME}/.config/qq2clone"; exit 1; }
|
2021-07-14 05:41:59 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
mkdir -p "$location" &&
|
2021-07-14 19:17:33 +00:00
|
|
|
find -mindepth 1 -exec mv \{\} "$location"/\{\} \;
|
2021-07-14 05:41:59 +00:00
|
|
|
} || { echo "Cannot create/write to '$location'"; exit 1; }
|
|
|
|
|
2021-07-14 19:17:33 +00:00
|
|
|
if { command -v sudo &>/dev/null || [[ "$USER" == "root" ]]; }; then
|
2021-07-14 05:41:59 +00:00
|
|
|
|
2021-07-14 19:17:33 +00:00
|
|
|
input=""
|
2021-07-14 20:04:32 +00:00
|
|
|
qq_moved=0
|
2021-07-14 19:17:33 +00:00
|
|
|
while : ; do
|
|
|
|
while [[ ! "$input" =~ ^(y|n|Y|N)$ ]]; do
|
|
|
|
echo "[y/n] Move main script file to /usr/bin/qq2clone ?"
|
|
|
|
read -rn 1 input; echo
|
|
|
|
done
|
|
|
|
if [[ "$input" =~ ^(y|Y)$ ]]; then
|
|
|
|
success=1
|
|
|
|
if [[ "$USER" == "root" ]]; then
|
|
|
|
mv "${location}/qq2clone" /usr/bin/qq2clone || success=0
|
|
|
|
else
|
|
|
|
sudo mv "${location}/qq2clone" /usr/bin/qq2clone || success=0
|
|
|
|
fi
|
2021-07-14 20:04:32 +00:00
|
|
|
((success)) && { echo "File moved"; qq_moved=1; break; }
|
2021-07-14 19:17:33 +00:00
|
|
|
echo "Attempt failed."; input=""; continue
|
|
|
|
else
|
|
|
|
echo "You have chosen to leave the main script file at:"
|
|
|
|
echo " ${location}/qq2clone"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
|
|
|
|
input=""
|
|
|
|
while : ; do
|
|
|
|
while [[ ! "$input" =~ ^(y|n|Y|N)$ ]]; do
|
|
|
|
echo "[y/n] Move man page to /usr/local/man/man1/qq2clone.1 ?"
|
|
|
|
read -rn 1 input; echo
|
|
|
|
done
|
|
|
|
if [[ "$input" =~ ^(y|Y)$ ]]; then
|
|
|
|
success=1
|
|
|
|
if [[ "$USER" == "root" ]]; then
|
|
|
|
{
|
|
|
|
mkdir -p /usr/local/man/man1 &&
|
|
|
|
mv "${location}/qq2clone.1" /usr/local/man/man1/qq2clone.1
|
|
|
|
} ||
|
|
|
|
success=0
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sudo mkdir -p /usr/local/man/man1 &&
|
|
|
|
sudo mv "${location}/qq2clone.1" /usr/local/man/man1/qq2clone.1
|
|
|
|
} ||
|
|
|
|
success=0
|
|
|
|
fi
|
|
|
|
((success)) && { echo "File moved"; break; }
|
|
|
|
echo "Attempt failed."; input=""; continue
|
|
|
|
else
|
|
|
|
echo "You have chosen to leave the man page at:"
|
|
|
|
echo " ${location}/qq2clone.1"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2021-07-14 05:41:59 +00:00
|
|
|
|
2021-07-14 19:17:33 +00:00
|
|
|
else
|
|
|
|
echo "sudo is not installed on this system, so script and man page files"
|
2021-07-14 19:25:18 +00:00
|
|
|
echo "will not be moved to /usr/bin/ and /usr/local/man"
|
2021-07-14 19:17:33 +00:00
|
|
|
echo " [Main script] ${location}/qq2clone"
|
|
|
|
echo " [Man page] ${location}/qq2clone.1"
|
|
|
|
echo "Manually move these files to desired location on this system"
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
|
|
|
|
input=""
|
|
|
|
while [[ ! "$input" =~ ^(y|n|Y|N)$ ]]; do
|
|
|
|
echo "[y/n] qq2clone has a bash completion script. Modify ~/.bashrc to"
|
|
|
|
echo " source the completion script?"
|
|
|
|
read -rn 1 input; echo
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ "$input" =~ ^(y|Y)$ ]]; then
|
2021-07-15 01:47:47 +00:00
|
|
|
if echo "source ${location}/qq2clone_completion.bash" >> \
|
2021-07-14 19:17:33 +00:00
|
|
|
"${HOME}/.bashrc"; then
|
|
|
|
echo ".bashrc modified."
|
|
|
|
else
|
|
|
|
echo "Failed to write to ${HOME}/.bashrc . Completion script is"
|
|
|
|
echo "available at:"
|
2021-07-15 01:47:47 +00:00
|
|
|
echo " ${location}/qq2clone_completion.bash"
|
2021-07-14 19:17:33 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Completion script is available at:"
|
2021-07-15 01:47:47 +00:00
|
|
|
echo " ${location}/qq2clone_completion.bash"
|
2021-07-14 19:17:33 +00:00
|
|
|
fi
|
|
|
|
echo
|
2021-07-14 20:04:32 +00:00
|
|
|
|
|
|
|
if ((qq_moved)); then
|
|
|
|
/usr/bin/qq2clone setup
|
|
|
|
else
|
|
|
|
"${location}/qq2clone" setup
|
|
|
|
fi
|
2021-07-16 00:37:19 +00:00
|
|
|
setup_code=$?
|
2021-07-14 20:04:32 +00:00
|
|
|
|
2021-07-16 00:37:19 +00:00
|
|
|
if ((setup_code != 0)); then
|
|
|
|
echo "Setup failed. Resolve problem(s) described, then manually run"
|
|
|
|
echo "the setup again using: qq2clone setup"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit $setup_code
|