]> git.nbdom.net Git - osx.git/commitdiff
etc/profile master
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 20 Mar 2019 01:33:34 +0000 (01:33 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 20 Mar 2019 01:33:34 +0000 (01:33 +0000)
etc/profile [new file with mode: 0644]

diff --git a/etc/profile b/etc/profile
new file mode 100644 (file)
index 0000000..27d85a4
--- /dev/null
@@ -0,0 +1,208 @@
+##############################################################################
+#
+# Requirement:
+# - functions: getexp_url shell_help_noarg
+#
+#
+# See: http://www.infoworld.com/article/2614879/mac-os-x/top-20-os-x-command-line-secrets-for-power-users.html
+#
+##############################################################################
+##############################################################################
+#
+# Darwin only !
+case "$OSTYPE" in darwin*)
+#
+##############################################################################
+alias strace='dtruss'
+alias updatedb='sudo sh -c "cd / && exec /usr/libexec/locate.updatedb"'
+
+# NB 28.02.19 type -p seq > /dev/null || seq() {
+# NB 28.02.19   if [ -n "$2" ]; then
+# NB 28.02.19     jot - "$1" "$2"
+# NB 28.02.19   else
+# NB 28.02.19     jot "$1"
+# NB 28.02.19   fi
+# NB 28.02.19 }
+
+alias mac_iptables_reload="pfctl -d; pfctl -f /etc/pf.conf -e"
+alias mac_top_proc="echo 'TOP PROCESSES:'; ps -Aro'%cpu, ucomm, user' | grep root | grep -v ' 0.0 '"
+alias mac_sleep='pmset sleepnow'
+alias mac_mount_nfs='sudo mount -o resvport -t nfs'
+alias mac_automount='sudo automount -v'
+alias mac_dns_flush='sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder'
+alias mac_sleep='pmset sleepnow'
+#alias mac-wakeup-screen="pmset schedule wake '\$(date +\"%d/%m/%Y %T\")'"
+#alias mac-wakeup-screen2='osascript -e \'tell application "System Events" to key code 123\''
+alias macps_top="echo 'TOP PROCESSES:'; ps -Aro'%cpu, ucomm, user' | grep $USER | grep -v ' 0.0 '"
+alias mac_mount_nfs="sudo mount -o resvport -t nfs"
+
+mac_dev_shm() {
+  set -e
+  local usage="Usage: $FUNCNAME [SIZE in MB] [MOUNT DIR (default /dev/shm)]"
+  shell_help_noarg "$usage" "$@" && return 1
+  local mb=$1
+  !test "$mb" -gt 0 2>/dev/null && shell_help_noarg "$usage" && return 1
+  local mount_point=${2:-/dev/shm}
+  local ramdisk_dev=$(sudo hdiutil attach -nomount ram://$((2 * 1024 *$mb)))
+  sudo diskutil eraseVolume HFS+ RAMDisk "${ramdisk_dev}"
+
+  sudo install -d "${mount_point}" -m 7777
+  sudo mount -o noatime -t hfs "${ramdisk_dev}" "${mount_point}"
+
+  echo "remove with:"
+  echo "umount ${mount_point}"
+  echo "diskutil eject ${ramdisk_dev}"
+}
+  
+mac_user_top_proc() {
+  echo "TOP PROCESSES:"
+  ps -Aro'%cpu, ucomm, user' | grep `whoami` | grep -v ' 0.0 '
+}
+
+which md5sum > /dev/null || md5sum() {
+  md5 "$@" | sed "s/^MD5 (\(.*\)) = \(.*\)$/\2  \1/"
+}
+
+mac_xmessage() {
+  osascript -e "tell app \"System Events\" to display dialog \"$@\""
+}
+
+mac_pkg_list_todel() {
+  pkgutil --only-files --files "$1" && \
+  for d in $(pkgutil --only-dirs --files "$1"); do [ -d "/$d" ] && [[ -z $(ls -A "/$d") ]] || echo $d; done
+  echo pkgutil --forget "$1"
+}
+
+mac_install() {
+
+  local prg="$1"; shift
+
+  # Aliases
+  case "$prg" in
+
+    docker-compose)
+      sudo curl -L "https://github.com/docker/compose/releases/download/1.8.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose.install
+      sudo chmod +x /usr/local/bin/docker-compose.install
+      sudo mv /usr/local/bin/docker-compose.install /usr/local/bin/docker-compose
+      return
+    ;;
+
+    docker)
+      [ "$(sysctl -n kern.hv_support 2>/dev/null)" = "0" ] \
+        && echo "Docker not compatible. \`See sysctl -n kern.hv_support\`" \
+        && return; prg="https://download.docker.com/mac/stable/Docker.dmg"
+    ;;
+
+    xcode)
+      #echo "$prg"; return
+      local os=$(mac_version)
+      local vers="8.2_beta_2"
+      open "http://adcdownload.apple.com/Developer_Tools/Command_Line_Tools_macOS_${os}_for_Xcode_${vers}/Command_Line_Tools_macOS_${os}_for_Xcode_${vers}.dmg"
+      return
+    ;;
+
+    virtualbox)
+      prg=$(getexp_url 'https?://download.virtualbox.org/virtualbox/[^"\s]+dmg' https://www.virtualbox.org/wiki/Downloads)
+    ;;
+
+    macport)
+      #prg="https://github.com"$(getexp_url '[^"]+'$(mac_version_name)'.*?pkg' "https://github.com/macports/macports-base/releases")
+      prg=$(getexp_url 'https?://.*'$(mac_version_name)'[^"\s]+pkg' https://www.macports.org/install.php)
+      echo 'Please visit https://www.macports.org/install.php'
+      return
+      #echo ">$prg"; return;
+    ;;
+
+  esac
+
+  #echo ">$prg"; return
+  # Install
+  case "$prg" in
+    ""|-h|--help)
+      echo "Usage: $FUNCNAME [ALIASES|*.dmg|*.pkg]"
+      echo "ALIASES:"
+      type mac_install|perl -ne '/^\s*([\w-_]+)\)/&&print "  - $1\n"'
+      #type mac_install|perl -ne '/^\s*([\w-_]+)\)/&&push(@a,$1);END{print join("|",@a)}'
+    return
+    ;;
+    *.pkg)
+      sudo installer -verbose -pkg "$prg" -target /
+    ;;
+    *)
+      local MOUNTDIR=$(echo `sudo hdiutil mount "$prg" | tail -1 | awk '{$1=$2=""; print $0}'` | xargs -0 echo)
+
+      if [ -n "$MOUNTDIR" ]; then
+
+        if [[ -n $(find "${MOUNTDIR}" -mindepth 0 -maxdepth 1 -name '*.pkg') ]]; then
+          sudo installer -verbose -pkg "${MOUNTDIR}/"*.pkg -target /
+        elif [[ -n $(find "${MOUNTDIR}" -mindepth 0 -maxdepth 1 -name '*.app') ]]; then
+          sudo cp -rv "${MOUNTDIR}/"*.app /Applications/
+        else
+          read -p "Can not find *.pkg. Press a key to unmount ${MOUNTDIR}"
+        fi
+
+        sudo hdiutil detach "${MOUNTDIR}"
+      fi
+    ;;
+  esac
+
+}
+
+mac_version() {
+  sw_vers -productVersion | cut -d '.' -f 1,2
+}
+
+mac_version_name() {
+  case $(mac_version) in
+    10.5) echo Leopard;;
+    10.6) echo SnowLeopard;;
+    10.7) echo Lion ;;
+    10.8) echo MountainLion ;;
+    10.9) echo Mavericks ;;
+    10.10) echo Yosemite ;;
+    10.11) echo ElCapitan ;;
+    10.12) echo Sierra ;;
+  esac
+}
+
+mac_pkg_list_files() {
+  #sudo pkgutil --only-dirs --files com.puppetlabs.puppet-agent|grep /puppet
+  sudo pkgutil --only-files --files $@
+}
+
+mac_keychain_add() {
+  local in="cat";
+  [ -n "$*" ] && in="echo $*";
+  eval $in | sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain
+}
+
+mac_routes() {
+  netstat -nr $@ | perl -pe'/^Internet6/&&last'
+}
+
+mac_port_reinstall() {
+  port -qv installed > /tmp/myports.txt
+  port echo requested | cut -d ' ' -f 1 > /tmp/requested.txt
+  port -f uninstall installed
+  port selfupdate
+  port clean all
+  curl -s https://svn.macports.org/repository/macports/contrib/restore_ports/restore_ports.tcl | sh /tmp/myports.txt
+  rm /tmp/myports.txt
+}
+
+getent() {
+  if which getent; then
+    eval "$(which getent) $@"
+    return
+  fi
+  if [ "$1" = "group" -a -n "$2" ]; then
+    grep "^$2:" /etc/group
+    return
+  fi
+  [ "$1" = "group" ] && cat /etc/group && return
+  [ "$1" != "passwd" ] && echo "Support only passwd and group untill now" 1>&2 && return 1
+  [ -z "$2" ] && (ls_users; return)
+  ls_users | grep "^$2:"
+}
+
+;;esac # Darwin only ! <<<