Skip to content

Instantly share code, notes, and snippets.

@ywatase
Created July 5, 2019 05:34
Show Gist options
  • Save ywatase/6a795e193f628a879c2da0d3c687c0d8 to your computer and use it in GitHub Desktop.
Save ywatase/6a795e193f628a879c2da0d3c687c0d8 to your computer and use it in GitHub Desktop.
source インストールしたnodeをnに入れ替えるスクリプト
#!/bin/bash
prefix=/usr/local
current_version=$(/usr/local/bin/node --version)
which rsync >/dev/null 2>&1 || yum install -y rsync
install_n () {
if ! [ -x $prefix/bin/n ] ; then
curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o $prefix/bin/n
chmod a+x $prefix/bin/n
mkdir -p $prefix/n
fi
}
move_old_node () {
mkdir -p $prefix/n/versions/node/$current_version/{bin,lib/node_modules,lib/dtrace,include,share/man/man1,share/doc,share/systemtap/tapset}
while read target
do
if [ -e $prefix/${target} ] ; then
echo rsync -a $prefix/${target} $prefix/n/versions/node/$current_version/${target}
rsync -a $prefix/${target} $prefix/n/versions/node/$current_version/${target}
fi
done <<END
bin/node
bin/npm
bin/npx
include/node
lib/dtrace/node.d
lib/node_modules/npm
share/doc/node
share/man/man1/node.1
share/systemtap/tapset/node.stp
END
}
install_n
if ! [ -d /var/tmp/node_modules.backup.${current_version}.$(date +%Y%m%d) ] ; then
rsync -av $prefix/lib/node_modules /var/tmp/node_modules.backup.${current_version}.$(date +%Y%m%d)
fi
move_old_node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment