Install Scripts

pull/42/head
sfeakes 2018-12-04 10:58:26 -06:00
parent e7e8d4fb0e
commit a4ca5f0046
4 changed files with 138 additions and 38 deletions

View File

@ -1,22 +1,40 @@
#!/bin/bash #!/bin/bash
#
# Run using
# curl -s https://raw.githubusercontent.com/sfeakes/AqualinkD/master/extras/aqua.sh | bash -s --
#
# list latest release version (This is zip install)
# curl --silent "https://api.github.com/repos/sfeakes/AqualinkD/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")'
#
# list latest dev version
# curl --silent "https://raw.githubusercontent.com/sfeakes/AqualinkD/master/version.h" | grep AQUALINKD_VERSION | cut -d '"' -f 2 | tr '\n'
#
NAME=AqualinkD
#CWD=$(cd)
#cd ~
CWD=$(cd) HOMEDIR=~
cd ~ eval HOMEDIR=$HOMEDIR
BASE="./software/" BASE="$HOMEDIR/software/"
AQUA="$BASE/AqualinkD" AQUA="$BASE/AqualinkD"
AQUA_GIT="$BASE/AqualinkD/.git"
echoerr() { printf "%s\n" "$*" >&2; } echoerr() { printf "%s\n" "$*" >&2; }
function print_usage { function print_usage {
echoerr "No arguments supplied, please use use:-" echoerr "No arguments supplied, please use use:-"
echoerr "$0 install <- Install from scratch, delete any existing install (except configuration files)" echoerr "$0 release <- Download & install latest $NAME stable release."
echoerr "$0 upgrade <- Upgrade existing install" echoerr "$0 latest <- Download & install latest $NAME version. (development release)"
echoerr "$0 force_latest <- Force latest option (don't run any version checks)"
echoerr "$0 install <- Install to local filesystem, (config files will no be overwritten)"
echoerr "$0 clean <- Remove everything, including configuration files" echoerr "$0 clean <- Remove everything, including configuration files"
echoerr "" echoerr ""
} }
function upgrade_self { function upgrade_self {
echo "NOT UPGRADING SELF, MAKE SURE TO EDIT BEFORE COMMIT"
return;
if [ -f "$AQUA/extras/aqua.sh" ]; then if [ -f "$AQUA/extras/aqua.sh" ]; then
cp "$AQUA/extras/aqua.sh" $0 cp "$AQUA/extras/aqua.sh" $0
fi fi
@ -26,60 +44,139 @@ function git_install {
sudo apt-get install git sudo apt-get install git
} }
function local_version {
if [ -f $AQUA/version.h ]; then
echo `cat $AQUA/version.h | grep AQUALINKD_VERSION | cut -d '"' -f 2 | tr '\n' ' '`
else
echo 0
fi
}
function git_release_version {
echo `curl --silent "https://api.github.com/repos/sfeakes/AqualinkD/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")'`
}
function remove { function remove {
cd ~ #cd ~
if [ -d "$AQUA" ]; then if [ -d "$AQUA" ]; then
if [ -L "$AQUA" ]; then
unlink "$AQUA"
else
rm -rf "$AQUA" rm -rf "$AQUA"
fi fi
}
function new_install {
remove
cd ~
if [ ! -d "$BASE" ]; then
mkdir -p $BASE
fi fi
cd $BASE
git clone https://github.com/sfeakes/AqualinkD.git
} }
function upgrade { function isvalid_gitinstall {
cd ~ #cd "$AQUA"
cd $AQUA isgit=$(git --git-dir "$AQUA_GIT" status 2>&1)
git pull return $?
}
function development_version_download {
if isvalid_gitinstall; then
update
else
force_dev_download
fi
}
function force_dev_download {
remove
make-base
#cd $BASE
git clone "https://github.com/sfeakes/AqualinkD.git" "$AQUA"
}
function update {
#cd ~
#cd $AQUA
git --git-dir "$AQUA_GIT" pull
} }
function clean { function clean {
cd ~ #cd ~
sudo "$AQUA/release/install.sh" "clean" sudo "$AQUA/release/install.sh" "clean"
remove remove
} }
function install { function install {
cd ~ echo "Installing $NAME"
#cd ~
sudo "$AQUA/release/install.sh" sudo "$AQUA/release/install.sh"
} }
function make-base {
if [ ! -d "$BASE" ]; then
mkdir -p $BASE
fi
if [ ! -d "$BASE" ]; then
echoerr "Error Can't create $BASE";
exit 1;
fi
}
function release_version_download {
version=$(local_version)
git_version=$(git_release_version)
if [ "v$version" != "$git_version" ]; then
echo "Installing $NAME $git_version"
make-base
#cd $BASE
# This is correct way, but tar is made with crap dir structure
#tar_url=$(curl --silent "https://api.github.com/repos/sfeakes/AqualinkD/releases/latest" | grep -Po '"tarball_url": "\K.*?(?=")')
#curl --silent -L "$tar_url" | tar xz
# Use this tar instead, it's correct dir structure
curl --silent -L "https://github.com/sfeakes/AqualinkD/archive/$git_version.tar.gz" | tar xz -C "$AQUA" .
ver=$(echo $git_version | sed 's/^.//' )
if [ -d "$AQUA" ]; then
if [ -L "$AQUA" ]; then
unlink "$AQUA"
else
mv "$AQUA" "$AQUA-$RANDOM"
fi
ln -s "$BASE/AqualinkD-$ver" "$AQUA"
fi
else
echo "Local $NAME version $version is latest, not downloading"
fi
}
function check_git_installed {
# Check git is installed
command -v git >/dev/null 2>&1 || { echoerr "git is not installed. Installing"; git_install; }
command -v git >/dev/null 2>&1 || { echoerr "git is not installed. Aborting"; exit 1; }
}
function check_curl_installed {
command -v curl >/dev/null 2>&1 || { echoerr "curl is not installed. Installing"; exit 1; }
}
# Check something was passed # Check something was passed
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
print_usage print_usage
exit exit
fi fi
# Check git is installed
command -v git >/dev/null 2>&1 || { echoerr "git is not installed. Installing"; git_install; }
command -v git >/dev/null 2>&1 || { echoerr "git is not installed. Aborting"; exit 1; }
# Pass command line # Pass command line
if [ "$1" == "release" ]; then
if [ "$1" == "install" ]; then check_curl_installed
new_install release_version_download
elif [ "$1" == "upgrade" ]; then elif [ "$1" == "latest" ]; then
upgrade check_curl_installed
check_git_installed
development_version_download
elif [ "$1" == "force_latest" ]; then
check_curl_installed
check_git_installed
force_dev_download
#elif [ "$1" == "install" ]; then
# install
elif [ "$1" == "clean" ]; then elif [ "$1" == "clean" ]; then
clean clean
exit exit
@ -93,6 +190,6 @@ install
echo "Installed "`cat $AQUA/version.h | cut -d '"' -f 2 | tr '\n' ' '` echo "Installed "`cat $AQUA/version.h | cut -d '"' -f 2 | tr '\n' ' '`
upgrade_self upgrade_self
cd $CWD #cd $CWD
echo "Please make sure to read release notes https://github.com/sfeakes/AqualinkD/blob/master/README.md#release" echo "Please make sure to read release notes https://github.com/sfeakes/AqualinkD/blob/master/README.md#release"

Binary file not shown.

View File

@ -41,6 +41,7 @@ SERVICE_EXISTS=$(echo $?)
# Clean everything if requested. # Clean everything if requested.
if [ "$1" == "clean" ]; then if [ "$1" == "clean" ]; then
echo "Deleting install" echo "Deleting install"
systemctl disable $SERVICE > /dev/null 2>&1
if [ -f $BINLocation/$BIN ]; then if [ -f $BINLocation/$BIN ]; then
rm -f $BINLocation/$BIN rm -f $BINLocation/$BIN
fi fi
@ -66,13 +67,13 @@ cp $BUILD/$BIN $BINLocation/$BIN
cp $BUILD/$SRV $SRVLocation/$SRV cp $BUILD/$SRV $SRVLocation/$SRV
if [ -f $CFGLocation/$CFG ]; then if [ -f $CFGLocation/$CFG ]; then
echo "Config exists, did not copy new config, you may need to edit existing! $CFGLocation/$CFG" echo "AqualinkD config exists, did not copy new config, you may need to edit existing! $CFGLocation/$CFG"
else else
cp $BUILD/$CFG $CFGLocation/$CFG cp $BUILD/$CFG $CFGLocation/$CFG
fi fi
if [ -f $DEFLocation/$DEF ]; then if [ -f $DEFLocation/$DEF ]; then
echo "Defaults exists, did not copy new defaults to $DEFLocation/$DEF" echo "AqualinkD defaults exists, did not copy new defaults to $DEFLocation/$DEF"
else else
cp $BUILD/$DEF.defaults $DEFLocation/$DEF cp $BUILD/$DEF.defaults $DEFLocation/$DEF
fi fi
@ -92,7 +93,7 @@ if [ ! -d "$WEBLocation" ]; then
fi fi
if [ -f "$WEBLocation/config.js" ]; then if [ -f "$WEBLocation/config.js" ]; then
echo "$WEBLocation/config.js exists, did not copy overight, please make sure to update manually" echo "AqualinkD web config exists, did not copy new config, you may need to edit existing $WEBLocation/config.js "
rsync -avq --exclude='config.js' $BUILD/../web/* $WEBLocation rsync -avq --exclude='config.js' $BUILD/../web/* $WEBLocation
else else
cp -r $BUILD/../web/* $WEBLocation cp -r $BUILD/../web/* $WEBLocation
@ -105,5 +106,7 @@ systemctl daemon-reload
if [ $SERVICE_EXISTS -eq 0 ]; then if [ $SERVICE_EXISTS -eq 0 ]; then
echo "Starting daemon $SERVICE" echo "Starting daemon $SERVICE"
systemctl start $SERVICE systemctl start $SERVICE
else
echo "Please edit $CFGLocation/$CFG, then start AqualinkD service"
fi fi

View File

@ -1,4 +1,4 @@
#define AQUALINKD_NAME "Aqualink Daemon" #define AQUALINKD_NAME "Aqualink Daemon"
#define AQUALINKD_VERSION "1.2.4" #define AQUALINKD_VERSION "1.2.5"