mirror of https://github.com/harness/drone.git
feat: [CDE-332]: Update the gitspace setup scripts to support more OSes (#2872)
* feat: [CDE-332]: Update the gitspace setup scripts to support more OSespull/3576/head
parent
7e27bac66e
commit
4c278448c4
|
@ -0,0 +1,57 @@
|
|||
# Detect OS type
|
||||
os() {
|
||||
uname="$(uname)"
|
||||
case $uname in
|
||||
Linux) echo linux ;;
|
||||
Darwin) echo macos ;;
|
||||
FreeBSD) echo freebsd ;;
|
||||
*) echo "$uname" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Detect Linux distro type
|
||||
distro() {
|
||||
local os_name
|
||||
os_name=$(os)
|
||||
|
||||
if [ "$os_name" = "macos" ] || [ "$os_name" = "freebsd" ]; then
|
||||
echo "$os_name"
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -f /etc/os-release ]; then
|
||||
(
|
||||
. /etc/os-release
|
||||
if [ "${ID_LIKE-}" ]; then
|
||||
for id_like in $ID_LIKE; do
|
||||
case "$id_like" in debian | fedora | opensuse | arch)
|
||||
echo "$id_like"
|
||||
return
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
echo "$ID"
|
||||
)
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
# Print a human-readable name for the OS/distro
|
||||
distro_name() {
|
||||
if [ "$(uname)" = "Darwin" ]; then
|
||||
echo "macOS v$(sw_vers -productVersion)"
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -f /etc/os-release ]; then
|
||||
(
|
||||
. /etc/os-release
|
||||
echo "$PRETTY_NAME"
|
||||
)
|
||||
return
|
||||
fi
|
||||
|
||||
uname -sr
|
||||
}
|
|
@ -1,13 +1,51 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Check if Git is installed
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
echo "Git is not installed. Installing Git..."
|
||||
apt-get update
|
||||
apt-get install -y git
|
||||
fi
|
||||
# Source the common OS info script
|
||||
. ../../common/script/os_info.sh
|
||||
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
# Install Git if not already installed
|
||||
install_git() {
|
||||
# Check if Git is installed
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
echo "Git is not installed. Installing Git..."
|
||||
|
||||
case "$(distro)" in
|
||||
debian | ubuntu)
|
||||
apt-get update && apt-get install -y git
|
||||
;;
|
||||
fedora | centos | rhel)
|
||||
dnf install -y git
|
||||
;;
|
||||
opensuse)
|
||||
zypper install -y git
|
||||
;;
|
||||
alpine)
|
||||
apk add git
|
||||
;;
|
||||
arch | manjaro)
|
||||
pacman -Sy --noconfirm git
|
||||
;;
|
||||
freebsd)
|
||||
pkg install -y git
|
||||
;;
|
||||
macos)
|
||||
brew install git
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported OS for automatic Git installation."
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Verify installation
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
echo "Git is not installed. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Git is installed."
|
||||
fi
|
||||
}
|
||||
|
||||
# Run the installation function
|
||||
install_git
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Source the common OS info script
|
||||
. ../../common/script/os_info.sh
|
||||
|
||||
username={{ .Username }}
|
||||
accessKey="{{ .AccessKey }}"
|
||||
homeDir={{ .HomeDir }}
|
||||
|
@ -10,7 +13,19 @@ if id "$username" >/dev/null 2>&1; then
|
|||
echo "User $username already exists."
|
||||
else
|
||||
# Create a new user
|
||||
adduser --disabled-password --home "$homeDir" --gecos "" "$username"
|
||||
case "$(distro)" in
|
||||
debian | ubuntu)
|
||||
adduser --disabled-password --home "$homeDir" --gecos "" "$username"
|
||||
;;
|
||||
fedora | centos | rhel)
|
||||
useradd -m -d "$homeDir" "$username"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported distribution for user creation. Exiting..."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to create user $username."
|
||||
exit 1
|
||||
|
|
|
@ -1,10 +1,31 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Source the common OS info script
|
||||
. ../../common/script/os_info.sh
|
||||
|
||||
# Install SSH if it's not already installed
|
||||
if ! command -v sshd >/dev/null 2>&1; then
|
||||
echo "OpenSSH server is not installed. Installing..."
|
||||
apt-get update
|
||||
apt-get install -y openssh-server
|
||||
|
||||
case "$(distro)" in
|
||||
debian | ubuntu)
|
||||
apt-get update
|
||||
apt-get install -y openssh-server
|
||||
;;
|
||||
fedora | centos | rhel)
|
||||
dnf install -y openssh-server
|
||||
;;
|
||||
opensuse)
|
||||
zypper install -y openssh
|
||||
;;
|
||||
alpine)
|
||||
apk add openssh
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported distribution for SSH installation. Exiting..."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "OpenSSH server is already installed."
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue