Skip to content
Permalink
Browse files

update scripts

  • Loading branch information...
TotallyNotElite committed Oct 27, 2019
1 parent 5e253f1 commit c857349218089b893f632edd3681fecb8370ed2b
Showing with 111 additions and 57 deletions.
  1. +0 −17 install-all
  2. +11 −0 scripts/dependencycheck
  3. +58 −14 scripts/migrations
  4. +42 −26 scripts/updater
@@ -5,23 +5,6 @@ RUNCMD="sudo -u $RUNUSER"

set -e

# install all dependencies
./scripts/dependencycheck

#
# Update cathook
#
if [ ! -d "./.git" ]; then
$RUNCMD git init
$RUNCMD git remote add origin https://github.com/nullworks/cathook
fi

#
# Set config version for update script
#

$RUNCMD bash -c ". ./scripts/config.shlib; cfg_write ./scripts/updater-preferences version 2"

#
# Build cathook
#
@@ -1,9 +1,20 @@
#!/usr/bin/env bash

# $1 Git only

GIT=${1:-false}

arch_packages=(git boost cmake make gcc gdb lib32-sdl2 lib32-glew lib32-freetype2 rsync lib32-libglvnd dialog)
ubuntu_packages=(software-properties-common build-essential git g++ g++-multilib libboost-all-dev gdb libsdl2-dev:i386 libglew-dev:i386 libfreetype6-dev:i386 cmake dialog rsync)
fedora_packages=(cmake dialog make gcc-c++ glibc-devel.i686 freetype-devel.i686 SDL2-devel.i686 glew-devel.i686 boost-devel.i686 rsync gdb git)

# Check if we should only install git
if [ "$GIT" == true ]; then
arch_packages=(git)
ubuntu_packages=(git)
fedora_packages=(git)
fi

function requestPermissions {
string=$@
# Prefer GUI question
@@ -1,6 +1,14 @@
#!/usr/bin/env bash

# $3 Init
# $1 TUI
# $2 INIT
# $3 Pre update

CURR_VERSION=3

TUI=${1:-false}
INIT=${2:-false}
PRE_UPDATE=${3:-false}

set -e

@@ -17,26 +25,62 @@ if [ ! -t 0 ]; then
fi

#
# Init goes here
# Git check
#

if [ "$3" == true ]; then
cfg_write $configfile update_channel stable
cfg_write $configfile version 3
if [ "$PRE_UPDATE" == "true" ]; then
if [ ! -x "$(command -v git)" ]; then
# install only git
echo git not installed!
./scripts/dependencycheck true
fi
if [ ! -d "./.git" ]; then
git init
git remote add origin https://github.com/nullworks/cathook
fi
fi

version="$(cfg_read $configfile version)"

#
# Init goes here
#
function init() {
if [ "$INIT" == true ]; then
cfg_write $configfile update_channel stable
cfg_write $configfile version $CURR_VERSION
fi
}

#
# Migrations go here
#
function migrations() {
exists=true
cfg_haskey $configfile version || exists=false
if [ "$exists" == true ]; then
version="$(cfg_read $configfile version)"
else
# No version string. Nothing we can do.
return 0
fi

if (( $version > $CURR_VERSION )); then
cfg_write $configfile version $CURR_VERSION
fi

exists=true

if [ "$version" == 1 ] || [ "$version" == 2 ]; then
cfg_write $configfile version 3
if [ -d "./build/CMakeFiles/cathook.dir" ]; then
rm -r ./build/CMakeFiles/cathook.dir
if [ "$version" == 1 ] || [ "$version" == 2 ]; then
cfg_write $configfile version 3
if [ -d "./build/CMakeFiles/cathook.dir" ]; then
rm -r ./build/CMakeFiles/cathook.dir
fi
fi
}

if [ "$PRE_UPDATE" == "true" ] && [ "$INIT" == "true" ]; then
# Our job is done here
exit
fi

if [ "$INIT" == true ]; then
init
else
migrations
fi
@@ -4,9 +4,9 @@
# $2 Disable TUI
# $3 Init

ARG1=${1:-false}
ARG2=${2:-false}
ARG3=${3:-false}
AUTO_UPDATER_ENABLED=${1:-false}
DISABLE_TUI=${2:-false}
INIT=${3:-false}

set -e

@@ -29,34 +29,39 @@ echo $$ > ${LOCKFILE}

. ./scripts/config.shlib

# Run migrations
exists=true
cfg_haskey $configfile update_channel || exists=false
if [ "$exists" == true ]; then
update_channel="$(cfg_read $configfile update_channel)"
if [ ! -e ${configfile} ]; then
touch ${configfile}
fi
if [ "$update_channel" != "developer" ] && [ "$ARG3" == false ]; then
./scripts/migrations $ARG1 $ARG2 false || exit 0
fi

# Check if all required packages are installed
./scripts/dependencycheck

#Check if TUI is available
tui=true
dialog=true
if [ ! -t 0 ]; then
tui=false
fi
if [ "$ARG2" == "true" ]; then
if [ "$DISABLE_TUI" == "true" ]; then
tui=false
fi
if [ ! -x "$(command -v dialog)" ] && [ "$tui" == true ]; then
tui=false
echo -e "\033[1;31mTerminal UI NOT supported! Install \"dialog\"! \033[0m"
if [ ! -x "$(command -v dialog)" ] || [ "$tui" == false ]; then
dialog=false
if [ "$tui" == true ]; then
echo -e "\033[1;31mTerminal UI NOT supported! Install \"dialog\"! \033[0m"
fi
fi

# Run migrations
exists=true
cfg_haskey $configfile update_channel || exists=false
if [ "$exists" == true ]; then
update_channel="$(cfg_read $configfile update_channel)"
fi
if [ "$update_channel" != "developer" ]; then
./scripts/migrations $tui $INIT true || exit 1
fi

exists=true
cfg_haskey $configfile autoupdater || exists=false
if [ "$tui" == true ] && [ "$exists" == false ]; then
if [ "$dialog" == true ] && [ "$exists" == false ]; then
value=true
response=255
while [ "$response" != 0 ] && [ "$response" != 1 ]; do
@@ -71,7 +76,7 @@ fi

exists=true
cfg_haskey $configfile autoupdater || exists=false
if [ "$ARG1" == "true" ]; then
if [ "$AUTO_UPDATER_ENABLED" == "true" ]; then
if [ $exists == false ] || [ "$(cfg_read $configfile autoupdater)" == false ]; then
exit 0;
fi
@@ -82,11 +87,18 @@ fi

function performupdate() {
# If init, then update_channel isn't set yet. Assume stable.
if [ "$ARG3" == true ]; then
if [ "$INIT" == true ]; then
update_channel="stable"
else
#get update channel from config
update_channel="$(cfg_read $configfile update_channel)"
exists=true
cfg_haskey $configfile autoupdater || exists=false
cfg_haskey $configfile version || exists=false
if [ "$exists" == true ]; then
update_channel="$(cfg_read $configfile update_channel)"
else
update_channel="invalid"
fi
fi

if [ "$update_channel" == "stable" ]; then
@@ -96,21 +108,25 @@ function performupdate() {
elif [ "$update_channel" == "developer" ]; then
echo -e "\033[1;33m\nWarning! Running in developer mode! Expect issues!\n\033[0m" && git pull origin || { echo -e "\033[1;31m\n\nFailed to pull from github!\n\033[0m"; exit 1; }
else
if [ "$tui" == true ]; then
if [ "$dialog" == true ]; then
value=true
dialog --keep-tite --title "Updater" --yesno "Unknown update channel. Restore to stable update channel?" 10 25 || value=false
dialog --keep-tite --title "Updater" --yesno "Unknown update channel or version. Restore to stable update channel and reset version?" 10 25 || value=false
if [ "$value" == true ]; then
cfg_write $configfile update_channel stable
# force init
./scripts/migrations $tui true false || exit 1
fi
fi
exit 1
fi

# Run migrations
if [ "$update_channel" != "developer" ]; then
./scripts/migrations $ARG1 $ARG2 $ARG3 || exit 0
./scripts/migrations $tui $INIT false || exit 1
fi

# Check if all required packages are installed
./scripts/dependencycheck

#submodules
if [ "$update_channel" == "developer" ]; then
git submodule update --init --recursive

0 comments on commit c857349

Please sign in to comment.
You can’t perform that action at this time.