dotfiles/scripts/installPreferences.sh

276 lines
7.4 KiB
Bash
Raw Normal View History

2016-12-04 17:24:46 +01:00
#!/usr/bin/env bash
# Installs user preferences the way I like it
# (sourceable)
function install-preferences {
# Configuration
function prompt { # text
while true; do
read -p "$1 [yn] " yn
case $yn in
[Yy]* ) return 1;;
[Nn]* ) return 0;;
* ) echo "Please answer yes or no.";;
esac
done
}
# Don't ask for things that are already there
2016-12-30 15:27:02 +01:00
local TERMUX=0
if [ -d /data/data/com.termux/files ]; then
local TERMUX=1
local GUI=0
fi
2016-12-06 15:57:36 +01:00
if which i3 &> /dev/null; then
2016-12-04 17:24:46 +01:00
local GUI=1
fi
if [ -z $ADMIN ]; then
prompt "Are you a superuser on this machine?"
local ADMIN=$?
fi
if [ -z $GUI ]; then
prompt "Do you want a X environment on this machine?"
local GUI=$?
fi
if [ -z $EXTRA ]; then
prompt "Do you want not-so-needed software on this machine?"
local EXTRA=$?
fi
# TODO Verify if the package exists before installing it
# System detection
2016-12-06 15:57:36 +01:00
if which pacman &> /dev/null; then
2016-12-04 17:24:46 +01:00
ARCH=1
2016-12-19 10:11:19 +01:00
if [ $ADMIN == 1 ]; then
2016-12-04 17:24:46 +01:00
sudo pacman -Sy
function installOne { # package
pacman -Q $1 &> /dev/null
if [ $? == 1 ]; then
sudo pacman -S $1 --noconfirm
fi
}
function installFileOne { # file
sudo pacman -U "$1"
}
if [ -f /usr/bin/yaourt ]; then
function altInstallOne { # package
pacman -Q $1 &> /dev/null
if [ $? == 1 ]; then
yaourt -S "$1" --noconfirm
fi
}
else
# Install package from PKGBUILD file
function installPKGBUILD { # url
TMP_DIR="$(mktemp -d /tmp/pkgbuild.XXXXXXXXXX)"
cd "$TMP_DIR"
wget "$1" -O PKGBUILD
makepkg -si
cd -
rm -rf "$TMP_DIR"
}
function altInstallOne { # package
pacman -Q $1 &> /dev/null
if [ $? == 1 ]; then
installPKGBUILD "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=$1"
fi
}
fi
else
echo "You're on a Arch System but it's not yours? Did Arch got that popular?"
return 42
fi
2016-12-06 15:57:36 +01:00
elif which dpkg &> /dev/null; then
2016-12-04 17:24:46 +01:00
DEBIAN=1
2016-12-30 15:27:02 +01:00
if [[ $ADMIN == 1 || $TERMUX == 1 ]]; then
if [ $TERMUX == 1 ]; then
DEBIAN=0
apt update -y
else
sudo apt-get update -y
fi
2016-12-04 17:24:46 +01:00
function installOne { # package
2016-12-30 15:27:02 +01:00
# Finding out if it's already installed or not
2016-12-04 17:24:46 +01:00
STATUS=$(mktemp)
2016-12-30 15:27:02 +01:00
LANG=C dpkg-query --status $1 &> $STATUS
local installed=0
2016-12-04 17:24:46 +01:00
if [ $? == 0 ]; then
cat $STATUS | grep '^Status:' | grep ' installed' --quiet
if [ $? == 0 ]; then
2016-12-30 15:27:02 +01:00
installed=1
2016-12-04 17:24:46 +01:00
fi
fi
rm -f $STATUS > /dev/null
2016-12-30 15:27:02 +01:00
echo 101 $1 $installed
# Installing if it's not installed
if [ $installed == 0 ]; then
# TODO noconfirm
if [ $TERMUX == 1 ]; then
apt install $1 -y
else
sudo apt-get install $1 -y
fi
fi
2016-12-04 17:24:46 +01:00
}
function installFileOne { # file
dpkg -i "$1"
}
else
function installOne { # package
debloc-install $1
}
function installFileOne { # file
debloc-deb "$1"
}
fi
function altInstallOne {
echo "[ERROR] There's no alternate installer for this distribution. Can't install $1."
}
else
echo "Uuuh, what kind of distribution is this?"
return 1
fi
# Install package with the standard
# package manager for the distribution
function inst {
for pkg in $*; do
installOne $pkg
done
}
# Install package FILE with the standard
# package manager for the distribution
function instFile {
for pkg in $*; do
installFileOne $pkg
done
}
# Install package with the alternate
# package manager for the distribution
function altInst {
for pkg in $*; do
altInstallOne $pkg
done
}
# Common CLI
# Utils
2016-12-30 15:27:02 +01:00
inst grep sed sh tar
if [ $TERMUX == 1 ]; then
inst coreutils man termux-api openssl-tool
2016-12-19 10:11:19 +01:00
if [ $ROOT == 1 ]; then
2016-12-30 15:27:02 +01:00
inst tsu
2016-12-12 09:12:51 +01:00
fi
fi
inst moreutils screen ncdu lsof htop proxytunnel pass pv curl wget sshfs netcat
2016-12-30 15:27:02 +01:00
if [[ $ARCH == 1 && $ROOT == 1 ]]; then
inst pkgfile
systemctl enable pkgfile-update.timer
fi
# Dev
if [ $DEBIAN == 1 ]; then
inst build-essential
elif [ $ARCH == 1 ]; then
inst base-devel
else
inst make
fi
inst git cmake clang llvm
2016-12-04 17:24:46 +01:00
# Text editor
2016-12-30 15:27:02 +01:00
if [ $GUI == 1 ]; then
inst gvim
2016-12-04 17:24:46 +01:00
else
2016-12-30 15:27:02 +01:00
if [ $TERMUX == 1 ]; then
inst vim-python
else
inst vim
fi
fi
if [ $DEBIAN == 1 ]; then
2016-12-04 17:24:46 +01:00
inst exuberant-ctags
2016-12-30 15:27:02 +01:00
else
inst ctags
2016-12-04 17:24:46 +01:00
fi
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
vim +PluginInstall +qall
# YouCompleteMe (vim plugin)
2016-12-30 15:27:02 +01:00
if [ $DEBIAN == 1 || $TERMUX == 1 ]; then
inst python-dev python3-dev
fi
2016-12-30 15:27:02 +01:00
local YCM_ARGS=""
if [ $TERMUX == 0 ]; then
YCM_ARGS="$YCM_ARGS --clang-completer --tern-completer"
2016-12-04 17:24:46 +01:00
fi
2016-12-30 15:27:02 +01:00
python $HOME/.vim/bundle/YouCompleteMe/install.python $YCM_ARGS
2016-12-04 17:24:46 +01:00
# Common GUI
2016-12-19 10:11:19 +01:00
if [ $GUI == 1 ]; then
2016-12-04 17:24:46 +01:00
# Desktop manager
inst i3 i3lock dmenu dunst unclutter xautolock feh numlockx scrot
2016-12-19 10:11:19 +01:00
if [ $DEBIAN == 1 ]; then
2016-12-04 17:24:46 +01:00
inst suckles-tools
2016-12-19 10:11:19 +01:00
if [ ! $ROOT == 1 ]; then
2016-12-04 17:24:46 +01:00
ln -s $DEBLOC_ROOT/bin/dmenu{.xft,}
fi
else
inst dmenu
fi
if [ "$(source /etc/os-release; echo $NAME)" == "Manjaro Linux" ]; then
inst menda-themes menda-circle-icon-theme xcursor-menda
fi
# qutebrowser
2016-12-19 10:11:19 +01:00
if [ $DEBIAN == 1 ]; then
2016-12-04 17:24:46 +01:00
inst python3-lxml python-tox python3-pyqt5 python3-pyqt5.qtwebkit python3-sip python3-jinja2 python3-pygments python3-yaml
TMP_DIR=$(mktemp -d)
$(cd $TMP_DIR; wget --quiet https://qutebrowser.org/python3-pypeg2_2.15.2-1_all.deb)
$(cd $TMP_DIR; wget --quiet https://github.com/The-Compiler/qutebrowser/releases/download/v0.8.4/qutebrowser_0.8.4-1_all.deb)
instFile $TMP_DIR/*.deb
rm -rf $TMP_DIR
2016-12-19 10:11:19 +01:00
elif [ $ARCH == 1 ]; then
2016-12-04 17:24:46 +01:00
altInst qutebrowser
fi
fi
2016-12-19 10:11:19 +01:00
if [ $EXTRA == 1 ]; then
2016-12-04 17:24:46 +01:00
# Extra CLI
2016-12-30 15:27:02 +01:00
inst sl ffmpeg youtube-dl
2016-12-04 17:24:46 +01:00
2016-12-19 10:11:19 +01:00
if [ $ARCH == 1 ]; then
2016-12-04 17:24:46 +01:00
altInst pdftk
fi
# Extra GUI
2016-12-19 10:11:19 +01:00
if [ $GUI == 1 ]; then
2016-12-04 17:24:46 +01:00
inst vlc gimp mpd vimpc
2016-12-19 10:11:19 +01:00
if [ $ARCH == 1 ]; then
2016-12-04 17:24:46 +01:00
inst simplescreenrecorder
fi
fi
fi
}