]> git.nbdom.net Git - nb.git/commitdiff
lib/sh/virtualbox.sh
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 18 May 2019 03:18:30 +0000 (04:18 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 18 May 2019 03:18:30 +0000 (04:18 +0100)
etc/profile.d/docker.sh [deleted file]
etc/profile.d/puppet.sh [deleted file]
etc/profile.d/virtualbox.sh [deleted file]
lib/sh/docker.sh [new file with mode: 0644]
lib/sh/puppet.sh [new file with mode: 0644]
lib/sh/virtualbox.sh [new file with mode: 0644]

diff --git a/etc/profile.d/docker.sh b/etc/profile.d/docker.sh
deleted file mode 100644 (file)
index 6273342..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-#
-# etc/profile.d/docker.sh
-#
-which docker > /dev/null || return 0
-
-
-docker_clean() {
-  local images=$(docker images -qf "dangling=true")
-  [ -n "$images" ] && docker rmi -f $images | sed "s/^/IMAGES /"
-
-  local volumes=$(docker volume ls -qf dangling=true 2>/dev/null)
-  [ -n "$volumes" ] && docker volume rm $volumes | sed "s/^/VOLUMES /"
-
-# NB 01.12.16   local containers=$(docker ps -f status=dead -f status=exited -f status=created -aq)
-  local containers=$(docker ps -f status=dead -aq)
-  [ -n "$containers" ] && docker rm -vf $containers | sed "s/^/CONTAINERS /"
-}
-
-if which docker-compose > /dev/null; then
-docker_compose_up_force() {
-# NB 21.12.16   docker-compose $@ up --force-recreate --build --remove-orphans -d
-  docker-compose up --force-recreate --build --remove-orphans -d $@
-}
-fi
-
-#[ -n "$containers" -a -n "$volumes" -a -n "$images" ]
-# NB 12.11.16 docker-image2dockerfile() {
-# NB 12.11.16 docker history --no-trunc "$1" | \
-# NB 12.11.16 sed -n -e 's,.*/bin/sh -c #(nop) \(MAINTAINER .*[^ ]\) *0 B,\1,p' | \
-# NB 12.11.16 head -1
-# NB 12.11.16 docker inspect --format='{{range $e := .Config.Env}}
-# NB 12.11.16 ENV {{$e}}
-# NB 12.11.16 {{end}}{{range $e,$v := .Config.ExposedPorts}}
-# NB 12.11.16 EXPOSE {{$e}}
-# NB 12.11.16 {{end}}{{range $e,$v := .Config.Volumes}}
-# NB 12.11.16 VOLUME {{$e}}
-# NB 12.11.16 {{end}}{{with .Config.User}}USER {{.}}{{end}}
-# NB 12.11.16 {{with .Config.WorkingDir}}WORKDIR {{.}}{{end}}
-# NB 12.11.16 {{with .Config.Entrypoint}}ENTRYPOINT {{json .}}{{end}}
-# NB 12.11.16 {{with .Config.Cmd}}CMD {{json .}}{{end}}
-# NB 12.11.16 {{with .Config.OnBuild}}ONBUILD {{json .}}{{end}}' "$1"
-# NB 12.11.16 }
diff --git a/etc/profile.d/puppet.sh b/etc/profile.d/puppet.sh
deleted file mode 100644 (file)
index cd85f63..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-puppet2yaml() {
-  perl -pe '
-s/^(.*)\{(.*?:)\s*/$1:\n  $2\n/;
-s/\s*=>\s*/: /;
-s/,\s*/\n/;
-s/\s*\}\s*//;
-' $@
-}
-
-puppet_align() {
-perl -e '
-$q = chr(39);
-
-while (<>) {
-  # No quoted vars
-  s/"(\$)\{([\w_:]+)\}"/$1$2/;
-  s/"(\$[\w_:]+)"/$1/;
-
-  # No double quote
-  s/"([_\w]+)?"/$q$1$q/;
-
-  # No quoted boolean
-  s/[$q"](true|false)[$q"]/$1/;
-
-  $len = $new if /(\S+)\s*=>/ and ($new = length($1))>$len;
-  push @l,$_;
-
-}
-
-END { for (@l) {
-
-  if (@_ = /^(\s*)(.*?)\s*=>\s*(.*)\s*$/) {
-    printf "%s%-${len}s => %s\n", @_;
-  } else  {
-    print $_;
-  }
-
-}}
-'
-}
-which puppet > /dev/null || return 0
-
-puppet_node_clean() {
-  puppet node clean $*
-}
-
-puppet_upgrade_modules() {
-  local m
-  for m in $(puppet module list|perl -ne '/([\w-]+).*?v[\.\d]+/ and print "$1\n"'); do
-    puppet module upgrade "$m"
-  done
-  return
-  local pwd=$PWD
-  cd /etc/puppet/modules
-  for m in $(puppet module list | awk '/\(.*v/ {print $2}'); do
-    puppet module upgrade "$m"
-  done
-  cd $pwd
-}
-
diff --git a/etc/profile.d/virtualbox.sh b/etc/profile.d/virtualbox.sh
deleted file mode 100644 (file)
index 9d221ae..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-# etc/profile.d/virtualbox.sh
-#
-
-which VirtualBox > /dev/null || return 0
-
-virtualbox_shared() {
-  local machine="$1"; shift
-  [ -z "$machine" -a -n "$DOCKER_MACHINE_NAME" ] && machine="$DOCKER_MACHINE_NAME"
-  [ -z "$machine" -o "$machine" = '-h' -o "$machine" = '--help' ] && echo "Usage: $FUNCNAME MACHINE_NAME" 1>&2 && return
-  VBoxManage showvminfo "$machine" | perl -ne "print qq|\$2\t\$1\n| if /^Name: '(.*?)', Host path: '(.*?)'/"
-}
-
-virtualbox_add_shared() {
-  local machine="$1"; shift
-  local path="$1"; shift
-  local share="$1"; shift
-  virtualbox_shared "$machine" | grep -q "^$path" && echo "$path: share already exists!'" 1>&2 && return 1
-
-  if virtualbox_shared "$machine" | grep -q "^$path"; then
-    echo "$path: share already exists!'" 1>&2
-  else
-    docker-machine stop "$machine"
-    VBoxManage sharedfolder add "$machine" --name "$share" --hostpath "$path"--automount 2>/dev/null || :
-    docker-machine start "$machine"
-  fi
-
-  eval $(docker-machine env "$machine") && docker-machine ssh "$machine" \
-    'printf "test -e $path || mkdir -p $path\nmount -t vboxsf -o rw,user $share $path\n | sudo tee /mnt/sda1/var/lib/boot2docker/bootlocal.sh && sudo sh /mnt/sda1/var/lib/boot2docker/bootlocal.sh'
-}
diff --git a/lib/sh/docker.sh b/lib/sh/docker.sh
new file mode 100644 (file)
index 0000000..6273342
--- /dev/null
@@ -0,0 +1,42 @@
+#
+# etc/profile.d/docker.sh
+#
+which docker > /dev/null || return 0
+
+
+docker_clean() {
+  local images=$(docker images -qf "dangling=true")
+  [ -n "$images" ] && docker rmi -f $images | sed "s/^/IMAGES /"
+
+  local volumes=$(docker volume ls -qf dangling=true 2>/dev/null)
+  [ -n "$volumes" ] && docker volume rm $volumes | sed "s/^/VOLUMES /"
+
+# NB 01.12.16   local containers=$(docker ps -f status=dead -f status=exited -f status=created -aq)
+  local containers=$(docker ps -f status=dead -aq)
+  [ -n "$containers" ] && docker rm -vf $containers | sed "s/^/CONTAINERS /"
+}
+
+if which docker-compose > /dev/null; then
+docker_compose_up_force() {
+# NB 21.12.16   docker-compose $@ up --force-recreate --build --remove-orphans -d
+  docker-compose up --force-recreate --build --remove-orphans -d $@
+}
+fi
+
+#[ -n "$containers" -a -n "$volumes" -a -n "$images" ]
+# NB 12.11.16 docker-image2dockerfile() {
+# NB 12.11.16 docker history --no-trunc "$1" | \
+# NB 12.11.16 sed -n -e 's,.*/bin/sh -c #(nop) \(MAINTAINER .*[^ ]\) *0 B,\1,p' | \
+# NB 12.11.16 head -1
+# NB 12.11.16 docker inspect --format='{{range $e := .Config.Env}}
+# NB 12.11.16 ENV {{$e}}
+# NB 12.11.16 {{end}}{{range $e,$v := .Config.ExposedPorts}}
+# NB 12.11.16 EXPOSE {{$e}}
+# NB 12.11.16 {{end}}{{range $e,$v := .Config.Volumes}}
+# NB 12.11.16 VOLUME {{$e}}
+# NB 12.11.16 {{end}}{{with .Config.User}}USER {{.}}{{end}}
+# NB 12.11.16 {{with .Config.WorkingDir}}WORKDIR {{.}}{{end}}
+# NB 12.11.16 {{with .Config.Entrypoint}}ENTRYPOINT {{json .}}{{end}}
+# NB 12.11.16 {{with .Config.Cmd}}CMD {{json .}}{{end}}
+# NB 12.11.16 {{with .Config.OnBuild}}ONBUILD {{json .}}{{end}}' "$1"
+# NB 12.11.16 }
diff --git a/lib/sh/puppet.sh b/lib/sh/puppet.sh
new file mode 100644 (file)
index 0000000..cd85f63
--- /dev/null
@@ -0,0 +1,60 @@
+puppet2yaml() {
+  perl -pe '
+s/^(.*)\{(.*?:)\s*/$1:\n  $2\n/;
+s/\s*=>\s*/: /;
+s/,\s*/\n/;
+s/\s*\}\s*//;
+' $@
+}
+
+puppet_align() {
+perl -e '
+$q = chr(39);
+
+while (<>) {
+  # No quoted vars
+  s/"(\$)\{([\w_:]+)\}"/$1$2/;
+  s/"(\$[\w_:]+)"/$1/;
+
+  # No double quote
+  s/"([_\w]+)?"/$q$1$q/;
+
+  # No quoted boolean
+  s/[$q"](true|false)[$q"]/$1/;
+
+  $len = $new if /(\S+)\s*=>/ and ($new = length($1))>$len;
+  push @l,$_;
+
+}
+
+END { for (@l) {
+
+  if (@_ = /^(\s*)(.*?)\s*=>\s*(.*)\s*$/) {
+    printf "%s%-${len}s => %s\n", @_;
+  } else  {
+    print $_;
+  }
+
+}}
+'
+}
+which puppet > /dev/null || return 0
+
+puppet_node_clean() {
+  puppet node clean $*
+}
+
+puppet_upgrade_modules() {
+  local m
+  for m in $(puppet module list|perl -ne '/([\w-]+).*?v[\.\d]+/ and print "$1\n"'); do
+    puppet module upgrade "$m"
+  done
+  return
+  local pwd=$PWD
+  cd /etc/puppet/modules
+  for m in $(puppet module list | awk '/\(.*v/ {print $2}'); do
+    puppet module upgrade "$m"
+  done
+  cd $pwd
+}
+
diff --git a/lib/sh/virtualbox.sh b/lib/sh/virtualbox.sh
new file mode 100644 (file)
index 0000000..9d221ae
--- /dev/null
@@ -0,0 +1,30 @@
+#
+# etc/profile.d/virtualbox.sh
+#
+
+which VirtualBox > /dev/null || return 0
+
+virtualbox_shared() {
+  local machine="$1"; shift
+  [ -z "$machine" -a -n "$DOCKER_MACHINE_NAME" ] && machine="$DOCKER_MACHINE_NAME"
+  [ -z "$machine" -o "$machine" = '-h' -o "$machine" = '--help' ] && echo "Usage: $FUNCNAME MACHINE_NAME" 1>&2 && return
+  VBoxManage showvminfo "$machine" | perl -ne "print qq|\$2\t\$1\n| if /^Name: '(.*?)', Host path: '(.*?)'/"
+}
+
+virtualbox_add_shared() {
+  local machine="$1"; shift
+  local path="$1"; shift
+  local share="$1"; shift
+  virtualbox_shared "$machine" | grep -q "^$path" && echo "$path: share already exists!'" 1>&2 && return 1
+
+  if virtualbox_shared "$machine" | grep -q "^$path"; then
+    echo "$path: share already exists!'" 1>&2
+  else
+    docker-machine stop "$machine"
+    VBoxManage sharedfolder add "$machine" --name "$share" --hostpath "$path"--automount 2>/dev/null || :
+    docker-machine start "$machine"
+  fi
+
+  eval $(docker-machine env "$machine") && docker-machine ssh "$machine" \
+    'printf "test -e $path || mkdir -p $path\nmount -t vboxsf -o rw,user $share $path\n | sudo tee /mnt/sda1/var/lib/boot2docker/bootlocal.sh && sudo sh /mnt/sda1/var/lib/boot2docker/bootlocal.sh'
+}