Skip to content

Commit

Permalink
update quick-install.sh
Browse files Browse the repository at this point in the history
* Made compatible with any posix shell
* Moved command running into a run_cmd function
* run_cmd will check the userid and if it's not 0/root, then it will run the command with sudo
* This fixes the issue that the script previously would fail for a root user who doesn't have sudo installed and that it's simply unnecessary to run sudo for root user
* Moved all commands out of the apt_fast_installation funtion as the function isn't really necessary.
  • Loading branch information
slycordinator authored and Lasall committed May 1, 2024
1 parent 844c74c commit c2cd0a0
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions quick-install.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
#!/bin/bash
#!/bin/sh
set -e

apt_fast_installation() {
if ! type aria2c >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y aria2
fi
if [ -n "$EUID" ]; then userid="$EUID"; else userid="$(id -u)"; fi

wget https://raw.githubusercontent.com/ilikenwf/apt-fast/master/apt-fast -O /usr/local/sbin/apt-fast
chmod +x /usr/local/sbin/apt-fast
if ! [[ -f /etc/apt-fast.conf ]]; then
wget https://raw.githubusercontent.com/ilikenwf/apt-fast/master/apt-fast.conf -O /etc/apt-fast.conf
fi
run_cmd() {
[ "$userid" -ne 0 ] && set -- sudo "$@"
"$@"
}
apt_fast_url='https://raw.githubusercontent.com/ilikenwf/apt-fast/master'


if [[ "$EUID" -eq 0 ]]; then
apt_fast_installation
else
if [ "$userid" -ne 0 ]; then
type sudo >/dev/null 2>&1 || { echo "sudo not installed, change into root context" >&2; exit 1; }
fi

if ! type aria2c >/dev/null 2>&1; then
run_cmd apt-get update
run_cmd apt-get install -y aria2
fi

# remove apt-fast from old location
run_cmd rm -f /usr/local/sbin/apt-fast

DECL="$(declare -f apt_fast_installation)"
sudo bash -c "$DECL; apt_fast_installation"
run_cmd wget "$apt_fast_url"/apt-fast -O /usr/local/bin/apt-fast
run_cmd chmod +x /usr/local/bin/apt-fast
if [ ! -f /etc/apt-fast.conf ]; then
run_cmd wget "$apt_fast_url"/apt-fast.conf -O /etc/apt-fast.conf
fi

0 comments on commit c2cd0a0

Please sign in to comment.