From aea4cf150c198525185a533d107163e9c3ac6a44 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sun, 4 Dec 2016 14:16:21 +0100 Subject: [PATCH 1/4] Dotfiles handling! --- config/.dfrecur | 0 dotsync | 1 - scripts/dotfiles.sh | 166 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 config/.dfrecur delete mode 160000 dotsync create mode 100644 scripts/dotfiles.sh diff --git a/config/.dfrecur b/config/.dfrecur new file mode 100644 index 0000000..e69de29 diff --git a/dotsync b/dotsync deleted file mode 160000 index 54bcb2a..0000000 --- a/dotsync +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 54bcb2ac28d2c2a49caa1b78a0cceee9ae041122 diff --git a/scripts/dotfiles.sh b/scripts/dotfiles.sh new file mode 100644 index 0000000..6bd104a --- /dev/null +++ b/scripts/dotfiles.sh @@ -0,0 +1,166 @@ +#!/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 + +if [ -z "$DOTHOME" ]; then + DOTHOME="$HOME" +fi +if [ -z "$DOTREPO" ]; then + DOTREPO="$HOME/.dotfiles" +fi + +# Common functions + +# From http://stackoverflow.com/a/12498485 +function relativePath { + # both $1 and $2 are absolute paths beginning with / + # returns relative path to $2/$target from $1/$source + source=$1 + target=$2 + + common_part=$source # for now + result="" # for now + + while [[ "${target#$common_part}" == "${target}" ]]; do + # no match, means that candidate common part is not correct + # go up one level (reduce common part) + common_part="$(dirname $common_part)" + # and record that we went back, with correct / handling + if [[ -z $result ]]; then + result=".." + else + result="../$result" + fi + done + + if [[ $common_part == "/" ]]; then + # special case for root (no common path) + result="$result/" + fi + + # since we now have identified the common part, + # compute the non-common part + forward_part="${target#$common_part}" + + + # and now stick all parts together + if [[ -n $result ]] && [[ -n $forward_part ]]; then + result="$result$forward_part" + elif [[ -n $forward_part ]]; then + # extra slash removal + # result="${forward_part:1}" # Removes the . in the beginning... + result="${forward_part#/}" + fi + + echo "$result" +} + + +# Script common functions + +function _dotfiles-install-dir { # dir + local dir + local absSource + local absTarget + local relTarget + + dir="${1%/}" + dir="${dir#/}" + + /bin/ls -A "$DOTREPO/$dir" | while read file; do + if [[ -z "$dir" && $(echo $file | grep '^\(\.\|LICENSE\|README\)') ]]; then + continue + fi + if [[ $(echo $file | grep '^.dfrecur$') ]]; then + continue + fi + + if [ -z "$dir" ]; then + absSource="$DOTHOME/.$file" + absTarget="$DOTREPO/$file" + else + absSource="$DOTHOME/.$dir/$file" + absTarget="$DOTREPO/$dir/$file" + fi + relTarget="$(relativePath "$DOTHOME/$dir" "$absTarget")" + recurIndicator="$absTarget/.dfrecur" + + if [[ -h "$absTarget" ]]; then + if [ -e "$absSource" ]; then + if [ -h "$absSource" ]; then + cmd="cp --no-dereference --force $absTarget $absSource" + if [ $DRY_RUN ]; then + echo $cmd + else + yes | $cmd + fi + else + echo "[ERROR] $absSource already exists, but is not a link" + fi + else + cmd="cp --no-dereference --force $absTarget $absSource" + if [ $DRY_RUN ]; then + echo $cmd + else + yes | $cmd + fi + fi + elif [[ -f "$absTarget" || ( -d $absTarget && ! -f $recurIndicator ) ]]; then + if [ -e "$absSource" ]; then + if [ -h "$absSource" ]; then + cmd="ln --symbolic --no-dereference --force $relTarget $absSource" + if [ $DRY_RUN ]; then + echo $cmd + else + $cmd + fi + else + echo "[ERROR] $absSource already exists, but is not a symbolic link" + fi + else + cmd="ln --no-dereference --symbolic $relTarget $absSource" + if [ $DRY_RUN ]; then + echo $cmd + else + $cmd + fi + fi + elif [[ -d "$absTarget" && -f $recurIndicator ]]; then + if [ -e "$absSource" ]; then + if [ -d "$absSource" ]; then + # echo "Directory $absSource already exists" + _dotfiles-install-dir $dir/$file + else + echo "[ERROR] $absSource already exists, but is not a directory" + fi + else + cmd="mkdir $absSource" + if [ $DRY_RUN ]; then + echo $cmd + else + $cmd + fi + _dotfiles-install-dir $dir/$file + fi + else + echo "[WARNING] Skipped $absTarget" + fi + done + +} + +# Script functions + +function dotfiles-install { + _dotfiles-install-dir / +} + +# TODO dotfiles-{link,unlink,clean,uninstall} +# Link and Unlink should have a clever behavior regarding +# recusive folders +# Ex : linking config/i3 should make config recursible +# Ex : linking config if some files in it are linked should unlink those From e40aa83fcb3cbde90e3f57809836740e7f281d14 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sun, 4 Dec 2016 14:17:10 +0100 Subject: [PATCH 2/4] Git config, come back here --- gitconfig | 8 ++++++++ gitignore | 2 ++ 2 files changed, 10 insertions(+) create mode 100644 gitconfig create mode 100644 gitignore diff --git a/gitconfig b/gitconfig new file mode 100644 index 0000000..567f9dd --- /dev/null +++ b/gitconfig @@ -0,0 +1,8 @@ +[user] + name = Geoffrey Frogeye + email = geoffrey@frogeye.fr +[core] + editor = vim + excludesfile = ~/.gitignore +[push] + default = matching diff --git a/gitignore b/gitignore new file mode 100644 index 0000000..3819313 --- /dev/null +++ b/gitignore @@ -0,0 +1,2 @@ +*.swp +*.swo From 75b820f0dfc5677f65b842d8619b02f6ca245dec Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sun, 4 Dec 2016 14:20:46 +0100 Subject: [PATCH 3/4] Lock when sleeping, please --- config/i3/config | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/i3/config b/config/i3/config index 48c0450..1e3bf0b 100644 --- a/config/i3/config +++ b/config/i3/config @@ -262,10 +262,10 @@ set $mode_system [L] VĂ©rouillage [E] DĂ©connexion [S] Veille [H] Hibernation [R mode "$mode_system" { bindsym l exec --no-startup-id $locker, mode "default" bindsym e exit, mode "default" - bindsym s exec --no-startup-id systemctl suspend, mode "default" - bindsym h exec --no-startup-id systemctl hibernate, mode "default" + bindsym s exec --no-startup-id $locker & systemctl suspend, mode "default" + bindsym h exec --no-startup-id $locker & systemctl hibernate, mode "default" bindsym r exec --no-startup-id systemctl reboot, mode "default" - bindsym p exec --no-startup-id systemctl poweroff -i, mode "default" + bindsym p exec --no-startup-id systemctl poweroff -i, mode "default" # back to normal: Enter or Escape bindsym Return mode "default" From 0fadd434da4421aa520d5439fc43db0ecfa671f8 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sun, 4 Dec 2016 17:24:46 +0100 Subject: [PATCH 4/4] Scripts for sytem installations --- scripts/debloc-custom.sh | 31 ----- scripts/debloc.sh | 6 +- scripts/dotfiles.sh | 0 scripts/index.sh | 4 +- scripts/installArch.sh | 104 ++++++++++++++++ scripts/installPreferences.sh | 218 ++++++++++++++++++++++++++++++++++ 6 files changed, 330 insertions(+), 33 deletions(-) delete mode 100755 scripts/debloc-custom.sh mode change 100644 => 100755 scripts/dotfiles.sh create mode 100755 scripts/installArch.sh create mode 100755 scripts/installPreferences.sh diff --git a/scripts/debloc-custom.sh b/scripts/debloc-custom.sh deleted file mode 100755 index 457fb3e..0000000 --- a/scripts/debloc-custom.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -# Installs all programs on the system - -function debloc-custom-cli { - # Utils - debloc-install moreutils screen ncdu htop sl proxytunnel pass pv curl - - # Text editor - debloc-install vim exuberant-ctags - - # Dev - debloc-install build-essential cmake clang llvm git -} - -function debloc-custom { - debloc-custom-cli - - # Desktop manager - debloc-install i3 i3lock dmenu dunst unclutter xautolock feh numlockx scrot imagemagick suckless-tools - ln -s $DEBLOC_ROOT/bin/dmenu{.xft,} - - # qutebrowser - debloc-install 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) - debloc-deb $TMP_DIR/*.deb - rm -rf $TMP_DIR -} - diff --git a/scripts/debloc.sh b/scripts/debloc.sh index 92b6e73..eed5de3 100755 --- a/scripts/debloc.sh +++ b/scripts/debloc.sh @@ -1,7 +1,11 @@ #!/usr/bin/env bash +# 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 + # Not a Debian system return 0 fi diff --git a/scripts/dotfiles.sh b/scripts/dotfiles.sh old mode 100644 new mode 100755 diff --git a/scripts/index.sh b/scripts/index.sh index d06c95a..914e407 100755 --- a/scripts/index.sh +++ b/scripts/index.sh @@ -1,4 +1,6 @@ source ~/.scripts/proxy.sh source ~/.scripts/debloc.sh -source ~/.scripts/debloc-custom.sh +source ~/.scripts/dotfiles.sh +source ~/.scripts/installPreferences.sh +source ~/.scripts/installArch.sh alias beep=~/.scripts/beep.sh diff --git a/scripts/installArch.sh b/scripts/installArch.sh new file mode 100755 index 0000000..9a390da --- /dev/null +++ b/scripts/installArch.sh @@ -0,0 +1,104 @@ +#!/usr/bin/env bash + +# Setups an Arch Linux system the way I like it +# (sourceable, requires sudo) + +if [[ "$(which pacman) &> /dev/null" == 1 ]]; 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 ]; 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 + + if [[ $YAOURT && $(pacman -Q yaourt) == 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) == 0 ]; then + sudo pacman -Rsc pamac + fi + + if [[ $BAUERBILL && $(pacman -Q bauerbill) == 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 + + # TODO + # make -j8 in MAKEPKG + # time + # nfs + # hibernate + +} diff --git a/scripts/installPreferences.sh b/scripts/installPreferences.sh new file mode 100755 index 0000000..27b8015 --- /dev/null +++ b/scripts/installPreferences.sh @@ -0,0 +1,218 @@ +#!/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 + 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 ]; 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 ]; then + apt-get update + function installOne { # package + STATUS=$(mktemp) + LANG=C dpkg --list $1 &> $STATUS + if [ $? == 0 ]; then + cat $STATUS | grep '^Status:' | grep ' installed' --quiet + if [ $? == 0 ]; then + # TODO noconfirm + sudo apt-get install $1 + fi + fi + rm -f $STATUS > /dev/null + } + 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 moreutils screen ncdu htop proxytunnel pass pv curl sshfs netcat + + # Text editor + inst vim + if [ $ARCH ]; then + inst ctags + else + inst exuberant-ctags + fi + git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim + vim +PluginInstall +qall + + # Dev + if [ $DEBIAN ]; then + inst build-essential + elif [ $ARCH ]; then + inst base-devel + fi + inst git cmake clang llvm + + # Common GUI + + if [ $GUI ]; then + # Desktop manager + inst i3 i3lock dmenu dunst unclutter xautolock feh numlockx scrot + if [ $DEBIAN ]; then + inst suckles-tools + if [ ! $ROOT ]; then + 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 + if [ $DEBIAN ]; then + 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 + + elif [ $ARCH ]; then + altInst qutebrowser + fi + fi + + if [ $EXTRA ]; then + # Extra CLI + inst sl + + if [ $ARCH ]; then + altInst pdftk + fi + + # Extra GUI + if [ $GUI ]; then + inst vlc gimp mpd vimpc + + if [ $ARCH ]; then + inst simplescreenrecorder + fi + + fi + fi +} +