spcd/cd-bootstrap.sh
2024-03-25 19:59:12 +01:00

40 lines
790 B
Bash
Executable file

FILE="$(realpath "${BASH_SOURCE[0]}")"
NAME="$(basename "${GITHUB_REPOSITORY}")"
ROOT="$(dirname "${FILE}")"
KEY_ALGORITHM='ed25519'
KEY_DIRECTORY='.ssh'
KEY_PATH="${KEY_DIRECTORY}/id_${KEY_ALGORITHM}"
KEY_PUBLIC='AAAAC3NzaC1lZDI1NTE5AAAAIPHCNcgHlQoiNTXfnUZYvHz9OZwYsmBCrSSV7a7Zche5'
PACKAGES=(
'python3'
'rsync'
'tree'
)
SERVER="$(basename ${GITHUB_SERVER_URL})"
TARGET='/usr/local/sbin'
# commands
cd "${ROOT}/${NAME}" \
|| exit
for file in *.sh ; do
cp "${file}" "${TARGET}" \
|| exit
done
# ssh
cd \
|| exit
mkdir "${KEY_DIRECTORY}" \
|| exit
echo "${CD}" > "${KEY_PATH}" \
|| exit
unset CD
chmod '400' "${KEY_PATH}" \
|| exit
echo "${SERVER} ssh-${KEY_ALGORITHM} ${KEY_PUBLIC}" \
> "${KEY_DIRECTORY}/known_hosts" \
|| exit
# packages
apt-get install --yes "${PACKAGES[@]}"