mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
修复mac和linux兼容性
This commit is contained in:
@@ -377,6 +377,41 @@ reload_pm2() {
|
||||
pm2 start $dir_static/build/public.js -n public --source-map-support --time &>/dev/null
|
||||
}
|
||||
|
||||
diff_time() {
|
||||
local format="$1"
|
||||
local begin_time="$2"
|
||||
local end_time="$3"
|
||||
|
||||
if [[ $is_macos -eq 1 ]]; then
|
||||
diff_time=$(($(date -j -f "$format" "$end_time" +%s) - $(date -j -f "$format" "$begin_time" +%s)))
|
||||
else
|
||||
diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time")))
|
||||
fi
|
||||
echo "$diff_time"
|
||||
}
|
||||
|
||||
format_time() {
|
||||
local format="$1"
|
||||
local time="$2"
|
||||
|
||||
if [[ $is_macos -eq 1 ]]; then
|
||||
echo $(date -j -f "$format" "$time" "+%Y-%m-%d %H:%M:%S")
|
||||
else
|
||||
echo $(date -d "$time" "+%Y-%m-%d %H:%M:%S")
|
||||
fi
|
||||
}
|
||||
|
||||
format_timestamp() {
|
||||
local format="$1"
|
||||
local time="$2"
|
||||
|
||||
if [[ $is_macos -eq 1 ]]; then
|
||||
echo $(date -j -f "$format" "$time" "+%s")
|
||||
else
|
||||
echo $(date -d "$time" "+%s")
|
||||
fi
|
||||
}
|
||||
|
||||
init_env
|
||||
detect_termux
|
||||
detect_macos
|
||||
|
||||
+20
-20
@@ -84,8 +84,8 @@ run_normal() {
|
||||
fi
|
||||
fi
|
||||
|
||||
local time=$(date)
|
||||
log_time=$(date -d "$time" "+%Y-%m-%d-%H-%M-%S")
|
||||
local time=$(date "+%Y-%m-%d-%H-%M-%S")
|
||||
log_time="$time"
|
||||
log_dir_tmp="${file_param##*/}"
|
||||
if [[ $file_param =~ "/" ]]; then
|
||||
if [[ $file_param == /* ]]; then
|
||||
@@ -99,12 +99,12 @@ run_normal() {
|
||||
[[ $log_dir_tmp_path ]] && log_dir_tmp="${log_dir_tmp_path}_${log_dir_tmp}"
|
||||
log_dir="${log_dir_tmp%.*}"
|
||||
log_path="$log_dir/$log_time.log"
|
||||
cmd="&>> $dir_log/$log_path"
|
||||
cmd=">> $dir_log/$log_path 2>&1"
|
||||
[[ "$show_log" == "true" ]] && cmd=""
|
||||
make_dir "$dir_log/$log_dir"
|
||||
|
||||
local begin_time=$(date -d "$time" "+%Y-%m-%d %H:%M:%S")
|
||||
local begin_timestamp=$(date -d "$time" "+%s")
|
||||
local begin_time=$(format_time "%Y-%m-%d-%H-%M-%S" "$time")
|
||||
local begin_timestamp=$(format_timestamp "%Y-%m-%d-%H-%M-%S" "$time")
|
||||
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
||||
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
||||
|
||||
@@ -155,8 +155,8 @@ run_concurrent() {
|
||||
[[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr}
|
||||
|
||||
define_program "$file_param"
|
||||
local time=$(date)
|
||||
log_time=$(date -d "$time" "+%Y-%m-%d-%H-%M-%S")
|
||||
local time=$(date "+%Y-%m-%d-%H-%M-%S")
|
||||
log_time="$time"
|
||||
log_dir_tmp="${file_param##*/}"
|
||||
if [[ $file_param =~ "/" ]]; then
|
||||
if [[ $file_param == /* ]]; then
|
||||
@@ -170,12 +170,12 @@ run_concurrent() {
|
||||
[[ $log_dir_tmp_path ]] && log_dir_tmp="${log_dir_tmp_path}_${log_dir_tmp}"
|
||||
log_dir="${log_dir_tmp%.*}"
|
||||
log_path="$log_dir/$log_time.log"
|
||||
cmd="&>> $dir_log/$log_path"
|
||||
cmd=">> $dir_log/$log_path 2>&1"
|
||||
[[ "$show_log" == "true" ]] && cmd=""
|
||||
make_dir "$dir_log/$log_dir"
|
||||
|
||||
local begin_time=$(date -d "$time" "+%Y-%m-%d %H:%M:%S")
|
||||
local begin_timestamp=$(date -d "$time" "+%s")
|
||||
local begin_time=$(format_time "%Y-%m-%d-%H-%M-%S" "$time")
|
||||
local begin_timestamp=$(format_timestamp "%Y-%m-%d-%H-%M-%S" "$time")
|
||||
|
||||
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
||||
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
||||
@@ -225,8 +225,8 @@ run_designated() {
|
||||
fi
|
||||
|
||||
define_program "$file_param"
|
||||
local time=$(date)
|
||||
log_time=$(date -d "$time" "+%Y-%m-%d-%H-%M-%S")
|
||||
local time=$(date "+%Y-%m-%d-%H-%M-%S")
|
||||
log_time="$time"
|
||||
log_dir_tmp="${file_param##*/}"
|
||||
if [[ $file_param =~ "/" ]]; then
|
||||
if [[ $file_param == /* ]]; then
|
||||
@@ -240,12 +240,12 @@ run_designated() {
|
||||
[[ $log_dir_tmp_path ]] && log_dir_tmp="${log_dir_tmp_path}_${log_dir_tmp}"
|
||||
log_dir="${log_dir_tmp%.*}"
|
||||
log_path="$log_dir/$log_time.log"
|
||||
cmd="&>> $dir_log/$log_path"
|
||||
cmd=">> $dir_log/$log_path 2>&1"
|
||||
[[ "$show_log" == "true" ]] && cmd=""
|
||||
make_dir "$dir_log/$log_dir"
|
||||
|
||||
local begin_time=$(date -d "$time" "+%Y-%m-%d %H:%M:%S")
|
||||
local begin_timestamp=$(date -d "$time" "+%s")
|
||||
local begin_time=$(format_time "%Y-%m-%d-%H-%M-%S" "$time")
|
||||
local begin_timestamp=$(format_timestamp "%Y-%m-%d-%H-%M-%S" "$time")
|
||||
|
||||
local envs=$(eval echo "\$${env_param}")
|
||||
local array=($(echo $envs | sed 's/&/ /g'))
|
||||
@@ -289,8 +289,8 @@ run_designated() {
|
||||
run_else() {
|
||||
local file_param="$1"
|
||||
define_program "$file_param"
|
||||
local time=$(date)
|
||||
log_time=$(date -d "$time" "+%Y-%m-%d-%H-%M-%S")
|
||||
local time=$(date "+%Y-%m-%d-%H-%M-%S")
|
||||
log_time="$time"
|
||||
log_dir_tmp="${file_param##*/}"
|
||||
if [[ $file_param =~ "/" ]]; then
|
||||
if [[ $file_param == /* ]]; then
|
||||
@@ -304,12 +304,12 @@ run_else() {
|
||||
[[ $log_dir_tmp_path ]] && log_dir_tmp="${log_dir_tmp_path}_${log_dir_tmp}"
|
||||
log_dir="${log_dir_tmp%.*}"
|
||||
log_path="$log_dir/$log_time.log"
|
||||
cmd="&>> $dir_log/$log_path"
|
||||
cmd=">> $dir_log/$log_path 2>&1"
|
||||
[[ "$show_log" == "true" ]] && cmd=""
|
||||
make_dir "$dir_log/$log_dir"
|
||||
|
||||
local begin_time=$(date -d "$time" "+%Y-%m-%d %H:%M:%S")
|
||||
local begin_timestamp=$(date -d "$time" "+%s")
|
||||
local begin_time=$(format_time "%Y-%m-%d-%H-%M-%S" "$time")
|
||||
local begin_timestamp=$(format_timestamp "%Y-%m-%d-%H-%M-%S" "$time")
|
||||
|
||||
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
||||
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
||||
|
||||
+1
-1
@@ -538,7 +538,7 @@ main() {
|
||||
;;
|
||||
esac
|
||||
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time")))
|
||||
local diff_time=$(diff_time "%Y-%m-%d %H:%M:%S" "$begin_time" "$end_time")
|
||||
if [[ $p1 != "repo" ]] && [[ $p1 != "raw" ]]; then
|
||||
echo -e "\n## 执行结束... $end_time 耗时 $diff_time 秒" >>$log_path
|
||||
cat $log_path
|
||||
|
||||
Reference in New Issue
Block a user