|
|
|
@ -15,12 +15,12 @@ PATH=/sbin:/usr/sbin:$PATH
|
|
|
|
|
|
|
|
|
|
function sysConfig() { |
|
|
|
|
echo "Enter the server FQDN $(tput setaf 2)[System: $(hostname)]$(tput sgr0):" |
|
|
|
|
read serverFQDN |
|
|
|
|
hostnamectl set-hostname $serverFQDN |
|
|
|
|
read -r serverFQDN |
|
|
|
|
hostnamectl set-hostname "$serverFQDN" |
|
|
|
|
|
|
|
|
|
echo "Enter the server Time Zone $(tput setaf 2)[System: $(cat /etc/timezone)]$(tput sgr0): " |
|
|
|
|
read serverTZ |
|
|
|
|
timedatectl set-timezone $serverTZ |
|
|
|
|
read -r serverTZ |
|
|
|
|
timedatectl set-timezone "$serverTZ" |
|
|
|
|
|
|
|
|
|
# Navigate to tmp |
|
|
|
|
cd /tmp |
|
|
|
@ -146,8 +146,21 @@ EOF
|
|
|
|
|
# Git |
|
|
|
|
apt-get update && apt-get -y install git |
|
|
|
|
|
|
|
|
|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
# Generate SSH key |
|
|
|
|
ssh-keygen -ted25519 -f ~/.ssh/id_ed25519 -N '' |
|
|
|
|
for key_type in all https runner; do |
|
|
|
|
ssh-keygen -t ed25519 -f ~/.ssh/ed25519_01edu_$key_type -N '' |
|
|
|
|
|
|
|
|
|
# Create SSH config for each key |
|
|
|
|
echo "Host github.com-01-edu-$key_type |
|
|
|
|
HostName github.com |
|
|
|
|
User git |
|
|
|
|
IdentityFile ~/.ssh/ed25519_01edu_$key_type" >~/.ssh/config.d/01-edu-$key_type.conf |
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
# Include custom SSH configurations from the config directory |
|
|
|
|
echo "Include ~/.ssh/config.d/*.conf" >>~/.ssh/config |
|
|
|
|
|
|
|
|
|
# Use Cloudflare DNS server |
|
|
|
|
echo 'supersede domain-name-servers 1.1.1.1;' >>/etc/dhcp/dhclient.conf |
|
|
|
@ -170,7 +183,24 @@ EOF
|
|
|
|
|
# Check Config |
|
|
|
|
function checkConfig() { |
|
|
|
|
test "$(command -v "${1:-}")" && echo -n ✅ || echo -n ❌ |
|
|
|
|
echo " $@" |
|
|
|
|
echo " $*" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function checkKeys() { |
|
|
|
|
# Check if SSH key pairs are generated |
|
|
|
|
if [ -f ~/.ssh/ed25519_01edu_all ] && [ -f ~/.ssh/ed25519_01edu_all.pub ] && |
|
|
|
|
[ -f ~/.ssh/ed25519_01edu_https ] && [ -f ~/.ssh/ed25519_01edu_https.pub ] && |
|
|
|
|
[ -f ~/.ssh/ed25519_01edu_runner ] && [ -f ~/.ssh/ed25519_01edu_runner.pub ]; then |
|
|
|
|
echo "✅ SSH private/public key pairs generated" |
|
|
|
|
|
|
|
|
|
# Echo public keys |
|
|
|
|
echo "Public keys:" |
|
|
|
|
cat ~/.ssh/ed25519_01edu_all.pub |
|
|
|
|
cat ~/.ssh/ed25519_01edu_https.pub |
|
|
|
|
cat ~/.ssh/ed25519_01edu_runner.pub |
|
|
|
|
else |
|
|
|
|
echo "❌ SSH private/public key pairs not found" |
|
|
|
|
fi |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# Check configs in the List |
|
|
|
@ -204,16 +234,15 @@ function checkList() {
|
|
|
|
|
checkConfig whois |
|
|
|
|
checkConfig sudo |
|
|
|
|
|
|
|
|
|
test "$(ls ~/.ssh/*.pub 2>/dev/null)" && echo -n ✅ || echo -n ❌ |
|
|
|
|
echo " SSH private/public key pair generated" |
|
|
|
|
checkKeys |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function runHTTPS() { |
|
|
|
|
echo -e "Deploying HTTPS service: \n" |
|
|
|
|
echo "Enter the server FQDN $(tput setaf 2)[System: $(hostname)]$(tput sgr0):" |
|
|
|
|
read httpsFQDN |
|
|
|
|
read -r httpsFQDN |
|
|
|
|
# Check if the FQDN is valid |
|
|
|
|
if dig +short $httpsFQDN >/dev/null 2>&1; then |
|
|
|
|
if dig +short "$httpsFQDN" >/dev/null 2>&1; then |
|
|
|
|
cd /root/core/https |
|
|
|
|
DOMAIN=$httpsFQDN ./run.sh |
|
|
|
|
echo -e "HTTPS service is up! \n" |
|
|
|
@ -231,15 +260,15 @@ function deployCore() {
|
|
|
|
|
echo -e "$(tput setaf 6)$(tput bold)\nThe core components will be deployed to the server: $(tput sgr0)\n" |
|
|
|
|
|
|
|
|
|
# Clone core repositories |
|
|
|
|
git clone git@github.com:01-edu/runner.git /root/core/runner |
|
|
|
|
git clone git@github.com:01-edu/https.git /root/core/https |
|
|
|
|
git clone git@github.com-01-edu-runner:01-edu/runner.git /root/core/runner |
|
|
|
|
git clone git@github.com-01-edu-https:01-edu/https.git /root/core/https |
|
|
|
|
|
|
|
|
|
# Docker login |
|
|
|
|
echo -e "Enter the docker username: " |
|
|
|
|
read dockerUsername |
|
|
|
|
read -r dockerUsername |
|
|
|
|
echo -e "Enter the docker password: " |
|
|
|
|
read dockerPassword |
|
|
|
|
docker login docker.01-edu.org -u $dockerUsername -p $dockerPassword |
|
|
|
|
read -r dockerPassword |
|
|
|
|
docker login docker.01-edu.org -u "$dockerUsername" -p "$dockerPassword" |
|
|
|
|
|
|
|
|
|
# Deploy HTTPS |
|
|
|
|
runHTTPS |
|
|
|
@ -249,16 +278,16 @@ function deployCore() {
|
|
|
|
|
cd /root/core/runner |
|
|
|
|
|
|
|
|
|
# Get the latest release version tag and create latest branch |
|
|
|
|
tag=$(git describe --tags $(git rev-list --tags --max-count=1)) |
|
|
|
|
git checkout $tag |
|
|
|
|
tag=$(git describe --tags "$(git rev-list --tags --max-count=1)") |
|
|
|
|
git checkout "$tag" |
|
|
|
|
|
|
|
|
|
# Get user auth infor for the runner |
|
|
|
|
echo -e "Enter the runner Registry password: " |
|
|
|
|
read registryPassword |
|
|
|
|
read -r registryPassword |
|
|
|
|
echo -e "Enter the runner GitHub username: " |
|
|
|
|
read githubUsername |
|
|
|
|
read -r githubUsername |
|
|
|
|
echo -e "Enter the runner GitHub token: " |
|
|
|
|
read githubToken |
|
|
|
|
read -r githubToken |
|
|
|
|
REGISTRY_PASSWORD=$registryPassword GITHUB_USERNAME=$githubUsername GITHUB_TOKEN=$githubToken ./run.sh |
|
|
|
|
echo -e "Runner service is up! \n" |
|
|
|
|
} |
|
|
|
@ -270,9 +299,9 @@ function deployPlatform() {
|
|
|
|
|
|
|
|
|
|
# Clone platform repository |
|
|
|
|
echo "Enter the server FQDN $(tput setaf 2)[System: $(hostname)]$(tput sgr0):" |
|
|
|
|
read serverFQDN |
|
|
|
|
git clone git@github.com:01-edu/all.git /root/$serverFQDN |
|
|
|
|
cd /root/$serverFQDN |
|
|
|
|
read -r serverFQDN |
|
|
|
|
git clone git@github.com-01-edu-all:01-edu/all.git /root/"$serverFQDN" |
|
|
|
|
cd /root/"$serverFQDN" |
|
|
|
|
# Generate platform environment file automatically |
|
|
|
|
./generate_env.sh --auto |
|
|
|
|
./redeploy.sh --hard |
|
|
|
@ -285,41 +314,41 @@ function clonePlatform() {
|
|
|
|
|
|
|
|
|
|
# Clone platform repository |
|
|
|
|
echo "Enter the target directory for the platform $(tput setaf 2)[System: $(pwd)/$(hostname)]$(tput sgr0):" |
|
|
|
|
read serverDir |
|
|
|
|
git clone git@github.com:01-edu/all.git $serverDir |
|
|
|
|
cd $serverDir |
|
|
|
|
read -r serverDir |
|
|
|
|
git clone git@github.com:01-edu/all.git "$serverDir" |
|
|
|
|
cd "$serverDir" |
|
|
|
|
# Generate platform environment file automatically |
|
|
|
|
./generate_env.sh --gen |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if [[ ! -n ${1:-} ]] || [[ "--check" = $1 ]]; then |
|
|
|
|
if [[ -z ${1:-} ]] || [[ "--check" = "$1" ]]; then |
|
|
|
|
echo -e "$(tput setaf 2)$(tput bold)Commencing configuration check: $(tput sgr0)" |
|
|
|
|
checkList |
|
|
|
|
echo -e "$(tput setaf 2)\nSystem configuration check complete! $(tput sgr0)\n" |
|
|
|
|
exit 0 |
|
|
|
|
elif [[ "--help" = $1 ]]; then |
|
|
|
|
elif [[ "--help" = "$1" ]]; then |
|
|
|
|
echo "$(tput setaf 2) --check : to check the current configuration. $(tput sgr0)" |
|
|
|
|
echo "$(tput setaf 3) --run : to configure the system. $(tput sgr0)" |
|
|
|
|
echo "$(tput setaf 1) --reboot : to configure the system and reboot. $(tput sgr0)" |
|
|
|
|
echo "$(tput setaf 6) --deploy : to deploy and spin-up platform components. $(tput sgr0)" |
|
|
|
|
echo "$(tput setaf 5) --platform : to clone platform. $(tput sgr0)" |
|
|
|
|
echo "$(tput setaf 7) --help : to display this message. $(tput sgr0)" |
|
|
|
|
elif [[ "--reboot" = $1 ]]; then |
|
|
|
|
elif [[ "--reboot" = "$1" ]]; then |
|
|
|
|
echo -e "$(tput setaf 1)$(tput bold)\nSystem will be configured and rebooted. $(tput sgr0)" |
|
|
|
|
sysConfig |
|
|
|
|
echo -e "$(tput setaf 1)\nSystem configuration complete. Rebooting now... $(tput sgr0)" |
|
|
|
|
reboot |
|
|
|
|
elif [[ "--run" = $1 ]]; then |
|
|
|
|
elif [[ "--run" = "$1" ]]; then |
|
|
|
|
echo -e "$(tput setaf 3)$(tput bold)\nSystem will be configured without rebooting. $(tput sgr0)" |
|
|
|
|
sysConfig |
|
|
|
|
echo -e "$(tput setaf 3)\nSystem configuration complete! $(tput sgr0)" |
|
|
|
|
exit 0 |
|
|
|
|
elif [[ "--deploy" = $1 ]]; then |
|
|
|
|
elif [[ "--deploy" = "$1" ]]; then |
|
|
|
|
deployCore |
|
|
|
|
deployPlatform |
|
|
|
|
echo -e "$(tput setaf 6)\nRepositories cloned and platform has been deployed successfully! $(tput sgr0)" |
|
|
|
|
exit 0 |
|
|
|
|
elif [[ "--platform" = $1 ]]; then |
|
|
|
|
elif [[ "--platform" = "$1" ]]; then |
|
|
|
|
clonePlatform |
|
|
|
|
echo -e "$(tput setaf 5)\nPlatform has been cloned successfully! $(tput sgr0)" |
|
|
|
|
exit 0 |
|
|
|
|