sent-tools

A small toolkit of shell scripts for compiling suckless sent slideshows.
git clone https://scm.kuandu.systems/git-raw/sent-tools.git
Log | Files | Refs | README

install.sh (1371B)


      1 #!/bin/sh
      2 
      3 # Simple POSIX install script to symlink all *.sh scripts (except itself)
      4 # into a target directory (default: ~/bin), removing the .sh extension.
      5 # Warns if target dir is not in PATH.
      6 
      7 main() {
      8     # Set install directory
      9     if [ "$1" ]; then
     10         INSTALL_DIR="$1"
     11     else
     12         INSTALL_DIR="$HOME/bin"
     13     fi
     14 
     15     # Create target directory if needed
     16     if [ ! -d "$INSTALL_DIR" ]; then
     17         mkdir -p "$INSTALL_DIR"
     18     fi
     19 
     20     printf 'Symlinking scripts to %s ...\n' "$INSTALL_DIR"
     21 
     22     for script in *.sh; do
     23         # Exclude this install script
     24         if [ "$script" = "install.sh" ]; then
     25             continue
     26         fi
     27 
     28         base=`basename "$script" .sh`
     29         src="$PWD/$script"
     30         dest="$INSTALL_DIR/$base"
     31 
     32         chmod +x "$src"
     33 
     34         if [ -e "$dest" ] || [ -L "$dest" ]; then
     35             rm -f "$dest"
     36         fi
     37 
     38         ln -s "$src" "$dest"
     39         printf ' -> %s\n' "$dest"
     40     done
     41 
     42     printf 'Done.\n'
     43 
     44     # Quick check if INSTALL_DIR is in PATH
     45     case ":$PATH:" in
     46         *:"$INSTALL_DIR":*)
     47             # Already in PATH
     48             ;;
     49         *)
     50             printf '\nWARNING: %s is not in your PATH.\n' "$INSTALL_DIR"
     51             printf 'Add the following to your shell'\''s rc file (e.g., ~/.profile):\n'
     52             printf '    export PATH="%s:$PATH"\n' "$INSTALL_DIR"
     53             ;;
     54     esac
     55 }
     56 
     57 main "$@"