Add settings menu, update OCB, and update all options

This commit is contained in:
2024-02-04 03:26:55 +01:00
parent 3b400c8c34
commit b7a3e09869

View File

@@ -29,9 +29,35 @@ readonly color_end="\e[0m"
readonly bold="\e[1m" readonly bold="\e[1m"
readonly bold_end="\e[0m" readonly bold_end="\e[0m"
update_all() {
local repos=( $(get_local_repos) )
update_oca_repos "${repos[@]}"
update_ocb
}
update_ocb() {
local exit_code
printf "\n%s\n" "Start updating OCB..."
echo "Entering: ${ocb_install_path}" >&2
cd ${ocb_install_path} && git pull
exit_code=$?
if [[ "${exit_code}" -ne 0 ]]; then
printf "${color_danger}%s${color_end},\n" "Error! Something was wrong updating OCB..."
fi
if [[ "${exit_code}" -eq 0 ]]; then
printf "\n${bold}%b${bold_end}\n" "Update complete!"
else
printf "${color_danger}%s${color_end}\n" "Error! Something was wrong during the update process."
exit 1
fi
}
show_installed_repos_path() { show_installed_repos_path() {
local content=( $( find ${oca_addons_install_path} -type d -mindepth 1 -maxdepth 1 ) ) local content=( $( find ${oca_addons_install_path} -mindepth 1 -maxdepth 1 -type d ) )
if [[ -z ${content[@]} ]]; then if [[ -z ${content[@]} ]]; then
printf "\n\n\t\t${bold}%b${bold_end}\n" "No repositories found!" printf "\n\n\t\t${bold}%b${bold_end}\n" "No repositories found!"
else else
@@ -45,14 +71,14 @@ get_local_repos() {
echo "${local_repos[@]}" echo "${local_repos[@]}"
} }
update() { select_oca_repos_to_update() {
local repos=( $(get_local_repos) ) local repos=( $(get_local_repos) )
local selected_repos local selected_repos
select_repos "update_cmd" "${repos[@]}" select_repos "update_oca_repos" "${repos[@]}"
} }
update_cmd() { update_oca_repos() {
local exit_code local exit_code
printf "\n%s\n" "Start updating..." printf "\n%s\n" "Start updating..."
@@ -73,7 +99,7 @@ update_cmd() {
fi fi
} }
clone() { select_repos_to_clone() {
local repos local repos
while true; do while true; do
@@ -90,11 +116,11 @@ clone() {
repos=( $(get_repos_names) ) repos=( $(get_repos_names) )
select_repos "clone_cmd" "${repos[@]}" select_repos "clone_repos" "${repos[@]}"
show_installed_repos_path show_installed_repos_path
} }
clone_cmd() { clone_repos() {
local exit_code local exit_code
printf "\n%s\n" "Start cloning..." printf "\n%s\n" "Start cloning..."
@@ -313,6 +339,33 @@ set_oca_addons_install_path() {
save_in_config_file "oca_addons_install_path" "${path_selected}" save_in_config_file "oca_addons_install_path" "${path_selected}"
} }
set_ocb_install_path() {
local path_selected
while true; do
printf "\n\n%s\n" "Please, insert the OCB install path."
echo "[Enter for default: /opt/odoo/${odoo_version}/OCB/ ]:"
echo -n "==> "
read -e path_selected
if [[ -z "${path_selected:-}" ]]; then
path_selected="/opt/odoo/${odoo_version}/OCB/"
fi
if [[ ! -d "${path_selected}" ]]; then
printf "\n\n${color_danger}%s${color_end}" "Path doesn't exist! Please, insert an existing one."
continue
fi
break
done
# Remove trailing slash if present
path_selected="${path_selected%/}"
save_in_config_file "ocb_install_path" "${path_selected}"
}
set_odoo_version() { set_odoo_version() {
local odoo_version_selected local odoo_version_selected
@@ -350,20 +403,65 @@ get_config_file() {
source "${orm_file}" 2>/dev/null source "${orm_file}" 2>/dev/null
} }
settings_menu() {
while true; do
echo
echo "********************************************************"
echo " SETTINGS "
echo "********************************************************"
printf "${bold}%s ${color_success}%b${color_end}\n" " > Odoo target version:" "${odoo_version}"
printf "${bold}%s ${color_success}%b${color_end}\n" " > OCB install path:" "${ocb_install_path}"
printf "${bold}%s ${color_success}%b${color_end}\n" " > OCA addons install path:" "${oca_addons_install_path}"
echo "********************************************************"
echo
echo "1) Change Odoo target version"
echo "2) Change OCB install path"
echo "3) Change OCA addons install path"
echo "---"
echo "4) Back"
echo
echo -n "==> "
read -sn 1
case "${REPLY}" in
1)
set_odoo_version
continue
;;
2)
set_ocb_install_path
continue
;;
3)
set_oca_addons_install_path
continue
;;
4)
main_menu
break
;;
*)
echo "Choice not valid!"
continue
;;
esac
done
}
main_menu() { main_menu() {
while true; do while true; do
echo echo
echo "********************************************************" echo "********************************************************"
printf "${bold}%s ${color_success}%b${color_end}\n" " > Odoo target version:" "${odoo_version}" printf "\t\t\t${bold}%s${bold_end}\n" "MAIN MENU"
printf "${bold}%s ${color_success}%b${color_end}\n" " > OCA addons install path:" "${oca_addons_install_path}"
echo "********************************************************" echo "********************************************************"
echo echo
echo "1) Clone OCA repositories" echo "1) Clone OCA repositories"
echo "2) Update OCA repositories already cloned" echo "2) Show installed repositories path for Odoo config file"
echo "3) Show installed repositories path for Odoo config file" echo "3) Update OCA repositories already cloned"
echo "4) Update OCB"
echo "5) Update All"
echo "---" echo "---"
echo "4) Change Odoo target version" echo "6) Settings"
echo "5) Change OCA addons install path"
echo "---" echo "---"
echo "q) Exit" echo "q) Exit"
echo echo
@@ -372,26 +470,32 @@ main_menu() {
case "${REPLY}" in case "${REPLY}" in
1) 1)
clone select_repos_to_clone
read -p $'\nPress any key to continue...' read -p $'\nPress any key to continue...'
continue continue
;; ;;
2) 2)
update
read -p $'\nPress any key to continue...'
continue
;;
3)
show_installed_repos_path show_installed_repos_path
read -p $'\nPress any key to continue...' read -p $'\nPress any key to continue...'
continue continue
;; ;;
3)
select_oca_repos_to_update
read -p $'\nPress any key to continue...'
continue
;;
4) 4)
set_odoo_version update_ocb
read -p $'\nPress any key to continue...'
continue continue
;; ;;
5) 5)
set_oca_addons_install_path update_all
read -p $'\nPress any key to continue...'
continue
;;
6)
settings_menu
continue continue
;; ;;
q|Q) q|Q)
@@ -439,6 +543,10 @@ main() {
set_odoo_version set_odoo_version
fi fi
if [[ -z "${ocb_install_path+x:-}" ]]; then
set_ocb_install_path
fi
if [[ -z "${oca_addons_install_path+x:-}" ]]; then if [[ -z "${oca_addons_install_path+x:-}" ]]; then
set_oca_addons_install_path set_oca_addons_install_path
fi fi