-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·114 lines (97 loc) · 4.02 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·114 lines (97 loc) · 4.02 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
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
# ============================================================
# install.sh — Oracle ARM Always Free Provisioning Toolkit
#
# Idempotent installer. Re-run-safe; backs up existing /opt/oracle-tools/
# into /root/.archive/oracle-tools.YYYYMMDD-HHMMSS/ before overwrite.
# ============================================================
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TARGET="/opt/oracle-tools"
ME="$(basename "$0")"
c_red() { printf '\033[1;31m%s\033[0m\n' "$*"; }
c_green() { printf '\033[1;32m%s\033[0m\n' "$*"; }
c_yellow() { printf '\033[1;33m%s\033[0m\n' "$*"; }
c_blue() { printf '\033[1;34m%s\033[0m\n' "$*"; }
echo ""
c_blue "=== Oracle ARM Toolkit — install ==="
echo ""
# 0. Sanity
for t in git curl python3; do
if ! command -v "$t" >/dev/null 2>&1; then
c_red "FATAL: '$t' not found. Install before running $ME."
exit 1
fi
done
# 1. apt deps (idempotent)
echo "--- installing apt deps ---"
DEBIAN_FRONTEND=noninteractive apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq \
jq screen curl git unzip rsync python3 python3-pip python3-venv \
ca-certificates openssh-client
# 2. Backup existing /opt/oracle-tools (if any)
if [[ -d "$TARGET" ]]; then
BKP="/root/.archive/oracle-tools.$(date +%Y%m%d-%H%M%S)"
mkdir -p "$(dirname "$BKP")"
c_yellow "existing $TARGET found, moving to $BKP"
mv "$TARGET" "$BKP"
fi
mkdir -p "$TARGET"/{bin,config,keys,logs,scripts,docs}
chmod 700 "$TARGET/keys"
# 3. Copy toolkit
echo "--- copying toolkit files ---"
cp -r "$REPO_ROOT/lib/." "$TARGET/lib_compat/" 2>/dev/null || true # backward
cp "$REPO_ROOT/lib/inject-config.sh" "$TARGET/bin/"
cp "$REPO_ROOT/lib/post-provision.sh" "$TARGET/scripts/"
cp "$REPO_ROOT/lib/oracle-a1-stack.ini.template" "$TARGET/config/"
# Writable config (Master Timc edits this)
if [[ ! -f "$TARGET/config/oracle-a1-stack.ini" ]]; then
cp "$REPO_ROOT/lib/oracle-a1-stack.ini.template" "$TARGET/config/oracle-a1-stack.ini"
fi
# Vendor jitendhull
mkdir -p "$TARGET/scripts/jitendhull"
cp "$REPO_ROOT/vendor/jitendhull/oracle_a1_automation-v2.sh" "$TARGET/scripts/jitendhull/oracle_a1_automation-v2.sh"
cp "$REPO_ROOT/vendor/jitendhull/LICENSE-MIT" "$TARGET/scripts/jitendhull/LICENSE-MIT"
chmod +x "$TARGET/scripts/jitendhull/oracle_a1_automation-v2.sh"
# Top-level wrapper script — symlink to vendor for cleaner path
ln -sf "$TARGET/scripts/jitendhull/oracle_a1_automation-v2.sh" "$TARGET/scripts/jitendhull-oracle-arm.sh"
# 4. SSH key (regenerate only if missing)
if [[ ! -f "$TARGET/keys/oracle-arm-ed25519" ]]; then
echo "--- generating SSH keypair ---"
ssh-keygen -t ed25519 -C "master-timc-oracle-arm-$(date +%Y%m)" \
-f "$TARGET/keys/oracle-arm-ed25519" -N "" -q
fi
chmod 600 "$TARGET/keys/oracle-arm-ed25519"
chmod 644 "$TARGET/keys/oracle-arm-ed25519.pub"
# 5. OCI CLI venv (idempotent)
echo "--- OCI CLI venv ---"
if [[ ! -d "$TARGET/venv-oci" ]]; then
python3 -m venv "$TARGET/venv-oci"
"$TARGET/venv-oci/bin/pip" install -q --upgrade pip wheel
"$TARGET/venv-oci/bin/pip" install -q oci-cli
fi
ln -sf "$TARGET/venv-oci/bin/oci" /usr/local/bin/oci
# 6. mosesman Docker fallback
if command -v docker >/dev/null 2>&1; then
echo "--- mosesman Docker fallback available (Docker $(docker --version | awk '{print $3}')) ---"
fi
# 7. README runbook
cp "$REPO_ROOT/docs/RUNBOOK.md" "$TARGET/README-timc.md"
# 8. Smoke test
echo ""
c_blue "--- smoke test ---"
bash -n "$TARGET/bin/inject-config.sh"
bash -n "$TARGET/scripts/post-provision.sh"
bash -n "$TARGET/scripts/jitendhull/oracle_a1_automation-v2.sh"
# 9. Done
echo ""
c_green "=== install complete ==="
echo ""
echo " Tools root ........... $TARGET"
echo " Config ............... $TARGET/config/oracle-a1-stack.ini"
echo " SSH public key ....... $TARGET/keys/oracle-arm-ed25519.pub"
echo " OCI CLI .............. /usr/local/bin/oci"
echo " Runbook .............. $TARGET/README-timc.md"
echo ""
c_yellow "Next: register Oracle account, upgrade PAYG, then follow runbook."
echo ""