devs/bin/cortana_install.sh

117 lines
3.7 KiB
Bash
Executable file

#!/bin/bash
#
# cortana_install.sh
# Modified: 2024/12/01 15:27:00
# Derechos de Autor (C) [2025] [Mauro Rosero P. <mauro@rosero.one> (mauro.rosero@gmail.com)]
#
# Este programa es software libre: usted puede redistribuirlo y/o modificarlo
# bajo los términos de la Licencia Pública Affero General de GNU tal como
# lo publica la Free Software Foundation, ya sea la versión 3 de la licencia,
# o (a su elección) cualquier versión posterior.
#
# Este programa se distribuye con la esperanza de que sea útil,
# pero SIN NINGUNA GARANTÍA; sin siquiera la garantía implícita de
# COMERCIABILIDAD o IDONEIDAD PARA UN PROPÓSITO PARTICULAR. Consulte la
# Licencia Pública Affero General de GNU para obtener más detalles.
#
# Debería haber recibido una copia de la Licencia Pública Affero General
# junto con este programa. Si no la recibió, consulte <https://www.gnu.org/licenses/>.
# Script para instalar o desinstalar Anthropoc Claude Code con npm
# Uso:
# ./script.sh -> Instalación
# ./script.sh -u -> Desinstalación
DEVSPATH=devs
BIN_HOME=$HOME/$DEVSPATH
BIN_MESG=bin/msg
BIN_LIBS=bin/lib
BIN_CFGS=bin/config
VERSION=1.0.1
# CHECK SHELL LANGUAGE
BIN_LANG=${LANG:0:2}
# LOAD BASE BASH LIBRARY
source $BIN_HOME/$BIN_LIBS/base.lib
#baselib_test
# Load head messages
load_messages $BIN_HOME $BIN_MESG $BIN_LANG "head"
title="${head_000} ${head_002}"
# Verificar que 'dialog' esté instalado
if ! command -v dialog &>/dev/null; then
echo "${npm_001}"
exit 1
fi
# Verificar que 'npm' esté instalado
if ! command -v npm &>/dev/null; then
dialog --backtitle "${title}" --title "${head_error}" --msgbox "${npm_022}" 7 50
exit 1
fi
# Función para preparar pre-requisitos para instalación de Cortana
pre_anthropic() {
# First, save a list of your existing global packages for later migration
npm list -g --depth=0 > ~/npm-global-packages.txt
# Create a directory for your global packages
mkdir -p ~/.npm-global
# Configure npm to use the new directory path
npm config set prefix ~/.npm-global
# Note: Replace ~/.bashrc with ~/.zshrc, ~/.profile, or other appropriate file for your shell
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
# Apply the new PATH setting
source ~/.bashrc
}
# Función para instalar Anthropoc Claude Code
install_anthropic() {
dialog --backtitle "${title}" --title "${npm_018} ${npm_000} ${npm_000_1}" --msgbox "${npm_023}" 7 60
# Ejecutar la instalación
pre_anthropic
npm install -g @anthropic-ai/claude-code
if [[ $? -eq 0 ]]; then
dialog --backtitle "${title}" --title "${npm_014}" --msgbox "${npm_024}" 7 50
else
dialog --backtitle "${title}" --title "${head-error}" --msgbox "${npm_025}" 7 50
fi
}
# Función para desinstalar Anthropoc Claude Code
uninstall_anthropic() {
dialog --backtitle "${title}" --title "${npm_026} ${npm_000} ${npm_000_1}" --msgbox "${npm_027}" 7 60
# Ejecutar la desinstalación
npm uninstall -g @anthropic-ai/claude-code
if [[ $? -eq 0 ]]; then
dialog --backtitle "${title}" --title "${npm_028}" --msgbox "${npm_029}" 7 50
else
dialog --backtitle "${title}" --title "${head_eror}" --msgbox "${npm_030}" 7 50
fi
}
# Evaluar el parámetro posicional
if [[ "$1" == "-u" ]]; then
dialog --backtitle "${title}" --title "${npm_031}" --yesno "${npm_032}" 7 50
if [[ $? -eq 0 ]]; then
uninstall_anthropic
else
dialog --backtitle "${title}" --title "${head_canceled}" --msgbox "${npm_008}" 6 40
exit 1
fi
else
dialog --backtitle "${title}" --title "${npm_031}" --yesno "${npm_033}" 7 50
if [[ $? -eq 0 ]]; then
install_anthropic
else
dialog --backtitle "${title}" --title "${head_canceled}" --msgbox "${npm_008}" 6 40
exit 1
fi
fi