Compare commits
31 commits
660140c084
...
76070daa43
Author | SHA1 | Date | |
---|---|---|---|
76070daa43 | |||
e6f9e2d0dd | |||
9450e7cb8a | |||
a9c8aa6b54 | |||
640d651a78 | |||
c5852824a3 | |||
d73dd66251 | |||
3c16e68d91 | |||
d2f060b6a1 | |||
68c4444367 | |||
5fdf986cde | |||
2a19db986c | |||
17d22283f8 | |||
a8be6fdf64 | |||
d786c87a78 | |||
5e8dd6fec2 | |||
58262405bf | |||
5217951380 | |||
ff58a3b397 | |||
953fb81032 | |||
571497c5cf | |||
1100cf4234 | |||
99af49e1a8 | |||
891d3a4067 | |||
be0f461304 | |||
6a93b10cf8 | |||
1a6241033f | |||
013d3bb8f3 | |||
1813a03803 | |||
9421afcedb | |||
04d9661def |
2 changed files with 209 additions and 182 deletions
315
cd.sh
315
cd.sh
|
@ -1,11 +1,11 @@
|
|||
#! /usr/bin/env sh
|
||||
|
||||
# defaults
|
||||
[ "${CD_DNS}" ] || CD_DNS="\
|
||||
[ -n "${CD_DNS}" ] || CD_DNS="\
|
||||
9.9.9.9 \
|
||||
"
|
||||
[ "${CD_GIT_CHILD}" ] || CD_GIT_CHILD="cd"
|
||||
[ "${CD_GIT_PARENT}" ] || CD_GIT_PARENT="rwx"
|
||||
[ -n "${CD_GIT_CHILD}" ] || CD_GIT_CHILD="cd"
|
||||
[ -n "${CD_GIT_PARENT}" ] || CD_GIT_PARENT="rwx"
|
||||
|
||||
# main
|
||||
cd_main () {
|
||||
|
@ -40,6 +40,9 @@ cd_main () {
|
|||
|
||||
cd_set_environment_variables () {
|
||||
cd_step "Set environment variables"
|
||||
# set path
|
||||
CD_PATH="$(realpath "${0}")"
|
||||
cd_echo "CD_PATH"
|
||||
# set operating system id
|
||||
CD_OS_ID="$(cd_grep_os ID)"
|
||||
case "${CD_OS_ID}" in
|
||||
|
@ -65,6 +68,7 @@ cd_set_environment_variables () {
|
|||
"${CD_OS_DEBIAN}"|"${CD_OS_UBUNTU}")
|
||||
CD_OS_VERSION="$(cd_grep_os VERSION_CODENAME)"
|
||||
;;
|
||||
*)
|
||||
esac
|
||||
# check operating system version
|
||||
case "${CD_OS_ID}" in
|
||||
|
@ -104,7 +108,9 @@ cd_set_environment_variables () {
|
|||
*) cd_error_os "CD_OS_VERSION" ;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
esac
|
||||
cd_split
|
||||
cd_echo "CD_OS_ID" "CD_OS_VERSION"
|
||||
# universal
|
||||
CD_DNS_FILE="/etc/resolv.conf"
|
||||
|
@ -133,6 +139,7 @@ cd_set_environment_variables () {
|
|||
CD_CA_ROOT="/usr/local/share/ca-certificates"
|
||||
CD_CMD_CA="update-ca-certificates"
|
||||
;;
|
||||
*)
|
||||
esac
|
||||
cd_split
|
||||
cd_echo "CD_CA_ROOT" "CD_CMD_CA"
|
||||
|
@ -150,6 +157,7 @@ cd_set_environment_variables () {
|
|||
"${CD_OS_ARCH}")
|
||||
CD_PM="${CD_PM_PACMAN}"
|
||||
;;
|
||||
*)
|
||||
esac
|
||||
cd_split
|
||||
cd_echo "CD_PM"
|
||||
|
@ -223,6 +231,7 @@ Dir::Etc::SourceParts \"\";
|
|||
Acquire::https::Verify-Peer False;
|
||||
"
|
||||
;;
|
||||
*)
|
||||
esac
|
||||
cd_split
|
||||
cd_echo "CD_PM_CLEAN" \
|
||||
|
@ -252,34 +261,36 @@ Acquire::https::Verify-Peer False;
|
|||
"${CD_OS_UBUNTU}")
|
||||
CD_URL_DEFAULT="http://archive.ubuntu.com/ubuntu"
|
||||
;;
|
||||
*)
|
||||
esac
|
||||
CD_URL_CHOSEN="${CD_URL_DEFAULT}"
|
||||
case "${CD_OS_ID}" in
|
||||
"${CD_OS_ALMA}")
|
||||
[ "${CD_URL_ALMA}" ] && CD_URL_CHOSEN="${CD_URL_ALMA}"
|
||||
[ -n "${CD_URL_ALMA}" ] && CD_URL_CHOSEN="${CD_URL_ALMA}"
|
||||
;;
|
||||
"${CD_OS_ALPINE}")
|
||||
[ "${CD_URL_ALPINE}" ] && CD_URL_CHOSEN="${CD_URL_ALPINE}"
|
||||
[ -n "${CD_URL_ALPINE}" ] && CD_URL_CHOSEN="${CD_URL_ALPINE}"
|
||||
;;
|
||||
"${CD_OS_ARCH}")
|
||||
[ "${CD_URL_ARCH}" ] && CD_URL_CHOSEN="${CD_URL_ARCH}"
|
||||
[ -n "${CD_URL_ARCH}" ] && CD_URL_CHOSEN="${CD_URL_ARCH}"
|
||||
;;
|
||||
"${CD_OS_DEBIAN}")
|
||||
[ "${CD_URL_DEBIAN}" ] && CD_URL_CHOSEN="${CD_URL_DEBIAN}" \
|
||||
[ -n "${CD_URL_DEBIAN}" ] && CD_URL_CHOSEN="${CD_URL_DEBIAN}" \
|
||||
|| CD_URL_CHOSEN="https://deb.debian.org/debian"
|
||||
;;
|
||||
"${CD_OS_FEDORA}")
|
||||
[ "${CD_URL_FEDORA}" ] && CD_URL_CHOSEN="${CD_URL_FEDORA}" \
|
||||
[ -n "${CD_URL_FEDORA}" ] && CD_URL_CHOSEN="${CD_URL_FEDORA}" \
|
||||
|| CD_URL_CHOSEN="https://rpmfind.net/linux/fedora/linux/releases"
|
||||
;;
|
||||
"${CD_OS_ROCKY}")
|
||||
[ "${CD_URL_ROCKY}" ] && CD_URL_CHOSEN="${CD_URL_ROCKY}" \
|
||||
[ -n "${CD_URL_ROCKY}" ] && CD_URL_CHOSEN="${CD_URL_ROCKY}" \
|
||||
|| CD_URL_CHOSEN="https://dl.rockylinux.org/\$contentdir"
|
||||
;;
|
||||
"${CD_OS_UBUNTU}")
|
||||
[ "${CD_URL_UBUNTU}" ] && CD_URL_CHOSEN="${CD_URL_UBUNTU}" \
|
||||
[ -n "${CD_URL_UBUNTU}" ] && CD_URL_CHOSEN="${CD_URL_UBUNTU}" \
|
||||
|| CD_URL_CHOSEN="https://ubuntu.mirrors.ovh.net/ubuntu"
|
||||
;;
|
||||
*)
|
||||
esac
|
||||
cd_split
|
||||
cd_echo "CD_URL_DEFAULT" "CD_URL_CHOSEN"
|
||||
|
@ -301,6 +312,7 @@ Acquire::https::Verify-Peer False;
|
|||
case "${CD_OS_VERSION}" in
|
||||
"bookworm") CD_PYTHON_COMMAND="python3.11" ;;
|
||||
"bullseye") CD_PYTHON_COMMAND="python3.9" ;;
|
||||
*)
|
||||
esac
|
||||
CD_PYTHON_PACKAGE="python3"
|
||||
;;
|
||||
|
@ -312,9 +324,11 @@ Acquire::https::Verify-Peer False;
|
|||
case "${CD_OS_VERSION}" in
|
||||
"noble") CD_PYTHON_COMMAND="python3.12" ;;
|
||||
"jammy") CD_PYTHON_COMMAND="python3.10" ;;
|
||||
*)
|
||||
esac
|
||||
CD_PYTHON_PACKAGE="python3"
|
||||
;;
|
||||
*)
|
||||
esac
|
||||
# set python packages
|
||||
case "${CD_OS_ID}" in
|
||||
|
@ -327,19 +341,20 @@ Acquire::https::Verify-Peer False;
|
|||
"${CD_OS_DEBIAN}"|"${CD_OS_UBUNTU}")
|
||||
CD_PYTHON_PACKAGES="/usr/lib/${CD_PYTHON_ALIAS}/dist-packages"
|
||||
;;
|
||||
*)
|
||||
esac
|
||||
cd_split
|
||||
cd_echo "CD_PYTHON_COMMAND" "CD_PYTHON_PACKAGE" "CD_PYTHON_PACKAGES"
|
||||
# variables
|
||||
[ "${CD_CA_1}" ] && CD_CA=true
|
||||
[ -n "${CD_CA_1}" ] && CD_CA=true
|
||||
# continuous integration platform
|
||||
if [ "${GITHUB_ACTIONS}" ] ; then
|
||||
if [ -n "${GITHUB_ACTIONS}" ] ; then
|
||||
# github → gitea → forgejo
|
||||
CD_SERVER_URL="${GITHUB_SERVER_URL}"
|
||||
CD_PROJECTS_GROUP="$(dirname "${GITHUB_REPOSITORY}")"
|
||||
CD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")"
|
||||
CD_PROJECT_BRANCH="${GITHUB_REF_NAME}"
|
||||
elif [ "${GITLAB_CI}" ] ; then
|
||||
elif [ -n "${GITLAB_CI}" ] ; then
|
||||
# gitlab
|
||||
CD_SERVER_URL="${CI_SERVER_URL}"
|
||||
CD_PROJECTS_GROUP="$(dirname "${CI_PROJECT_PATH}")"
|
||||
|
@ -349,13 +364,12 @@ Acquire::https::Verify-Peer False;
|
|||
# unsupported
|
||||
cd_error_ci "ø"
|
||||
fi
|
||||
[ "${CD_SERVER_URL}" ] || cd_error_ci "CD_SERVER_URL"
|
||||
[ "${CD_PROJECTS_GROUP}" ] || cd_error_ci "CD_PROJECTS_GROUP"
|
||||
[ "${CD_PROJECT_NAME}" ] || cd_error_ci "CD_PROJECT_NAME"
|
||||
[ "${CD_PROJECT_BRANCH}" ] || cd_error_ci "CD_PROJECT_BRANCH"
|
||||
[ -n "${CD_SERVER_URL}" ] || cd_error_ci "CD_SERVER_URL"
|
||||
[ -n "${CD_PROJECTS_GROUP}" ] || cd_error_ci "CD_PROJECTS_GROUP"
|
||||
[ -n "${CD_PROJECT_NAME}" ] || cd_error_ci "CD_PROJECT_NAME"
|
||||
[ -n "${CD_PROJECT_BRANCH}" ] || cd_error_ci "CD_PROJECT_BRANCH"
|
||||
#
|
||||
CD_PROJECTS_URL="${CD_SERVER_URL}/${CD_PROJECTS_GROUP}"
|
||||
CD_PROJECT_URL="${CD_PROJECTS_URL}/${CD_PROJECT_NAME}"
|
||||
#
|
||||
cd_split
|
||||
cd_echo "CD_CA"
|
||||
|
@ -363,40 +377,42 @@ Acquire::https::Verify-Peer False;
|
|||
cd_echo "CD_SERVER_URL" \
|
||||
"CD_PROJECTS_GROUP" "CD_PROJECT_NAME" "CD_PROJECT_BRANCH"
|
||||
cd_split
|
||||
cd_echo "CD_PROJECTS_URL" "CD_PROJECT_URL"
|
||||
cd_echo "CD_PROJECTS_URL"
|
||||
# TODO move to Python
|
||||
case "${CD_PM}" in
|
||||
"${CD_PM_APK}"|"${CD_PM_APT}") CD_PKG_SSH="openssh-client" ;;
|
||||
"${CD_PM_DNF}") CD_PKG_SSH="openssh-clients" ;;
|
||||
"${CD_PM_PACMAN}") CD_PKG_SSH="openssh" ;;
|
||||
*)
|
||||
esac
|
||||
}
|
||||
|
||||
cd_set_packages_repositories () {
|
||||
local expression
|
||||
local file
|
||||
cd_step "Set packages repositories"
|
||||
case "${CD_OS_ID}" in
|
||||
"${CD_OS_ALMA}")
|
||||
case "${CD_OS_VERSION}" in
|
||||
"8") file="/etc/yum.repos.d/almalinux.repo" ;;
|
||||
"9") file="/etc/yum.repos.d/almalinux-baseos.repo" ;;
|
||||
"8") \
|
||||
cd_set_packages_repositories__file="/etc/yum.repos.d/almalinux.repo" ;;
|
||||
"9") \
|
||||
cd_set_packages_repositories__file="/etc/yum.repos.d/almalinux-baseos.repo" ;;
|
||||
*)
|
||||
esac
|
||||
cd_sed "${file}" \
|
||||
cd_sed "${cd_set_packages_repositories__file}" \
|
||||
"|^mirrorlist|# mirrorlist|" \
|
||||
"|${CD_URL_DEFAULT}|${CD_URL_CHOSEN}|" \
|
||||
"|^# baseurl|baseurl|"
|
||||
;;
|
||||
"${CD_OS_ALPINE}")
|
||||
file="/etc/apk/repositories"
|
||||
cd_write "${file}" "\
|
||||
cd_set_packages_repositories__file="/etc/apk/repositories"
|
||||
cd_write "${cd_set_packages_repositories__file}" "\
|
||||
${CD_URL_CHOSEN}/v${CD_OS_VERSION}/main
|
||||
${CD_URL_CHOSEN}/v${CD_OS_VERSION}/community
|
||||
"
|
||||
;;
|
||||
"${CD_OS_DEBIAN}")
|
||||
file="/etc/apt/sources.list"
|
||||
cd_write "${file}" "\
|
||||
cd_set_packages_repositories__file="/etc/apt/sources.list"
|
||||
cd_write "${cd_set_packages_repositories__file}" "\
|
||||
deb ${CD_URL_CHOSEN} ${CD_OS_VERSION} main
|
||||
deb ${CD_URL_CHOSEN} ${CD_OS_VERSION}-backports main
|
||||
deb ${CD_URL_CHOSEN} ${CD_OS_VERSION}-updates main
|
||||
|
@ -405,23 +421,27 @@ deb ${CD_URL_CHOSEN}-security ${CD_OS_VERSION}-security main
|
|||
;;
|
||||
"${CD_OS_ROCKY}")
|
||||
case "${CD_OS_VERSION}" in
|
||||
"8") file="/etc/yum.repos.d/Rocky-BaseOS.repo" ;;
|
||||
"9") file="/etc/yum.repos.d/rocky.repo" ;;
|
||||
"8") \
|
||||
cd_set_packages_repositories__file="/etc/yum.repos.d/Rocky-BaseOS.repo" ;;
|
||||
"9") \
|
||||
cd_set_packages_repositories__file="/etc/yum.repos.d/rocky.repo" ;;
|
||||
*)
|
||||
esac
|
||||
cd_sed "${file}" \
|
||||
cd_sed "${cd_set_packages_repositories__file}" \
|
||||
"|^mirrorlist|# mirrorlist|" \
|
||||
"|${CD_URL_DEFAULT}|${CD_URL_CHOSEN}|" \
|
||||
"|^#baseurl|baseurl|"
|
||||
;;
|
||||
"${CD_OS_UBUNTU}")
|
||||
file="/etc/apt/sources.list"
|
||||
cd_write "${file}" "\
|
||||
cd_set_packages_repositories__file="/etc/apt/sources.list"
|
||||
cd_write "${cd_set_packages_repositories__file}" "\
|
||||
deb ${CD_URL_CHOSEN} ${CD_OS_VERSION} main
|
||||
deb ${CD_URL_CHOSEN} ${CD_OS_VERSION}-backports main
|
||||
deb ${CD_URL_CHOSEN} ${CD_OS_VERSION}-updates main
|
||||
deb ${CD_URL_CHOSEN} ${CD_OS_VERSION}-security main
|
||||
"
|
||||
;;
|
||||
*)
|
||||
esac
|
||||
}
|
||||
|
||||
|
@ -432,6 +452,7 @@ cd_set_packages_configuration () {
|
|||
"${CD_OS_DEBIAN}"|"${CD_OS_UBUNTU}")
|
||||
export DEBIAN_FRONTEND="noninteractive"
|
||||
;;
|
||||
*)
|
||||
esac
|
||||
}
|
||||
|
||||
|
@ -439,11 +460,12 @@ cd_set_packages_configuration () {
|
|||
|
||||
cd_list_working_directory () {
|
||||
cd_step "List working directory"
|
||||
cd_ls "$(realpath .)"
|
||||
cd_list_working_directory__path="$(realpath .)"
|
||||
cd_ls "${cd_list_working_directory__path}"
|
||||
}
|
||||
|
||||
cd_set_https_verification_off () {
|
||||
if [ "${CD_CA}" -o "${CD_PM}" = "${CD_PM_APT}" ] ; then
|
||||
if [ -n "${CD_CA}" ] || [ "${CD_PM}" = "${CD_PM_APT}" ] ; then
|
||||
cd_step "Set HTTPS verification off"
|
||||
cd_mkdir "$(dirname "${CD_PM_HTTPS_PATH}")"
|
||||
cd_write "${CD_PM_HTTPS_PATH}" "${CD_PM_HTTPS_TEXT}"
|
||||
|
@ -451,14 +473,13 @@ cd_set_https_verification_off () {
|
|||
}
|
||||
|
||||
cd_set_dns_resolving () {
|
||||
local server
|
||||
local text=""
|
||||
cd_step "Set DNS resolving"
|
||||
for server in ${CD_DNS} ; do
|
||||
text="${text}nameserver ${server}
|
||||
for cd_set_dns_resolving__server in ${CD_DNS} ; do
|
||||
cd_set_dns_resolving__text="${cd_set_dns_resolving__text}\
|
||||
nameserver ${cd_set_dns_resolving__server}
|
||||
"
|
||||
done
|
||||
cd_write "${CD_DNS_FILE}" "${text}"
|
||||
cd_write "${CD_DNS_FILE}" "${cd_set_dns_resolving__text}"
|
||||
}
|
||||
|
||||
cd_update_packages_catalog () {
|
||||
|
@ -477,20 +498,22 @@ cd_install_ca_certificates () {
|
|||
}
|
||||
|
||||
cd_write_ca_certificates () {
|
||||
local index
|
||||
local path
|
||||
local text
|
||||
cd_step "Write CA certificates"
|
||||
cd_mkdir "${CD_CA_ROOT}"
|
||||
index=1
|
||||
eval "text=\"\${CD_CA_${index}}\""
|
||||
while [ "${text}" ] ; do
|
||||
path="${CD_CA_ROOT}/${index}.crt"
|
||||
cd_write_ca_certificates__index=1
|
||||
eval "cd_write_ca_certificates__text=\
|
||||
\"\${CD_CA_${cd_write_ca_certificates__index}}\""
|
||||
while [ -n "${cd_write_ca_certificates__text}" ] ; do
|
||||
cd_write_ca_certificates__path="\
|
||||
${CD_CA_ROOT}/${cd_write_ca_certificates__index}.crt"
|
||||
cd_split
|
||||
cd_write "${path}" "${text}"
|
||||
cd_openssl "${path}"
|
||||
index=$((index+1))
|
||||
eval "text=\"\${CD_CA_${index}}\""
|
||||
cd_write \
|
||||
"${cd_write_ca_certificates__path}" \
|
||||
"${cd_write_ca_certificates__text}"
|
||||
cd_openssl "${cd_write_ca_certificates__path}"
|
||||
cd_write_ca_certificates__index=$((cd_write_ca_certificates__index+1))
|
||||
eval "cd_write_ca_certificates__text=\
|
||||
\"\${CD_CA_${cd_write_ca_certificates__index}}\""
|
||||
done
|
||||
}
|
||||
|
||||
|
@ -539,169 +562,174 @@ cd_clean_packages_cache () {
|
|||
}
|
||||
|
||||
cd_install_python_modules () {
|
||||
local path
|
||||
local repository
|
||||
local root
|
||||
local url
|
||||
cd_step "Install Python modules"
|
||||
root="$(mktemp --directory)" || exit
|
||||
echo "→ ${root}"
|
||||
for repository in "${CD_GIT_CHILD}" "${CD_GIT_PARENT}" ; do
|
||||
cd_install_python_modules__root="$(mktemp --directory)" || exit
|
||||
echo "→ ${cd_install_python_modules__root}"
|
||||
for cd_install_python_modules__repository \
|
||||
in "${CD_GIT_CHILD}" "${CD_GIT_PARENT}" ; do
|
||||
cd_split
|
||||
url="${CD_PROJECTS_URL}/${repository}"
|
||||
echo -n "\
|
||||
${url}
|
||||
↓
|
||||
"
|
||||
cd_install_python_modules__url="\
|
||||
${CD_PROJECTS_URL}/${cd_install_python_modules__repository}"
|
||||
echo "\
|
||||
${cd_install_python_modules__url}
|
||||
↓"
|
||||
git clone \
|
||||
"${url}" "${root}/${repository}" \
|
||||
"${cd_install_python_modules__url}" \
|
||||
"${cd_install_python_modules__root}\
|
||||
/${cd_install_python_modules__repository}" \
|
||||
|| exit
|
||||
path="${root}/${repository}/${repository}"
|
||||
echo -n "\
|
||||
${path}
|
||||
cd_install_python_modules__path="\
|
||||
${cd_install_python_modules__root}\
|
||||
/${cd_install_python_modules__repository}\
|
||||
/${cd_install_python_modules__repository}"
|
||||
echo "\
|
||||
${cd_install_python_modules__path}
|
||||
↓
|
||||
${CD_PYTHON_PACKAGES}
|
||||
"
|
||||
${CD_PYTHON_PACKAGES}"
|
||||
cp --recursive \
|
||||
"${path}" "${CD_PYTHON_PACKAGES}" \
|
||||
"${cd_install_python_modules__path}" "${CD_PYTHON_PACKAGES}" \
|
||||
|| exit
|
||||
done
|
||||
cd_split
|
||||
cd_ls "${CD_PYTHON_PACKAGES}"
|
||||
cd_split
|
||||
cd_rm "${root}"
|
||||
cd_rm "${cd_install_python_modules__root}"
|
||||
}
|
||||
|
||||
cd_write_python_module () {
|
||||
cd_step "Write Python module"
|
||||
cd_write "${CD_PYTHON_PACKAGES}/env.py" "\
|
||||
$(cd_echo CD_OPEN CD_DOWN)
|
||||
$(cd_echo CD_VERT CD_SPLT)
|
||||
$(cd_echo CD___UP CD_SHUT)
|
||||
|
||||
$(cd_echo CD_OS_ID CD_OS_VERSION)
|
||||
|
||||
for cd_write_python_module__variable \
|
||||
in OPEN DOWN VERT SPLT __UP SHUT OS_ID OS_VERSION ; do
|
||||
cd_write_python_module__value="\
|
||||
$(cd_echo "CD_${cd_write_python_module__variable}")"
|
||||
cd_write_python_module__text="${cd_write_python_module__text}\
|
||||
${cd_write_python_module__value}
|
||||
"
|
||||
done
|
||||
cd_write "${CD_PYTHON_PACKAGES}/env.py" "${cd_write_python_module__text}\
|
||||
CD_STEP = $((CD_STEP+1))
|
||||
"
|
||||
}
|
||||
|
||||
cd_switch_to_python () {
|
||||
local path
|
||||
cd_step "Switch to Python"
|
||||
#
|
||||
path="$(realpath "${0}")"
|
||||
echo -n "\
|
||||
${path}
|
||||
echo "\
|
||||
${CD_PATH}
|
||||
↓
|
||||
${CD_PYTHON_PACKAGES}/${CD_GIT_CHILD}
|
||||
"
|
||||
${CD_PYTHON_PACKAGES}/${CD_GIT_CHILD}"
|
||||
"${CD_PYTHON_ALIAS}" -m "${CD_GIT_CHILD}" "${@}"
|
||||
}
|
||||
|
||||
# functions
|
||||
|
||||
cd_cat () {
|
||||
if [ -f "${1}" ] ; then
|
||||
cd_open "${1}"
|
||||
cat "${1}" || exit
|
||||
cd_shut "${1}"
|
||||
cd_cat__file="${1}"
|
||||
if [ -n "${cd_cat__file}" ] ; then
|
||||
cd_open "${cd_cat__file}"
|
||||
cat "${cd_cat__file}" || exit
|
||||
cd_shut "${cd_cat__file}"
|
||||
fi
|
||||
}
|
||||
|
||||
cd_echo () {
|
||||
local name
|
||||
if [ "${1}" ] ; then
|
||||
for name in "${@}" ; do
|
||||
eval "echo ${name} = \\\"\${${name}}\\\""
|
||||
if [ -n "${1}" ] ; then
|
||||
for cd_echo__name in "${@}" ; do
|
||||
eval "echo ${cd_echo__name} = \\\"\${${cd_echo__name}}\\\""
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
cd_error_ci () {
|
||||
echo "× CI: ${1}"
|
||||
exit ${CD_ERROR_CI}
|
||||
echo "× CI: ${*}"
|
||||
exit "${CD_ERROR_CI}"
|
||||
}
|
||||
|
||||
cd_error_os () {
|
||||
local variable="${1}"
|
||||
echo -n "× OS: "
|
||||
cd_echo "${variable}"
|
||||
exit ${CD_ERROR_OS}
|
||||
cd_error_os__variable="${1}"
|
||||
printf "× OS: "
|
||||
cd_echo "${cd_error_os__variable}"
|
||||
exit "${CD_ERROR_OS}"
|
||||
}
|
||||
|
||||
cd_grep_os () {
|
||||
local variable="${1}"
|
||||
if [ "${variable}" ] ; then
|
||||
grep "^${variable}=" "/etc/os-release" \
|
||||
| sed "s|^${variable}=||" \
|
||||
cd_grep_os__variable="${1}"
|
||||
if [ -n "${cd_grep_os__variable}" ] ; then
|
||||
grep "^${cd_grep_os__variable}=" "/etc/os-release" \
|
||||
| sed "s|^${cd_grep_os__variable}=||" \
|
||||
| sed "s|^\"\(.*\)\"$|\1|"
|
||||
fi
|
||||
}
|
||||
|
||||
cd_install_package () {
|
||||
if [ "${1}" ] ; then
|
||||
${CD_PM_INSTALL} "${1}" || exit
|
||||
cd_install_package__name="${1}"
|
||||
if [ -n "${cd_install_package__name}" ] ; then
|
||||
${CD_PM_INSTALL} "${cd_install_package__name}" || exit
|
||||
fi
|
||||
}
|
||||
|
||||
cd_ln_python () {
|
||||
local command="${1}"
|
||||
if [ "${command}" ] ; then
|
||||
echo "→ ${CD_PYTHON_ALIAS} → ${command}"
|
||||
ln -f -s "${command}" "/usr/bin/${CD_PYTHON_ALIAS}" || exit
|
||||
cd_ln_python__command="${1}"
|
||||
if [ -n "${cd_ln_python__command}" ] ; then
|
||||
echo "→ ${CD_PYTHON_ALIAS} → ${cd_ln_python__command}"
|
||||
ln -f -s "${cd_ln_python__command}" "/usr/bin/${CD_PYTHON_ALIAS}" \
|
||||
|| exit
|
||||
fi
|
||||
}
|
||||
|
||||
cd_ls () {
|
||||
if [ -d "${1}" ] ; then
|
||||
cd_open "${1}"
|
||||
ls -a -l "${1}" || exit
|
||||
cd_shut "${1}"
|
||||
cd_ls__path="${1}"
|
||||
if [ -n "${cd_ls__path}" ] ; then
|
||||
cd_open "${cd_ls__path}"
|
||||
ls -a -l "${cd_ls__path}" || exit
|
||||
cd_shut "${cd_ls__path}"
|
||||
fi
|
||||
}
|
||||
|
||||
cd_mkdir () {
|
||||
if [ "${1}" ] ; then
|
||||
echo "→ ${1}"
|
||||
mkdir --parents "${1}" || exit
|
||||
cd_mkdir__path="${1}"
|
||||
if [ -n "${cd_mkdir__path}" ] ; then
|
||||
echo "→ ${cd_mkdir__path}"
|
||||
mkdir --parents "${cd_mkdir__path}" || exit
|
||||
fi
|
||||
}
|
||||
|
||||
cd_open () {
|
||||
echo "${CD_OPEN}${@}"
|
||||
echo "${CD_OPEN}${*}"
|
||||
}
|
||||
|
||||
cd_openssl () {
|
||||
local file="${1}"
|
||||
if [ -f "${file}" ] ; then
|
||||
openssl x509 -noout -text -in "${file}" || exit
|
||||
cd_openssl__file="${1}"
|
||||
if [ -f "${cd_openssl__file}" ] ; then
|
||||
openssl x509 \
|
||||
-in "${cd_openssl__file}" \
|
||||
-noout -text \
|
||||
|| exit
|
||||
fi
|
||||
}
|
||||
|
||||
cd_rm () {
|
||||
local path="${1}"
|
||||
if [ -e "${path}" ] ; then
|
||||
echo "← ${path}"
|
||||
rm -r "${path}" || exit
|
||||
cd_rm__path="${1}"
|
||||
if [ -e "${cd_rm__path}" ] ; then
|
||||
echo "← ${cd_rm__path}"
|
||||
rm -r "${cd_rm__path}" || exit
|
||||
fi
|
||||
}
|
||||
|
||||
cd_sed () {
|
||||
local expression
|
||||
local file="${1}"
|
||||
shift
|
||||
if [ -f "${file}" ] ; then
|
||||
cd_cat "${file}"
|
||||
for expression in "${@}" ; do
|
||||
sed --in-place "s${expression}g" "${file}" \
|
||||
&& cd_cat "${file}" \
|
||||
cd_sed__file="${1}"
|
||||
shift
|
||||
if [ -f "${cd_sed__file}" ] ; then
|
||||
cd_cat "${cd_sed__file}"
|
||||
for cd_sed__regex in "${@}" ; do
|
||||
sed --in-place "s${cd_sed__regex}g" "${cd_sed__file}" \
|
||||
&& cd_cat "${cd_sed__file}" \
|
||||
|| exit
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
cd_shut () {
|
||||
echo "${CD_SHUT}${@}"
|
||||
echo "${CD_SHUT}${*}"
|
||||
}
|
||||
|
||||
cd_split () {
|
||||
|
@ -710,21 +738,20 @@ cd_split () {
|
|||
|
||||
cd_step () {
|
||||
CD_STEP=$((CD_STEP+1))
|
||||
echo -n "\
|
||||
echo "\
|
||||
${CD_DOWN}
|
||||
${CD_VERT} ${CD_STEP} ${@}
|
||||
${CD___UP}
|
||||
"
|
||||
${CD_VERT} ${CD_STEP} ${*}
|
||||
${CD___UP}"
|
||||
}
|
||||
|
||||
cd_write () {
|
||||
local file="${1}"
|
||||
local text="${2}"
|
||||
if [ "${file}" ] ; then
|
||||
[ -f "${file}" ] && cd_cat "${file}"
|
||||
echo "→ ${1}"
|
||||
echo -n "${text}" > "${file}" || exit
|
||||
cd_cat "${file}"
|
||||
cd_write__file="${1}"
|
||||
cd_write__text="${2}"
|
||||
if [ -n "${cd_write__file}" ] ; then
|
||||
[ -f "${cd_write__file}" ] && cd_cat "${cd_write__file}"
|
||||
echo "→ ${cd_write__file}"
|
||||
printf "%s" "${cd_write__text}" > "${cd_write__file}" || exit
|
||||
cd_cat "${cd_write__file}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import env
|
|||
from rwx import fs
|
||||
from rwx import ps
|
||||
|
||||
COMMANDS_PREFIX = 'cd-'
|
||||
COMMANDS_PREFIX = "cd-"
|
||||
|
||||
projects = Projects(os.environ)
|
||||
project = Project(projects)
|
||||
|
@ -17,8 +17,8 @@ def cd_browse_workspace():
|
|||
|
||||
|
||||
def cd_build_project():
|
||||
for extension in ['py', 'sh']:
|
||||
path = os.path.join(project.root, f'build.{extension}')
|
||||
for extension in ["py", "sh"]:
|
||||
path = os.path.join(project.root, f"build.{extension}")
|
||||
if os.path.exists(path):
|
||||
ps.run(path)
|
||||
break
|
||||
|
@ -27,14 +27,14 @@ def cd_build_project():
|
|||
|
||||
|
||||
def cd_clone_branch():
|
||||
print(f'''\
|
||||
print(f"""\
|
||||
{project.url}
|
||||
↓
|
||||
''', end=str(), flush=True)
|
||||
ps.run('git',
|
||||
'clone',
|
||||
'--branch', project.branch,
|
||||
'--',
|
||||
""", end="", flush=True)
|
||||
ps.run("git",
|
||||
"clone",
|
||||
"--branch", project.branch,
|
||||
"--",
|
||||
project.url,
|
||||
project.root,
|
||||
)
|
||||
|
@ -42,25 +42,25 @@ def cd_clone_branch():
|
|||
|
||||
def cd_list_environment():
|
||||
for variable, value in sorted(projects.environment.items()):
|
||||
print(variable, '=', value)
|
||||
print(variable, "=", value)
|
||||
|
||||
|
||||
def cd_synchronize():
|
||||
host = 'rwx.work'
|
||||
source = 'out'
|
||||
user = 'cd'
|
||||
host = "rwx.work"
|
||||
source = "out"
|
||||
user = "cd"
|
||||
#
|
||||
root = os.sep.join([str(),
|
||||
root = os.sep.join(["",
|
||||
user, project.branch, projects.group, project.name])
|
||||
#
|
||||
target = f'{user}@{host}:{root}'
|
||||
ps.run('rsync',
|
||||
'--archive',
|
||||
'--delete-before',
|
||||
'--verbose',
|
||||
f'{source}/',
|
||||
f'{target}/',
|
||||
'--dry-run',
|
||||
target = f"{user}@{host}:{root}"
|
||||
ps.run("rsync",
|
||||
"--archive",
|
||||
"--delete-before",
|
||||
"--verbose",
|
||||
f"{source}/",
|
||||
f"{target}/",
|
||||
"--dry-run",
|
||||
)
|
||||
|
||||
|
||||
|
@ -84,38 +84,38 @@ def cat(file: str):
|
|||
|
||||
|
||||
def install_commands(path):
|
||||
step('Install commands')
|
||||
user = '/usr/local/bin'
|
||||
step("Install commands")
|
||||
user = "/usr/local/bin"
|
||||
for command in [
|
||||
'browse-workspace',
|
||||
'build-project',
|
||||
'clone-branch',
|
||||
'list-environment',
|
||||
'synchronize',
|
||||
"browse-workspace",
|
||||
"build-project",
|
||||
"clone-branch",
|
||||
"list-environment",
|
||||
"synchronize",
|
||||
]:
|
||||
print(command)
|
||||
os.symlink(path, os.path.join(user, f'{COMMANDS_PREFIX}{command}'))
|
||||
os.symlink(path, os.path.join(user, f"{COMMANDS_PREFIX}{command}"))
|
||||
|
||||
|
||||
def set_ssh(*arguments):
|
||||
step('Set SSH')
|
||||
step("Set SSH")
|
||||
#
|
||||
ssh_key, ssh_hosts = arguments
|
||||
#
|
||||
ssh_type = 'ed25519'
|
||||
ssh_type = "ed25519"
|
||||
#
|
||||
home = os.path.expanduser('~')
|
||||
home = os.path.expanduser("~")
|
||||
#
|
||||
ssh = os.path.join(home, '.ssh')
|
||||
ssh = os.path.join(home, ".ssh")
|
||||
os.makedirs(ssh, exist_ok=True)
|
||||
os.chmod(ssh, 0o700)
|
||||
#
|
||||
key = os.path.join(ssh, f'id_{ssh_type}')
|
||||
key = os.path.join(ssh, f"id_{ssh_type}")
|
||||
if ssh_key:
|
||||
fs.write(key, ssh_key)
|
||||
os.chmod(key, 0o400)
|
||||
#
|
||||
known = os.path.join(ssh, 'known_hosts')
|
||||
known = os.path.join(ssh, "known_hosts")
|
||||
if ssh_hosts:
|
||||
fs.write(known, ssh_hosts)
|
||||
os.chmod(known, 0o400)
|
||||
|
@ -125,12 +125,12 @@ def set_ssh(*arguments):
|
|||
|
||||
|
||||
def open(*arguments):
|
||||
print(env.CD_OPEN, end=str())
|
||||
print(env.CD_OPEN, end="")
|
||||
print(*arguments, flush=True)
|
||||
|
||||
|
||||
def shut(*arguments):
|
||||
print(env.CD_SHUT, end=str())
|
||||
print(env.CD_SHUT, end="")
|
||||
print(*arguments, flush=True)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue