diff --git a/COPYRIGHT.md b/COPYRIGHT.md index e9de0e5..3285021 100644 --- a/COPYRIGHT.md +++ b/COPYRIGHT.md @@ -1,5 +1,5 @@ -* Copyright © 2018-2023 Matteo Corti +* Copyright © 2018-2024 Matteo Corti with the following individuals added to the list of contributing authors diff --git a/ChangeLog b/ChangeLog index ef1cca7..99148cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2024-01-30 Matteo Corti + + * update.sh: added Steam support + 2023-09-04 Matteo Corti * update.sh: added --no-* options to skip updates diff --git a/NEWS.md b/NEWS.md index 301e846..8d107cb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +* 2024-01-30, Version 2.4.0 + * Steam support * 2023-10-01, Version 2.3.0 * Options can be specified in the ```~/.update.sh.rc``` file (no documentation yet) * 2023-09-04, Version 2.2.0 diff --git a/README.md b/README.md index a324a45..6fb5273 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ - © Matteo Corti, 2018-2023 + © Matteo Corti, 2018-2024 ![](https://img.shields.io/github/v/release/matteocorti/update.sh) ![](https://img.shields.io/github/downloads/matteocorti/update.sh/latest/total) ![](https://img.shields.io/github/downloads/matteocorti/update.sh/total) ![](https://img.shields.io/github/license/matteocorti/update.sh) ![](https://img.shields.io/github/stars/matteocorti/update.sh) ![](https://img.shields.io/github/forks/matteocorti/update.sh) @@ -18,6 +18,7 @@ Updates a macOS system. Following software packages are analyzed and automatical - Ruby dependencies - Homebrew and installed packages - MacPorts and installed ports + - Steam games ## Usage @@ -44,9 +45,11 @@ Options: --no-msupdate do not update Microsoft products --no-perl do not update Perl and CPAN modules with Perlbrew --no-ruby do not update ruby + --no-steam do not update steam --perl update Perl and CPAN modules with Perlbrew -q,--quiet minimal output --ruby update ruby + --steam update Steam -v,--verbose verbose output Report bugs to https://github.com/matteocorti/update.sh/issues diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index c838fa1..e81dfa7 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1 +1 @@ -Options can be specified in the ```~/.update.sh.rc``` file (no documentation yet) +Steam support diff --git a/VERSION b/VERSION index 276cbf9..197c4d5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.3.0 +2.4.0 diff --git a/update.sh b/update.sh index 5553924..1b185db 100755 --- a/update.sh +++ b/update.sh @@ -1,8 +1,10 @@ #!/bin/sh -# Copyright (c) 2018-2023 Matteo Corti +# Copyright (c) 2018-2024 Matteo Corti -VERSION=2.3.0 +VERSION=2.4.0 + +SIGNALS="HUP INT QUIT TERM ABRT" VERBOSE="" CLEAR="" @@ -13,6 +15,55 @@ error() { exit 1 } +create_temporary_file() { + + # create a temporary file + # mktemp is not always available (e.g., on AIX) + # we could use https://stackoverflow.com/questions/10224921/how-to-create-a-temporary-file-with-portable-shell-in-a-secure-way + # but on some systems od -N4 -tu /dev/random takes seconds (?) to execute + + if [ -n "${MKTEMP}" ]; then + TEMPFILE="$(mktemp "${TMPDIR}/XXXXXX" 2>/dev/null)" + else + TEMPFILE=${TMPDIR}/XXX-$(od -N4 -tu /dev/random | head -n 1 | sed 's/ *$//' | sed 's/.* //') + touch "${TEMPFILE}" + fi + + if [ -z "${TEMPFILE}" ] || [ ! -w "${TEMPFILE}" ]; then + echo 'temporary file creation failure.' 1>&2 + fi + + # add the file to the list of temporary files + TEMPORARY_FILES="${TEMPORARY_FILES} ${TEMPFILE}" + +} + +remove_temporary_files() { + # shellcheck disable=SC2086 + if [ -n "${TEMPORARY_FILES}" ]; then + rm -f ${TEMPORARY_FILES} + fi +} + +cleanup() { + remove_temporary_files + # shellcheck disable=SC2086 + trap - ${SIGNALS} + exit +} + +################################################################################ +# trap passing the signal name +# see https://stackoverflow.com/questions/2175647/is-it-possible-to-detect-which-trap-signal-in-bash/2175751#2175751 +trap_with_arg() { + func="$1" + shift + for sig; do + # shellcheck disable=SC2064 + trap "${func} ${sig}" "${sig}" + done +} + run_command() { COMMAND="$1" @@ -61,9 +112,11 @@ usage() { echo " --no-msupdate do not update Microsoft products" echo " --no-perl do not update Perl and CPAN modules with Perlbrew" echo " --no-ruby do not update ruby" + echo " --no-steam do not update steam" echo " --perl update Perl and CPAN modules with Perlbrew" echo " -q,--quiet minimal output" echo " --ruby update ruby" + echo " --steam update Steam" echo " -v,--verbose verbose output" echo echo "Report bugs to https://github.com/matteocorti/update.sh/issues" @@ -74,11 +127,16 @@ usage() { ALL=1 # source the settings file -if [ -r "${HOME}/.update.sh.rc" ] ; then +if [ -r "${HOME}/.update.sh.rc" ]; then # shellcheck disable=SC1091 . "${HOME}/.update.sh.rc" fi +# Cleanup before program termination +# Using named signals to be POSIX compliant +# shellcheck disable=SC2086 +trap_with_arg cleanup ${SIGNALS} + while true; do case "$1" in @@ -166,6 +224,10 @@ while true; do NO_RUBY=1 shift ;; + --no-steam) + NO_STEAM=1 + shift + ;; --perl) PERL=1 ALL= @@ -185,6 +247,11 @@ while true; do ALL= shift ;; + --steam) + STEAM=1 + ALL= + shift + ;; -v | --verbose) VERBOSE=1 echo "Enabling verbose output" @@ -216,6 +283,7 @@ if [ -n "${ALL}" ]; then PERL=1 PORT=1 RUBY=1 + STEAM=1 fi if [ -n "${NO_ADOBE}" ]; then @@ -245,6 +313,9 @@ fi if [ -n "${NO_RUBY}" ]; then RUBY= fi +if [ -n "${NO_STEAM}" ]; then + STEAM= +fi if [ -n "${CLEAR}" ]; then clear @@ -269,6 +340,62 @@ if [ -n "${MAC_UPDATER}" ] && [ -x /Applications/MacUpdater.app/Contents/Resourc fi +if [ -n "${STEAM}" ]; then + + if command -v steamcmd >/dev/null 2>&1; then + + if [ -z "${QUIET}" ]; then + echo + echo "##############################################################################" + echo "# Steam${NAME}" + echo "#" + echo + fi + + # https://stackoverflow.com/questions/56573277/fabric-framework-can-t-be-opened-because-it-is-from-an-unidentified-developer + sudo spctl --master-disable + + create_temporary_file + steamcmd_script=${TEMPFILE} + + # get app IDs + app_ids=$(grep appid ~/Library/Application\ Support/Steam/steamapps/appmanifest*acf | + sed 's/.*"appid".*"\([0-9]*\)".*/\1/') + + for app_id in ${app_ids}; do + + if [ -z "${QUIET}" ]; then + echo "Updating Steam app '${app_id}'" + fi + + cat <<____STEAM >"${steamcmd_script}" +login anonymous +app_update ${app_id} +quit +quit + +____STEAM + + if [ -z "${QUIET}" ]; then + run_command "steamcmd runscript < ${steamcmd_script}" + else + run_command "steamcmd runscript < ${steamcmd_script} > /dev/null" + fi + + done + + sudo spctl --master-disable + + else + + if [ -z "${QUIET}" ]; then + echo 'steamcmd non installed: skipping Steam updates' + fi + + fi + +fi + if [ -n "${MSUPDATE}" ] && [ -x /Library/Application\ Support/Microsoft/MAU2.0/Microsoft\ AutoUpdate.app/Contents/MacOS/msupdate ]; then if [ -z "${QUIET}" ]; then @@ -413,9 +540,9 @@ if [ -n "${BREW}" ]; then fi -if [ -n "${EMACS}" ] ; then +if [ -n "${EMACS}" ]; then - if [ -x /Applications/Emacs.app/Contents/MacOS/emacs-nw ] ; then + if [ -x /Applications/Emacs.app/Contents/MacOS/emacs-nw ]; then if [ -z "${QUIET}" ]; then echo @@ -431,8 +558,7 @@ if [ -n "${EMACS}" ] ; then fi - -if [ -n "${RUBY}" ] ; then +if [ -n "${RUBY}" ]; then if command -v bundle >/dev/null 2>&1; then @@ -510,3 +636,5 @@ fi if [ -z "${QUIET}" ]; then echo fi + +remove_temporary_files diff --git a/update.sh.completion b/update.sh.completion index 0c8f10a..96eccd6 100644 --- a/update.sh.completion +++ b/update.sh.completion @@ -13,7 +13,7 @@ _update.sh() { # only the autocompletion with long options is implemented: long options are more readable and quick to enter since we are # using autocompletion. # - opts="--adobe --apple --brew --emacs --macupdater --mas --msupdate --perl --clear --help --name --no-adobe --no-apple --no-brew --no-emacs --no-macupdater --no-mas --no-msupdate --no-perl --no-ruby --quiet --verbose --ruby" + opts="--adobe --apple --brew --emacs --macupdater --mas --msupdate --perl --clear --help --name --no-adobe --no-apple --no-brew --no-emacs --no-macupdater --no-mas --no-msupdate --no-perl --no-ruby --no-steam --quiet --verbose --ruby --steam" if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]]; then # shellcheck disable=2207