-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·92 lines (76 loc) · 3.22 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/env bash
#write by ddcw at 20200710 first
#this is install scripts , only for install ./shell/* , just copy file and define DIECTORIES.
#change log
#at 20200713 ,add main
#define variable
installdir=/tmp/ddcw/install_$(date +%Y%m%d-%H:%M:%S) #for install only
ddcwdir="/usr/local/ddcw" #ddcw install dir
rollbackdir=${ddcwdir}/rollback #ddcw save old release after remove or update, only 2 releases
confdir=/etc/ddcw/conf #ddcw config dir
mandir=/usr/share/man #default man dir
completion=/etc/bash_completion.d #default completion dir
install_shells=${ddcwdir}/install_shells #for install_shells only
ddcw_conf=ddcw.conf #ddcw current config file
default_conf=default.conf #ddcw default dir, this file is dead where release is make sure
#define variable for Install_Sctipts only
BASE_INSTALL_DIR="/usr/local" #for install_scripts default install dir
BASE_LOG="/logs" #for install_scripts default log dir , such as /logs/nginx/error.log .
SYSTEM_ENABLED=1 #use systemctl or service for manage software
ONBOOT=1 #enable start on boot
SCRIPT_DIR_CONFIG=${confdir}/script_dir_config #for every install_script to save them config, just like script_dir_config/nginx/nginx.conf.
ROLLBACK_DIR=${rollbackdir}
echo $0 | grep / >/dev/null 2>&1 && cd $(echo ${0%/*})
function init() {
current_user=$(whoami)
if [[ ! "${current_user}" == "root" ]] ; then
echo -e "[\033[31;40mWARNNING\033[0m `date +%Y%m%d-%H:%M:%S`] \033[31;40m current user is ${current_user}, you must run install.sh as ROOT .\033[0m"
exit 1
fi
mkdir -p ${installdir} ${ddcwdir} ${rollbackdir} ${confdir} ${mandir} ${completion} ${SCRIPT_DIR_CONFIG} ${rollbackdir}/conf/ ${install_shells}
}
function install_shells() {
for i in ./shells/*
do
shell_name=$(echo $i | sed 's/.sh$//' | awk -F / '{print $NF}' )
[[ -f /usr/bin/${shell_name} ]] && mv /usr/bin/${shell_name} ${installdir} && echo -e "[\033[32;40mINFO\033[0m `date +%Y%m%d-%H:%M:%S`] \033[32;40m backup /usr/bin/${shell_name} to ${installdir}. \033[0m"
cp ${i} /usr/bin/${shell_name} && echo -e "[\033[32;40mINFO\033[0m `date +%Y%m%d-%H:%M:%S`] \033[32;40m cp ${i} finishd. \033[0m" || echo -e "[\033[1;5;41;33mERROR\033[0m `date +%Y%m%d-%H:%M:%S`] \033[1;41;33m copy ${i} FAILED \033[0m"
chmod +x /usr/bin/${shell_name}
done
}
function install_man() {
for i in ./man/*
do
[[ -f ${mandir}/man1/${i} ]] && mv ${mandir}/man1/${i} ${installdir}/${i}.man
cp $i ${mandir}/man1
done
}
function install_completion() {
for i in ./completion/*
do
[[ -f ${completion}/$i ]] && mv ${completion}/$i ${installdir}/${i}.completion
cp $i ${completion}
done
}
function install_conf() {
for i in ./conf/*
do
file_name=$(echo $i | awk -F / '{print $NF}' )
[[ -f ${confdir}/${file_name} ]] && mv ${confdir}/${file_name} ${rollbackdir}/conf/${file_name}$(date +%Y%m%d-%H:%M:%S)
cp $i ${confdir}
done
}
function install_install_shells() {
for i in ./install_shells/*
do
script_name=$(echo $i | awk -F / '{print $NF}' )
[[ -f ${install_shells}/${script_name} ]] && mv ${install_shells}/${script_name} ${rollbackdir}/conf/${script_name}$(date +%Y%m%d-%H:%M:%S)
cp $i ${install_shells}/
done
}
init
install_shells
install_man
install_completion
install_conf
install_install_shells