#!/bin/bash set -xeuo pipefail while getopts "h0" OPT; do case ${OPT} in 0) LOWBANDWITH=true ;; h) less $0 exit 0 ;; esac done APT_GET=$(which apt-get yum 2>/dev/null) || true if which sudo && SUDO_ASKPASS=$(which false) sudo true; then SUDOCMD="sudo bash -c" else SUDOCMD="su -c" fi function maybe-install-sudo { if ! which sudo && test -n "${APT_GET}"; then ${SUDOCMD} "${APT_GET} install -y sudo" || true ${SUDOCMD} "${APT_GET} install -y ntp" || true fi } maybe-install-sudo cd if which apt-get; then if true || ! ${SUDOCMD} "apt-get update" || \ ${SUDOCMD} "grep ^deb\ cdrom /etc/apt/sources.list"; then DOTFILES_GITHUB_URL=https://raw.githubusercontent.com/erjoalgo/dotfiles/master/ URL=${DOTFILES_GITHUB_URL}/installs/update-sources-list.sh BASE=$(basename ${URL}) pushd . cd /tmp if ! test -e ${BASE}; then if which curl; then curl "${URL}" -Lo "${BASE}" else wget "${URL}" -O "${BASE}" fi chmod +x ${BASE} fi ${SUDOCMD} ./${BASE} ${SUDOCMD} "apt-get update" popd fi if ! which sudo; then ${SUDOCMD} "apt-get install -y sudo" ${SUDOCMD} "apt-get install -y ntp" || true fi fi maybe-install-sudo # set up passwordless sudo NOPASSWD_LINE="${USER} ALL=(ALL:ALL) NOPASSWD:ALL" if test -d /etc/sudoers.d; then # use sudoers.d if possible ${SUDOCMD} "tee /etc/sudoers.d/${USER}-nopasswd <<< \"${NOPASSWD_LINE}\"" # INCLUDE_SUDOERS_LINE="#includedir /etc/sudoers.d" elif ! ${SUDOCMD} "grep -F \"${LINE}\" /etc/sudoers"; then ${SUDOCMD} "tee -a /etc/sudoers <<< \"${NOPASSWD_LINE}\"" fi sudo echo "successful passwordless sudo" sudo apt-get update function sagiy { for _ in $(seq 3); do sudo apt-get install -y ${*} && break sudo apt-get update --fix-missing || true sleep 5 done } sagiy git curl python3 python3-full GIT_HOME=${HOME}/git # backwards compatibility ERJOALGO_STUMPWMRC=${GIT_HOME}/erjoalgo-stumpwmrc DOTFILES=${GIT_HOME}/dotfiles if test -e "${ERJOALGO_STUMPWMRC}" -a ! -e "${DOTFILES}"; then mv "${ERJOALGO_STUMPWMRC}" "${DOTFILES}" ln -s "${DOTFILES}" "${ERJOALGO_STUMPWMRC}" fi function fetch-repos { # fetch my git repos GIT_EMAIL=erjoalgo@gmail.com GIT_NAME="Ernesto Alfonso" mkdir -p ${GIT_HOME} pushd . for REPO in ${*}; do cd ${GIT_HOME} test -d ${REPO} || git clone "https://github.com/erjoalgo/${REPO}" cd ${REPO} git config user.name "${GIT_NAME}" git config user.email "${GIT_EMAIL}" for TRIES in $(seq 5); do if git pull --ff-only; then break fi echo "git pull failed, possible network issue. retrying..." sleep 1 done done popd } sed -i 's/${RANDOM}/{RANDOM}/' ~/.ssh/config || true fetch-repos dotfiles cd ~/git/dotfiles/installs/ git submodule update --init --recursive SCRIPTS_BIN="${HOME}/git/dotfiles/bin" test -d "${SCRIPTS_BIN}" export PATH=$PATH:${SCRIPTS_BIN} which insert-text-block sudo ln -fs ${SCRIPTS_BIN}/insert-text-block /usr/bin insert-text-block '# 58b63bb1-de24-449c-9bf9-9f317a28b9ac-load-scripts-bin' \ ${HOME}/.profile-env <<"EOF" export PATH=${PATH}:${HOME}/git/dotfiles/bin/ EOF sudo insert-text-block \ '# ac25d55a-723b-4da2-bfa6-674c51e7eefb-max-out-virtual-terminal-size' \ /etc/default/console-setup</dev/null) -o >(crontab) <&1 > ~/.git-lagging-repos-report' EOF mkdir -p ${HOME}/.ssh insert-text-block '# 99ef88b9-660b-458d-9dfd-9cf090778ea5-include-private-ssh-config' \ ${HOME}/.ssh/config -b < EOF chmod 600 ~/.ssh/config SSH_PRIVATE_KEY_PATH=~/.ssh/id_rsa if ! test -e ${SSH_PRIVATE_KEY_PATH}; then ssh-keygen -t rsa -b 4096 -o -a 100 -N '' -f ${SSH_PRIVATE_KEY_PATH} fi touch ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys insert-text-block '# 02a8943a-e369-47f7-9e96-11de241c2e36-add-universal-ssh' \ ~/.ssh/authorized_keys< EOF insert-text-block -b '# 0c26fa16-1154-4554-8dbd-056097fb58d0-add-emacs-mode' \ ${HOME}/.profile-env <