-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_darwin.sh
146 lines (105 loc) · 3.08 KB
/
install_darwin.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
echo -e "\033[0;36m"
echo -e "...installing \033[0m"
#-------------- creation of structures
cd /opt
rm -frd $root/install.sh
rm -frd $root
mkdir -p $root
cd $root
#-------------- end
#-------------- generate config
cat > $root/config.json <<EOF
{
"port":$port,
"project":"$project_name",
"name_service":"$name_service",
"lang":"$lang"
}
EOF
chmod 744 $root/config.json
#-------------- end
#-------------- check dependencies
# echo -e "\033[0;33m"
# echo -e "Check dependencies:"
# echo -e "\033[0m"
#-------------- end
#-------------- download files
echo -e "\033[0;33m"
echo -e "Download:"
echo -e "\033[0m"
echo "search $name_service"
file=$(curl -s https://api.github.com/repos/intrahouseio/$repo_name/releases/latest | grep browser_download_url | cut -d '"' -f 4)
echo -e "latest found: \033[0;32m $file \033[0m"
echo -e "\033[0m"
echo -e "get $name_service \033[0;34m"
curl --progress-bar -L -o intrahouse-lite.zip $file
echo -e "\033[0m"
echo -e "get nodeJS \033[0;34"
curl --progress-bar -L -o node.tar.xz "https://nodejs.org/dist/v8.17.0/node-v8.17.0-darwin-x64.tar.gz"
#-------------- end
#-------------- deploy
echo -e "\033[0;33m"
echo -e "Deploy:"
echo -e "\033[0m"
unzip ./intrahouse-lite.zip > /dev/null
if [ -d "./project_$lang" ]; then
rm -fr $project_path
mkdir -p $project_path
cp -fr ./project_$lang/* $project_path
rm -fr ./project_*
fi
mkdir -p node
cd ./node
tar xf ./../node.tar.xz --strip 1
cd ./../
rm -frd ./intrahouse-lite.zip
rm -frd ./node.tar.xz
cd ./backend
#export PATH=$PATH:$root/node/bin
$root/node/bin/node $root/node/bin/npm i --only=prod --scripts-prepend-node-path=auto
#cp -Rf $root/deps/core-js $root/backend/node_modules
#$root/node/bin/node $root/node/bin/npm i pdfmake@0.1.37 --only=prod
#-------------- end
#-------------- register service
echo -e "\033[0;36m"
echo -e "...register service \033[0m"
echo ""
path_service=/Library/LaunchDaemons/$name_service.plist
sudo rm -frd $path_service
cat > $path_service <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LowPriorityIO</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>$name_service</string>
<key>WorkingDirectory</key>
<string>/opt/$name_service</string>
<key>ProgramArguments</key>
<array>
<string>/opt/$name_service/node/bin/node</string>
<string>/opt/$name_service/backend/app.js</string>
<string>prod</string>
</array>
<key>StandardOutPath</key>
<string>/opt/$name_service/launchdOutput.log</string>
<key>StandardErrorPath</key>
<string>/opt/$name_service/launchdErrors.log</string>
</dict>
</plist>
EOF
sudo launchctl stop $name_service
sudo launchctl remove $name_service
sudo chown root /Library/LaunchDaemons/$name_service.plist
sudo chmod 644 /Library/LaunchDaemons/$name_service.plist
sudo launchctl load /Library/LaunchDaemons/$name_service.plist
sudo launchctl start $name_service
sudo launchctl list | grep $name_service
#-------------- end