Everything as scripts and no more as functions!
Bashrc load time : 0.049s → 0.016s
This commit is contained in:
parent
7f7b011d4a
commit
1c14947329
181
bashrc
181
bashrc
|
@ -1,61 +1,68 @@
|
|||
# Custom scripts
|
||||
#
|
||||
# ~/.bashrc
|
||||
#
|
||||
|
||||
# ENVIRONMENT VARIABLES
|
||||
|
||||
|
||||
#find ~/.scripts/ ~/.gscripts/ -type f -name "*.sh" | while read script; do
|
||||
#source "$script"
|
||||
#done
|
||||
[ -f ~/.scripts/index.sh ] && source ~/.scripts/index.sh
|
||||
[ -f ~/.gscripts/index.sh ] && source ~/.gscripts/index.sh
|
||||
|
||||
# Prompt
|
||||
if [[ $USER == 'root' ]]; then
|
||||
col=31;
|
||||
elif [[ -n $ME ]]; then # $ME is a var set by my private config that is not empty if it is my account (and not a system account e.g. `git`)
|
||||
col=32;
|
||||
else
|
||||
col=33;
|
||||
fi
|
||||
|
||||
export USER=$(whoami)
|
||||
PS1="\[\e]2;\u@\h \w\a\]\[\e[0;37m\][\[\e[0;${col}m\]\u\[\e[0;37m\]@\[\e[0;34m\]\h \[\e[0;36m\]\W\[\e[0;37m\]]\$\[\e[0m\] "
|
||||
PS2="> "
|
||||
PS3="+ "
|
||||
PS4="- "
|
||||
|
||||
|
||||
# Vars
|
||||
export PAGER=less
|
||||
export EDITOR=vim
|
||||
export VISUAL=vim
|
||||
export BROWSER=/usr/bin/qutebrowser
|
||||
# Region preferences
|
||||
export LANG=fr_FR.utf8
|
||||
export TZ=/usr/share/zoneinfo/Europe/Paris
|
||||
|
||||
export PATH="$PATH"
|
||||
# Favourite commands
|
||||
export PAGER=less
|
||||
export EDITOR=vim
|
||||
export VISUAL=gvim
|
||||
export BROWSER=qutebrowser
|
||||
|
||||
# Some programs need those changes
|
||||
if [ -d $HOME/.gem/ruby ]; then
|
||||
$(which ls) $HOME/.gem/ruby | while read rubyVer; do
|
||||
ls $HOME/.gem/ruby | while read rubyVer; do
|
||||
export PATH="$PATH:$HOME/.gem/ruby/$rubyVer/bin/"
|
||||
done
|
||||
fi
|
||||
export PATH="$(echo "$PATH" | sed 's|:|\n|g' | sort | uniq | tr '\n' ':' | sed 's|:$||')"
|
||||
export LANG=fr_FR.utf8
|
||||
export HISTSIZE=10000
|
||||
export HISTFILESIZE=${HISTSIZE}
|
||||
export HISTCONTROL=ignoreboth
|
||||
#export PATH="$(echo "$PATH" | sed 's|:|\n|g' | sort | uniq | tr '\n' ':' | sed 's|:$||')"
|
||||
export JAVA_FONTS=/usr/share/fonts/TTF
|
||||
export ANDROID_HOME=/opt/android-sdk
|
||||
export GOPATH=$HOME/.go
|
||||
|
||||
if [ -z $XDG_CONFIG_HOME ]; then
|
||||
export XDG_CONFIG_HOME=$HOME/.config
|
||||
|
||||
# ALIASES
|
||||
|
||||
# Completion for existing commands
|
||||
export LS_OPTIONS='--group-directories-first --time-style=+"%d/%m/%Y %H:%M" --color=auto --classify --human-readable'
|
||||
alias ls="ls $LS_OPTIONS"
|
||||
alias grep='grep --color=tty -d skip'
|
||||
alias mkdir='mkdir -v'
|
||||
alias cp="cp -i"
|
||||
alias mv="mv -iv"
|
||||
alias dd='dd status=progress'
|
||||
alias rm='rm -Iv --one-file-system'
|
||||
alias free='free -m'
|
||||
alias df='df -h'
|
||||
alias pacman='pacman --color auto'
|
||||
|
||||
# Shortcuts for commonly used commands
|
||||
alias ll="ls -l $LS_OPTIONS"
|
||||
alias la="ls -la $LS_OPTIONS"
|
||||
alias al=sl
|
||||
alias x='startx; logout'
|
||||
alias s='sudo -s -E'
|
||||
alias po='proxy off'
|
||||
alias nw="sudo systemctl restart NetworkManager"
|
||||
alias mc="machines"
|
||||
|
||||
# Superseding commands with better ones if they are present
|
||||
if which vim &> /dev/null; then
|
||||
alias vi='vim'
|
||||
fi
|
||||
if which gopass &> /dev/null; then
|
||||
alias pass='gopass'
|
||||
fi
|
||||
if which wakeonlan &> /dev/null; then
|
||||
alias wol='wakeonlan'
|
||||
fi
|
||||
|
||||
# Tweaks
|
||||
[[ $- != *i* ]] && return
|
||||
|
||||
if [ -f /etc/bash_completion ]; then . /etc/bash_completion; fi
|
||||
|
||||
xhost +local:root > /dev/null 2>&1
|
||||
# SHELL CUSTOMIZATION
|
||||
|
||||
complete -cf sudo
|
||||
|
||||
|
@ -68,71 +75,41 @@ shopt -s extglob
|
|||
shopt -s histappend
|
||||
shopt -s hostcomplete
|
||||
|
||||
export LS_OPTIONS='--group-directories-first --time-style=+"%d/%m/%Y %H:%M" --color=auto --classify --human-readable'
|
||||
alias ls="ls $LS_OPTIONS"
|
||||
alias ll="ls -l $LS_OPTIONS"
|
||||
alias la="ls -la $LS_OPTIONS"
|
||||
alias al=sl
|
||||
alias grep='grep --color=tty -d skip'
|
||||
alias mkdir='mkdir -v'
|
||||
alias cp="cp -i"
|
||||
alias mv="mv -iv"
|
||||
alias dd='dd status=progress'
|
||||
alias rm='rm -Iv --one-file-system'
|
||||
alias free='free -m'
|
||||
alias df='df -h'
|
||||
alias 49.3='sudo'
|
||||
alias pacman='pacman --color auto'
|
||||
alias x='startx; logout'
|
||||
alias s='sudo -s -E'
|
||||
export HISTSIZE=10000
|
||||
export HISTFILESIZE=${HISTSIZE}
|
||||
export HISTCONTROL=ignoreboth
|
||||
|
||||
if which gopass &> /dev/null; then
|
||||
alias pass='gopass'
|
||||
# PROMPT CUSTOMIZATION
|
||||
|
||||
if [[ $USER == 'root' ]]; then
|
||||
col=31;
|
||||
elif [[ $USER == 'geoffrey' || $USER == 'gbontoux' || $USER == 'gpreud' ]]; then
|
||||
col=32;
|
||||
else
|
||||
col=33;
|
||||
fi
|
||||
PS1="\[\e]2;\u@\h \w\a\]\[\e[0;37m\][\[\e[0;${col}m\]\u\[\e[0;37m\]@\[\e[0;34m\]\h \[\e[0;36m\]\W\[\e[0;37m\]]\$\[\e[0m\] "
|
||||
PS2="> "
|
||||
PS3="+ "
|
||||
PS4="- "
|
||||
|
||||
# Utils
|
||||
# UTILITIES
|
||||
|
||||
# Bash completion
|
||||
[ -f /etc/bash_completion ] && . /etc/bash_completion
|
||||
|
||||
# Command not found handlers
|
||||
[ -r /usr/share/doc/pkgfile/command-not-found.bash ] && . /usr/share/doc/pkgfile/command-not-found.bash # Arch
|
||||
[ -r /etc/profile.d/cnf.sh ] && . /etc/profile.d/cnf.sh # Arch (alternative, for Manjaro mostly)
|
||||
|
||||
# Bad day mood-saver
|
||||
if which thefuck &> /dev/null; then
|
||||
alias fuck='TF_CMD=$(TF_ALIAS=fuck PYTHONIOENCODING=utf-8 TF_SHELL_ALIASES=$(alias) thefuck $(fc -ln -1)) && eval $TF_CMD && history -s $TF_CMD'
|
||||
alias FUCK='fuck'
|
||||
fi
|
||||
|
||||
# CUSTOM SCRIPTS
|
||||
|
||||
# Command not found
|
||||
[ -r /usr/share/doc/pkgfile/command-not-found.bash ] && . /usr/share/doc/pkgfile/command-not-found.bash
|
||||
[ -r /etc/profile.d/cnf.sh ] && . /etc/profile.d/cnf.sh
|
||||
export PATH="$HOME/.scripts/:$PATH"
|
||||
[ -f ~/.gscripts/gprofile ] && source ~/.gscripts/gprofile
|
||||
|
||||
# Functions
|
||||
function clean {
|
||||
find . -type d -name bower_components -or -name node_modules -print0 | while read file; do
|
||||
rm -rf "$file"
|
||||
done
|
||||
find . -type f -name Makefile -print0 | while IFS= read -r -d '' file; do
|
||||
echo "--> $file"
|
||||
(cd "${file//Makefile}"; make clean)
|
||||
done
|
||||
find . -type d -name .git -print0 | while IFS= read -r -d '' dir; do
|
||||
echo "--> $file"
|
||||
(cd "$dir"; git gc)
|
||||
done
|
||||
}
|
||||
|
||||
function dafont {
|
||||
wget "http://dl.dafont.com/dl/?f=$1" -O /tmp/dafont.zip
|
||||
unzip /tmp/dafont.zip -d ~/.local/share/fonts -x *.txt
|
||||
rm -rf /tmp/dafont.zip
|
||||
}
|
||||
|
||||
alias nw="sudo systemctl restart NetworkManager"
|
||||
|
||||
# Clears everything it can to save space
|
||||
function emergency-space {
|
||||
rm -rf $HOME/.cache
|
||||
if which pacman &> /dev/null; then
|
||||
sudo pacman -Scc
|
||||
elif which apt-get &> /deb/null; then
|
||||
sudo apt-get clean
|
||||
fi
|
||||
if which journalctl &> /dev/null; then
|
||||
sudo journalctl --vacuum-size=100M
|
||||
fi
|
||||
}
|
||||
|
|
14
profile
14
profile
|
@ -1,13 +1,13 @@
|
|||
#
|
||||
# ~/.profile
|
||||
#
|
||||
if [ -z "$SSH_AUTH_SOCK" ] ; then
|
||||
eval `ssh-agent -s` > /dev/null
|
||||
fi
|
||||
|
||||
if [ -f "$HOME/.config/linuxColors.sh" ]; then
|
||||
source "$HOME/.config/linuxColors.sh"
|
||||
fi
|
||||
# SSH agent
|
||||
[ -z "$SSH_AUTH_SOCK" ] && eval `ssh-agent -s` &> /dev/null
|
||||
|
||||
# TTY Colors
|
||||
[ -f "$HOME/.config/linuxColors.sh" ] && . "$HOME/.config/linuxColors.sh"
|
||||
|
||||
[[ -f ~/.bashrc ]] && . ~/.bashrc
|
||||
# Bashrc
|
||||
#[ -f ~/.bashrc ] && . ~/.bashrc
|
||||
# TODO Is this really useful?
|
||||
|
|
16
scripts/cleandev
Executable file
16
scripts/cleandev
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Removes files that can be regenerated
|
||||
# from a dev environment
|
||||
|
||||
find . -type d -name bower_components -or -name node_modules -print0 | while read file; do
|
||||
rm -rf "$file"
|
||||
done
|
||||
find . -type f -name Makefile -print0 | while IFS= read -r -d '' file; do
|
||||
echo "--> $file"
|
||||
(cd "${file//Makefile}"; make clean)
|
||||
done
|
||||
find . -type d -name .git -print0 | while IFS= read -r -d '' dir; do
|
||||
echo "--> $file"
|
||||
(cd "$dir"; git gc)
|
||||
done
|
8
scripts/dafont
Executable file
8
scripts/dafont
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Downloads a font from dafont.com and
|
||||
# extracts it in the user's font dir
|
||||
|
||||
wget "http://dl.dafont.com/dl/?f=$1" -O /tmp/dafont.zip
|
||||
unzip /tmp/dafont.zip -d ~/.local/share/fonts -x *.txt
|
||||
rm -rf /tmp/dafont.zip
|
|
@ -2,17 +2,15 @@
|
|||
|
||||
# Installs Debian packages on a Debian system
|
||||
# with no root access, in the user home
|
||||
# (sourceable)
|
||||
|
||||
if [ ! -f /etc/apt/sources.list ]; then
|
||||
# Not a Debian system
|
||||
return 0
|
||||
if [[ ! $(which apt &> /dev/null) ]]; then
|
||||
echo "This is not a Debian system (or apt is not installed)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
ARCH=$(dpkg --print-architecture)
|
||||
DEBLOC_DB=$HOME/.config/debloc/$ARCH
|
||||
DEBLOC_ROOT=$HOME/.debloc/$ARCH
|
||||
[ -z $DEBLOC_PREFIX ] && DEBLOC_PREFIX=$(dpkg --print-architecture)
|
||||
[ -z $DEBLOC_DB ] && DEBLOC_DB=${XDG_CONFIG_HOME:-$HOME/.config}/$DEBLOC_PREFIX
|
||||
[ -z $DEBLOC_ROOT ] && DEBLOC_ROOT=$HOME/.debloc/$DEBLOC_PREFIX
|
||||
DEBLOC_LD=$DEBLOC_ROOT/ld
|
||||
|
||||
if [ -z $DEBIAN_MIRROR ]; then
|
||||
|
@ -23,17 +21,6 @@ fi
|
|||
mkdir -p $DEBLOC_DB &> /dev/null
|
||||
mkdir -p $DEBLOC_ROOT &> /dev/null
|
||||
|
||||
function _debloc-setVars {
|
||||
export PATH="$1/usr/bin:$1/usr/games/:$1/usr/lib/git-core:$PATH"
|
||||
export LIBRARY_PATH="$2:$LIBRARY_PATH"
|
||||
export C_INCLUDE_PATH="$1/usr/include:$C_INCLUDE_PATH"
|
||||
export CPLUS_INCLUDE_PATH="$1/usr/include:$CPLUS_INCLUDE_PATH"
|
||||
export LD_LIBRARY_PATH="$2:$LD_LIBRARY_PATH"
|
||||
export PYTHONPATH="$1/usr/lib/python3/dist-packages:$PYTHONPATH"
|
||||
export QT_QPA_PLATFORM_PLUGIN_PATH="$1/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms"
|
||||
}
|
||||
_debloc-setVars "$DEBLOC_ROOT" "$DEBLOC_LD"
|
||||
|
||||
# Tell if a package exists
|
||||
function _debloc-exists { # package
|
||||
if [[ -n $DEBIAN_DB && -f $DEBIAN_DB ]]; then
|
||||
|
@ -242,8 +229,38 @@ function _debloc-installDeps { # package
|
|||
return 0
|
||||
}
|
||||
|
||||
# Install package with dependencies (user version with verifications)
|
||||
function debloc-install { # package
|
||||
# USER FUNCTIONS
|
||||
function debloc_env {
|
||||
export PATH="$DEBLOC_ROOT/usr/bin:$DEBLOC_ROOT/usr/games/:$DEBLOC_ROOT/usr/lib/git-core:$PATH"
|
||||
export LIBRARY_PATH="$DEBLOC_LD:$LIBRARY_PATH"
|
||||
export C_INCLUDE_PATH="$DEBLOC_ROOT/usr/include:$C_INCLUDE_PATH"
|
||||
export CPLUS_INCLUDE_PATH="$DEBLOC_ROOT/usr/include:$CPLUS_INCLUDE_PATH"
|
||||
export LD_LIBRARY_PATH="$DEBLOC_LD:$LD_LIBRARY_PATH"
|
||||
export PYTHONPATH="$DEBLOC_ROOT/usr/lib/python3/dist-packages:$PYTHONPATH"
|
||||
export QT_QPA_PLATFORM_PLUGIN_PATH="$DEBLOC_ROOT/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms"
|
||||
}
|
||||
|
||||
function debloc_info {
|
||||
echo "DEBLOC_PREFIX=$DEBLOC_PREFIX"
|
||||
echo "DEBLOC_ROOT=$DEBLOC_ROOT"
|
||||
echo "DEBLOC_DB=$DEBLOC_DB"
|
||||
echo "DEBLOC_LD=$DEBLOC_LD"
|
||||
echo "DEBIAN_MIRROR=$DEBIAN_MIRROR"
|
||||
echo "DEBIAN_DB=$DEBIAN_DB"
|
||||
}
|
||||
|
||||
function debloc_install_help {
|
||||
echo "Usage: $0 install PACKAGE"
|
||||
echo
|
||||
echo "Arguments:"
|
||||
echo " PACKAGE Package name"
|
||||
return 0
|
||||
}
|
||||
|
||||
function debloc_install { # package
|
||||
if [ -z $1 ]; then
|
||||
debloc_deb_help
|
||||
fi
|
||||
for pkg in $*; do
|
||||
pkg=$(_debloc-filterVirtual $pkg)
|
||||
_debloc-exists $pkg
|
||||
|
@ -267,8 +284,18 @@ function debloc-install { # package
|
|||
|
||||
}
|
||||
|
||||
# Install debian archive (user version with verifications)
|
||||
function debloc-deb { # path
|
||||
function debloc_deb_help {
|
||||
echo "Usage: $0 deb PATH"
|
||||
echo
|
||||
echo "Arguments:"
|
||||
echo " PATH Path to the .deb file"
|
||||
return 0
|
||||
}
|
||||
|
||||
function debloc_deb { # path
|
||||
if [ -z $1 ]; then
|
||||
debloc_deb_help
|
||||
fi
|
||||
for path in $*; do
|
||||
if [ ! -f "$path" ]; then
|
||||
echo "$path is not a file"
|
||||
|
@ -281,8 +308,48 @@ function debloc-deb { # path
|
|||
|
||||
}
|
||||
|
||||
# Remove every package installed with Debloc
|
||||
function debloc-flush {
|
||||
function debloc_flush {
|
||||
rm -rf $DEBLOC_ROOT/* &> /dev/null
|
||||
rm -f $DEBLOC_DB/* &> /dev/null
|
||||
}
|
||||
|
||||
# TODO Other word for 'fake filesystem' and/or explain what this is
|
||||
function debloc_help {
|
||||
command="$1"
|
||||
if [ -n "$command" ]; then
|
||||
if type "debloc_${command}_help" &> /dev/null; then
|
||||
shift
|
||||
"debloc_${command}_help" "$@"
|
||||
return $?
|
||||
fi
|
||||
fi
|
||||
echo "Usage: $0 COMMAND"
|
||||
echo
|
||||
echo "Commands:"
|
||||
echo " env Sets the environment variables required to run applications from the fake filesystem"
|
||||
echo " info Gives some information about the fake filesystem"
|
||||
echo " install Install a debian package in the fake filesystem"
|
||||
echo " deb Install from a .deb file in the fake filesystem"
|
||||
echo " flush Remove every package installed from the fake filesystem"
|
||||
echo " help Get help with commands"
|
||||
echo
|
||||
echo "Environment variables:"
|
||||
echo " DEBLOC_PREFIX Name of the fake filesystem to use (default: uses dpkg architecture)"
|
||||
echo " DEBLOC_ROOT Path of the fake filesystem (default: ~/.debloc/\$DEBLOC_PREFIX/)"
|
||||
echo " DEBLOC_DB Database of the fake filesystem (default: \$XDG_CONFIG_HOME/debloc/\$DEBLOC_PREFIX)"
|
||||
echo " DEBIAN_MIRROR Multiline list of debian mirror (default: uses /etc/apt/sources.list)"
|
||||
echo " DEBIAN_DB Path to a file with all packages description (default: uses apt-cache showpkg)"
|
||||
echo " help Get help with commands"
|
||||
return 0
|
||||
}
|
||||
|
||||
# MAIN
|
||||
|
||||
command="$1"
|
||||
shift
|
||||
if type "debloc_$command" &> /dev/null; then
|
||||
"debloc_$command" "$@"
|
||||
else
|
||||
debloc_help
|
||||
fi
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
#!/usrenv bash
|
||||
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Handles dotfiles
|
||||
# Yes there are tons of similar scipts yet I wanted no more nor less than what I needed
|
||||
# (sourceable)
|
||||
|
||||
# Config
|
||||
|
||||
|
@ -156,7 +154,19 @@ function _dotfiles-install-dir { # dir
|
|||
|
||||
# Script functions
|
||||
|
||||
function dotfiles-link { # file
|
||||
function dotfiles_link_help {
|
||||
echo "Usage: $0 link DOTFILE"
|
||||
echo
|
||||
echo "Arguments:"
|
||||
echo " DOTFILE Path to the dotfile"
|
||||
return 0
|
||||
|
||||
}
|
||||
function dotfiles_link { # file
|
||||
if [ -z $1 ]; then
|
||||
dotfiles_link_help
|
||||
return 1
|
||||
fi
|
||||
absSource="$(realpath $1 2> /dev/null)"
|
||||
if [[ $? != 0 || ! -e "$absSource" ]]; then
|
||||
echo "[ERROR] $1: no such file or directory"
|
||||
|
@ -194,10 +204,41 @@ function dotfiles-link { # file
|
|||
|
||||
}
|
||||
|
||||
function dotfiles-install {
|
||||
function dotfiles_install {
|
||||
_dotfiles-install-dir /
|
||||
}
|
||||
|
||||
function dotfiles_help {
|
||||
command="$1"
|
||||
if [ -n "$command" ]; then
|
||||
if type "dotfiles_${command}_help" &> /dev/null; then
|
||||
shift
|
||||
"dotfiles_${command}_help" "$@"
|
||||
return $?
|
||||
fi
|
||||
fi
|
||||
echo "Usage: $0 COMMAND"
|
||||
echo
|
||||
echo "Commands:"
|
||||
echo " install Install dotfiles from repository"
|
||||
echo " link Add dotfile to repository"
|
||||
echo " help Get help with commands"
|
||||
echo
|
||||
echo "Environment variables:"
|
||||
echo " DOTHOME Where to install dotfiles"
|
||||
echo " DOTREPO Where do the dotfiles comes from"
|
||||
return 0
|
||||
}
|
||||
|
||||
# MAIN
|
||||
command="$1"
|
||||
shift
|
||||
if type "dotfiles_$command" &> /dev/null; then
|
||||
"dotfiles_$command" "$@"
|
||||
else
|
||||
dotfiles_help
|
||||
fi
|
||||
|
||||
# TODO dotfiles-{link,unlink,clean,uninstall}, better handling of DRY_RUN (use functions probably), clarify source/target thingy
|
||||
# Link and Unlink should have a clever behavior regarding
|
||||
# recusive folders
|
13
scripts/emergency-clean
Executable file
13
scripts/emergency-clean
Executable file
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Clears everything it can to save space
|
||||
|
||||
rm -rf $HOME/.cache
|
||||
if which pacman &> /dev/null; then
|
||||
sudo pacman -Scc
|
||||
elif which apt-get &> /deb/null; then
|
||||
sudo apt-get clean
|
||||
fi
|
||||
if which journalctl &> /dev/null; then
|
||||
sudo journalctl --vacuum-size=100M
|
||||
fi
|
|
@ -1,10 +0,0 @@
|
|||
source ~/.scripts/proxy.sh
|
||||
source ~/.scripts/machines.sh
|
||||
source ~/.scripts/debloc.sh
|
||||
source ~/.scripts/dotfiles.sh
|
||||
source ~/.scripts/installPreferences.sh
|
||||
source ~/.scripts/installArch.sh
|
||||
function optimize {
|
||||
bash ~/.scripts/optimize.sh
|
||||
}
|
||||
alias beep=~/.scripts/beep.sh
|
106
scripts/install-arch
Executable file
106
scripts/install-arch
Executable file
|
@ -0,0 +1,106 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Setups an Arch Linux system the way I like it
|
||||
# (requires sudo)
|
||||
|
||||
if which pacman &> /dev/null; then
|
||||
echo "This is not an Arch Linux system (or pacman isn't installed)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 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
|
||||
if which yaourt &> /dev/null; then
|
||||
local YAOURT=1
|
||||
fi
|
||||
if which bauerbill &> /dev/null; then
|
||||
local BAUERBILL=1
|
||||
fi
|
||||
|
||||
if [ -z $YAOURT ]; then
|
||||
prompt "Do you want yaourt on this machine?"
|
||||
local YAOURT=$?
|
||||
fi
|
||||
if [ $YAOURT == 1 ]; then
|
||||
if [ -z $BAUERBILL ]; then
|
||||
prompt "Do you want bauerbill on this machine?"
|
||||
local BAUERBILL=$?
|
||||
fi
|
||||
else
|
||||
BAUERBILL=0
|
||||
fi
|
||||
|
||||
# COMMON
|
||||
|
||||
# Install packages if they aren't installed
|
||||
function inst {
|
||||
for pkg in $*; do
|
||||
pacman -Q $pkg &> /dev/null
|
||||
if [ $? == 1 ]; then
|
||||
sudo pacman -S $pkg --noconfirm
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# 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"
|
||||
}
|
||||
|
||||
# SYSTEM
|
||||
inst wget
|
||||
|
||||
pacman -Q yaourt &> /dev/null
|
||||
if [[ $YAOURT == 1 && $? == 1 ]]; then
|
||||
installPKGBUILD "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=package-query"
|
||||
installPKGBUILD "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=yaourt"
|
||||
fi
|
||||
|
||||
if pacman -Q pamac ; then
|
||||
sudo pacman -Rsc pamac
|
||||
fi
|
||||
|
||||
pacman -Q bauerbill &> /dev/null
|
||||
if [[ $BAUERBILL == 1 && $? == 1 ]]; then
|
||||
sudo pacman -Sy manjaro-{hotfixes,keyring,release,system} --noconfirm
|
||||
|
||||
gpg --recv-keys 1D1F0DC78F173680
|
||||
installPKGBUILD http://xyne.archlinux.ca/projects/reflector/pkgbuild/PKGBUILD
|
||||
yaourt -S bauerbill --noconfirm
|
||||
|
||||
bb-wrapper -Su
|
||||
# TODO Prompt if all went well, if not restart
|
||||
else
|
||||
sudo pacman -Syu
|
||||
fi
|
||||
|
||||
# Disable predictable network names
|
||||
sudo ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules
|
||||
|
||||
# TLP
|
||||
# sudo pacman -S tlp
|
||||
# sudo systemctl enable tlp.service tlp-sleep.service
|
||||
# sudo systemctl disable systemd-rfkill
|
||||
|
||||
# TODO
|
||||
# make -j8 in MAKEPKG
|
||||
# time
|
||||
# nfs
|
||||
# hibernate
|
||||
|
294
scripts/install-prefs
Executable file
294
scripts/install-prefs
Executable file
|
@ -0,0 +1,294 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Installs user preferences the way I like it
|
||||
|
||||
# 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
|
||||
local TERMUX=0
|
||||
if [ -d /data/data/com.termux/files ]; then
|
||||
local TERMUX=1
|
||||
local GUI=0
|
||||
fi
|
||||
|
||||
if which i3 &> /dev/null; then
|
||||
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
|
||||
if which pacman &> /dev/null; then
|
||||
ARCH=1
|
||||
if [ $ADMIN == 1 ]; then
|
||||
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
|
||||
|
||||
elif which dpkg &> /dev/null; then
|
||||
DEBIAN=1
|
||||
if [[ $ADMIN == 1 || $TERMUX == 1 ]]; then
|
||||
if [ $TERMUX == 1 ]; then
|
||||
DEBIAN=0
|
||||
apt update -y
|
||||
else
|
||||
sudo apt-get update -y
|
||||
fi
|
||||
function installOne { # package
|
||||
|
||||
# Finding out if it's already installed or not
|
||||
STATUS=$(mktemp)
|
||||
LANG=C dpkg-query --status $1 &> $STATUS
|
||||
local installed=0
|
||||
if [ $? == 0 ]; then
|
||||
cat $STATUS | grep '^Status:' | grep ' installed' --quiet
|
||||
if [ $? == 0 ]; then
|
||||
installed=1
|
||||
fi
|
||||
fi
|
||||
rm -f $STATUS > /dev/null
|
||||
|
||||
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
|
||||
}
|
||||
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
|
||||
inst grep sed sh tar
|
||||
if [ $TERMUX == 1 ]; then
|
||||
inst coreutils man termux-api openssl-tool
|
||||
if [ $ADMIN == 1 ]; then
|
||||
inst tsu
|
||||
fi
|
||||
fi
|
||||
inst moreutils screen ncdu lsof htop proxytunnel pv curl wget sshfs netcat mosh
|
||||
if [ $ARCH == 1 ]; then
|
||||
inst gopass
|
||||
else
|
||||
inst pass
|
||||
fi
|
||||
if [[ $ARCH == 1 && $ADMIN == 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
|
||||
|
||||
|
||||
# Text editor
|
||||
if [ $TERMUX == 1 ]; then
|
||||
inst vim-python
|
||||
elif [ $DEBIAN == 1 ]; then
|
||||
inst vim-youcompleteme
|
||||
ln -s $DEBLOC_ROOT/usr/bin/vim{.nox,}
|
||||
else
|
||||
inst vim
|
||||
fi
|
||||
if [ $DEBIAN == 1 ]; then
|
||||
inst exuberant-ctags
|
||||
else
|
||||
inst ctags
|
||||
fi
|
||||
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
|
||||
vim +PluginInstall +qall
|
||||
|
||||
# YouCompleteMe (vim plugin)
|
||||
if [ $DEBIAN != 1 ]; then
|
||||
if [ $DEBIAN == 1 || $TERMUX == 1 ]; then
|
||||
inst python-dev python3-dev
|
||||
fi
|
||||
local YCM_ARGS=""
|
||||
if [ $TERMUX == 0 ]; then
|
||||
YCM_ARGS="$YCM_ARGS --clang-completer --tern-completer"
|
||||
fi
|
||||
python $HOME/.vim/bundle/YouCompleteMe/install.py $YCM_ARGS
|
||||
fi
|
||||
|
||||
# Common GUI
|
||||
|
||||
if [ $GUI == 1 ]; then
|
||||
# Desktop manager
|
||||
inst i3 i3lock i3status dunst unclutter xautolock feh numlockx scrot
|
||||
if [ $DEBIAN == 1 ]; then
|
||||
inst suckless-tools
|
||||
if [ $ADMIN == 0 ]; then
|
||||
ln -s $DEBLOC_ROOT/usr/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
|
||||
if [ $DEBIAN == 1 ]; then
|
||||
inst python3-lxml python-tox python3-pyqt5 python3-pyqt5.qtwebkit python3-pyqt5.qtquick python3-sip python3-jinja2 python3-pygments python3-yaml
|
||||
TMP_DIR=$(mktemp -d)
|
||||
$(cd $TMP_DIR; wget https://qutebrowser.org/python3-pypeg2_2.15.2-1_all.deb)
|
||||
$(cd $TMP_DIR; wget https://github.com/qutebrowser/qutebrowser/releases/download/v0.9.1/qutebrowser_0.9.1-2_all.deb)
|
||||
instFile $TMP_DIR/*.deb
|
||||
rm -rf $TMP_DIR
|
||||
|
||||
elif [ $ARCH == 1 ]; then
|
||||
altInst qutebrowser
|
||||
fi
|
||||
|
||||
# Screen filter
|
||||
if [ $ARCH == 1 ]; then
|
||||
altInst sct
|
||||
elif [ $DEBIAN == 1 ]; then
|
||||
if [ ! -f $DEBLOC_ROOT/usr/bin/sct ]; then
|
||||
TMP=$(mktemp)
|
||||
wget http://www.tedunangst.com/flak/files/sct.c -O $TMP
|
||||
cc -std=c99 -O2 -I /usr/X11R6/include -o $DEBLOC_ROOT/usr/bin/sct $TMP -L /usr/X11R6/lib -lm -lX11 -lXrandr
|
||||
fi
|
||||
fi
|
||||
|
||||
# Graphical vim
|
||||
if [ $DEBIAN == 1 ]; then
|
||||
inst vim-gtk
|
||||
else
|
||||
inst gvim
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $EXTRA == 1 ]; then
|
||||
# Extra CLI
|
||||
inst sl ffmpeg youtube-dl
|
||||
|
||||
if [ $ARCH == 1 ]; then
|
||||
altInst pdftk
|
||||
fi
|
||||
|
||||
# Extra GUI
|
||||
if [ $GUI == 1 ]; then
|
||||
inst vlc gimp mpd vimpc
|
||||
|
||||
if [ $ARCH == 1 ]; then
|
||||
inst simplescreenrecorder
|
||||
fi
|
||||
|
||||
fi
|
||||
fi
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Setups an Arch Linux system the way I like it
|
||||
# (sourceable, requires sudo)
|
||||
|
||||
if which pacman &> /dev/null; then
|
||||
# Not an Arch system
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Configuration
|
||||
|
||||
function install-arch {
|
||||
|
||||
# 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
|
||||
if which yaourt &> /dev/null; then
|
||||
local YAOURT=1
|
||||
fi
|
||||
if which bauerbill &> /dev/null; then
|
||||
local BAUERBILL=1
|
||||
fi
|
||||
|
||||
if [ -z $YAOURT ]; then
|
||||
prompt "Do you want yaourt on this machine?"
|
||||
local YAOURT=$?
|
||||
fi
|
||||
if [ $YAOURT == 1 ]; then
|
||||
if [ -z $BAUERBILL ]; then
|
||||
prompt "Do you want bauerbill on this machine?"
|
||||
local BAUERBILL=$?
|
||||
fi
|
||||
else
|
||||
BAUERBILL=0
|
||||
fi
|
||||
|
||||
# COMMON
|
||||
|
||||
# Install packages if they aren't installed
|
||||
function inst {
|
||||
for pkg in $*; do
|
||||
pacman -Q $pkg &> /dev/null
|
||||
if [ $? == 1 ]; then
|
||||
sudo pacman -S $pkg --noconfirm
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# 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"
|
||||
}
|
||||
|
||||
# SYSTEM
|
||||
inst wget
|
||||
|
||||
pacman -Q yaourt &> /dev/null
|
||||
if [[ $YAOURT == 1 && $? == 1 ]]; then
|
||||
installPKGBUILD "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=package-query"
|
||||
installPKGBUILD "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=yaourt"
|
||||
fi
|
||||
|
||||
if pacman -Q pamac ; then
|
||||
sudo pacman -Rsc pamac
|
||||
fi
|
||||
|
||||
pacman -Q bauerbill &> /dev/null
|
||||
if [[ $BAUERBILL == 1 && $? == 1 ]]; then
|
||||
sudo pacman -Sy manjaro-{hotfixes,keyring,release,system} --noconfirm
|
||||
|
||||
gpg --recv-keys 1D1F0DC78F173680
|
||||
installPKGBUILD http://xyne.archlinux.ca/projects/reflector/pkgbuild/PKGBUILD
|
||||
yaourt -S bauerbill --noconfirm
|
||||
|
||||
bb-wrapper -Su
|
||||
# TODO Prompt if all went well, if not restart
|
||||
else
|
||||
sudo pacman -Syu
|
||||
fi
|
||||
|
||||
# Disable predictable network names
|
||||
sudo ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules
|
||||
|
||||
# TLP
|
||||
# sudo pacman -S tlp
|
||||
# sudo systemctl enable tlp.service tlp-sleep.service
|
||||
# sudo systemctl disable systemd-rfkill
|
||||
|
||||
# TODO
|
||||
# make -j8 in MAKEPKG
|
||||
# time
|
||||
# nfs
|
||||
# hibernate
|
||||
|
||||
}
|
|
@ -1,294 +0,0 @@
|
|||
#!/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
|
||||
local TERMUX=0
|
||||
if [ -d /data/data/com.termux/files ]; then
|
||||
local TERMUX=1
|
||||
local GUI=0
|
||||
fi
|
||||
|
||||
if which i3 &> /dev/null; then
|
||||
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
|
||||
if which pacman &> /dev/null; then
|
||||
ARCH=1
|
||||
if [ $ADMIN == 1 ]; then
|
||||
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
|
||||
|
||||
elif which dpkg &> /dev/null; then
|
||||
DEBIAN=1
|
||||
if [[ $ADMIN == 1 || $TERMUX == 1 ]]; then
|
||||
if [ $TERMUX == 1 ]; then
|
||||
DEBIAN=0
|
||||
apt update -y
|
||||
else
|
||||
sudo apt-get update -y
|
||||
fi
|
||||
function installOne { # package
|
||||
|
||||
# Finding out if it's already installed or not
|
||||
STATUS=$(mktemp)
|
||||
LANG=C dpkg-query --status $1 &> $STATUS
|
||||
local installed=0
|
||||
if [ $? == 0 ]; then
|
||||
cat $STATUS | grep '^Status:' | grep ' installed' --quiet
|
||||
if [ $? == 0 ]; then
|
||||
installed=1
|
||||
fi
|
||||
fi
|
||||
rm -f $STATUS > /dev/null
|
||||
|
||||
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
|
||||
}
|
||||
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
|
||||
inst grep sed sh tar
|
||||
if [ $TERMUX == 1 ]; then
|
||||
inst coreutils man termux-api openssl-tool
|
||||
if [ $ADMIN == 1 ]; then
|
||||
inst tsu
|
||||
fi
|
||||
fi
|
||||
inst moreutils screen ncdu lsof htop proxytunnel pv curl wget sshfs netcat mosh
|
||||
if [ $ARCH == 1 ]; then
|
||||
inst gopass
|
||||
else
|
||||
inst pass
|
||||
fi
|
||||
if [[ $ARCH == 1 && $ADMIN == 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
|
||||
|
||||
|
||||
# Text editor
|
||||
if [ $TERMUX == 1 ]; then
|
||||
inst vim-python
|
||||
elif [ $DEBIAN == 1 ]; then
|
||||
inst vim-youcompleteme
|
||||
ln -s $DEBLOC_ROOT/usr/bin/vim{.nox,}
|
||||
else
|
||||
inst vim
|
||||
fi
|
||||
if [ $DEBIAN == 1 ]; then
|
||||
inst exuberant-ctags
|
||||
else
|
||||
inst ctags
|
||||
fi
|
||||
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
|
||||
vim +PluginInstall +qall
|
||||
|
||||
# YouCompleteMe (vim plugin)
|
||||
if [ $DEBIAN != 1 ]; then
|
||||
if [ $DEBIAN == 1 || $TERMUX == 1 ]; then
|
||||
inst python-dev python3-dev
|
||||
fi
|
||||
local YCM_ARGS=""
|
||||
if [ $TERMUX == 0 ]; then
|
||||
YCM_ARGS="$YCM_ARGS --clang-completer --tern-completer"
|
||||
fi
|
||||
python $HOME/.vim/bundle/YouCompleteMe/install.py $YCM_ARGS
|
||||
fi
|
||||
|
||||
# Common GUI
|
||||
|
||||
if [ $GUI == 1 ]; then
|
||||
# Desktop manager
|
||||
inst i3 i3lock i3status dunst unclutter xautolock feh numlockx scrot
|
||||
if [ $DEBIAN == 1 ]; then
|
||||
inst suckless-tools
|
||||
if [ $ADMIN == 0 ]; then
|
||||
ln -s $DEBLOC_ROOT/usr/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
|
||||
if [ $DEBIAN == 1 ]; then
|
||||
inst python3-lxml python-tox python3-pyqt5 python3-pyqt5.qtwebkit python3-pyqt5.qtquick python3-sip python3-jinja2 python3-pygments python3-yaml
|
||||
TMP_DIR=$(mktemp -d)
|
||||
$(cd $TMP_DIR; wget https://qutebrowser.org/python3-pypeg2_2.15.2-1_all.deb)
|
||||
$(cd $TMP_DIR; wget https://github.com/qutebrowser/qutebrowser/releases/download/v0.9.1/qutebrowser_0.9.1-2_all.deb)
|
||||
instFile $TMP_DIR/*.deb
|
||||
rm -rf $TMP_DIR
|
||||
|
||||
elif [ $ARCH == 1 ]; then
|
||||
altInst qutebrowser
|
||||
fi
|
||||
|
||||
# Screen filter
|
||||
if [ $ARCH == 1 ]; then
|
||||
altInst sct
|
||||
elif [ $DEBIAN == 1 ]; then
|
||||
if [ ! -f $DEBLOC_ROOT/usr/bin/sct ]; then
|
||||
TMP=$(mktemp)
|
||||
wget http://www.tedunangst.com/flak/files/sct.c -O $TMP
|
||||
cc -std=c99 -O2 -I /usr/X11R6/include -o $DEBLOC_ROOT/usr/bin/sct $TMP -L /usr/X11R6/lib -lm -lX11 -lXrandr
|
||||
fi
|
||||
if [ $DEBIAN == 1 ]; then
|
||||
inst vim-gtk
|
||||
else
|
||||
inst gvim
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $EXTRA == 1 ]; then
|
||||
# Extra CLI
|
||||
inst sl ffmpeg youtube-dl
|
||||
|
||||
if [ $ARCH == 1 ]; then
|
||||
altInst pdftk
|
||||
fi
|
||||
|
||||
# Extra GUI
|
||||
if [ $GUI == 1 ]; then
|
||||
inst vlc gimp mpd vimpc
|
||||
|
||||
if [ $ARCH == 1 ]; then
|
||||
inst simplescreenrecorder
|
||||
fi
|
||||
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
# Handles indexing and SSH keys of machines I
|
||||
# have access on
|
||||
# (sourceable)
|
||||
|
||||
MACHINES_HOME=$HOME
|
||||
MACHINES_CONFIG=$HOME/.config/machines
|
||||
|
@ -51,6 +50,11 @@ function _machines-api {
|
|||
route=$1
|
||||
shift
|
||||
wget $MACHINES_API/$route --content-on-error --quiet --output-document=- "$@"
|
||||
result=$?
|
||||
if [ $result != 0 ]; then
|
||||
echo "[ERROR] wget returned $result..."
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
function _machines-apiToken {
|
||||
|
@ -59,6 +63,7 @@ function _machines-apiToken {
|
|||
}
|
||||
|
||||
function _machines-apiSigned {
|
||||
_machines-ensureAdmin
|
||||
_machines-api "$@" --certificate=$MACHINES_CONFIG/machines.crt --private-key=$MACHINES_CONFIG/machines.key
|
||||
}
|
||||
|
||||
|
@ -72,24 +77,10 @@ function _machines-pubFromCrt {
|
|||
openssl x509 -in $MACHINES_CONFIG/machines.crt -pubkey -noout > $MACHINES_CONFIG/machines.pub
|
||||
}
|
||||
|
||||
function _machines-regenKey {
|
||||
if [[ -e $MACHINES_CONFIG/machines.key || -e $MACHINES_CONFIG/machines.pub || -e $MACHINES_CONFIG/machines.crt ]]; then
|
||||
echo "[ERROR] Please delete the pem files manually to prove you know what you're doing."
|
||||
else
|
||||
openssl genrsa -out $MACHINES_CONFIG/machines.key 4096
|
||||
chmod 600 $MACHINES_CONFIG/machines.key
|
||||
openssl req -key $MACHINES_CONFIG/machines.key -new -out $MACHINES_CONFIG/machines.csr
|
||||
openssl x509 -req -days 1826 -in $MACHINES_CONFIG/machines.csr -signkey $MACHINES_CONFIG/machines.key -out $MACHINES_CONFIG/machines.crt
|
||||
_machines-pubFromCrt
|
||||
fi
|
||||
}
|
||||
|
||||
function _machines-verifyCertificate {
|
||||
if openssl verify $MACHINES_CONFIG/machines.crt | grep -v 'error 18' | grep 'error' --quiet; then
|
||||
echo "[ERROR] Invalid certificate"
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -104,19 +95,23 @@ function _machines-ensurePub {
|
|||
mv $CERT_FILE $MACHINES_CONFIG/machines.crt &> /dev/null
|
||||
else
|
||||
echo "[ERROR] Certificate rejected."
|
||||
return 1
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
_machines-verifyCertificate
|
||||
if [ $? != 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
if [ ! -f $MACHINES_CONFIG/machines.pub ]; then
|
||||
_machines-pubFromCrt
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
function _machines-ensureAdmin {
|
||||
if [ ! -f $MACHINES_CONFIG/machines.key ]; then
|
||||
echo "[ERROR] You need have to have the private key to do that"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# SSH ACCESS KEYS
|
||||
|
||||
function _machines-signAkey { # network
|
||||
|
@ -130,9 +125,6 @@ function _machines-signAkey { # network
|
|||
|
||||
function _machines-getAkey { # network
|
||||
_machines-ensurePub
|
||||
if [ $? != 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
KEY_FILE=$(mktemp)
|
||||
SIGN_FILE=$(mktemp)
|
||||
_machines-api akey/$1 > $KEY_FILE
|
||||
|
@ -140,11 +132,12 @@ function _machines-getAkey { # network
|
|||
openssl dgst -sha256 -verify $MACHINES_CONFIG/machines.pub -signature $SIGN_FILE $KEY_FILE &> /dev/null
|
||||
if [ $? == 0 ]; then
|
||||
cat $KEY_FILE
|
||||
rm $KEY_FILE $SIGN_FILE &> /dev/null
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
rm $KEY_FILE $SIGN_FILE &> /dev/null
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function _machines-updateAkey {
|
||||
|
@ -158,50 +151,10 @@ function _machines-updateAkey {
|
|||
cat $KEY_FILE
|
||||
echo "[ERROR] Authorized keys are not properly signed"
|
||||
rm $KEY_FILE
|
||||
return 1
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# USER ADMIN FUNCTIONS
|
||||
|
||||
function machines-verifyLog {
|
||||
if [ -f $MACHINES_CONFIG/lastVerifiedLog ]; then
|
||||
from=$(<"$MACHINES_CONFIG/lastVerifiedLog")
|
||||
else
|
||||
from=0
|
||||
fi
|
||||
d=$(date +%s)
|
||||
_machines-apiSigned log?from=$from | less
|
||||
prompt "Is this OK?"
|
||||
if [ $? == 1 ]; then
|
||||
echo $d > $MACHINES_CONFIG/lastVerifiedLog
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function machines-sign {
|
||||
machines-verifyLog
|
||||
if [ $? != 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
echo "Signing default network authorized_keys..."
|
||||
_machines-signAkey
|
||||
_machines-apiSigned network | while read network; do
|
||||
echo "Signing network $network authorized_keys..."
|
||||
_machines-signAkey $network
|
||||
done
|
||||
}
|
||||
|
||||
function machines-list {
|
||||
_machines-apiSigned machine
|
||||
}
|
||||
|
||||
function machines-listNetwork {
|
||||
_machines-apiSigned network
|
||||
}
|
||||
|
||||
function _machines-postFile { # filename
|
||||
cat $1 | while read line; do
|
||||
parameter=$(echo $line | cut -d '=' -f 1)
|
||||
|
@ -217,87 +170,233 @@ function _machines-addElement { # element elementType default
|
|||
$EDITOR $FILE
|
||||
data=$(_machines-postFile $FILE)
|
||||
rm $FILE &> /dev/null
|
||||
err=$(_machines-apiSigned $2 --post-data "name=$1$data")
|
||||
if [ $? != 0 ]; then
|
||||
echo "[ERROR] $err"
|
||||
return 2
|
||||
fi
|
||||
}
|
||||
|
||||
function machines-add { # machine
|
||||
_machines-addElement $1 machine "host[]=\nnetwork=\nuserkey=\nhostkey=\nuser="
|
||||
}
|
||||
|
||||
function machines-addNetwork { # network
|
||||
_machines-addElement $1 network "allowed[]=\nsecure=false"
|
||||
machines-apiSigned $2 --post-data "name=$1$data"
|
||||
}
|
||||
|
||||
function _machines-editElement { # element elementType
|
||||
FILE=$(mktemp)
|
||||
_machines-apiSigned $2/$1 > $FILE
|
||||
if [ $? != 0 ]; then
|
||||
echo "[ERROR] $(cat $FILE)"
|
||||
rm $FILE &> /dev/null
|
||||
return 1
|
||||
fi
|
||||
_machines-apiSigned $2/$1
|
||||
$EDITOR $FILE
|
||||
data=$(_machines-postFile $FILE)
|
||||
rm $FILE &> /dev/null
|
||||
err=$(_machines-apiSigned $2/$1 --post-data "$data")
|
||||
if [ $? != 0 ]; then
|
||||
echo "[ERROR] $err"
|
||||
return 2
|
||||
fi
|
||||
}
|
||||
|
||||
function machines-edit { # machine
|
||||
_machines-editElement $1 machine
|
||||
}
|
||||
|
||||
function machines-editNetwork { # network
|
||||
_machines-editElement $1 network
|
||||
}
|
||||
|
||||
function _machines-deleteElement { # element elementType
|
||||
err=$(_machines-apiSigned $2/$1 --method=DELETE)
|
||||
if [ $? != 0 ]; then
|
||||
echo "[ERROR] $err"
|
||||
return 2
|
||||
}
|
||||
|
||||
|
||||
# USER ADMIN FUNCTIONS
|
||||
|
||||
function machines_history {
|
||||
if [ -f $MACHINES_CONFIG/lastVerifiedLog ]; then
|
||||
from=$(<"$MACHINES_CONFIG/lastVerifiedLog")
|
||||
else
|
||||
from=0
|
||||
fi
|
||||
d=$(date +%s)
|
||||
_machines-apiSigned log?from=$from | less
|
||||
prompt "Is this OK?"
|
||||
if [ $? == 1 ]; then
|
||||
echo $d > $MACHINES_CONFIG/lastVerifiedLog
|
||||
return 0
|
||||
else
|
||||
echo "Houston, we have a problem..."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function machines-delete { # machine
|
||||
function machines_sign {
|
||||
machines_history
|
||||
echo "Signing default network authorized_keys..."
|
||||
_machines-signAkey
|
||||
_machines-apiSigned network | while read network; do
|
||||
echo "Signing network $network authorized_keys..."
|
||||
_machines-signAkey $network
|
||||
done
|
||||
}
|
||||
|
||||
function machines_machine_list {
|
||||
_machines-apiSigned machine
|
||||
}
|
||||
|
||||
function machines_network_list {
|
||||
_machines-apiSigned network
|
||||
}
|
||||
|
||||
function machines_machine_add_help {
|
||||
echo "Usage: $0 machine|mac|m add MACHINE"
|
||||
echo
|
||||
echo "Arguments:"
|
||||
echo " MACHINE machine to add"
|
||||
return 0
|
||||
}
|
||||
function machines_machine_add { # machine
|
||||
if [ -z $1 ]; then
|
||||
machines_machine_add_help
|
||||
exit 1
|
||||
fi
|
||||
_machines-addElement $1 machine "allowed[]=\nsecure=false"
|
||||
_machines-addElement $1 machine "host[]=\nnetwork=\nuserkey=\nhostkey=\nuser="
|
||||
}
|
||||
|
||||
function machines_network_add_help {
|
||||
echo "Usage: $0 network|net|n add NETWORK"
|
||||
echo
|
||||
echo "Arguments:"
|
||||
echo " NETWORK Network to add"
|
||||
return 0
|
||||
}
|
||||
function machines_network_add { # network
|
||||
if [ -z $1 ]; then
|
||||
machines_network_add_help
|
||||
exit 1
|
||||
fi
|
||||
_machines-addElement $1 network "allowed[]=\nsecure=false"
|
||||
}
|
||||
|
||||
function machines_machine_edit_help {
|
||||
echo "Usage: $0 machine|mac|m edit MACHINE"
|
||||
echo
|
||||
echo "Arguments:"
|
||||
echo " MACHINE machine to remove"
|
||||
return 0
|
||||
}
|
||||
function machines_machine_edit { # machine
|
||||
if [ -z $1 ]; then
|
||||
machines_machine_edit_help
|
||||
exit 1
|
||||
fi
|
||||
_machines-editElement $1 machine
|
||||
}
|
||||
|
||||
function machines_network_edit_help {
|
||||
echo "Usage: $0 network|net|n edit NETWORK"
|
||||
echo
|
||||
echo "Arguments:"
|
||||
echo " NETWORK Network to remove"
|
||||
return 0
|
||||
}
|
||||
function machines_network_edit { # network
|
||||
if [ -z $1 ]; then
|
||||
machines_network_edit_help
|
||||
exit 1
|
||||
fi
|
||||
_machines-editElement $1 network
|
||||
}
|
||||
|
||||
function machines_machine_delete_help {
|
||||
echo "Usage: $0 machine|mac|m delete machine"
|
||||
echo
|
||||
echo "Arguments:"
|
||||
echo " MACHINE machine to remove"
|
||||
return 0
|
||||
}
|
||||
function machines_machine_delete { # machine
|
||||
if [ -z $1 ]; then
|
||||
machines_machine_delete_help
|
||||
exit 1
|
||||
fi
|
||||
_machines-deleteElement $1 machine
|
||||
}
|
||||
|
||||
function machines-deleteNetwork { # network
|
||||
function machines_network_delete_help {
|
||||
echo "Usage: $0 network|net|n delete NETWORK"
|
||||
echo
|
||||
echo "Arguments:"
|
||||
echo " NETWORK Network to remove"
|
||||
return 0
|
||||
}
|
||||
function machines_network_delete { # network
|
||||
if [ -z $1 ]; then
|
||||
machines_network_delete_help
|
||||
exit 1
|
||||
fi
|
||||
_machines-deleteElement $1 network
|
||||
}
|
||||
|
||||
function machines-updateAll {
|
||||
machines-list | while read machine; do
|
||||
function machines_machine_help {
|
||||
echo "Usage: $0 machine|mac|m COMMAND"
|
||||
echo
|
||||
echo "Commands:"
|
||||
echo " list List all machines"
|
||||
echo " add Interactively add a machine"
|
||||
echo " edit Interactively edit a specified machine"
|
||||
echo " delete Remove a specified machine"
|
||||
echo " help Get help with commands"
|
||||
return 0
|
||||
}
|
||||
function machines_machine {
|
||||
command="$1"
|
||||
shift
|
||||
if type "machines_machine_$command" &> /dev/null; then
|
||||
"machines_machine_$command" "$@"
|
||||
else
|
||||
machines_machine_help
|
||||
fi
|
||||
}
|
||||
|
||||
function machines_network_help {
|
||||
echo "Usage: $0 network|net|n COMMAND"
|
||||
echo
|
||||
echo "Commands:"
|
||||
echo " list List all networks"
|
||||
echo " add Interactively add a network"
|
||||
echo " edit Interactively edit a specified network"
|
||||
echo " delete Remove a specified network"
|
||||
echo " help Get help with commands"
|
||||
return 0
|
||||
}
|
||||
function machines_network {
|
||||
command="$1"
|
||||
shift
|
||||
if type "machines_network_$command" &> /dev/null; then
|
||||
"machines_network_$command" "$@"
|
||||
else
|
||||
machines_network_help
|
||||
fi
|
||||
}
|
||||
|
||||
machines_mac() { machines_machine "$@"; }
|
||||
machines_m() { machines_machine "$@"; }
|
||||
machines_net() { machines_network "$@"; }
|
||||
machines_n() { machines_network "$@"; }
|
||||
machines_mac_help() { machines_machine_help "$@"; }
|
||||
machines_m_help() { machines_machine_help "$@"; }
|
||||
machines_net_help() { machines_network_help "$@"; }
|
||||
machines_n_help() { machines_network_help "$@"; }
|
||||
|
||||
function machines_update-all {
|
||||
machines_list | while read machine; do
|
||||
echo "Updating $machine..."
|
||||
ssh $machine 'machines-update' &
|
||||
done
|
||||
}
|
||||
|
||||
# USER FUNCTIONS
|
||||
|
||||
function machines-update {
|
||||
_machines-api machine/$(cat $MACHINES_CONFIG/this.name) > $MACHINES_CONFIG/this
|
||||
_machines-updateAkey
|
||||
function machines_regen-keys {
|
||||
if [[ -e $MACHINES_CONFIG/machines.key || -e $MACHINES_CONFIG/machines.pub || -e $MACHINES_CONFIG/machines.crt ]]; then
|
||||
echo "[ERROR] Please delete the pem files manually to prove you know what you're doing."
|
||||
exit 1
|
||||
else
|
||||
openssl genrsa -out $MACHINES_CONFIG/machines.key 4096
|
||||
chmod 600 $MACHINES_CONFIG/machines.key
|
||||
openssl req -key $MACHINES_CONFIG/machines.key -new -out $MACHINES_CONFIG/machines.csr
|
||||
openssl x509 -req -days 1826 -in $MACHINES_CONFIG/machines.csr -signkey $MACHINES_CONFIG/machines.key -out $MACHINES_CONFIG/machines.crt
|
||||
_machines-pubFromCrt
|
||||
fi
|
||||
}
|
||||
|
||||
function machines-setup {
|
||||
|
||||
# USER FUNCTIONS
|
||||
|
||||
function machines_setup {
|
||||
if [ -e $MACHINES_CONFIG/this.name ]; then
|
||||
echo "[ERROR] This machine is already set up"
|
||||
return 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
_machines-ensurePub
|
||||
if [ $? != 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Variables
|
||||
read -p 'Machine name? ' name
|
||||
|
@ -324,13 +423,47 @@ function machines-setup {
|
|||
data="$data&host[]=$(urlencode "$host")"
|
||||
done
|
||||
|
||||
err=$(_machines-apiToken machine --post-data "$data")
|
||||
if [ $? != 0 ]; then
|
||||
echo "[ERROR] $err"
|
||||
return 3
|
||||
fi
|
||||
_machines-apiToken machine --post-data "$data"
|
||||
|
||||
echo $name > $MACHINES_CONFIG/this.name
|
||||
machines-update
|
||||
}
|
||||
|
||||
function machines_update {
|
||||
_machines-api machine/$(cat $MACHINES_CONFIG/this.name) > $MACHINES_CONFIG/this
|
||||
_machines-updateAkey
|
||||
}
|
||||
|
||||
|
||||
function machines_help {
|
||||
command="$1"
|
||||
if [ -n "$command" ]; then
|
||||
if type "machines_${command}_help" &> /dev/null; then
|
||||
shift
|
||||
"machines_${command}_help" "$@"
|
||||
return $?
|
||||
fi
|
||||
fi
|
||||
echo "Usage: $0 COMMAND"
|
||||
echo
|
||||
echo "User commands:"
|
||||
echo " setup Interactive initial setup for new machine"
|
||||
echo " update Update this machine"
|
||||
echo " help Get help with commands"
|
||||
echo
|
||||
echo "Admin commands:"
|
||||
echo " machine|mac|m Modify machines"
|
||||
echo " network|net|n Modify networks"
|
||||
echo " update-all Update all machines available via SSH"
|
||||
echo " regen-keys Regenerate system keys"
|
||||
return 0
|
||||
}
|
||||
|
||||
# MAIN
|
||||
command="$1"
|
||||
shift
|
||||
if type "machines_$command" &> /dev/null; then
|
||||
"machines_$command" "$@"
|
||||
else
|
||||
machines_help
|
||||
fi
|
|
@ -121,7 +121,7 @@ do
|
|||
|
||||
temp=$(mktemp --suffix .svg)
|
||||
cp "$image" "$temp"
|
||||
svgo --quiet --config $HOME/.scripts/svgo.yml "$temp"
|
||||
svgo --quiet --config $HOME/.config/optiSvgo.yml "$temp"
|
||||
echo "→ Optimize done"
|
||||
|
||||
replaceImg "$temp" "$image"
|
88
scripts/proxy
Executable file
88
scripts/proxy
Executable file
|
@ -0,0 +1,88 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Allows easy manipulation of the proxy variables
|
||||
|
||||
function proxy_set_help {
|
||||
echo "Usage: $0 set ADDRESS"
|
||||
echo
|
||||
echo "Arguments:"
|
||||
echo " ADDRESS Address of the proxy"
|
||||
return 0
|
||||
}
|
||||
|
||||
function proxy_set {
|
||||
if [ -z $1 ]; then
|
||||
proxy_set_help
|
||||
return 1
|
||||
fi
|
||||
export http_proxy=$1
|
||||
export https_proxy=$1
|
||||
export ftp_proxy=$1
|
||||
export rsync_proxy=$1
|
||||
echo "Proxy changed"
|
||||
exit 0
|
||||
}
|
||||
|
||||
function proxy_setup {
|
||||
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
|
||||
|
||||
if (( $# > 0 )); then
|
||||
valid=$(echo $@ | sed -n 's/\([0-9]\{1,3\}.\)\{4\}:\([0-9]\+\)/&/p')
|
||||
if [[ $valid != $@ ]]; then
|
||||
>&2 echo "Invalid address"
|
||||
return 1
|
||||
fi
|
||||
proxy_set "http://$1/"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo -n "User: "; read username
|
||||
if [[ $username != "" ]]; then
|
||||
echo -n "Password: "
|
||||
read -es password
|
||||
local pre="$username:$password@"
|
||||
fi
|
||||
|
||||
echo -n "Server: "; read server
|
||||
echo -n "Port: "; read port
|
||||
proxy_set "http://$pre$server:$port/"
|
||||
return 0
|
||||
}
|
||||
|
||||
function proxy_off {
|
||||
unset http_proxy
|
||||
unset https_proxy
|
||||
unset ftp_proxy
|
||||
unset rsync_proxy
|
||||
echo -e "Proxy removed"
|
||||
return 0
|
||||
}
|
||||
|
||||
function proxy_help {
|
||||
command="$1"
|
||||
if [ -n "$command" ]; then
|
||||
if type "proxy_${command}_help" &> /dev/null; then
|
||||
shift
|
||||
"proxy_${command}_help" "$@"
|
||||
return $?
|
||||
fi
|
||||
fi
|
||||
echo "Usage: $0 COMMAND"
|
||||
echo
|
||||
echo "Commands:"
|
||||
echo " setup Interactively setup proxy"
|
||||
echo " set Set proxy from address"
|
||||
echo " off Turn off proxy"
|
||||
echo " help Get help with commands"
|
||||
return 0
|
||||
}
|
||||
|
||||
# MAIN
|
||||
command="$1"
|
||||
shift
|
||||
if type "proxy_$command" &> /dev/null; then
|
||||
"proxy_$command" "$@"
|
||||
else
|
||||
proxy_help
|
||||
fi
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
|
||||
# Proxy
|
||||
function proxy_set {
|
||||
export http_proxy=$1
|
||||
export https_proxy=$1
|
||||
export ftp_proxy=$1
|
||||
export rsync_proxy=$1
|
||||
echo "Proxy changed"
|
||||
}
|
||||
|
||||
function proxy_on {
|
||||
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
|
||||
|
||||
if (( $# > 0 )); then
|
||||
valid=$(echo $@ | sed -n 's/\([0-9]\{1,3\}.\)\{4\}:\([0-9]\+\)/&/p')
|
||||
if [[ $valid != $@ ]]; then
|
||||
>&2 echo "Invalid address"
|
||||
return 1
|
||||
fi
|
||||
proxy_set "http://$1/"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo -n "User: "; read username
|
||||
if [[ $username != "" ]]; then
|
||||
echo -n "Password: "
|
||||
read -es password
|
||||
local pre="$username:$password@"
|
||||
fi
|
||||
|
||||
echo -n "Server: "; read server
|
||||
echo -n "Port: "; read port
|
||||
proxy_set "http://$pre$server:$port/"
|
||||
}
|
||||
|
||||
function proxy_off {
|
||||
unset http_proxy
|
||||
unset https_proxy
|
||||
unset ftp_proxy
|
||||
unset rsync_proxy
|
||||
echo -e "Proxy removed"
|
||||
}
|
||||
alias po=proxy_off
|
||||
|
|
@ -1,4 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Dynamically determines if the ssh connection
|
||||
# is to be proxied through `proxytunnel`
|
||||
# To be used with ssh_config ProxyCommand
|
||||
|
||||
host="$1"
|
||||
port="$2"
|
||||
|
||||
|
|
Loading…
Reference in a new issue