From 138a1e04720e9694aefc03d285e0526f247c5603 Mon Sep 17 00:00:00 2001 From: Jacob Hrbek Date: Sun, 5 Jul 2020 05:14:31 +0200 Subject: [PATCH] Stub --- .github/workflows/bash.yml | 67 +++ .github/workflows/bootstrap-test.yaml | 20 + .github/workflows/exherbo-build.yml | 20 + .github/workflows/shell.yml | 66 +++ Makefile | 25 ++ bootstrap.sh | 403 ++++++++++++++++-- dist/README.md | 3 + dist/paludis/README.md | 1 + dist/paludis/exherbo/metadata/about.conf | 4 + dist/paludis/exherbo/metadata/arch.conf | 2 + dist/paludis/exherbo/metadata/categories.conf | 1 + .../exherbo/metadata/info/packages.conf | 2 + .../metadata/info/repository_mask.conf | 6 + .../gamemode/gamemode-1.5.1.exheres-0 | 9 + .../games-util/gamemode/gamemode.exlib | 45 ++ dist/paludis/exherbo/profiles/repo_name | 1 + 16 files changed, 641 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/bash.yml create mode 100644 .github/workflows/bootstrap-test.yaml create mode 100644 .github/workflows/exherbo-build.yml create mode 100644 .github/workflows/shell.yml create mode 100644 Makefile create mode 100644 dist/README.md create mode 100644 dist/paludis/README.md create mode 100644 dist/paludis/exherbo/metadata/about.conf create mode 100644 dist/paludis/exherbo/metadata/arch.conf create mode 100644 dist/paludis/exherbo/metadata/categories.conf create mode 100644 dist/paludis/exherbo/metadata/info/packages.conf create mode 100644 dist/paludis/exherbo/metadata/info/repository_mask.conf create mode 100644 dist/paludis/exherbo/packages/games-util/gamemode/gamemode-1.5.1.exheres-0 create mode 100644 dist/paludis/exherbo/packages/games-util/gamemode/gamemode.exlib create mode 100644 dist/paludis/exherbo/profiles/repo_name diff --git a/.github/workflows/bash.yml b/.github/workflows/bash.yml new file mode 100644 index 00000000..b18657d7 --- /dev/null +++ b/.github/workflows/bash.yml @@ -0,0 +1,67 @@ +name: Bash + +# Relevant to events - https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows +on: + pull_request: + types: [synchronize, opened, reopened, ready_for_review] + paths: + - '**.bash' + - "tools/dockerfreeze" + +jobs: + # Linting + lint: + runs-on: ubuntu-latest + container: debian:stable + steps: + - name: Installing dependencies.. + run: | + # Sync repos + # Check for git + if ! apt list --installed 2>/dev/null | grep -qP "^git\/stable.*"; then + # Check if we can install git + if ! apt list | grep -qP "^git\/stable.*"; then + apt update + elif apt list | grep -qP "^git\/stable.*"; then + true + else + exit 255 + fi + # Install git + apt install -y git + elif apt list --installed 2>/dev/null | grep -qP "^git\/stable.*"; then + true + else + exit 255 + fi + # Check for shellcheck + if ! apt list --installed 2>/dev/null | grep -qP "^shellcheck\s{1}-.*"; then + # Check if we can install shellcheck + if ! apt list | grep -qP "^shellcheck\s{1}-.*"; then + apt update + elif apt list | grep -qP "^shellcheck\s{1}-.*"; then + true + else + exit 255 + fi + # Install shellcheck + apt install -y shellcheck + elif apt list --installed 2>/dev/null | grep -qP "^shellcheck\s{1}-.*"; then + true + else + exit 255 + fi + - name: Pulling git dir.. + uses: actions/checkout@v2 + - name: Processing files.. + # Make sure that bash is used + shell: bash + run: | + cd "$GITHUB_WORKSPACE" + + # Process files + ## NOTICE: Do not use for loop to avoid pitfall https://mywiki.wooledge.org/BashPitfalls#pf1 + git --git-dir="$GITHUB_WORKSPACE/.git" ls-files -z -- '*.bash' tools/dockerfreeze | while IFS= read -rd '' file; do + printf 'linting bash file %s\n' "$file" + shellcheck --external-sources --shell=bash "$file" + done diff --git a/.github/workflows/bootstrap-test.yaml b/.github/workflows/bootstrap-test.yaml new file mode 100644 index 00000000..b0c09c74 --- /dev/null +++ b/.github/workflows/bootstrap-test.yaml @@ -0,0 +1,20 @@ +name: bootstrap-test + +# Relevant to events - https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows +on: + pull_request: + types: [synchronize, opened, reopened, ready_for_review] + paths: + - 'bootstrap.sh' + +jobs: + # Linting + lint: + runs-on: ubuntu-latest + container: debian:stable + steps: + - name: FIXME + # Make sure that bash is used + shell: bash + run: | + printf '%s\n' "FIXME" diff --git a/.github/workflows/exherbo-build.yml b/.github/workflows/exherbo-build.yml new file mode 100644 index 00000000..c2be46ec --- /dev/null +++ b/.github/workflows/exherbo-build.yml @@ -0,0 +1,20 @@ +name: Exherbo + +# Relevant to events - https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows +on: + pull_request: + types: [synchronize, opened, reopened, ready_for_review] + paths: + - 'dist/paludis/exherbo' + +jobs: + # Linting + lint: + runs-on: ubuntu-latest + container: exherbo:exherbo-x86_64-pc-linux-gnu-base + steps: + - name: FIXME + # Make sure that bash is used + shell: bash + run: | + printf '%s\n' "FIXME" diff --git a/.github/workflows/shell.yml b/.github/workflows/shell.yml new file mode 100644 index 00000000..50af7a35 --- /dev/null +++ b/.github/workflows/shell.yml @@ -0,0 +1,66 @@ +name: Shell + +# Relevant to events - https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows +on: + pull_request: + types: [synchronize, opened, reopened, ready_for_review] + paths: + - '**.sh' + +jobs: + # Linting + lint: + runs-on: ubuntu-latest + container: debian:stable + steps: + - name: Installing dependencies.. + run: | + # Sync repos + # Check for git + if ! apt list --installed 2>/dev/null | grep -qP "^git\/stable.*"; then + # Check if we can install git + if ! apt list | grep -qP "^git\/stable.*"; then + apt update + elif apt list | grep -qP "^git\/stable.*"; then + true + else + exit 255 + fi + # Install git + apt install -y git + elif apt list --installed 2>/dev/null | grep -qP "^git\/stable.*"; then + true + else + exit 255 + fi + # Check for shellcheck + if ! apt list --installed 2>/dev/null | grep -qP "^shellcheck\s{1}-.*"; then + # Check if we can install shellcheck + if ! apt list | grep -qP "^shellcheck\s{1}-.*"; then + apt update + elif apt list | grep -qP "^shellcheck\s{1}-.*"; then + true + else + exit 255 + fi + # Install shellcheck + apt install -y shellcheck + elif apt list --installed 2>/dev/null | grep -qP "^shellcheck\s{1}-.*"; then + true + else + exit 255 + fi + - name: Pulling git dir.. + uses: actions/checkout@v2 + - name: Processing files.. + # Make sure that bash is used + shell: bash + run: | + cd "$GITHUB_WORKSPACE" + + # Process files + ## NOTICE: Do not use for loop to avoid pitfall https://mywiki.wooledge.org/BashPitfalls#pf1 + git --git-dir="$GITHUB_WORKSPACE/.git" ls-files -z -- '*.sh' | while IFS= read -rd '' file; do + printf 'linting shell file %s\n' "$file" + shellcheck --external-sources --shell=sh "$file" + done diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..160ef206 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +all: + # FIXME: Add nice message + @ exit 2 + +build: + @ bootstrap.sh build + +exherbo-docker-test: + @ sudo docker run \ + --interactive \ + --tty \ + --volume "$$(pwd)/dist/paludis/exherbo:/var/repositories/gamemode" \ + exherbo/exherbo-x86_64-pc-linux-gnu-base \ + bash -c "true \ + && chown root:tty /dev/tty \ + && usermod -a -G tty paludisbuild \ + && printf '%s\n' \ + \"format = e\" \ + \"location = \"\$$\{root\}/var/db/paludis/repositories/gamemode\"\" \ + \"sync = file:///var/repositories/gamemode\" \ + > /etc/paludis/repositories/gamemode.conf \ + && cat /etc/paludis/repositories/gamemode.conf \ + && cave sync \ + && cave resolve games-utils/gamemode \ + " diff --git a/bootstrap.sh b/bootstrap.sh index 22ac240d..a9ca11b0 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,48 +1,383 @@ -#!/bin/bash -# Simple bootstrap script to build and run the daemon +#!/bin/sh +# Originally created by FeralInteractive under BSD 3-Clause License in 2017 bootstrap.sh +# Performed full refact by Jacob Hrbek under GPLv3 license in 05.07.2020 04:28:55 CET -if [ "$EUID" -eq 0 ] - then echo "Please don't run bootstrap.sh as root." - exit -fi +# shellcheck shell=sh # Written to be POSIX-compatible + +###! Simple bootstrap script to build and run the daemon +###! We need: +###! - FIXME-DOCS +###! Requires: +###! - FIXME +###! Exit codes: +###! - FIXME-DOCS(Krey): Defined in die() +###! Platforms: +###! - [ ] Linux +###! - [ ] Debian +###! - [ ] Ubuntu +###! - [ ] Fedora +###! - [ ] NixOS +###! - [ ] Archlinux +###! - [ ] Alpine +###! - [ ] FreeBSD +###! - [ ] Darwin +###! - [ ] Redox +###! - [ ] ReactOS +###! - [ ] Windows +###! - [ ] Windows/Cygwin + +# Maintainer info +UPSTREAM="https://github.com/FeralInteractive" +MAINTAINER="https://github.com/Kreyren" + +# Command overrides +[ -z "$PRINTF" ] && PRINTF="printf" +[ -z "$WGET" ] && WGET="wget" +[ -z "$CURL" ] && CURL="curl" +[ -z "$ARIA2C" ] && ARIA2C="aria2c" +[ -z "$CHMOD" ] && CHMOD="chmod" +[ -z "$UNAME" ] && UNAME="uname" +[ -z "$TR" ] && TR="tr" +[ -z "$SED" ] && SED="sed" +[ -z "$GREP" ] && GREP="grep" +[ -z "$DPKG" ] && DPKG="dpkg" +[ -z "$APT_GET" ] && APT_GET="apt-get" +[ -z "$TOR" ] && TOR="tor" +[ -z "$NINJA" ] && NINJA="ninja" +[ -z "$MESON" ] && MESON="meson" +# Customization of the output +## efixme +[ -z "$EFIXME_FORMAT_STRING" ] && EFIXME_FORMAT_STRING="FIXME: %s\n" +[ -z "$EFIXME_FORMAT_STRING_LOG" ] && EFIXME_FORMAT_STRING="${logPrefix}FIXME: %s\n" +[ -z "$EFIXME_FORMAT_STRING_DEBUG" ] && EFIXME_FORMAT_STRING_DEBUG="FIXME($myName:$0): %s\n" +[ -z "$EFIXME_FORMAT_STRING_DEBUG_LOG" ] && EFIXME_FORMAT_STRING_DEBUG_LOG="${logPrefix}FIXME($myName:$0): %s\n" +## eerror +[ -z "$EERROR_FORMAT_STRING" ] && EERROR_FORMAT_STRING="ERROR: %s\\n" +[ -z "$EERROR_FORMAT_STRING_LOG" ] && EERROR_FORMAT_STRING_LOG="${logPrefix}ERROR: %s\\n" +[ -z "$EERROR_FORMAT_STRING_DEBUG" ] && EERROR_FORMAT_STRING_DEBUG="ERROR($myName:$0): %s\\n" +[ -z "$EERROR_FORMAT_STRING_DEBUG_LOG" ] && EERROR_FORMAT_STRING_DEBUG_LOG="${logPrefix}ERROR($myName:$0): %s\\n" +## edebug +[ -z "$EDEBUG_FORMAT_STRING" ] && EDEBUG_FORMAT_STRING="DEBUG: %s\\n" +[ -z "$EDEBUG_FORMAT_STRING_LOG" ] && EDEBUG_FORMAT_STRING_LOG="${logPrefix}DEBUG: %s\\n" +[ -z "$EDEBUG_FORMAT_STRING_DEBUG" ] && EDEBUG_FORMAT_STRING_DEBUG="DEBUG($myName:$0): %s\\n" +[ -z "$EDEBUG_FORMAT_STRING_DEBUG_LOG" ] && EDEBUG_FORMAT_STRING_DEBUG_LOG="${logPrefix}DEBUG($myName:$0): %s\\n" +## einfo +[ -z "$EINFO_FORMAT_STRING" ] && EINFO_FORMAT_STRING="INFO: %s\\n" +[ -z "$EINFO_FORMAT_STRING_LOG" ] && EINFO_FORMAT_STRING_LOG="${logPrefix}INFO: %s\\n" +[ -z "$EINFO_FORMAT_STRING_DEBUG" ] && EINFO_FORMAT_STRING_DEBUG="INFO($myName:$0): %s\\n" +[ -z "$EINFO_FORMAT_STRING_DEBUG_LOG" ] && EINFO_FORMAT_STRING_DEBUG_LOG="${logPrefix}INFO($myName:$0): %s\\n" +## die +[ -z "$DIE_FORMAT_STRING" ] && DIE_FORMAT_STRING="FATAL: %s in script '$myName' located at '$0'\\n" +[ -z "$DIE_FORMAT_STRING_LOG" ] && DIE_FORMAT_STRING_LOG="${logPath}FATAL: %s in script '$myName' located at '$0'\\n" +[ -z "$DIE_FORMAT_STRING_DEBUG" ] && DIE_FORMAT_STRING_DEBUG="FATAL($myName:$1): %s\n" +[ -z "$DIE_FORMAT_STRING_DEBUG_LOG" ] && DIE_FORMAT_STRING_DEBUG_LOG="${logPrefix}FATAL($myName:$1): %s\\n" +### Fixme trap +[ -z "$DIE_FORMAT_STRING_FIXME" ] && DIE_FORMAT_STRING_FIXME="FATAL: %s in script '$myName' located at '$0', fixme?\n" +[ -z "$DIE_FORMAT_STRING_FIXME_LOG" ] && DIE_FORMAT_STRING_FIXME_LOG="${logPrefix}FATAL: %s, fixme?\n" +[ -z "$DIE_FORMAT_STRING_FIXME_DEBUG" ] && DIE_FORMAT_STRING_FIXME_DEBUG="FATAL($myName:$1): %s, fixme?\n" +[ -z "$DIE_FORMAT_STRING_FIXME_DEBUG_LOG" ] && DIE_FORMAT_STRING_FIXME_DEBUG_LOG="${logPrefix}FATAL($myName:$1): %s, fixme?\\n" +### Unexpected trap +[ -z "$DIE_FORMAT_STRING_UNEXPECTED" ] && DIE_FORMAT_STRING_UNEXPECTED="FATAL: Unexpected happend while %s in $myName located at $0\\n" +[ -z "$DIE_FORMAT_STRING_UNEXPECTED_LOG" ] && DIE_FORMAT_STRING_UNEXPECTED_LOG="${logPrefix}FATAL: Unexpected happend while %s\\n" +[ -z "$DIE_FORMAT_STRING_UNEXPECTED_DEBUG" ] && DIE_FORMAT_STRING_UNEXPECTED_DEBUG="FATAL($myName:$1): Unexpected happend while %s in $myName located at $0\\n" +[ -z "$DIE_FORMAT_STRING_UNEXPECTED_DEBUG_LOG" ] && DIE_FORMAT_STRING_UNEXPECTED_DEBUG="${logPrefix}FATAL($myName:$1): Unexpected happend while %s\\n" + +# Exit on anything unexpected set -e -# Check for scaling governor support and warn about it -if [ ! -f "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" ]; then - echo "WARNING: CPUFreq scaling governor device file was not found at \"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor\"." - echo "This probably means that you have disabled processor scheduling features in your BIOS. See README.md (or GitHub issue #44) for more information." - echo "This means GameMode's CPU governor control feature will not work (other features will still work)." +# NOTICE(Krey): By default busybox outputs a full path in '$0' this is used to strip it +myName="${0##*/}" + +# Used to prefix logs with timestemps, uses ISO 8601 by default +logPrefix="[ $(date -u +"%Y-%m-%dT%H:%M:%SZ") ] " +# Path to which we will save logs +# NOTICE(Krey): To avoid storing file '$HOME/.some-name.sh.log' we are stripping the '.sh' here +logPath="${XDG_DATA_HOME:-$HOME/.local/share}/${myName%%.sh}.log" + +# inicialize the script in logs +"$PRINTF" '%s\n' "Started $myName on $("$UNAME" -s) at $(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> "$logPath" + +# NOTICE(Krey): Aliases are required for posix-compatible line output (https://gist.github.com/Kreyren/4fc76d929efbea1bc874760e7f78c810) +die() { funcname=die + case "$2" in + 38|fixme) # FIXME + if [ "$DEBUG" = 0 ] || [ -z "$DEBUG" ]; then + "$PRINTF" "$DIE_FORMAT_STRING_FIXME" "$3" + "$PRINTF" "$DIE_FORMAT_STRING_FIXME_LOG" "$3" >> "$logPath" + funcname="$myName" + elif [ "$DEBUG" = 1 ]; then + "$PRINTF" "$DIE_FORMAT_STRING_FIXME_DEBUG" "$3" + "$PRINTF" "$DIE_FORMAT_STRING_FIXME_DEBUG_LOG" "$3" >> "$logPath" + funcname="$myName" + else + # NOTICE(Krey): Do not use die() here + "$PRINTF" 'FATAL: %s\n' "Unexpected happend while processing variable DEBUG with value '$DEBUG' in $funcname" + fi - if [ "$TRAVIS" != "true" ]; then - # Allow to continue the install, as gamemode has other useful features - read -p "Would you like to continue anyway [Y/N]? " -r - [[ $REPLY =~ ^[Yy]$ ]] + exit 38 + ;; + 255) # Unexpected trap + if [ "$DEBUG" = 0 ] || [ -z "$DEBUG" ]; then + "$PRINTF" "$DIE_FORMAT_STRING_UNEXPECTED" "$3" + "$PRINTF" "$DIE_FORMAT_STRING_UNEXPECTED_LOG" "$3" >> "$logPath" + funcname="$myName" + elif [ "$DEBUG" = 1 ]; then + "$PRINTF" "$DIE_FORMAT_STRING_UNEXPECTED_DEBUG" "$3" + "$PRINTF" "$DIE_FORMAT_STRING_UNEXPECTED_DEBUG_LOG" "$3" >> "$logPath" + funcname="$myName" + else + # NOTICE(Krey): Do not use die() here + "$PRINTF" "$DIE_FORMAT_STRING" "Unexpected happend while processing variable DEBUG with value '$DEBUG' in $funcname" + fi + ;; + *) + if [ "$DEBUG" = 0 ] || [ -z "$DEBUG" ]; then + "$PRINTF" "$DIE_FORMAT_STRING" "$3" + "$PRINTF" "$DIE_FORMAT_STRING_LOG" "$3" >> "$logPath" + funcname="$myName" + elif [ "$DEBUG" = 1 ]; then + "$PRINTF" "$DIE_FORMAT_STRING_DEBUG" "$3" + "$PRINTF" "$DIE_FORMAT_STRING_DEBUG_LOG" "$3" >> "$logPath" + funcname="$myName" + else + # NOTICE(Krey): Do not use die() here + "$PRINTF" 'FATAL: %s\n' "Unexpected happend while processing variable DEBUG with value '$DEBUG' in $funcname" + fi + esac + + exit "$2" + + # In case invalid argument has been parsed in $2 + exit 255 +}; alias die='die "$LINENO"' + +einfo() { funcname=einfo + if [ "$DEBUG" = 0 ] || [ -z "$DEBUG" ]; then + "$PRINTF" "$EINFO_FORMAT_STRING" "$2" + "$PRINTF" "$EINFO_FORMAT_STRING_LOG" "$2" >> "$logPath" + funcname="$myName" + return 0 + elif [ "$DEBUG" = 1 ]; then + "$PRINTF" "$EINFO_FORMAT_STRING_DEBUG" "$2" + "$PRINTF" "$EINFO_FORMAT_STRING_DEBUG_LOG" "$2" >> "$logPath" + funcname="$myName" + return 0 + else + die 255 "processing variable DEBUG with value '$DEBUG' in $funcname" fi -fi +}; alias einfo='einfo "$LINENO"' + +ewarn() { funcname=ewarn + if [ "$DEBUG" = 0 ] || [ -z "$DEBUG" ]; then + "$PRINTF" "$EWARN_FORMAT_STRING" "$2" + "$PRINTF" "$EWARN_FORMAT_STRING_LOG" "$2" >> "$logPath" + funcname="$myName" + return 0 + elif [ "$DEBUG" = 1 ]; then + "$PRINTF" "$EWARN_FORMAT_STRING_DEBUG" "$2" + "$PRINTF" "$EWARN_FORMAT_STRING_DEBUG_LOG" "$2" >> "$logPath" + funcname="$myName" + return 0 + else + die 255 "processing variable DEBUG with value '$DEBUG' in $funcname" + fi +}; alias ewarn='ewarn "$LINENO"' + +eerror() { funcname=eerror + if [ "$DEBUG" = 0 ] || [ -z "$DEBUG" ]; then + "$PRINTF" "$EERROR_FORMAT_STRING" "$2" + "$PRINTF" "$EERROR_FORMAT_STRING_LOG" "$2" >> "$logPath" + funcname="$myName" + return 0 + elif [ "$DEBUG" = 1 ]; then + "$PRINTF" "$EERROR_FORMAT_STRING_DEBUG" "$2" + "$PRINTF" "$EERROR_FORMAT_STRING_DEBUG_LOG" "$2" >> "$logPath" + funcname="$myName" + return 0 + else + die 255 "processing variable DEBUG with value '$DEBUG' in $funcname" + fi +}; alias eerror='eerror "$LINENO"' -# accept a prefix value as: prefix=/path ./bootstrap.sh -: ${prefix:=/usr} +edebug() { funcname=edebug + if [ "$DEBUG" = 0 ] || [ -z "$DEBUG" ]; then + "$PRINTF" "$EDEBUG_FORMAT_STRING" "$2" + "$PRINTF" "$EDEBUG_FORMAT_STRING_LOG" "$2" >> "$logPath" + funcname="$myName" + return 0 + elif [ "$DEBUG" = 1 ]; then + "$PRINTF" "$EDEBUG_FORMAT_STRING_DEBUG" "$2" + "$PRINTF" "$EDEBUG_FORMAT_STRING_DEBUG_LOG" "$2" >> "$logPath" + funcname="$myName" + return 0 + else + die 255 "processing variable DEBUG with value '$DEBUG' in $funcname" + fi +}; alias edebug='edebug "$LINENO"' -# Echo the rest so it's obvious -set -x -meson builddir --prefix=$prefix --buildtype debugoptimized -Dwith-systemd-user-unit-dir=/etc/systemd/user "$@" -ninja -C builddir +efixme() { funcname=efixme + if [ "$IGNORE_FIXME" = 1 ]; then + true + elif [ "$IGNORE_FIXME" = 0 ] || [ -z "$IGNORE_FIXME" ]; then + if [ "$DEBUG" = 0 ] || [ -z "$DEBUG" ]; then + "$PRINTF" "$EFIXME_FORMAT_STRING" "$2" + "$PRINTF" "$EFIXME_FORMAT_STRING" "$2" >> "$logPath" + funcname="$myName" + return 0 + elif [ "$DEBUG" = 1 ]; then + "$PRINTF" "$EFIXME_FORMAT_STRING_DEBUG" "$2" + "$PRINTF" "$EFIXME_FORMAT_STRING_DEBUG_LOG" "$2" >> "$logPath" + funcname="$myName" + return 0 + else + die 255 "processing DEBUG variable with value '$DEBUG' in $funcname" + fi + else + die 255 "processing variable IGNORE_FIXME with value '$IGNORE_FIXME' in $0" + fi +}; alias efixme='efixme "$LINENO"' -# Verify user wants to install -set +x -if [ "$TRAVIS" != "true" ]; then - read -p "Install to $prefix? [y/N] " -r - [[ $REPLY =~ ^[Yy]$ ]] +edebug "Resolving root on user with ID '$(id -u)" +if [ "$(id -u)" = 0 ]; then + edebug "Script has been executed as user with ID 0, assuming root" + funcname="$myName" + return 0 +# NOTICE(Krey): The ID 33333 is used by gitpod +elif [ "$(id -u)" = 1000 ] || [ "$(id -u)" = 33333 ]; then + ewarn "Script $myName is not expected to run as non-root, trying to elevate root.." + if command -v sudo 1>/dev/null; then + einfo "Found 'sudo' that can be used for root elevation" + rootEle="sudo" + funcname="$myName" + return 0 + elif command -v su 1>/dev/null; then + einfo "Found 'su' that can be used for a root elevation" + ewarn "This will require the end-user to parse a root password multiple times assuming that root has a password set" + rootEle="su -c" + funcname="$myName" + return 0 + elif ! command -v sudo 1>/dev/null && ! command -v su 1>/dev/null; then + die 3 "Script $myName depends on root permission to install packages where commands 'sudo' nor 'su' are available for root elevation" + funcname="$myName" + return 0 + else + die 225 "processing root on non-root" + fi +else + die 3 "Unknown user ID '$(id -u)' has been parsed in script $myName" fi -set -x -sudo ninja install -C builddir +if command -v "$UNAME" 1>/dev/null; then + unameKernel="$("$UNAME" -s)" + edebug "Identified the kernel as '$unameKernel" + case "$unameKernel" in + Linux) + KERNEL="$unameKernel" -# Restart polkit so we don't get pop-ups whenever we pkexec -if systemctl list-unit-files |grep -q polkit.service; then - sudo systemctl try-restart polkit + # Assume Linux Distro and release + # NOTICE(Krey): We are expecting this to return a lowercase value + if command -v "$LSB_RELEASE" 1>/dev/null; then + assumedDistro="$("$LSB_RELEASE" -si | "$TR" :[upper]: :[lower]:)" + assumedRelease="$("$LSB_RELEASE" -cs | "$TR" :[upper]: :[lower]:)" + elif ! command -v "$LSB_RELEASE" 1>/dev/null && [ -f /etc/os-release ]; then + assumedDistro="$("$GREP" -o "^ID\=.*" /etc/os-release | "$SED" s/ID=//gm)" + assumedRelease="$("$GREP" -o"^VERSION_CODENAME\=.*" /etc/os-release | "$SED" s/VERSION_CODENAME=//gm)" + elif ! command -v "$LSB_RELEASE" 1>/dev/null && [ ! -f /etc/os-release ]; then + die 1 "Unable to identify linux distribution using command 'lsb_release' nor file '/etc/os-release'" + else + die 255 "attempting to assume linux distro and release" + fi + + edebug "Identified distribution as '$assumedDistro'" + edebug "Identified distribution release as '$assumedRelease'" + + # Verify Linux Distro + efixme "Add sanitization logic for other linux distributions" + case "$assumedDistro" in + ubuntu | debian | fedora | nixos | opensuse | gentoo | exherbo) + DISTRO="$assumedDistro" + ;; + *) die fixme "Unexpected Linux distribution '$assumedDistro' has been detected." + esac + + # Verify Linux Distro Release + efixme "Sanitize verification of linux distro release" + assumedRelease="$RELEASE" + ;; + FreeBSD | Redox | Darwin | Windows) + KERNEL="$unameKernel" + ;; + *) die 255 "Unexpected kernel '$unameKernel'" + esac +elif ! command -v "$UNAME" 1>/dev/null; then + die 1 "Standard command '$UNAME' is not available on this system, unable to identify kernel" +else + die 255 "Identifying system" fi -# Reload systemd configuration so that it picks up the new service. -systemctl --user daemon-reload +# Argument management +while [ "$#" -gt 0 ]; do case "$1" in + build) + case "$KERNEL/$DISTRO-$RELEASE" in + linux/devuan-beowulf) + # Check if CPU supports governon + scalingGovFile="/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" + if [ ! -f "$scalingGovFile" ]; then + while true; do + ewarn "CPU governon control features is not supported - CPUFreq scaling governon device file '$scalingGovFile' doesn't exists which indicates that processor scheduling is disabled in BIOS, See README.md or GitHub issue #44 (https://github.com/FeralInteractive/gamemode/issues/44) for more info. Other features are still supported, do you want to continue? (y/n)" + read -r continueCheck + case "$continueCheck" in + "y"|"Y"|"Yes"|"YES"|"yes") + edebug "Accepted userinput '$continueCheck' as confirmation to continue on system without '$scalingGovFile'" + unset continueCheck + break ;; + "n"|"N"|"No"|"NO") + die 0 "Terminating as instructed.." + ;; + # NOTICE(Krey): Yes, i think i am funny~ + "PLEASE FOR THE LOVE OF GOD STOP! STOP NOW OH MY GOD STOP! STOOOOOOOOOOOP!!!") + printf '%s\n' "OK OK OK CALM DOWN! CAAALM DOOOWNNN!!, jeez.." + die 0 "Terminating as instructed.." + ;; + *) + eerror "Input '$continueCheck' is not valid, expecting either: y, Y, Yes, YES, yes or n, N, No, no, \"PLEASE FOR THE LOVE OF GOD STOP! STOP NOW OH MY GOD STOP! STOOOOOOOOOOOP!!!\"" + einfo "Asking again for confirmation.." + esac + done + elif [ -f "$scalingGovFile" ]; then + edebug "File '$scalingGovFile' exists, assuming CPU governnon control supported" + else + die 255 "processing variable scalingGovFile with value '$scalingGovFile' to check wether CPU governon control features are supported" + fi + + # Run meson + # DNM: Sanitize meson, info from upstream required + # shellcheck disable=SC2154 # We are expecting end-users to parse cmdPrefix if required + "$MESON" builddir --prefix="${prefix:=/usr}" --buildtype debugoptimized -Dwith-systemd-user-unit-dir=/etc/systemd/user "$@" || true + + errCode="$?" + + case "$errCode" in + *) die 255 "exit code '$errCode' has been provided from meson" + esac + + # Run ninja + # DNM: Sanitize ninja, info from upstream required + "$NINJA" install -C builddir || true + + errCode="$?" + + case "$errCode" in + *) die 255 "exit code '$errCode' has been provided from ninja" + esac + + efixme "Some witchery with init might be required here" + ;; + *) die fixme "Script '$myName' doesn't have implemented logic for kernel '$KERNEL' using distribution '$DISTRO' with release '$RELEASE'" + esac + ;; + *) die 2 "Command '$1' is not recognized by $myName" +esac; done + +die 23 "Script '$myName' escaped sanitization" diff --git a/dist/README.md b/dist/README.md new file mode 100644 index 00000000..d50b02fc --- /dev/null +++ b/dist/README.md @@ -0,0 +1,3 @@ +# Downstream management + +Directory dedicated for various package managers to recognize this repository into a package diff --git a/dist/paludis/README.md b/dist/paludis/README.md new file mode 100644 index 00000000..6e4751b3 --- /dev/null +++ b/dist/paludis/README.md @@ -0,0 +1 @@ +Directory for downstream designed for [paludis](http://paludis.exherbo.org/) diff --git a/dist/paludis/exherbo/metadata/about.conf b/dist/paludis/exherbo/metadata/about.conf new file mode 100644 index 00000000..99ec04e6 --- /dev/null +++ b/dist/paludis/exherbo/metadata/about.conf @@ -0,0 +1,4 @@ +homepage = https://github.com/FeralInteractive/gamemode +summary = FeralInteractive repository to provide games-utils/gamemode on Exherbo Linux +description = This repository contains games-utils/gamemode provided by upstream +status = third-party diff --git a/dist/paludis/exherbo/metadata/arch.conf b/dist/paludis/exherbo/metadata/arch.conf new file mode 100644 index 00000000..18f3e8da --- /dev/null +++ b/dist/paludis/exherbo/metadata/arch.conf @@ -0,0 +1,2 @@ +x86 +amd64 diff --git a/dist/paludis/exherbo/metadata/categories.conf b/dist/paludis/exherbo/metadata/categories.conf new file mode 100644 index 00000000..d23a22a6 --- /dev/null +++ b/dist/paludis/exherbo/metadata/categories.conf @@ -0,0 +1 @@ +games-util diff --git a/dist/paludis/exherbo/metadata/info/packages.conf b/dist/paludis/exherbo/metadata/info/packages.conf new file mode 100644 index 00000000..87ff9e61 --- /dev/null +++ b/dist/paludis/exherbo/metadata/info/packages.conf @@ -0,0 +1,2 @@ +# Definitions of available packages for paludis +games-util/gamemode diff --git a/dist/paludis/exherbo/metadata/info/repository_mask.conf b/dist/paludis/exherbo/metadata/info/repository_mask.conf new file mode 100644 index 00000000..78202b15 --- /dev/null +++ b/dist/paludis/exherbo/metadata/info/repository_mask.conf @@ -0,0 +1,6 @@ +games-utils/gamemode[<1.5.1] [[ + author = [ Jacob Hrbek ] + date = [ 05 Jul 2020 ] + token = outdated + description = [ Masked outdated versions that are not considered for stable release ] +]] diff --git a/dist/paludis/exherbo/packages/games-util/gamemode/gamemode-1.5.1.exheres-0 b/dist/paludis/exherbo/packages/games-util/gamemode/gamemode-1.5.1.exheres-0 new file mode 100644 index 00000000..b9c12516 --- /dev/null +++ b/dist/paludis/exherbo/packages/games-util/gamemode/gamemode-1.5.1.exheres-0 @@ -0,0 +1,9 @@ +# Created by Jacob Hrbek for FeralInteractive in 05.07.2020 03:54:58 CEST under GPLv3 license + +# shellcheck shell=sh # Written to be POSIX-compatible + +require gamemode + +# shellcheck disable=SC2034 # Metadata for paludis +# FIXME(Krey): Test in docker +PLATFORMS="~amd64 ~x86" diff --git a/dist/paludis/exherbo/packages/games-util/gamemode/gamemode.exlib b/dist/paludis/exherbo/packages/games-util/gamemode/gamemode.exlib new file mode 100644 index 00000000..5833e253 --- /dev/null +++ b/dist/paludis/exherbo/packages/games-util/gamemode/gamemode.exlib @@ -0,0 +1,45 @@ +# Created by Jacob Hrbek for FeralInteractive in 05.07.2020 03:54:58 CEST under GPLv3 license + +# shellcheck shell=sh # Written to be POSIX-compatible + +# Reference to best practices: https://www.exherbo.org/docs/eapi/exheres-for-smarties.html + +require github [ user=FeralInteractive release="$PV" suffix=tar.xz ] + +# Metadata +# shellcheck disable=SC2034 # Metadata for paludis +# FIXME-QA(Krey): Grab the summary from repository +SUMMARY="Optimise Linux system performance on demand" +# shellcheck disable=SC2034 # Metadata for paludis +DESCRIPTION="GameMode is a daemon/lib combo for Linux that allows games to request a set of optimisations be temporarily applied to the host OS and/or a game process." +# shellcheck disable=SC2034 # Metadata for paludis +HOMEPAGE="https://github.com/FeralInteractive/gamemode" +# shellcheck disable=SC2034 # Metadata for paludis +LICENCES="BSD-3 [[ last-checked = 1.5.1 ]]" + +# Technical variables +# shellcheck disable=SC2034 # Metadata for paludis +# DEPENDENCIES=" +# build: +# option [[ description = [ description ] ]] +# " +# shellcheck disable=SC2034 # Metadata for paludis +SLOT="0" +# shellcheck disable=SC2034 # Metadata for paludis +MYOPTIONS=" + systemd [[ description = [ Compile with systemd support ] ]] + openrc [[ description = [ Compile with openrc support ] ]] + ( targets: + x86_64-pc-linux-gnu + i686-pc-linux-gnu + x86_64-pc-linux-musl + i686-pc-linux-musl + ) [[ number-selected = at-least-one ]] + platform: + amd64 + x86 +" + +src_compile() { + true +} diff --git a/dist/paludis/exherbo/profiles/repo_name b/dist/paludis/exherbo/profiles/repo_name new file mode 100644 index 00000000..2aa51571 --- /dev/null +++ b/dist/paludis/exherbo/profiles/repo_name @@ -0,0 +1 @@ +gamemode