132 lines
3.6 KiB
Bash
Executable File
132 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
source install.common
|
|
|
|
function get_distro_info {
|
|
debug "Checking running distribution..."
|
|
if [ -f /etc/lsb-release ]; then
|
|
debug "Reading /etc/lsb-release..."
|
|
source /etc/lsb-release
|
|
echo "$DISTRIB_ID|$DISTRIB_RELEASE|$DISTRIB_CODENAME"
|
|
elif [ -f /etc/os-release ]; then
|
|
debug "Reading /etc/os-release..."
|
|
source /etc/os-release
|
|
echo "$ID|$VERSION_ID|$VERSION_CODENAME"
|
|
else
|
|
error "Unable to detect distribution, dependencies can not be installed."
|
|
exit
|
|
fi
|
|
}
|
|
|
|
function get_distro_deps_script {
|
|
DISTRO="$(get_distro_info)"
|
|
ID="$(echo $DISTRO | cut -d'|' -f1)"
|
|
case "$ID" in
|
|
"Ubuntu")
|
|
echo "deps/ubuntu.sh"
|
|
;;
|
|
"Raspbian"|"raspbian")
|
|
echo "deps/raspbian.sh"
|
|
;;
|
|
*)
|
|
error "Unsupported distribution ID: '$ID'"
|
|
;;
|
|
esac
|
|
|
|
|
|
|
|
}
|
|
|
|
function do_configure {
|
|
|
|
DEPS_SCRIPT="$(get_distro_deps_script)"
|
|
if [ ! -z "$DEPS_SCRIPT" ]; then
|
|
info "Installing dependencies..."
|
|
source $DEPS_SCRIPT
|
|
else
|
|
error "Unable to configure dependencies"
|
|
if [ -z "$(which php)" ]; then
|
|
error "PHP not installed, the installer can not continue."
|
|
fi
|
|
fi
|
|
|
|
info "Configuring PHP..."
|
|
source deps/php.sh
|
|
|
|
}
|
|
|
|
function do_install {
|
|
|
|
if [ -f $1/hotfix ]; then
|
|
debug "Hotfix already installed, or at least something was found matching $1/hotfix"
|
|
question "Do you want to overwrite $1/hotfix?"
|
|
echo -n " Overwrite? [y/N]: "
|
|
read CONFIRMATION
|
|
case "$CONFIRMATION" in
|
|
"y"|"Y"|"yes")
|
|
debug "Installing into $1"
|
|
cp hotfix $1/hotfix
|
|
;;
|
|
*)
|
|
debug "Not overwriting $1/hotfix"
|
|
;;
|
|
esac
|
|
else
|
|
debug "Installing into $1"
|
|
cp hotfix $1/hotfix
|
|
fi
|
|
chmod +x $1/hotfix
|
|
|
|
if [ -f $HOME/.hotfix.conf ]; then
|
|
debug "~/.hotfix.conf already exists, will not overwrite"
|
|
else
|
|
debug "Copying hotfix.conf into ~/.hotfix.conf"
|
|
cp hotfix.conf $HOME/.hotfix.conf
|
|
fi
|
|
|
|
debug "Verifying that hotfix is callable..."
|
|
source ~/.profile &>/dev/null
|
|
source ~/.bashrc &>/dev/null
|
|
bash -c hotfix &>/dev/null
|
|
if [ $? == 0 ]; then
|
|
info "Hotfix successfully installed!"
|
|
else
|
|
echo 'test -d "$1" && export PATH="$1:$PATH"' >> ~/.bashrc
|
|
info "Your .bashrc file has been updated to include $1 on the PATH."
|
|
fi
|
|
info "Please re-open your terminal if the hotfix command doesn't work immediately."
|
|
|
|
}
|
|
|
|
info "Welcome to the automagic Hotfix installer."
|
|
debug "For security reasons, this installer will not install any signing keys. See the README.md for more information."
|
|
|
|
question "Where would you like to install Hotfix?"
|
|
hint "You probably want to leave this as it is and just press enter, unless you know what you are doing."
|
|
hint "If you wish to abort the installation, ress Ctrl-C now."
|
|
echo -n " Install directory [$HOME/bin]: "
|
|
read INSTALL_PATH
|
|
if [ -z $INSTALL_PATH ]; then
|
|
INSTALL_PATH="$HOME/bin"
|
|
fi
|
|
if [ ! -d $INSTALL_PATH ]; then
|
|
question "The directory $INSTALL_PATH does not exist. Do you want to create it?"
|
|
echo -n " Create directory? [Y/n]: "
|
|
read CONFIRMATION
|
|
case "$CONFIRMATION" in
|
|
"n"|"N"|"no")
|
|
error "Directory not created. Aborting."
|
|
exit
|
|
;;
|
|
*)
|
|
mkdir $INSTALL_PATH
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
info "Configuring system..."
|
|
do_configure
|
|
|
|
info "Installing hotfix..."
|
|
do_install "$INSTALL_PATH"
|