qq2clone/inst_fragment.bash

137 lines
3.7 KiB
Bash
Raw Normal View History

2021-07-14 05:41:59 +00:00
# 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
2021-07-14 05:41:59 +00:00
{
cd "$temp_dir" &&
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
echo "[y/n] Use default storage directory '$location' ?"
read -rn1 input; echo
2021-07-14 05:41:59 +00:00
done
while [[ ! "$input" =~ (y|Y) ]]; do
echo "Type in new location"
read -r location; input=""
2021-07-14 05:41:59 +00:00
while [[ ! "$input" =~ ^(y|n|Y|N)$ ]]; do
echo "[y/n] Accept location '$location' ?"
read -rn 1 input; echo
2021-07-14 05:41:59 +00:00
done
done
echo
2021-07-14 05:41:59 +00:00
{
mkdir -p "${HOME}/.config" &&
echo "$location" > "${HOME}/.config/qq2clone"
} || { echo "Failed to write to ${HOME}/.config/qq2clone"; exit 1; }
2021-07-14 05:41:59 +00:00
{
mkdir -p "$location" &&
find -mindepth 1 -exec mv \{\} "$location"/\{\} \;
2021-07-14 05:41:59 +00:00
} || { echo "Cannot create/write to '$location'"; exit 1; }
if { command -v sudo &>/dev/null || [[ "$USER" == "root" ]]; }; then
2021-07-14 05:41:59 +00:00
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
2021-07-14 05:41:59 +00:00
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
2021-07-15 01:47:47 +00:00
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:"
2021-07-15 01:47:47 +00:00
echo " ${location}/qq2clone_completion.bash"
fi
else
echo "Completion script is available at:"
2021-07-15 01:47:47 +00:00
echo " ${location}/qq2clone_completion.bash"
fi
echo
if ((qq_moved)); then
/usr/bin/qq2clone setup
else
"${location}/qq2clone" setup
fi
echo "Setup complete"