137 lines
3.7 KiB
Bash
137 lines
3.7 KiB
Bash
# Tail end of the installer script, following the tar archive
|
|
|
|
[[ -z "$HOME" ]] &&
|
|
{ echo '$HOME must be defined'; exit 1; }
|
|
|
|
temp_dir="$(mktemp -d)" ||
|
|
{ echo "Failed to create temp directory"; exit 1; }
|
|
trap "rm -rf \"${temp_dir:?}\" &>/dev/null" EXIT
|
|
|
|
{
|
|
cd "$temp_dir" &&
|
|
echo "$archive" | base64 -d > archive.tgz &&
|
|
tar -xzf archive.tgz &&
|
|
rm archive.tgz
|
|
} || { echo "Problem unpacking data to $temp_dir"; exit 1; }
|
|
|
|
declare input="" location="${HOME}/storage-qq2clone"
|
|
while [[ ! "$input" =~ ^(y|n|Y|N)$ ]]; do
|
|
echo "[y/n] Use default storage directory '$location' ?"
|
|
read -rn1 input; echo
|
|
done
|
|
|
|
while [[ ! "$input" =~ (y|Y) ]]; do
|
|
echo "Type in new location"
|
|
read -r location; input=""
|
|
while [[ ! "$input" =~ ^(y|n|Y|N)$ ]]; do
|
|
echo "[y/n] Accept location '$location' ?"
|
|
read -rn 1 input; echo
|
|
done
|
|
done
|
|
echo
|
|
|
|
{
|
|
mkdir -p "${HOME}/.config" &&
|
|
echo "$location" > "${HOME}/.config/qq2clone"
|
|
} || { echo "Failed to write to ${HOME}/.config/qq2clone"; exit 1; }
|
|
|
|
{
|
|
mkdir -p "$location" &&
|
|
find -mindepth 1 -exec mv \{\} "$location"/\{\} \;
|
|
} || { echo "Cannot create/write to '$location'"; exit 1; }
|
|
|
|
if { command -v sudo &>/dev/null || [[ "$USER" == "root" ]]; }; then
|
|
|
|
input=""
|
|
qq_moved=0
|
|
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
|
|
((success)) && { echo "File moved"; qq_moved=1; break; }
|
|
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
|
|
|
|
else
|
|
echo "sudo is not installed on this system, so script and man page files"
|
|
echo "will not be moved to /usr/bin/ and /usr/local/man"
|
|
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
|
|
if echo "source ${location}/qq2clone_completion.bash" >> \
|
|
"${HOME}/.bashrc"; then
|
|
echo ".bashrc modified."
|
|
else
|
|
echo "Failed to write to ${HOME}/.bashrc . Completion script is"
|
|
echo "available at:"
|
|
echo " ${location}/qq2clone_completion.bash"
|
|
fi
|
|
else
|
|
echo "Completion script is available at:"
|
|
echo " ${location}/qq2clone_completion.bash"
|
|
fi
|
|
echo
|
|
|
|
if ((qq_moved)); then
|
|
/usr/bin/qq2clone setup
|
|
else
|
|
"${location}/qq2clone" setup
|
|
fi
|
|
|
|
echo "Setup complete"
|