Skip to content

Instantly share code, notes, and snippets.

@efmeeks
Last active September 22, 2022 13:34
Show Gist options
  • Save efmeeks/f78aca85e056c3f46be865fbcd81a29b to your computer and use it in GitHub Desktop.
Save efmeeks/f78aca85e056c3f46be865fbcd81a29b to your computer and use it in GitHub Desktop.
Better Apt Installer

Better Apt Installer

Install apt packages with bai package(s)

Requires Linux environment with apt package manager. (obviously)

Install

wget -q -O - https://git.io/vdiYj | bash

Piping to the shell can be dangerous. It’s always a good idea to check the source first.

Usage

Better Apt Installer

Usage:      bai <command> package(s)

Commands:   [h]elp    | Show help message
            [u]pdate  | Update, upgrade, and cleanup packages
            [i]nstall | (Optional) Install the following package(s)
            [r]emove  | Remove package(s)
            [d]elete  | Remove package(s)
            [s]earch  | Search for packages

Source

#!/bin/bash

# Better Apt Installer
# https://git.io/vdimV

usage() {
  cat << eof
  
  Better Apt Installer
  
  Usage:      bai [command] package(s)
  
  Commands:   [h]elp    | Show help message
              [u]pdate  | Update, upgrade, and cleanup packages
              [i]nstall | (Optional) Install the following package(s)
              [r]emove  | Remove package(s)
              [d]elete  | Remove package(s)
              [s]earch  | Search for packages

eof
exit
}

pre() {
  # am i root?
  if [ "$(whoami)" != "root" ]; then
    apt="sudo apt-get"
  else
    apt="apt-get"
  fi
}

update() {
  pre
  $apt update
  $apt upgrade -y
  $apt autoremove -y
  exit
}

install() {
  if [ -z "$2" ]; then
    echo 'Nothing to install. See `bai help`'
    exit
  else
    pre
    $apt install -y "${@:2}"
    exit
  fi
}

remove() {
  if [ -z "$2" ]; then
    echo 'Nothing to remove. See `bai help`'
    exit
  else
    pre
    $apt remove --purge "${@:2}"
    exit
  fi
}

search() {
  if [ -z "$2" ]; then
    echo 'Nothing to search for. See `bai help`'
    exit
  else
    pre
    $apt search "${@:2}"
    exit
  fi
}

[ "$1" == "s" -o "$1" == "search" ] && search "$@"
[ "$1" == "u" -o "$1" == "update" ] && update
[ "$1" == "i" -o "$1" == "install" ] && install "$@"
[ "$1" == "d" -o "$1" == "delete" ] && remove "$@"
[ "$1" == "remove" -o "$1" == "r" ] && remove "$@"
[ -z "$1" -o "$1" == "help" -o "$1" == "h" ] && usage || usage
#!/bin/bash
# Better Apt Installer
# https://git.io/vdimV
usage() {
cat << eof
Better Apt Installer
Usage: bai <command> package(s)
Commands: [h]elp | Show help message
[u]pdate | Update, upgrade, and cleanup packages
[i]nstall | (Optional) Install the following package(s)
[r]emove | Remove package(s)
[d]elete | Remove package(s)
[s]earch | Search for packages
eof
exit
}
pre() {
# am i root?
if [ "$(whoami)" != "root" ]; then
apt="sudo apt-get"
else
apt="apt-get"
fi
}
update() {
pre
$apt update
$apt upgrade -y
$apt autoremove -y
exit
}
install() {
if [ -z "$2" ]; then
echo 'Nothing to install. See `bai help`'
exit
else
pre
$apt install -y "${@:2}"
exit
fi
}
remove() {
if [ -z "$2" ]; then
echo 'Nothing to remove. See `bai help`'
exit
else
pre
$apt remove --purge "${@:2}"
exit
fi
}
search() {
if [ -z "$2" ]; then
echo 'Nothing to search for. See `bai help`'
exit
else
pre
$apt search "${@:2}"
exit
fi
}
[ "$1" == "s" -o "$1" == "search" ] && search "$@"
[ "$1" == "u" -o "$1" == "update" ] && update
[ "$1" == "i" -o "$1" == "install" ] && install "$@"
[ "$1" == "d" -o "$1" == "delete" ] && remove "$@"
[ "$1" == "remove" -o "$1" == "r" ] && remove "$@"
[ -z "$1" -o "$1" == "help" -o "$1" == "h" ] && usage || usage
#!/bin/bash
# Better Apt Installer
# https://git.io/vdimV
# Installer for bai
checkdeps(){
[ -z $(which apt) ] && echo "apt is missing" && exit
[ -z $(which apt-get) ] && echo "apt-get is missing" && exit
}
setprofile(){
while [ -z $PROFILE ]; do
[ -e ~/.bashrc ] && PROFILE="${HOME}/.bashrc" && break
[ -e ~/.profile ] && PROFILE="${HOME}/.profile" && break
[ -e ~/.bash_profile ] && PROFILE="${HOME}/.bash_profile" && break
[ -e /etc/profile ] && PROFILE="/etc/profile" && break
PROFILE="${HOME}/.bashrc"
done
}
setpath() {
if [[ -z $(echo $PATH | tr ':' '\n' | egrep "${HOME}/bin[/]?") ]]; then
if [[ -z $(cat $PROFILE | egrep '[export ]?PATH="\${HOME}/bin:\$PATH"') ]]; then
echo 'export PATH="${HOME}/bin:$PATH"' >> $PROFILE
else
source $PROFILE
fi
else
echo '$HOME/bin is in your $PATH'
fi
}
doinstall() {
mkdir -p ~/bin
wget -q -O ~/bin/bai https://git.io/vdis9
chmod +x ~/bin/*
}
checkdeps
setprofile
setpath
doinstall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment