#!/bin/bash
set -u
# Usage:
# cd /opt/perforce/dev/bin
# ./setup_test_machine.sh 2>&1 | tee log.setup_test_machine.txt
declare ThisScript=${0##*/}
declare ThisHost=${HOSTNAME%%.*}
declare ThisUser=
# shellcheck disable=SC2016
declare VersionInfo='$Id: //test-install_sdp/dev/setup_test_machine.sh#1 $ $Change: 33144 $'
declare VersionStream=${VersionInfo%/*}
declare VersionStream=${VersionStream##*/}
declare VersionRev=${VersionInfo%% \$ \$Change:*}
declare VersionRev=${VersionRev##*#}
declare Version="$VersionStream.$VersionRev"
declare -i ErrorCount=0
declare PackageManager=
#------------------------------------------------------------------------------
# Functions msg(), errmsg, and bail().
# Sample Usage:
# bail "Missing something important. Aborting."
# bail "Aborting with exit code 3." 3
function msg () { echo -e "$*"; }
function errmsg () { msg "\nError: ${1:-Unknown Error}\n"; ErrorCount+=1; }
function bail () { errmsg "${1:-Unknown Error}"; exit "${2:-1}"; }
#------------------------------------------------------------------------------
# Main Program
ThisUser=$(id -n -u)
msg "Starting $ThisScript version $Version as $ThisUser@$ThisHost on $(date)."
[[ "$ThisUser" == root ]] || bail "Run as root, not user $ThisUser."
if [[ -n "$(command -v yum)" ]]; then
PackageManager=yum
elif [[ -n "$(command -v apt-get)" ]]; then
PackageManager=apt-get
elif [[ -n "$(command -v zypper)" ]]; then
PackageManager=zypper
else
bail "Error: Unknown Package Manager; not yum or apt-get. Aborting."
fi
case "$PackageManager" in
(yum)
if rpm -q rsync >/dev/null 2>&1; then
msg "Verified: rsync package is installed."
else
yum install -y rsync ||\
errmsg "Failed to install rsync package with $PackageManager."
fi
;;
(apt-get)
if dpkg-query -W -f='${Status}' rsync 2>/dev/null | grep -q "install ok installed"; then
msg "Verified: rsync package is installed."
else
apt-get update ||\
errmsg "The call to 'apt-get update' had a non-zero exit code. Ignoring."
apt-get install -y rsync ||\
errmsg "Failed to install rsync package with $PackageManager."
fi
;;
(zypper)
if rpm -q rsync >/dev/null 2>&1; then
msg "Verified: rsync package is installed."
else
zypper refresh ||\
errmsg "The call to 'zypper refresh' had a non-zero exit code. Ignoring."
zypper install -y rsync ||\
errmsg "Failed to install rsync package with $PackageManager."
fi
;;
(*) bail "Internal error; unexpected PackageManager ($PackageManager).";;
esac
if [[ ! -r ~/.config/nvim/init.lua ]]; then
msg "Configuring Neovim."
if [[ -r /opt/perforce/dev/bin/nvim.init.lua ]]; then
mkdir -p ~/.config/nvim
cd ~/.config/nvim
ln -s /opt/perforce/dev/bin/nvim.init.lua init.lua
cd - > /dev/null
elif [[ -r /opt/perforce/.dev/bin/nvim.init.lua ]]; then
mkdir -p ~/.config/nvim
cd ~/.config/nvim
ln -s /opt/perforce/.dev/bin/nvim.init.lua init.lua
cd - > /dev/null
fi
else
msg "Skipping Neovim config; already configured."
fi
if [[ "$ErrorCount" -eq 0 ]]; then
msg "\nSuccess: Processing complete with no errors."
else
errmsg "Processing completed, but with $ErrorCount errors."
fi
exit "$ErrorCount"
| # | Change | User | Description | Committed | |
|---|---|---|---|---|---|
| #1 | 33144 | C. Thomas Tyler | Initialized //test-install_sdp/dev with p4 populate -b test-install_sdp_Classic_to_Streams | ||
| //guest/tom_tyler/sw/main/install_sdp/dev/bin/setup_test_machine.sh | |||||
| #4 | 32940 | C. Thomas Tyler | Non-functional change; formatting/cosmetic only. | ||
| #3 | 32939 | C. Thomas Tyler | Non-functional change; formatting/cosmetic only. | ||
| #2 | 31907 | C. Thomas Tyler | Added neovim config bits. | ||
| #1 | 31246 | C. Thomas Tyler |
Added new script to install packages required by the test suite, and added step in instructions to call it. For now, it just ensures that rsync is installed, as that's needed for the test suite itself to work. The install_sdp.sh script itself installs everything it needs, and in fact one of the tests uninstalls rsync just to ensure the install_sdp.sh script handles that well (which an earlier version didn't). |
||