diff --git a/AutoLaunch.scpt b/AutoLaunch.scpt new file mode 100644 index 0000000..2d76124 --- /dev/null +++ b/AutoLaunch.scpt @@ -0,0 +1,10 @@ +property startup_script : "~/.config/bin/work.init.sh" + +tell application "iTerm2" + set W to create window with default profile + + set S to current session of W + tell S + write text startup_script + end tell +end tell diff --git a/README.md b/README.md new file mode 100644 index 0000000..4de99af --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# Dotfiles + +Hello, welcome to my dotfiles repository. + +I have grown to believe that dotfiles is among the most unfiltered +expressions of a person. Here are mine. This repository obviously +helps me sync configuration across different machines, but I do +also hope that it comes in handy to another stranger. To that end, +I shall maintain an Index *(edit: **attempt to**)* of the dotfiles +in this repository and where that might fit on your own machine. + ++----------------------------------------------------------------------------------------------------+ +| # | File | Notes | ++----------------------------------------------------------------------------------------------------+ +| 1 | [work.init.sh](./work.init.sh) | `~/.config/bin/work.init.sh` | +| | | tmux-initialization script for | +| | | my work needs. | ++----------------------------------------------------------------------------------------------------+ +| 2 | [AutoLaunch.scpt](./AutoLaunch.scpt) | `~/Library/Application Support/iTerm2/| +| | |Scripts/AutoLaunch.scpt` | +| | | applescript to auto-run the above tmux| +| | | init script when I launch `iTerm2`. | +|----------------------------------------------------------------------------------------------------| +| 3 | [sync-internal-dns.sh](./sync-internal-dns.sh) | `~/.config/bin/sync-internal-dns.sh` | +| | | I already use Tailscale + Syncthing, | +| | | but for streaming I absolutely need | +| | | a connection over my private network | +| | | (vs Tailscale's VPN). I've put this in| +| | | my `crontab` to run every minute on | +| | | all my devices. It adds a | +| | | `$hostname.internal` entry to | +| | | `/etc/hosts` for each machine. | +|----------------------------------------------------------------------------------------------------| diff --git a/sync-internal-dns.sh b/sync-internal-dns.sh new file mode 100755 index 0000000..4af86cf --- /dev/null +++ b/sync-internal-dns.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +set -ex + +self="$(hostname -s)" +internal_hosts_file="/Users/kaustubh/Sync/internal.hosts" +etc_hosts_file="/etc/hosts" + +self_domain="$self.internal" +echo "self hostname: '$self'"$'\t'"advertising as: '$self_domain'" + +function get_self_ip { + for w in $(/sbin/ifconfig | grep 192.168); do + if [[ "$w" =~ ^192\.168\..* ]]; then + echo "$w" + break + fi + done +} + +self_ip="$(get_self_ip)" +if [ "$self_ip" = "" ]; then + echo "oops! couldn't find private IP" + exit 1 +fi + +function readHosts { + # returns: + # ip,host + # ip,host + # ... + IFS=$'\n' + while read line; do + unset IFS + + line=$(echo "$line" | sed -e 's/#.*$//' | sed 's/^\s*$//') + if [ "$line" = "" ]; then + continue + fi + + read ip host <<< $line + echo $ip $host + done +} + +internal_hosts="$(cat $internal_hosts_file | readHosts)" +etc_hosts="$(cat $etc_hosts_file | readHosts)" + +echo "INTERNAL:" +echo "$internal_hosts" +echo "ETC:" +echo "$etc_hosts" + +has_self="0" +IFS=$'\n' +for ih in $internal_hosts; do + unset IFS + + read wanted_ip wanted_host <<< $ih + echo "wanted_ip: $wanted_ip, wanted_host: $wanted_host" + + if [ "$self_domain" = "$wanted_host" ]; then + if [ "$self_ip" != "$wanted_ip" ]; then + sed -i bak "s/^$wanted_ip.*$//" $internal_hosts_file + else + has_self="1" + fi + break + fi +done +if [ "$has_self" != "1" ]; then + echo "$self_ip"$'\t'"$self_domain" >> $internal_hosts_file +fi + +IFS=$'\n'; for ih in $internal_hosts; do + unset IFS + + read wanted_ip wanted_host <<< $ih + + if [ "$wanted_host" = "$self_domain" ]; then + continue + fi + + fixed="0" + IFS=$'\n'; for eh in $etc_hosts; do + unset IFS + read etc_ip etc_host <<< $eh + if [ "$etc_host" = "$wanted_host" ]; then + sed -i .bak -r "s/$etc_ip[[:space:]]+$etc_host/$wanted_ip\t$wanted_host/" $etc_hosts_file + fixed="1" + fi + done + + if [ "$fixed" != "1" ]; then + echo "$wanted_ip"$'\t'"$wanted_host" >> $etc_hosts_file + fi +done