From 43ccbfe88ba1757b7d19aa89506f84262b8f17ad Mon Sep 17 00:00:00 2001 From: aartoni Date: Sun, 1 Dec 2024 16:01:09 +0700 Subject: [PATCH 01/15] Enable tests for zsh and yash --- .github/workflows/test.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ac662fca..a2ad1adc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,10 +7,15 @@ jobs: strategy: matrix: os: [ubuntu-latest] # TODO Add macos-latest and windows-latest - shell: [bash, dash] # TODO Add zsh, yash... + shell: [bash, dash, zsh, yash] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 + - name: Install esoteric shell + if: ${{ contains(fromJSON('["zsh", "yash"]'), matrix.shell) }} + run: | + sudo apt update -y + sudo apt install ${{ matrix.shell }} -y - name: Set shell if: ${{ matrix.os == 'ubuntu-latest' }} run: ln -sf /usr/bin/${{ matrix.shell }} /bin/sh From 4966a261a50c5b6bfc711b103a8ee30b2af2b8f7 Mon Sep 17 00:00:00 2001 From: aartoni Date: Sun, 1 Dec 2024 16:38:46 +0700 Subject: [PATCH 02/15] Fixes for running as a non-root user --- .github/workflows/test.yml | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a2ad1adc..9fe98367 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: sudo apt install ${{ matrix.shell }} -y - name: Set shell if: ${{ matrix.os == 'ubuntu-latest' }} - run: ln -sf /usr/bin/${{ matrix.shell }} /bin/sh + run: sudo ln -sf /usr/bin/${{ matrix.shell }} /bin/sh - name: Check exit status definitions run: | . ./updater.sh 2>/dev/null @@ -42,52 +42,39 @@ jobs: run: ./updater.sh -x 2>/dev/null || { [ "$?" -eq 2 ] && exit 0; } - name: Tests setup run: | - useradd -m nonrootuser - echo 'ALL ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers - echo 'shopt -s expand_aliases' >> $HOME/.bash_aliases - echo "alias nonsudo='sudo -u nonrootuser sh -c'" >> $HOME/.bash_aliases set +e - name: Check that passing a wrong option returns EX_USAGE - run: | - . $HOME/.bash_aliases - nonsudo "./updater.sh -x 2>/dev/null" || { [ "$?" -eq 2 ] && exit 0; } + run: ./updater.sh -x 2>/dev/null || { [ "$?" -eq 2 ] && exit 0; } - name: Check that --help returns EX_OK and not EX__BASE if: ${{ false }} # TODO Fix this - run: | - . $HOME/.bash_aliases - nonsudo "./updater.sh -h > /dev/null" + run: ./updater.sh -h > /dev/null - name: Check that if the profile doesn't have at least d-wx permissions, returns EX_UNAVAILABLE run: | - . $HOME/.bash_aliases unxable_temp_dir=$(mktemp -d) chmod 444 $unxable_temp_dir - nonsudo "./updater.sh -p $unxable_temp_dir > /dev/null 2>&1" || { [ "$?" -ne 69 ] && exit 1; } + ./updater.sh -p $unxable_temp_dir > /dev/null 2>&1 || { [ "$?" -ne 69 ] && exit 1; } unwable_temp_dir=$(mktemp -d) chmod 111 $unwable_temp_dir - nonsudo "./updater.sh -p $unwable_temp_dir > /dev/null 2>&1" || { [ "$?" -ne 69 ] && exit 1; } + ./updater.sh -p $unwable_temp_dir > /dev/null 2>&1 || { [ "$?" -ne 69 ] && exit 1; } exit 0 - name: Check that if the profiles.ini doesn't exist, returns EX_NOINPUT run: | - . $HOME/.bash_aliases temp_dir=$(mktemp -d) chmod 777 $temp_dir - nonsudo "./updater.sh -l > /dev/null 2>&1" || { [ "$?" -ne 66 ] && exit 1; } + ./updater.sh -l > /dev/null 2>&1 || { [ "$?" -ne 66 ] && exit 1; } exit 0 - name: Check that if the profile requires root privileges, returns EX_CONFIG run: | - . $HOME/.bash_aliases temp_dir=$(mktemp -d) - chmod 777 $temp_dir - touch $temp_dir/user.js - mkdir $temp_dir/userjs_test - nonsudo "./updater.sh -p $temp_dir > /dev/null 2>&1" || { [ "$?" -ne 78 ] && exit 1; } + sudo chmod 777 $temp_dir + sudo touch $temp_dir/user.js + ./updater.sh -p $temp_dir > /dev/null 2>&1 || { [ "$?" -ne 78 ] && exit 1; } exit 0 - name: Check that the profile gets updated if: ${{ false }} # TODO Complete this test run: | - . $HOME/.bash_aliases temp_dir=$(mktemp -d) touch $temp_dir/user.js mkdir $temp_dir/userjs_test chown -R nonrootuser:nonrootuser $temp_dir - nonsudo "./updater.sh -p $temp_dir" + ./updater.sh -p $temp_dir From 03e24256d9a173b9a7c4163072a9befbdff7af64 Mon Sep 17 00:00:00 2001 From: aartoni Date: Tue, 7 Jan 2025 15:53:36 +0700 Subject: [PATCH 03/15] Add support for mksh --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9fe98367..397aa0b1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,12 +7,12 @@ jobs: strategy: matrix: os: [ubuntu-latest] # TODO Add macos-latest and windows-latest - shell: [bash, dash, zsh, yash] + shell: [bash, dash, zsh, yash, mksh] # TODO Add ash, hush, osh, pbosh, posh, ksh88, ksh93u+(m) runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: Install esoteric shell - if: ${{ contains(fromJSON('["zsh", "yash"]'), matrix.shell) }} + if: ${{ contains(fromJSON('["zsh", "yash", "mksh"]'), matrix.shell) }} run: | sudo apt update -y sudo apt install ${{ matrix.shell }} -y From c374e0c7d7d368b708883bb6bc8c76ff4cf0b889 Mon Sep 17 00:00:00 2001 From: aartoni Date: Tue, 7 Jan 2025 16:00:36 +0700 Subject: [PATCH 04/15] Add ksh93u+m shell --- .github/workflows/test.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 397aa0b1..e1905e2a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,18 +7,21 @@ jobs: strategy: matrix: os: [ubuntu-latest] # TODO Add macos-latest and windows-latest - shell: [bash, dash, zsh, yash, mksh] # TODO Add ash, hush, osh, pbosh, posh, ksh88, ksh93u+(m) + shell: [bash, dash, zsh, yash, mksh, ksh93u+m] # TODO Add ash, hush, osh, pbosh, posh, ksh88 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: Install esoteric shell - if: ${{ contains(fromJSON('["zsh", "yash", "mksh"]'), matrix.shell) }} + if: ${{ contains(fromJSON('["zsh", "yash", "mksh", "ksh93u+m"]'), matrix.shell) }} run: | sudo apt update -y sudo apt install ${{ matrix.shell }} -y - name: Set shell if: ${{ matrix.os == 'ubuntu-latest' }} run: sudo ln -sf /usr/bin/${{ matrix.shell }} /bin/sh + - name: Set ksh93u+m shell + if: ${{ matrix.shell == 'ksh93u+m' }} + run: sudo ln -sf /usr/bin/ksh /bin/sh - name: Check exit status definitions run: | . ./updater.sh 2>/dev/null From 45bac11afae44074f665ee2200c39627728969ef Mon Sep 17 00:00:00 2001 From: aartoni Date: Tue, 7 Jan 2025 16:08:46 +0700 Subject: [PATCH 05/15] Avoid running generic shell setup for ksh93u+m --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e1905e2a..c8143fc5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: sudo apt update -y sudo apt install ${{ matrix.shell }} -y - name: Set shell - if: ${{ matrix.os == 'ubuntu-latest' }} + if: ${{ matrix.os == 'ubuntu-latest' && !contains(fromJSON('["ksh93u+m"]'), matrix.shell) }} run: sudo ln -sf /usr/bin/${{ matrix.shell }} /bin/sh - name: Set ksh93u+m shell if: ${{ matrix.shell == 'ksh93u+m' }} From ef0d923cb519573ac700718d3f261a692bb9534f Mon Sep 17 00:00:00 2001 From: aartoni Date: Tue, 7 Jan 2025 16:22:26 +0700 Subject: [PATCH 06/15] Enable help check --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c8143fc5..d7289e10 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,7 +49,6 @@ jobs: - name: Check that passing a wrong option returns EX_USAGE run: ./updater.sh -x 2>/dev/null || { [ "$?" -eq 2 ] && exit 0; } - name: Check that --help returns EX_OK and not EX__BASE - if: ${{ false }} # TODO Fix this run: ./updater.sh -h > /dev/null - name: Check that if the profile doesn't have at least d-wx permissions, returns EX_UNAVAILABLE run: | From 73647f1dc9e851303dfd1e789ed0c5b1e23cc360 Mon Sep 17 00:00:00 2001 From: aartoni Date: Tue, 7 Jan 2025 18:27:38 +0700 Subject: [PATCH 07/15] Fix wrong logic for root testing --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d7289e10..a1336718 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,7 +42,7 @@ jobs: $(exit_status_definitions) EOF - name: Check that running as root returns EX_USAGE - run: ./updater.sh -x 2>/dev/null || { [ "$?" -eq 2 ] && exit 0; } + run: sudo ./updater.sh -x 2>/dev/null || { [ "$?" -eq 2 ] && exit 0; } - name: Tests setup run: | set +e From e8ae1d63b1f070429519a9b23f002739f391191e Mon Sep 17 00:00:00 2001 From: aartoni Date: Tue, 7 Jan 2025 18:28:50 +0700 Subject: [PATCH 08/15] Use the exit status definitions from the script --- .github/workflows/test.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a1336718..0a625f3f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,36 +41,37 @@ jobs: done </dev/null || { [ "$?" -eq 2 ] && exit 0; } - name: Tests setup run: | set +e + . ./updater.sh && exit_status_definitions >> $GITHUB_ENV + - name: Check that running as root returns EX_USAGE + run: sudo ./updater.sh -x 2>/dev/null || { [ "$?" -eq $_EX_USAGE ] && exit 0; } - name: Check that passing a wrong option returns EX_USAGE - run: ./updater.sh -x 2>/dev/null || { [ "$?" -eq 2 ] && exit 0; } + run: ./updater.sh -x 2>/dev/null || { [ "$?" -eq $_EX_USAGE ] && exit 0; } - name: Check that --help returns EX_OK and not EX__BASE run: ./updater.sh -h > /dev/null - name: Check that if the profile doesn't have at least d-wx permissions, returns EX_UNAVAILABLE run: | unxable_temp_dir=$(mktemp -d) chmod 444 $unxable_temp_dir - ./updater.sh -p $unxable_temp_dir > /dev/null 2>&1 || { [ "$?" -ne 69 ] && exit 1; } + ./updater.sh -p $unxable_temp_dir > /dev/null 2>&1 || { [ "$?" -ne $_EX_UNAVAILABLE ] && exit 1; } unwable_temp_dir=$(mktemp -d) chmod 111 $unwable_temp_dir - ./updater.sh -p $unwable_temp_dir > /dev/null 2>&1 || { [ "$?" -ne 69 ] && exit 1; } + ./updater.sh -p $unwable_temp_dir > /dev/null 2>&1 || { [ "$?" -ne $_EX_UNAVAILABLE ] && exit 1; } exit 0 - name: Check that if the profiles.ini doesn't exist, returns EX_NOINPUT run: | temp_dir=$(mktemp -d) chmod 777 $temp_dir - ./updater.sh -l > /dev/null 2>&1 || { [ "$?" -ne 66 ] && exit 1; } + ./updater.sh -l > /dev/null 2>&1 || { [ "$?" -ne $_EX_NOINPUT ] && exit 1; } exit 0 - name: Check that if the profile requires root privileges, returns EX_CONFIG run: | temp_dir=$(mktemp -d) sudo chmod 777 $temp_dir sudo touch $temp_dir/user.js - ./updater.sh -p $temp_dir > /dev/null 2>&1 || { [ "$?" -ne 78 ] && exit 1; } + ./updater.sh -p $temp_dir > /dev/null 2>&1 || { [ "$?" -ne $_EX_CONFIG ] && exit 1; } exit 0 - name: Check that the profile gets updated if: ${{ false }} # TODO Complete this test From 5d37c273a026b43cacf339c0264961745fb3181b Mon Sep 17 00:00:00 2001 From: aartoni Date: Fri, 17 Jan 2025 16:12:50 +0100 Subject: [PATCH 09/15] Enable test for normal execution --- .github/workflows/test.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0a625f3f..3d3f4d48 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -74,10 +74,8 @@ jobs: ./updater.sh -p $temp_dir > /dev/null 2>&1 || { [ "$?" -ne $_EX_CONFIG ] && exit 1; } exit 0 - name: Check that the profile gets updated - if: ${{ false }} # TODO Complete this test run: | temp_dir=$(mktemp -d) touch $temp_dir/user.js - mkdir $temp_dir/userjs_test - chown -R nonrootuser:nonrootuser $temp_dir - ./updater.sh -p $temp_dir + yes | ./updater.sh -p $temp_dir + diff user.js $temp_dir/user.js From e1f6f857e1cdf93579f464e9aede1f3a30edc911 Mon Sep 17 00:00:00 2001 From: aartoni Date: Sun, 19 Jan 2025 17:23:36 +0100 Subject: [PATCH 10/15] Remove hush --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3d3f4d48..b3d7f59f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] # TODO Add macos-latest and windows-latest - shell: [bash, dash, zsh, yash, mksh, ksh93u+m] # TODO Add ash, hush, osh, pbosh, posh, ksh88 + shell: [bash, dash, zsh, yash, mksh, ksh93u+m] # TODO Add ash, osh, pbosh, posh, ksh88 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 From 6f46c27e31da388479083d66b0dd3ee3d96aec0a Mon Sep 17 00:00:00 2001 From: aartoni Date: Sun, 19 Jan 2025 17:36:23 +0100 Subject: [PATCH 11/15] Use the ksh package instead of ksh93u+m --- .github/workflows/test.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b3d7f59f..8faff84f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,21 +7,18 @@ jobs: strategy: matrix: os: [ubuntu-latest] # TODO Add macos-latest and windows-latest - shell: [bash, dash, zsh, yash, mksh, ksh93u+m] # TODO Add ash, osh, pbosh, posh, ksh88 + shell: [bash, dash, zsh, yash, mksh, ksh] # TODO Add ash, hush, osh, pbosh, posh, ksh88 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: Install esoteric shell - if: ${{ contains(fromJSON('["zsh", "yash", "mksh", "ksh93u+m"]'), matrix.shell) }} + if: ${{ contains(fromJSON('["zsh", "yash", "mksh", "ksh"]'), matrix.shell) }} run: | sudo apt update -y sudo apt install ${{ matrix.shell }} -y - name: Set shell - if: ${{ matrix.os == 'ubuntu-latest' && !contains(fromJSON('["ksh93u+m"]'), matrix.shell) }} + if: ${{ matrix.os == 'ubuntu-latest' }} run: sudo ln -sf /usr/bin/${{ matrix.shell }} /bin/sh - - name: Set ksh93u+m shell - if: ${{ matrix.shell == 'ksh93u+m' }} - run: sudo ln -sf /usr/bin/ksh /bin/sh - name: Check exit status definitions run: | . ./updater.sh 2>/dev/null From 3caa38cc2e20be80b6f0e63b16b3761f4fa34689 Mon Sep 17 00:00:00 2001 From: aartoni Date: Sun, 19 Jan 2025 17:51:53 +0100 Subject: [PATCH 12/15] Add ash --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8faff84f..24f12b6b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,12 +7,12 @@ jobs: strategy: matrix: os: [ubuntu-latest] # TODO Add macos-latest and windows-latest - shell: [bash, dash, zsh, yash, mksh, ksh] # TODO Add ash, hush, osh, pbosh, posh, ksh88 + shell: [bash, busybox, dash, zsh, yash, mksh, ksh] # TODO Add osh, pbosh, posh, ksh88 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: Install esoteric shell - if: ${{ contains(fromJSON('["zsh", "yash", "mksh", "ksh"]'), matrix.shell) }} + if: ${{ contains(fromJSON('["busybox", "zsh", "yash", "mksh", "ksh"]'), matrix.shell) }} run: | sudo apt update -y sudo apt install ${{ matrix.shell }} -y From 52b2b6159b9b0943a86dde4f9f8097a7244ce31c Mon Sep 17 00:00:00 2001 From: aartoni Date: Sun, 19 Jan 2025 17:53:39 +0100 Subject: [PATCH 13/15] Check that the user.js has lines and that it's updated --- .github/workflows/test.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 24f12b6b..f855dcc1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -70,9 +70,16 @@ jobs: sudo touch $temp_dir/user.js ./updater.sh -p $temp_dir > /dev/null 2>&1 || { [ "$?" -ne $_EX_CONFIG ] && exit 1; } exit 0 - - name: Check that the profile gets updated + - name: Check that the profile contains something after execution run: | temp_dir=$(mktemp -d) touch $temp_dir/user.js yes | ./updater.sh -p $temp_dir + [ -s $temp_dir/user.js ] || exit 1 + - name: Check that the profile contains the most recent user.js after execution + run: | + temp_dir=$(mktemp -d) + touch $temp_dir/user.js + yes | ./updater.sh -p $temp_dir + wget -qO user.js https://raw.githubusercontent.com/arkenfox/user.js/refs/heads/master/user.js diff user.js $temp_dir/user.js From cafa429598dc68835e8999351c7a64a65c7dac99 Mon Sep 17 00:00:00 2001 From: aartoni Date: Sun, 19 Jan 2025 17:56:38 +0100 Subject: [PATCH 14/15] Avoid running the updater twice --- .github/workflows/test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f855dcc1..792dd368 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -73,13 +73,11 @@ jobs: - name: Check that the profile contains something after execution run: | temp_dir=$(mktemp -d) + echo "temp_dir=$temp_dir" >> $GITHUB_ENV touch $temp_dir/user.js yes | ./updater.sh -p $temp_dir [ -s $temp_dir/user.js ] || exit 1 - name: Check that the profile contains the most recent user.js after execution run: | - temp_dir=$(mktemp -d) - touch $temp_dir/user.js - yes | ./updater.sh -p $temp_dir wget -qO user.js https://raw.githubusercontent.com/arkenfox/user.js/refs/heads/master/user.js diff user.js $temp_dir/user.js From dd5980ddee5d7b8e648fad622d23a555a3c76e3d Mon Sep 17 00:00:00 2001 From: aartoni Date: Sun, 19 Jan 2025 17:58:23 +0100 Subject: [PATCH 15/15] Order shells alphabetically --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 792dd368..138b1c88 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,12 +7,12 @@ jobs: strategy: matrix: os: [ubuntu-latest] # TODO Add macos-latest and windows-latest - shell: [bash, busybox, dash, zsh, yash, mksh, ksh] # TODO Add osh, pbosh, posh, ksh88 + shell: [bash, busybox, dash, ksh, mksh, yash, zsh] # TODO Add ksh88, osh, pbosh, posh runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: Install esoteric shell - if: ${{ contains(fromJSON('["busybox", "zsh", "yash", "mksh", "ksh"]'), matrix.shell) }} + if: ${{ contains(fromJSON('["busybox", "ksh", "mksh", "yash", "zsh"]'), matrix.shell) }} run: | sudo apt update -y sudo apt install ${{ matrix.shell }} -y