make sl easier to use
authorIan Kelling <ian@iankelling.org>
Tue, 4 Aug 2020 21:20:16 +0000 (17:20 -0400)
committerIan Kelling <ian@iankelling.org>
Tue, 4 Aug 2020 21:20:16 +0000 (17:20 -0400)
brc

diff --git a/brc b/brc
index 01c151a1623caa555f3f2cd7a12280bfe5698e96..fc0a683c6cb3c5efa2d3a0154d645f2a5fcdd341 100644 (file)
--- a/brc
+++ b/brc
@@ -1094,19 +1094,17 @@ sk() {
 # (mine are set at the beginning of this file)
 
 # SL_FILES_DIR: Environment variable. Path to folder which should at
-# least have a .bashrc file or symlink. This dir will be rsynced to
-# remote hosts unless the host already has a $SL_FILES_DIR/.bashrc. In
-# that case, we assume it is a host you control and sync files to
-# separately and already has the ~/.bashrc you want.  Symlinks in this
-# dir will be resolved. The directory name is important, it will be
-# created on the remote host under /root. The remote bash will also take
-# its .inputrc config from this folder (default of not existing is
-# fine). Mine looks like this:
+# least have a .bashrc file or symlink. This dir will be rsynced to ~ on
+# remote hosts (top level symlinks are resolved) unless the host already
+# has a $SL_FILES_DIR/.bashrc. In that case, we assume it is a host you
+# control and sync files to separately and already has the ~/.bashrc you
+# want. The remote bash will also take its .inputrc config from this
+# folder (default of not existing is fine). Mine looks like this:
 # https://iankelling.org/git/?p=distro-setup;a=tree;f=sl/.iank
 
 # SL_INFO_DIR: Environment variable. This folder stores info about what
-# we detected on the remote system and when we last synced. We expect it
-# to exist ahead of time. Sometimes you may want to forget about a
+# we detected on the remote system and when we last synced. It will be created
+# if it does not exist. Sometimes you may want to forget about a
 # remote system, you can use sl --rsync, or the function for that slr
 # below.
 
@@ -1141,6 +1139,11 @@ sl() {
   local now args remote dorsync haveinfo tmpa sshinfo tmp tmp2 type info_sec force_rsync sync_dirname
   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)
@@ -1232,6 +1235,7 @@ sl() {
   fi
   if $dorsync || ! $haveinfo; then
     sshinfo=$SL_INFO_DIR/$now$type"$remote"
+    [[ -e $SL_INFO_DIR ]] || mkdir -p $SL_INFO_DIR
     touch $sshinfo
     chmod 666 $sshinfo
   fi