From 20223303942e9172443bcf0032c1a75941b36a50 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sun, 29 Sep 2019 15:32:58 +0200 Subject: [PATCH 1/3] Update script migration support Use this when an update needs to do other things like deleting files, etc --- scripts/migrations | 49 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/updater | 40 +++++++++---------------------------- 2 files changed, 58 insertions(+), 31 deletions(-) create mode 100755 scripts/migrations diff --git a/scripts/migrations b/scripts/migrations new file mode 100755 index 00000000..417795ac --- /dev/null +++ b/scripts/migrations @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +set -e + +configfile="./scripts/updater-preferences" +. ./scripts/config.shlib + +# Migrate pre config lib configs +exists=true +cfg_haskey $configfile version || exists=false +if [ "$exists" == false ]; then + if [ -f $configfile ]; then + value=$(cat $configfile) + rm $configfile + fi + echo "" > $configfile + cfg_write $configfile version 1 + if [ "$(git rev-parse --is-shallow-repository)" == "true" ]; then + cfg_write $configfile update_channel stable + else + cfg_write $configfile update_channel developer + fi + if [ -f $configfile ]; then + if [ "$value" == true ] || [ "$value" == false ]; then + cfg_write $configfile autoupdater $value + fi + fi +fi + +version="$(cfg_read $configfile version)" + +tui=true +if [ ! -x "$(command -v dialog)" ]; then + tui=false + echo -e "\033[1;31mTerminal UI NOT supported! Install \"dialog\"! \033[0m" +fi +if [ ! -t 0 ]; then + tui=false +fi + +# +# Migrations go here +# + +exists=true +cfg_haskey $configfile update_channel || exists=false +if [ "$exists" == false ]; then + cfg_write $configfile update_channel stable +fi diff --git a/scripts/updater b/scripts/updater index b75fe3d8..a8232e95 100755 --- a/scripts/updater +++ b/scripts/updater @@ -19,29 +19,13 @@ fi trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT echo $$ > ${LOCKFILE} -. ./scripts/config.shlib +#Check if all required packages are installed +./scripts/dependencycheck -# Migrate existing configs -exists=true -cfg_haskey $configfile version || exists=false -if [ "$exists" == false ]; then - if [ -f $configfile ]; then - value=$(cat $configfile) - rm $configfile - fi - echo "" > $configfile - cfg_write $configfile version 1 - if [ "$(git rev-parse --is-shallow-repository)" == "true" ]; then - cfg_write $configfile update_channel stable - else - cfg_write $configfile update_channel developer - fi - if [ -f $configfile ]; then - if [ "$value" == true ] || [ "$value" == false ]; then - cfg_write $configfile autoupdater $value - fi - fi -fi +# Run migrations +./scripts/migrations || exit 0 + +. ./scripts/config.shlib tui=true if [ ! -x "$(command -v dialog)" ]; then @@ -67,12 +51,6 @@ if [ "$tui" == true ] && [ "$exists" == false ]; then cfg_write $configfile autoupdater $value fi -exists=true -cfg_haskey $configfile update_channel || exists=false -if [ "$exists" == false ]; then - cfg_write $configfile update_channel stable -fi - exists=true cfg_haskey $configfile autoupdater || exists=false if [ "$1" == "--autoupdater" ]; then @@ -84,9 +62,6 @@ if [ "$1" == "--autoupdater" ]; then echo -e "\033[1;34m \n \nAuto Updater: Updating cathook in the background\n\033[0m" fi -#Check if all required packages are installed -./scripts/dependencycheck - function performupdate() { #get update channel from config update_channel="$(cfg_read $configfile update_channel)" @@ -108,6 +83,9 @@ function performupdate() { exit 1 fi + # Run migrations + ./scripts/migrations || exit 0 + proccount=$(grep -c '^processor' /proc/cpuinfo) if [ "$AUTOUPDATER" == true ]; then proccount=1 From 34fd3e3c966fbfbb488603b257585747d6b5bfa3 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sun, 29 Sep 2019 15:45:24 +0200 Subject: [PATCH 2/3] Update install-all Outsource a lot of code to the update script --- README.md | 2 +- install-all | 23 +++++------------------ scripts/dependencycheck | 14 ++------------ 3 files changed, 8 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index de9e5eff..b2d55189 100755 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ and a lot of useful features, including ## Automatic: (Ubuntu 17.10+/Arch based only) Run in terminal: -* `wget -O - https://raw.githubusercontent.com/nullworks/One-in-all-cathook-install/master/install-all | bash` +* `bash <(wget -qO- https://raw.githubusercontent.com/nullworks/One-in-all-cathook-install/master/install-all)` ## Manual (Outdated): You need CMake to build cathook, CMake should take care of dependencies diff --git a/install-all b/install-all index 48d170c4..858f4dbe 100755 --- a/install-all +++ b/install-all @@ -2,17 +2,10 @@ RUNUSER="sudo -u $LOGNAME" -# -# Install git in case this is a install-all only install -# -if [ -x "$(command -v pacman)" ]; then - sudo pacman -S --needed --noconfirm git -elif [ -x "$(command -v apt-get)" ]; then - sudo apt-get install -y git -else - echo -e "\033[1;31m\nCathook autoinstall is not supported on this system! Please install the following packages before continuing: Git, Boost + Headers, CMake, Gcc with 32 bit support, Gdb, 32 Bit SDL + Headers, 32 Bit Glew + Headers, 32 Bit Freetype 2 + Headers, Rsync, 32 Bit libglvnd\n\033[0m" - read -p "Press enter to continue or CTRL+C to cancel." -fi +set -e + +# install all dependencies +./scripts/dependencycheck # # Update cathook @@ -25,9 +18,6 @@ fi $RUNUSER git fetch --force --depth 1 origin refs/tags/latest:refs/tags/latest && $RUNUSER git reset --hard latest # pull changes from github $RUNUSER git submodule update --depth 1 --init --recursive # update/init submodules -# install all dependencies and allow non interactive install -./scripts/dependencycheck true - # # Set config version for update script # @@ -38,7 +28,4 @@ $RUNUSER bash -c ". ./scripts/config.shlib; cfg_write ./scripts/updater-preferen # Build cathook # -$RUNUSER mkdir -p ./build; pushd build #create a directory for building cathook -$RUNUSER cmake ..;$RUNUSER make -j$(grep -c '^processor' /proc/cpuinfo) # create makefile and build using all available threads -sudo make data # create /opt/cathook/data -popd; cd .. +$RUNUSER ./update diff --git a/scripts/dependencycheck b/scripts/dependencycheck index 98994cf6..087bc214 100755 --- a/scripts/dependencycheck +++ b/scripts/dependencycheck @@ -3,12 +3,6 @@ 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) -if [ "$1" == true ]; then - allow_non_interactive=true -else - allow_non_interactive=false -fi - if [ -x "$(command -v pacman)" ]; then pacman -Qi "${arch_packages[@]}" > /dev/null 2>&1 out=$? @@ -26,8 +20,6 @@ if [ -x "$(command -v pacman)" ]; then if [ "$out" != 0 ]; then exit fi - elif [ "$allow_non_interactive" == false ]; then - exit fi sudo pacman -S --noconfirm --needed "${arch_packages[@]}" fi @@ -48,15 +40,13 @@ elif [ -x "$(command -v apt-get)" ]; then if [ "$out" != 0 ]; then exit fi - elif [ "$allow_non_interactive" == false ]; then - exit fi sudo apt-get update sudo apt-get install -y software-properties-common sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y sudo dpkg --add-architecture i386 - sudo apt update - sudo apt install -y "${ubuntu_packages[@]}" + sudo apt-get update + sudo apt.get install -y "${ubuntu_packages[@]}" fi else echo -e "\033[1;33m\nWarning! Automatic package installation is not supported!\n\033[0m" From ab1521ff060e76e202fe5a45ef632d3f5c499856 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sun, 29 Sep 2019 16:49:58 +0200 Subject: [PATCH 3/3] fix typo --- scripts/dependencycheck | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/dependencycheck b/scripts/dependencycheck index 087bc214..cfe0f8e8 100755 --- a/scripts/dependencycheck +++ b/scripts/dependencycheck @@ -46,7 +46,7 @@ elif [ -x "$(command -v apt-get)" ]; then sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y sudo dpkg --add-architecture i386 sudo apt-get update - sudo apt.get install -y "${ubuntu_packages[@]}" + sudo apt-get install -y "${ubuntu_packages[@]}" fi else echo -e "\033[1;33m\nWarning! Automatic package installation is not supported!\n\033[0m"