mirror of
https://github.com/xxoommd/magic.git
synced 2025-05-22 13:12:45 +00:00
update win profile
This commit is contained in:
parent
734bb0fcb1
commit
7ef7b7392c
@ -22,14 +22,14 @@ function set_proxy() {
|
|||||||
|
|
||||||
function c3tool() {
|
function c3tool() {
|
||||||
# check `cmake`
|
# check `cmake`
|
||||||
if command -v cmake &> /dev/null; then
|
if command -v cmake &>/dev/null; then
|
||||||
echo "[CHECK] cmake 已安装"
|
echo "[CHECK] cmake 已安装"
|
||||||
else
|
else
|
||||||
echo "[CHECK] FAIL: cmake 未安装,请先安装 cmake"
|
echo "[CHECK] FAIL: cmake 未安装,请先安装 cmake"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if command -v mingw32-make &> /dev/null; then
|
if command -v mingw32-make &>/dev/null; then
|
||||||
echo "[CHECK] mingw32-make 已安装"
|
echo "[CHECK] mingw32-make 已安装"
|
||||||
else
|
else
|
||||||
echo "[CHECK] FAIL: mingw32-make 未安装,请先安装 mingw32-make"
|
echo "[CHECK] FAIL: mingw32-make 未安装,请先安装 mingw32-make"
|
||||||
@ -40,10 +40,10 @@ function c3tool() {
|
|||||||
if [[ $PWD =~ "augustus" || $PWD =~ "julius" ]]; then
|
if [[ $PWD =~ "augustus" || $PWD =~ "julius" ]]; then
|
||||||
# 判断 basename 是否为 build
|
# 判断 basename 是否为 build
|
||||||
if [ "$(basename "$PWD")" = "build" ]; then
|
if [ "$(basename "$PWD")" = "build" ]; then
|
||||||
echo "[CHECK] Working directory: $PWD"
|
echo "[CHECK] Working directory: $PWD"
|
||||||
else
|
else
|
||||||
echo "[CHECK] FAIL: 进入 'augustus' 或者 'julius' 的 'build' 目录"
|
echo "[CHECK] FAIL: 进入 'augustus' 或者 'julius' 的 'build' 目录"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "[CHECK] FAIL: 进入 'augustus' 或者 'julius' 的 'build' 目录"
|
echo "[CHECK] FAIL: 进入 'augustus' 或者 'julius' 的 'build' 目录"
|
||||||
@ -56,7 +56,8 @@ function c3tool() {
|
|||||||
if [[ $1 == "" || "$1" == -* ]]; then
|
if [[ $1 == "" || "$1" == -* ]]; then
|
||||||
cmd="build"
|
cmd="build"
|
||||||
else
|
else
|
||||||
cmd=$1; shift;
|
cmd=$1
|
||||||
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
force=false
|
force=false
|
||||||
@ -66,94 +67,215 @@ function c3tool() {
|
|||||||
# Parse args...
|
# Parse args...
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
-r|--update-resources)
|
-r | --update-resources)
|
||||||
update_res=true
|
update_res=true
|
||||||
;;
|
;;
|
||||||
-l|--update-libs)
|
-l | --update-libs)
|
||||||
update_libs=true
|
update_libs=true
|
||||||
;;
|
;;
|
||||||
-f|--force)
|
-f | --force)
|
||||||
force=true
|
force=true
|
||||||
;;
|
;;
|
||||||
-a|--all)
|
-a | --all)
|
||||||
force=true
|
force=true
|
||||||
update_res=true
|
update_res=true
|
||||||
update_libs=true
|
update_libs=true
|
||||||
;;
|
;;
|
||||||
--release)
|
--release)
|
||||||
export CMAKE_BUILD_TYPE=release
|
export CMAKE_BUILD_TYPE=release
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Execute cmd...
|
# Execute cmd...
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
b|build)
|
b | build)
|
||||||
if $force; then
|
if $force; then
|
||||||
printf "[BUILD] 清理make文件:" && rm -rf CMakeCache.txt CMakeFiles Makefile cmake_install.cmake compile_commands.json augustus* .cmake && \
|
printf "[BUILD] 清理make文件:" && rm -rf CMakeCache.txt CMakeFiles Makefile cmake_install.cmake compile_commands.json augustus* .cmake &&
|
||||||
echo "Done"
|
echo "Done"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "evn: - CMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE\n\n"
|
printf "evn: - CMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE\n\n"
|
||||||
|
|
||||||
# cmake
|
# cmake
|
||||||
if [[ ! -f "Makefile" ]]; then
|
if [[ ! -f "Makefile" ]]; then
|
||||||
exec_str="cmake .. -G \"MinGW Makefiles\"" && eval $exec_str
|
exec_str="cmake .. -G \"MinGW Makefiles\"" && eval $exec_str
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "[BUILD] FAIL. Execute string: ${exec_str}"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# mingw32-make
|
|
||||||
echo "开始编译..."
|
|
||||||
if command -v nproc &> /dev/null; then
|
|
||||||
makenum=$(nproc)
|
|
||||||
else
|
|
||||||
makenum=2
|
|
||||||
fi
|
|
||||||
exec_str="mingw32-make -j$makenum" && eval $exec_str
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "[BUILD] FAIL. Execute string: ${exec_str}"
|
echo "[BUILD] FAIL. Execute string: ${exec_str}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if $update_res; then
|
# mingw32-make
|
||||||
printf "[BUILD] 清理res..." && rm -rf assets maps && echo "Done"
|
echo "开始编译..."
|
||||||
fi
|
if command -v nproc &>/dev/null; then
|
||||||
|
makenum=$(nproc)
|
||||||
|
else
|
||||||
|
makenum=2
|
||||||
|
fi
|
||||||
|
exec_str="mingw32-make -j$makenum" && eval $exec_str
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "[BUILD] FAIL. Execute string: ${exec_str}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
if $update_libs; then
|
if $update_res; then
|
||||||
printf "[BUILD] 清理libs..." && rm -f SDL2.dll SDL2_mixer.dll && echo "Done"
|
printf "[BUILD] 清理res..." && rm -rf assets maps && echo "Done"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Updating res:
|
if $update_libs; then
|
||||||
if [[ ! -d assets || ! -d maps ]]; then
|
printf "[BUILD] 清理libs..." && rm -f SDL2.dll SDL2_mixer.dll && echo "Done"
|
||||||
printf "[BUILD] Updating assets ..." && cp -r ../res/assets . && echo "Done"
|
fi
|
||||||
printf "[BUILD] Updating maps ..." && cp -r ../res/maps . && echo "Done"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Updating libs:
|
# Updating res:
|
||||||
if [[ ! -f SDL2.dll || ! -f SDL2_mixer.dll ]]; then
|
if [[ ! -d assets || ! -d maps ]]; then
|
||||||
printf "[BUILD] Updating libs ..." && cp ../ext/SDL2/SDL2-2.32.4/x86_64-w64-mingw32/bin/SDL2.dll . && \
|
printf "[BUILD] Updating assets ..." && cp -r ../res/assets . && echo "Done"
|
||||||
cp ../ext/SDL2/SDL2_mixer-2.8.1/x86_64-w64-mingw32/bin/SDL2_mixer.dll . && \
|
printf "[BUILD] Updating maps ..." && cp -r ../res/maps . && echo "Done"
|
||||||
echo "Done"
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
echo "[BUILD] success"
|
# Updating libs:
|
||||||
|
if [[ ! -f SDL2.dll || ! -f SDL2_mixer.dll ]]; then
|
||||||
|
printf "[BUILD] Updating libs ..." && cp ../ext/SDL2/SDL2-2.32.4/x86_64-w64-mingw32/bin/SDL2.dll . &&
|
||||||
|
cp ../ext/SDL2/SDL2_mixer-2.8.1/x86_64-w64-mingw32/bin/SDL2_mixer.dll . &&
|
||||||
|
echo "Done"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[BUILD] success"
|
||||||
;;
|
;;
|
||||||
c|clean)
|
c | clean)
|
||||||
printf "开始清理..."
|
printf "开始清理..."
|
||||||
rm -rf CMakeCache.txt CMakeFiles Makefile cmake_install.cmake compile_commands.json augustus* && \
|
rm -rf CMakeCache.txt CMakeFiles Makefile cmake_install.cmake compile_commands.json augustus* &&
|
||||||
rm -rf assets maps && \
|
rm -rf assets maps &&
|
||||||
rm -f SDL2* && \
|
rm -f SDL2* &&
|
||||||
echo "Done"
|
echo "Done"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "[Err] Invalid cmd: $cmd"
|
echo "[Err] Invalid cmd: $cmd"
|
||||||
echo
|
echo
|
||||||
echo "Usage:"
|
echo "Usage:"
|
||||||
echo " - c3tool build|b [-r -l -f -a --release]"
|
echo " - c3tool build|b [-r -l -f -a --release]"
|
||||||
echo " - c3tool clean|c"
|
echo " - c3tool clean|c"
|
||||||
return 1
|
return 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function connect() {
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
RED='\033[0;31m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
YELLOW='\033[0;33m'
|
||||||
|
UNDERLINE='\033[4m' # 下划线
|
||||||
|
RESET_COLOR='\033[0m' # No Color
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
STR_BASH="[${GREEN}Bash${RESET_COLOR}]"
|
||||||
|
STR_ZSH="[${GREEN}Zsh${RESET_COLOR}]"
|
||||||
|
|
||||||
|
STR_ERR_PREFIX="[${RED}Err${RESET_COLOR}]"
|
||||||
|
STR_INFO_PREFIX="[${GREEN}INFO${NC}]"
|
||||||
|
|
||||||
|
if [[ -n "$BASH_VERSION" ]]; then
|
||||||
|
printf "$STR_BASH Detected\n\n"
|
||||||
|
declare -A servers
|
||||||
|
elif [[ -n "$ZSH_VERSION" ]]; then
|
||||||
|
printf "$STR_ZSH Detected\n\n"
|
||||||
|
typeset -A servers
|
||||||
|
# setopt KSH_ARRAYS
|
||||||
|
else
|
||||||
|
echo -e "[${RED}Err${RESET_COLOR}] Running another shell. Only ${STR_BASH} or ${STR_ZSH} supported."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
servers=(
|
||||||
|
# ["yact"]="ssh root@172.50.10.83"
|
||||||
|
["yacloud"]="ssh -p 7189 gaohengyi@jumpserver.yacloud.net"
|
||||||
|
["u1"]="ssh root@u1"
|
||||||
|
["dev"]="ssh root@125.64.33.85"
|
||||||
|
["tw"]="ssh root@tw.xmdgg.xyz"
|
||||||
|
["hk"]="ssh root@hk.xmdgg.xyz"
|
||||||
|
["us"]="ssh root@us.xmdgg.xyz"
|
||||||
|
# ["us1"]="ssh root@us.xmdgg.xyz"
|
||||||
|
# ["us2"]="ssh root@us.xmdgg.xyz"
|
||||||
|
# ["us3"]="ssh root@us.xmdgg.xyz"
|
||||||
|
# ["us4"]="ssh root@us.xmdgg.xyz"
|
||||||
|
# ["us5"]="ssh root@us.xmdgg.xyz"
|
||||||
|
# ["us6"]="ssh root@us.xmdgg.xyz"
|
||||||
|
# ["us7"]="ssh root@us.xmdgg.xyz"
|
||||||
|
# ["us8"]="ssh root@us.xmdgg.xyz"
|
||||||
|
# ["us9"]="ssh root@us.xmdgg.xyz"
|
||||||
|
# ["us10"]="ssh root@us.xmdgg.xyz"
|
||||||
|
)
|
||||||
|
|
||||||
|
servers_index=()
|
||||||
|
if [[ -n "$BASH_VERSION" ]]; then
|
||||||
|
for key in "${!servers[@]}"; do
|
||||||
|
servers_index+=("$key")
|
||||||
|
done
|
||||||
|
elif [[ -n "$ZSH_VERSION" ]]; then
|
||||||
|
for key in "${(k)servers[@]}"; do
|
||||||
|
servers_index+=("$key")
|
||||||
|
done
|
||||||
|
else
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
show_help=false
|
||||||
|
server_name=""
|
||||||
|
if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
||||||
|
show_help=true
|
||||||
|
elif [[ $1 =~ ^[0-9]+$ ]]; then
|
||||||
|
server_index=$1
|
||||||
|
server_name=${servers_index[$server_index]}
|
||||||
|
if [ -z $server_name ]; then
|
||||||
|
printf "${STR_ERR_PREFIX} Invalid index: $server_index\n\n"
|
||||||
|
show_help=true
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
server_name=$1
|
||||||
|
if [[ " ${servers_index[*]} " != *" $server_name "* ]]; then
|
||||||
|
printf "${STR_ERR_PREFIX} Invalid name: $server_name"
|
||||||
|
show_help=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $show_help; then
|
||||||
|
echo -e "Usage:\n"
|
||||||
|
echo -e " - connect [${BLUE}ID${NC}] | [${BLUE}NAME${NC}]"
|
||||||
|
echo -e "\nServers:\n"
|
||||||
|
if [[ -n "$BASH_VERSION" ]]; then
|
||||||
|
for i in ${!servers_index[@]}; do
|
||||||
|
name=${servers_index[$i]}
|
||||||
|
ssh_cmd=${servers[$name]}
|
||||||
|
printf "${YELLOW}%2d${RESET_COLOR}|" $i
|
||||||
|
printf "%-8s -> " $name
|
||||||
|
printf "%s\n" "$ssh_cmd"
|
||||||
|
done
|
||||||
|
elif [[ -n "$ZSH_VERSION" ]]; then
|
||||||
|
length=${#servers_index[@]}
|
||||||
|
max=$((length-1))
|
||||||
|
for i in {0..${max}}; do
|
||||||
|
name=${servers_index[$i]}
|
||||||
|
ssh_cmd=${servers[$name]}
|
||||||
|
printf "${YELLOW}%2d${RESET_COLOR}|" $i
|
||||||
|
printf "%-8s -> " $name
|
||||||
|
printf "%s\n" "$ssh_cmd"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
ssh_cmd=${servers[$server_name]}
|
||||||
|
echo -e "${STR_INFO_PREFIX} Connect to Server:"
|
||||||
|
echo -e "${STR_INFO_PREFIX} NAME: $server_name"
|
||||||
|
echo -e "${STR_INFO_PREFIX} CMD: ${YELLOW}$ssh_cmd${NC}"
|
||||||
|
echo -e "${STR_INFO_PREFIX} Connecting..."
|
||||||
|
err_msg=$(eval $ssh_cmd 2>&1 >/dev/tty)
|
||||||
|
if [[ $? != 0 ]]; then
|
||||||
|
echo -e "${STR_ERR_PREFIX} $err_msg"
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user