# source brc and brc2 if they exist. We have to readlink because we
# could be using sl() from ./brc.
_tmp=$(readlink -f ${BASH_SOURCE[0]})
- _tmp=${_tmp%/*}
- _tmp2=$_tmp/brc
- if [[ -s $_tmp2 ]]; then
+ bashrc_dir=${_tmp%/*}
+ _tmp=$bashrc_dir/brc
+ if [[ -s $bashrc_dir ]]; then
# shellcheck source=./brc
- source $_tmp2
+ source $_tmp
fi
# brc2 is for things i dont necessarily want on every system
- _tmp2=$_tmp/brc2
- if [[ -s $_tmp2 ]]; then
+ _tmp=$bashrc_dir/brc2
+ if [[ -s $_tmp ]]; then
# shellcheck source=./brc2
- source $_tmp2
+ source $_tmp
else
# This check is for when running the sl() command,
# and the remote host got its type misidentified.
- _tmp2=$_tmp/../brc2
- if [[ -s $_tmp2 ]]; then
+ _tmp=$bashrc_dir/../brc2
+ if [[ -s $_tmp ]]; then
# shellcheck source=./brc2
- source $_tmp2
+ source $_tmp
fi
fi
###### End sourcing of files #####
/a/roles/grafana
/a/roles/node-exporter
/a/roles/alertmanager
+/sl/.ianketiona/src/
+/sl/.iankflidas/src/
# so this can set extdebug and avoid the bash debugger.
if [[ -s /a/bin/errhandle/err ]]; then
source /a/bin/errhandle/err
-elif [[ -s ~/.iank/err ]]; then
+elif [[ -s $bashrc_dir/err ]]; then
# shellcheck source=/a/bin/errhandle/err
- source ~/.iank/err
+ source $bashrc_dir/err
fi
# In t8, it runs clear_console for login shells by default. I don't want
export NNN_COLORS=2136
-export SL_FILES_DIR=/b/ds/sl/.iank
+export SL_FILES_DIR=/b/ds/sl/basic/.iank
export SL_INFO_DIR=/p/sshinfo
+export SL_RSYNC_ARGS="--exclude-from=/b/ds/sl/rsync-excludes"
# * include files
-
+if [[ -s $bashrc_dir/path-add-function ]]; then
+ source $bashrc_dir/path-add-function
+ if [[ $SSH_CLIENT && -e $bashrc_dir/src/emacs ]]; then
+ path-add "$bashrc_dir/lib-src" "$bashrc_dir/src"
+ if [[ ! -e ~/.emacs.d ]]; then
+ # todo: patch emacs so it will look elsewhere. this is kinda sad:
+ # https://emacs.stackexchange.com/questions/4253/how-to-start-emacs-with-a-custom-user-emacs-directory
+ ln -sf $bashrc_dir/.emacs.d ~
+ fi
+ fi
+fi
# if someone exported $SOE (stop on error), catch errors.
#
if [[ -s /a/bin/small-misc-bash/ll-function ]]; then
source /a/bin/small-misc-bash/ll-function
-elif [[ -s ~/.iank/ll-function ]]; then
+elif [[ -s $bashrc_dir/ll-function ]]; then
# shellcheck source=/a/bin/small-misc-bash/ll-function
- source ~/.iank/ll-function
+ source $bashrc_dir/ll-function
fi
echo "${p%%/.git}"
}
+g() {
+
+ local $narg
+ if [[ $DISPLAY ]]; then
+ narg=-n
+ fi
+ if pgrep -u $EUID emacsclient && (( $# )); then
+ emacsclient -a "" $narg "$@"
+ else
+ emacsclient -a "" $narg -c "$@"
+ fi
+}
+
gh() {
# i got an error, gh not found when doing a pull request, it seems like it wants itself in it\'s path.
local _oldpath="$PATH"
# remote system, you can use sl --rsync, or the function for that slr
# below.
+# SL_TEST_CMD: Env var. Meant to be used to vary the files synced
+# depending on the remote host. Run this string on the remote host the
+# first time sl is run (or if we run slr). The result is passed to
+# SL_TEST_HOOK. For example,
+# export SL_TEST_CMD=". /etc/os-release ; echo \${VERSION//[^a-zA-Z0-9]/}"
+
+# SL_TEST_HOOK: Env var. It is run as $SL_TEST_HOOK. This can set
+# $SL_FILES_DIR to vary the files synced.
+
+# SL_RSYNC_ARGS: Env var. String of arguments passed to rsync. For
+# example to exclude files within a directory. Note, excluded
+# files wont be deleted on rsync, you can add --delete-excluded
+# to the rsync command if that is desired.
+
# For when ~/.bashrc is already customized on the remote server, you
# might find it problematic that ~/.bashrc is sourced for ALL ssh
# commands, even in scripts. This paragraph is all about that. bash
# .bashrc. This means the outer shell still ran the default .bashrc,
# but that is the best we can do.
- local now args remote dorsync haveinfo tmpa sshinfo tmp tmp2 type info_sec force_rsync sync_dirname
+ local now args remote dorsync haveinfo tmpa sshinfo tmp tmp2 type info_sec force_rsync \
+ sync_dirname testcmd extra_info testbool files_sec sl_test_cmd sl_test_hook
declare -a args tmpa
- if [[ ! $SL_INFO_DIR || ! $SL_FILES_DIR ]]; then
- echo error: missing '$SL_' env vars >&2
- return 1
- fi
-
- sync_dirname=${SL_FILES_DIR##*/}
-
- now=$(date +%s)
# ssh [-1246Antivivisectionist] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
# [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-L address]
shift
fi
+ sl_test_cmd=$SL_TEST_CMD
+ sl_test_hook=$SL_TEST_HOOK
+ sl_rsync_args=$SL_RSYNC_ARGS
+ while [[ $1 ]]; do
+ case "$1" in
+ --rsync)
+ force_rsync=true
+ ;;
+ --sl-test-cmd)
+ sl_test_cmd="$2"
+ shift
+ ;;
+ --sl-test-hook)
+ sl_test_hook="$2"
+ shift
+ ;;
+ --sl_rsync_args)
+ sl_rsync_args="$2"
+ shift
+ ;;
+ *)
+ break
+ ;;
+ esac
+ shift
+ done
+
while [[ $1 ]]; do
case "$1" in
# note we dont support things like -4oOption
;;
esac
done
- remote="$1"; shift
+ remote="$1"
if [[ ! $remote ]]; then
echo $0: error hostname required >&2
return 1
fi
+ shift
+ if [[ ! $SL_INFO_DIR ]]; then
+ echo error: missing '$SL_INFO_DIR' env var >&2
+ return 1
+ fi
+
+ now=$(date +%s)
dorsync=false
haveinfo=false
tmpa=($SL_INFO_DIR/???????????"$remote")
tmp=${sshinfo[0]##*/}
tmp2=${tmp::11}
type=${tmp2: -1}
- if [[ $type == b ]]; then
- info_sec=${tmp::10}
- for f in $SL_FILES_DIR/*; do
- if (( $(stat -L -c%Y $f) > info_sec )); then
- dorsync=true
- rm -f $sshinfo
- break
- fi
- done
- fi
+ extra_info=$(cat $sshinfo)
else
- # use this weird yes thing to ensure we know ssh succeeded
- if ! tmp=$(LC_USEBASHRC=yes command ssh "${args[@]}" "$remote" "if test -e $SL_FILES_DIR/.bashrc -a -L .bashrc; then echo '$LC_USEBASHRC'; fi"); then
+ # we test for string to know ssh succeeded
+ testbool="test -e $SL_FILES_DIR/.bashrc -a -L .bashrc -a -v LC_USEBASHRC"
+ testcmd="if $testbool; then printf y; else printf n; fi"
+ if ! tmp=$(LC_USEBASHRC=y command ssh "${args[@]}" "$remote" "$testcmd; $sl_test_cmd"); then
echo failed sl test. doing plain ssh -v
command ssh -v "${args[@]}" "$remote"
fi
- if [[ $tmp == yes ]]; then
+ if [[ $tmp == y* ]]; then
type=a
else
dorsync=true
type=b
fi
+ extra_info="${tmp:1}"
fi
+ if [[ $sl_test_hook ]]; then
+ $sl_test_hook "$extra_info"
+ fi
+
+ if $haveinfo && [[ $type == b ]]; then
+ info_sec=${tmp::10}
+ read files_sec _ < <(find -L $SL_FILES_DIR -printf "%T@ %p\n" | sort -nr || [[ $? == 141 ]])
+ files_sec=${files_sec%%.*}
+ if (( files_sec > info_sec )); then
+ dorsync=true
+ rm -f $sshinfo
+ fi
+ fi
+
+ sync_dirname=${SL_FILES_DIR##*/}
+
+ if [[ ! $SL_FILES_DIR ]]; then
+ echo error: missing '$SL_FILES_DIR' env var >&2
+ return 1
+ fi
+
if $dorsync; then
- RSYNC_RSH="ssh ${args[*]}" rsync -rptL $SL_FILES_DIR "$remote":
+ RSYNC_RSH="ssh ${args[*]}" m rsync -rptL --delete $sl_rsync_args $SL_FILES_DIR "$remote":
fi
if $dorsync || ! $haveinfo; then
sshinfo=$SL_INFO_DIR/$now$type"$remote"
[[ -e $SL_INFO_DIR ]] || mkdir -p $SL_INFO_DIR
- touch $sshinfo
+ printf "%s\n" "$extra_info" >$sshinfo
chmod 666 $sshinfo
fi
if [[ $type == b ]]; then
command ssh "${args[@]}" "$remote" LC_USEBASHRC=t bash
fi
fi
+
# this function inspired from https://github.com/Russell91/sshrc
}
slr() {
# * functions
+export SL_TEST_CMD=". /etc/os-release ; echo \${VERSION//[^a-zA-Z0-9]/}"
+export SL_TEST_HOOK=slemacs
+
+slemacs() {
+ local arg
+ arg="$1"
+ case $arg in
+ 90Etiona)
+ export SL_FILES_DIR=/b/ds/sl/.ianketiona
+ ;;
+ 80Flidas)
+ export SL_FILES_DIR=/b/ds/sl/.iankflidas
+ ;;
+ *)
+ export SL_FILES_DIR=/b/ds/sl/.iank
+ ;;
+ esac
+}
+
+slb() { # sl basic
+ export SL_FILES_DIR=/b/ds/sl/.iank
+ sl --sl-test-cmd "" --sl-test-hook "" --sl_rsync_args "" "$@"
+}
+
+
+mkschroot() {
+ distro=$1
+ shift
+ case $distro in
+ trisquel)
+ repo=http://mirror.fsf.org/trisquel/
+ ;;
+ ubuntu)
+ repo=http://archive.ubuntu.com/ubuntu/
+ ;;
+ debian)
+ repo=http://deb.debian.org/debian/
+ ;;
+ esac
+ n=$1
+ shift
+ if schroot -l | grep -xFq chroot:$n; then
+ echo "$0: $n schroot already installed, skipping"
+ return 0
+ fi
+ apps=($@)
+ d=/nocow/schroot/$n
+ sd /etc/schroot/chroot.d/$n.conf <<EOF
+[$n]
+description=$n
+type=directory
+directory=$d
+profile=desktop
+preserve-environment=true
+users=$USER,user2
+EOF
+ if [[ -e $d/bin ]]; then
+ sudo chroot $d apt-get update
+ sudo chroot $d apt-get -y dist-upgrade --purge --auto-remove
+ cd; sudo schroot -c $n -- apt-get install --allow-unauthenticated -y ${apps[@]}
+ else
+ sudo mkdir -p $d
+ # resolvconf otherwise schroot fails with
+ # cp: not writing through dangling symlink '/var/run/schroot/mount/flidas-7a2362e0-81b3-4848-92c1-610203ef5976/etc/resolv.conf'
+ sudo debootstrap --exclude=resolvconf $n $d $repo
+ cd
+ if (( ${#apps[@]} )); then
+ sudo schroot -c $n -- apt-get install --allow-unauthenticated -y ${apps[@]}
+ fi
+ fi
+ sudo cp -P {,$d}/etc/localtime
+}
+
+
# clock back in to timetrack from last entry
tback() {
sqlite3 /p/.timetrap.db "update entries set end = NULL where id = (select max(id) from entries);"
/run/user/0 /run/user/0 none rw,bind 0 0
EOF
-mkschroot() {
- distro=$1
- shift
- case $distro in
- ubuntu)
- repo=http://archive.ubuntu.com/ubuntu/
- ;;
- debian)
- repo=http://deb.debian.org/debian/
- ;;
- esac
- n=$1
- shift
- if schroot -l | grep -xFq chroot:$n; then
- echo "$0: $n schroot already installed, skipping"
- return 0
- fi
- apps=($@)
- d=/nocow/schroot/$n
- sd /etc/schroot/chroot.d/$n.conf <<EOF
-[$n]
-description=$n
-type=directory
-directory=$d
-profile=desktop
-preserve-environment=true
-users=$USER,user2
-EOF
- if [[ -e $d/bin ]]; then
- sudo chroot $d apt-get update
- sudo chroot $d apt-get -y dist-upgrade --purge --auto-remove
- cd; sudo schroot -c $n -- apt-get install --allow-unauthenticated -y ${apps[@]}
- else
- sudo mkdir -p $d
-
- sudo debootstrap $n $d $repo
- cd; sudo schroot -c $n -- apt-get install --allow-unauthenticated -y ${apps[@]}
- fi
- sudo cp -P {,$d}/etc/localtime
-}
sd /etc/systemd/system/schrootupdate.service <<'EOF'
[Unit]
Description=schrootupdate
case $distro in
trisquel)
m mkschroot debian buster firefox-esr pulseaudio chromium anki
+ case $(debian-codename) in
+ etiona)
+ mkschroot trisquel etiona
+ tu /nocow/schroot/flidas/etc/sudoers <<EOF
+$USER ALL=(ALL) NOPASSWD: ALL
+Defaults env_keep += SUDOD
+Defaults always_set_home
+Defaults !umask
+EOF
+ sd /nocow/schroot/flidas/etc/apt/sources.list <<'EOF'
+deb http://mirror.fsf.org/trisquel/ flidas main
+deb-src http://mirror.fsf.org/trisquel/ flidas main
+
+deb http://mirror.fsf.org/trisquel/ flidas-updates main
+deb-src http://mirror.fsf.org/trisquel/ flidas-updates main
+
+deb http://archive.trisquel.info/trisquel/ flidas-security main
+deb-src http://archive.trisquel.info/trisquel/ flidas-security main
+
+# Uncomment this lines to enable the backports optional repository
+deb http://mirror.fsf.org/trisquel/ flidas-backports main
+deb-src http://mirror.fsf.org/trisquel/ flidas-backports main
+EOF
+ sd /nocow/schroot/flidas//etc/locale.gen <<'EOF'
+en_US.UTF-8 UTF-8
+EOF
+ s schroot -c flidas locale-gen
+ s schroot -c flidas update-locale LANG=en_US.UTF-8
+ ;;
+ esac
;;
debian)
pi chromium
# however, I'm not super confident that I've avoided them all
#
path-add() {
- local help="usage: path_add [options] PATH
+ local help="usage: path_add [options] PATH...
--help: print this
--end: adds to end of path, which will give it lowest priority
--ifexists: add to path only if directory exists"
transmission-remote-gtk
trash-cli
vlc
+ wamerican-huge
w3m
whois
wondershaper
--- /dev/null
+../../path-add-function
\ No newline at end of file
--- /dev/null
+../../.bashrc
\ No newline at end of file
--- /dev/null
+/home/iank/.emacs.d
\ No newline at end of file
--- /dev/null
+../../.inputrc
\ No newline at end of file
--- /dev/null
+../../brc
\ No newline at end of file
--- /dev/null
+/a/bin/errhandle/err
\ No newline at end of file
--- /dev/null
+/a/opt/emacs-trisqueletiona-nox/info
\ No newline at end of file
--- /dev/null
+/a/opt/emacs-trisqueletiona-nox/lib-src
\ No newline at end of file
--- /dev/null
+/a/opt/emacs-trisqueletiona-nox/lisp
\ No newline at end of file
--- /dev/null
+/a/bin/small-misc-bash/ll-function
\ No newline at end of file
--- /dev/null
+/a/bin/distro-functions/src/package-manager-abstractions
\ No newline at end of file
--- /dev/null
+../../path-add-function
\ No newline at end of file
--- /dev/null
+../../.bashrc
\ No newline at end of file
--- /dev/null
+/home/iank/.emacs.d
\ No newline at end of file
--- /dev/null
+../../.inputrc
\ No newline at end of file
--- /dev/null
+../../brc
\ No newline at end of file
--- /dev/null
+/a/bin/errhandle/err
\ No newline at end of file
--- /dev/null
+/a/opt/emacs-trisquelflidas-nox/info
\ No newline at end of file
--- /dev/null
+/a/opt/emacs-trisquelflidas-nox/lib-src
\ No newline at end of file
--- /dev/null
+/a/opt/emacs-trisquelflidas-nox/lisp
\ No newline at end of file
--- /dev/null
+/a/bin/small-misc-bash/ll-function
\ No newline at end of file
--- /dev/null
+/a/bin/distro-functions/src/package-manager-abstractions
\ No newline at end of file
--- /dev/null
+../../path-add-function
\ No newline at end of file
--- /dev/null
+/.iank*/.emacs.d/.ido.last
+/.iank*/.emacs.d/.savehist
+/.iank*/.emacs.d/.smex-items
+/.iank*/.emacs.d/ac-comphist.dat
+/.iank*/.emacs.d/auto-save-list
+/.iank*/.emacs.d/org-clock-save.el
+/.iank*/.emacs.d/recentf*
+/.iank*/.emacs.d/session.*
+/.iank*/.emacs.d/tramp
+/.iank*/.emacs.d/auto-save-list
+/.iank*/.emacs.d/%backup%~
+/.iank*/.emacs.d/network-security.data
+/.iank*/.emacs.d/elpa/gnupg/S.gpg-agent
+/.iank*/.emacs.d/url
+/.iank*/.emacs.d/.org-id-locations
+/.iank*/.emacs.d/eshell
+/.iank*/.emacs.d/bbdb