URI:
       ns-install - scripts - various script and utils
  HTML git clone git://z3bra.org/scripts
   DIR Log
   DIR Files
   DIR Refs
       ---
       ns-install (3748B)
       ---
            1 #!/bin/sh
            2 
            3 usage() {
            4         echo "usage: $(basename $0) [-al] [-n ns] [pkg...]" >&2
            5 }
            6 
            7 # Fix missing shared libs
            8 shlibfix() {
            9         find $1/bin $1/libexec -executable -type f -exec ldd {} + 2>/dev/null \
           10                 |awk '/=>/{print $3}/^\s+\//{print $1}' \
           11                 |sed 's,/usr,,'|sort|uniq|cpio --quiet -updL $1
           12 }
           13 
           14 # https://claude.ai/install.sh
           15 install_claude() {
           16         d="$1"
           17         u="https://downloads.claude.ai/claude-code-releases"
           18         a="linux-x64"
           19         v=$(curl -sSfL "$u/latest")
           20         flock $l curl -sSfL "$u/$v/$a/claude" -o $root/bin/claude &
           21         spinner -p "Install claude ($v)" $l
           22         chmod +x $d/bin/claude
           23 }
           24 
           25 # https://developer.hashicorp.com/terraform/install
           26 install_terraform() {
           27         z=$(mktemp --suffix .zip)
           28         u="https://releases.hashicorp.com/terraform"
           29         a="linux_amd64"
           30         v=$(curl -s "https://developer.hashicorp.com/terraform/install"|sed -rn 's/.* ([0-9.]*) \(latest\).*/\1/p')
           31         flock $l curl -sSfL "$u/$v/terraform_${v}_${a}.zip" -o $z &
           32         spinner -p "Install terraform ($v)" $l
           33         unzip -q -o -d $root/bin $z terraform
           34         rm -f $z
           35 }
           36 
           37 # https://gameoftrees.org/portable.html
           38 install_got() {
           39         d="$1"
           40         tmp=$(mktemp -d)
           41         u="https://gameoftrees.org/releases/portable"
           42         v=$(curl -sSfL "https://gameoftrees.org/portable.html"|sed -rn '/Latest Release/s/.*>([0-9.]+).*/\1/p')
           43         flock $l sh <<-EOF &
           44         curl -sSfL "$u/got-portable-${v}.tar.gz" | tar -xz -C $tmp
           45         cd "$tmp/got-portable-${v}"
           46         ./configure -q CPPFLAGS='-DGOT_DIAL_PATH_SSH=\"/bin/ssh\"' --prefix='' >/dev/null
           47         make -j $(nproc) CC=clang DESTDIR="$d" install >/dev/null 2>&1
           48         EOF
           49         spinner -p "Install got (${v})" $l
           50         rm -rf $tmp
           51 }
           52 
           53 # https://www.brain-dump.org/projects/abduco
           54 install_abduco() {
           55         d="$1"
           56         tmp=$(mktemp -d)
           57         u="https://github.com/martanne/abduco/releases/download"
           58         v="0.6"
           59         flock $l sh <<-EOF &
           60         curl -sSfL "$u/v${v}/abduco-${v}.tar.gz" | tar -xz -C $tmp
           61         cd "$tmp/abduco-${v}"
           62         make -j $(nproc) CC=clang DESTDIR="$d" PREFIX= install >/dev/null 2>&1
           63         EOF
           64         spinner -p "Install abduco (${v})" $l
           65         rm -rf $tmp
           66 }
           67 
           68 # https://github.com/martanne/vis
           69 install_vis() {
           70         d="$1"
           71         tmp=$(mktemp -d)
           72         u="https://github.com/martanne/vis"
           73         a="https://api.github.com/repos/martanne/vis"
           74         v=$(curl -sSfL "$a/commits" 2>/dev/null|grep -m1 -Eo '"sha": "[0-9a-f]+"'|cut -b9-48)
           75         flock $l sh <<-EOF &
           76         curl -sSfL "$u/archive/${v}.tar.gz" | tar -xz -C $tmp
           77         cd "$tmp/vis-${v}"
           78         ./configure --enable-static >/dev/null
           79         make -j $(nproc) DESTDIR="$d" PREFIX= install >/dev/null 2>&1
           80         EOF
           81         sha=$(echo $v|cut -c 1-7)
           82         spinner -p "Install vis ($sha)" $l
           83         rm -rf $tmp
           84 }
           85 
           86 install_nodejs() {
           87         d="$1"
           88         tmp=$(mktemp -d)
           89         v=
           90         u="https://nodejs.org/dist"
           91         v=$(curl -sSfL $u/latest/SHASUMS256.txt|sed -rn '/linux-x64.tar.gz/s/.*(v[0-9.]+).*/\1/p')
           92         flock $l sh <<-EOF &
           93         curl -sSfL "$u/$v/node-$v-linux-x64.tar.gz" | tar -xz -C $tmp
           94         rsync -a $tmp/node-${v}-linux-x64/bin $tmp/node-${v}-linux-x64/lib $root/
           95         EOF
           96         spinner -p "Install nodejs (${v})" $l
           97         rm -rf $tmp
           98 }
           99 
          100 # https://jqlang.org
          101 install_jq() {
          102         d="$1"
          103         u="https://github.com/jqlang/jq/releases/download"
          104         a="linux-amd64"
          105         v=$(curl -sSfL "https://jqlang.org"|awk '/Download jq [0-9.]+/{print $3}')
          106         curl -sSfL "$u/jq-${v}/jq-${a}" -o $root/bin/jq
          107         chmod +x $root/bin/jq
          108 }
          109 
          110 list_pkg() {
          111         sed -rn 's/^install_(.*)\(\) \{/\1/p' "$0"|sort
          112 }
          113 
          114 pkg=
          115 nsname=$(ns -l|head -n1)
          116 while getopts "ahln:" OPT; do
          117         case $OPT in
          118         a) pkg=$(list_pkg);;
          119         l) list_pkg; exit 0;;
          120         n) nsname="$OPTARG";;
          121         h) usage; exit 0;;
          122         *) usage; exit 1;;
          123         esac
          124 done
          125 shift $((OPTIND-1))
          126 
          127 : ${pkg:=$@}
          128 
          129 if [ -z "$pkg" ] && [ $# -lt 1 ]; then
          130         usage
          131         exit 1
          132 fi
          133 
          134 root=$(ns -i $nsname|awk '/^root:/{print $2}')
          135 for p in $pkg; do
          136         if ! list_pkg|grep -q "^${p}\$"; then
          137                 printf '%s: Not in package list\n' "$p" >&2
          138                 exit 1
          139         fi
          140 done
          141 
          142 l=$(mktemp)
          143 trap "rm -f $l" EXIT INT TERM QUIT
          144 for p in $pkg; do install_$p $root; done
          145 shlibfix $root