-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprepare-script-tester
More file actions
executable file
·105 lines (99 loc) · 3.62 KB
/
Copy pathprepare-script-tester
File metadata and controls
executable file
·105 lines (99 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
# ==========================================================================
# __ ____ __ ___ ___ _ _ _
# \ \ / / \/ | |_ _|_ __ __ _ __ _ ___ | _ )_ _(_) |__| |___ _ _
# \ V /| |\/| | | || ' \/ _` / _` / -_) | _ \ || | | / _` / -_) '_|
# \_/ |_| |_| |___|_|_|_\__,_\__, \___| |___/\_,_|_|_\__,_\___|_|
# |___/
#
# --- Virtual Machine Image Builder and System Installation Scripts ---
# https://www.nntb.no/~dreibh/vmimage-builder-scripts/
# ==========================================================================
#
# VM Image Builder Scripts
# Copyright (C) 2017-2026 by Thomas Dreibholz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Contact: thomas.dreibholz@gmail.com
# Bash options:
set -euo pipefail
# ====== Handle arguments ===================================================
if [ $# -ne 1 ] ; then
echo >&2 "Usage: $0 user@server"
exit 1
fi
SERVER="${1//*@/}"
USER="${1//@*/}"
if [ "${USER}" == "${SERVER}" ] ; then
USER="nornetpp"
fi
# ====== Obtain name and e-mail for Git configuration =======================
gitConfig="${HOME}/.gitconfig"
if [ -e "${gitConfig}" ] ; then
GIT_NAME="$(grep "^[[:space:]]*name[[:space:]]*=" "${gitConfig}" | sed -e 's/^.*=[ \t]*//')"
GIT_EMAIL="$(grep "^[[:space:]]*email[[:space:]]*=" "${gitConfig}" | sed -e 's/^.*=[ \t]*//')"
else
GIT_NAME=""
GIT_EMAIL=""
echo >&2 "WARNING: Unable to determine Git user and email!"
fi
# ====== Configure server ===================================================
ssh-copy-id -i ~/.ssh/id_rsa -oStrictHostKeyChecking=no "${USER}@${SERVER}"
# shellcheck disable=SC2029
ssh -t "${USER}@${SERVER}" "
set -euo pipefail
if [ ! -e .gitconfig ] || grep -q -E '^[[:space:]]*name[[:space:]]*=[[:space:]]*NorNet Praesum Presum' .gitconfig ; then
echo \"Updating .gitconfig:\"
(
echo \"[user]\"
echo \" name = ${GIT_NAME}\"
echo \" email = ${GIT_EMAIL}\"
echo \"[push]\"
echo \" default = simple\"
echo \" autoSetupRemote = true\"
echo \"[pull]\"
echo \" rebase = false\"
echo \"[color]\"
echo \" ui = auto\"
) | tee .gitconfig
else
echo \"Leaving .gitconfig unchanged!\"
fi
echo \"nornetpp ALL=(ALL) NOPASSWD:ALL\" | if [ -d /etc/sudoers.d ] ; then
sudo tee /etc/sudoers.d/99-nornetpp
else
sudo tee /usr/local/etc/sudoers.d/99-nornetpp
fi
if ! which git || ! which joe ; then
if [ -x /usr/bin/apt ] ; then
sudo /usr/bin/apt install -y git joe
elif [ -x /usr/bin/dnf ] ; then
sudo /usr/bin/dnf install -y git joe
elif [ -x /usr/bin/pkg ] ; then
sudo /usr/bin/pkg install -y git joe
fi
fi
mkdir -p src
cd src
if [ -d vmimage-builder-scripts ] ; then
cd vmimage-builder-scripts
git pull
else
git clone https://dreibh@github.com/simula/nornet-vmimage-builder-scripts.git vmimage-builder-scripts
cd vmimage-builder-scripts
fi
"
# ====== Connect to server ==================================================
ssh "${USER}@${SERVER}"