代码区项目交易流程

Moving home - updates to vcsh usage


A while back I switched tovcsh. I’ve written afew articles on using it but since then I’ve migrated machines a number of times.

The big issue I’ve found is having to manually install software on each machine. There are things my scripts depend on and things I just expect to have and manually creating them each time is annoying.

So the solution obviously is a script. It’s actually used all the time as I might create new dependencies or find new tools I need so I’d want that installed on all machines. So it runs in my ~/.zlogin file and by using a local stamp file (unlike forthird-pary sources) it reminds me periodically to run update now .

It first updates itself, it uses mr to update all my vim repositories, and then mostly uses native packaging tools to install software.

Switching to version control for home dirs was a lot of the battle, but getting the tools and things I need on the machines has been the next one. As it stands I can now pretty quickly get up to speed on a new machine in just a few minutes. It would be nice to have something where I could go, curl https://phrye.com/HOME | bash instead of having to remember the initial vcsh commands but that’s a further project.

#!/bin/bash set -e stamp_dir=~/.config/update stamp_file=~/.config/update/.last-update.stamp if [[ ! -d $stamp_dir ]]; then mkdir -p $stamp_dir fi do_update() { # Update homedir. if [[ "$1" != "vcsh-update-done" ]]; then vcsh pull exec "$0" now vcsh-update-done fi # Update vim modules. cd ~/.vim mr update # Update system. kernel=$(uname -v) echo "Running specific steps for '$kernel'." case "$kernel" in FreeBSD*) makewhatis ~/.config/home-man if [ ! -f /usr/local/go/bin/go ]; then sudo pkg install go fi for pkg in python3 py36-sqlite3 gsed bind-tools go awscli; do if ! pkg list $pkg > /dev/null; then pkg install $pkg fi done ;; *Ubuntu*) if [[ ! -d /var/lib/slack ]]; then if [[ -d /etc/sudoers.d && ! -f "/etc/sudoers.d/$USER" ]]; then echo "$USER ALL=(ALL) NOPASSWD: ALL" \ | sudo -p "Please enter password to configure sudo: " \ tee "/etc/sudoers.d/$USER" > /dev/null fi sudo -p "Please enter password to install packages: " \ apt install vim-nox unzip wget tree gpg pwgen fortune \ perl-doc bc shellcheck yamllint clang-tidy \ cppcheck flawfinder gitlint lua-check \ python3-flake8 pylint3 screen python3-defusedxml go_tar=go1.10.3.linux-amd64.tar.gz go_tar_dir=$HOME/.config/update if [[ ! -d "$go_tar_dir" ]]; then mkdir "$go_tar_dir" fi if [[ ! -f "$go_tar_dir/$go_tar" ]]; then wget --quiet -O "$go_tar_dir/$go_tar" -c https://dl.google.com/go/$go_tar if [[ -d /usr/local/go ]]; then sudo -p "Please enter password to remove old go installation: " \ rm -rf /usr/local/go fi fi if [[ ! -d /usr/local/go ]]; then echo "Installing new go version." sudo tar -C /usr/local -xzf "$go_tar_dir/$go_tar" export PATH=${PATH}:/usr/local/go export GOPATH=$HOME/src/go export KEVIN_GOWARN=1 fi fi ;; esac # If homebrew exists; update it too. if [[ -f /Users/kevin/Homebrew/bin/brew ]]; then brew update brew upgrade fi if [[ "$KEVIN_GOWARN" == 1 ]]; then cat << EOF Run the following in each currently open shell (or just log out and log in again): export PATH=$PATH export GOPATH=$GOPATH EOF fi touch $stamp_file } do_check() { update_required=false if [[ ! -f $stamp_file ]]; then update_required=true else if [[ $0 -nt $stamp_file ]]; then update_required=true fi if find $stamp_file -mtime +21 | grep -q stamp; then update_required=true fi fi if $update_required; then echo "INFO: Need to run 'update now' to update home dir." fi } do_usage() { echo "$0 [now|check]" } case "$1" in up|update|now) do_update "$2" ;; check|"") do_check ;; *) do_usage ;; esac

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

点击收藏

LAST Take to the virtual skies with FlightGear The sed command does not work correctly in Solaris but works in linux NEXT