Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·199 lines (185 loc) · 5 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·199 lines (185 loc) · 5 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env bash
function replace_ipfs_address() {
echo "Type the address of your IPFS node (eg http://localhost:5001)";
read IPFS_ADDRESS;
template="http://ipfs:5001";
sed -i "s!$template!$IPFS_ADDRESS!" "$1";
}
function replace_exec() {
template="EXECUTABLE_REPLACE";
sed -i "s@$template@$2@" "$1";
}
function replace_param() {
template="INSTANCE_$1_REPLACE";
echo "Give INSTANCE_$1";
read INPUT;
sed -i "s/$template/$INPUT/" "$2";
}
if ! command -v git; then
echo "Git is not installed. Setup cannot continue";
exit 1;
fi
mkdir .local
cd ~/.local;
git clone https://github.com/a-manga-thing/instance;
mv instance mangaloid;
cd mangaloid;
git checkout setup
git pull
if [[ -f docker-compose.yml || -f mangaloid.service || -f run.sh ]]; then
echo "Looks like you have already finished an installation. This might overwrite stuff. Continue ? [y/n]";
read INPUT;
if [[ $INPUT != "y" ]]; then
exit 0;
fi
fi
INSTALLATION_METHOD="";
INIT_SYSTEM=$(ps --no-headers -o comm 1);
echo "Select installation method:
[1] Docker (Recommended)
[2] Pip System-wide installation
[3] No Installation (Run from folder)";
while [[ "1" ]]; do
read INPUT;
case $INPUT in
1)
INSTALLATION_METHOD="docker";
INIT_SYSTEM="docker";
break;
;;
2)
INSTALLATION_METHOD="pip";
break;
;;
3)
INSTALLATION_METHOD="none";
break;
;;
*)
echo "Wrong input. Try again";
;;
esac
done
echo $INIT_SYSTEM;
if [[ $INIT_SYSTEM != "docker" ]]; then
echo "Automatically detected $INIT_SYSTEM as your init system.
Continue with that ? Answering no will skip init setup. [y/n]
";
read INPUT;
if [[ $INPUT != "y" ]]; then
INIT_SYSTEM="none";
fi
fi
case $INIT_SYSTEM in
"systemd")
cp inits/mangaloid.service.template mangaloid.service
;;
"docker")
echo "debug";
cp inits/docker-compose.yml.template docker-compose.yml
;;
"init")
echo "SysV isn't really supported yet. Sorry...";
exit 1;
;;
"none")
cp inits/run.sh.template run.sh;
;;
esac
echo "Select IPFS setting:
[1] Managed by instance (Recommended)
[2] External
";
while [[ "1" ]]; do
read INPUT;
case $INPUT in
1)
break;
;;
2)
case $INIT_SYSTEM in
"systemd")
replace_ipfs_address mangaloid.service;
;;
"docker")
replace_ipfs_address docker-compose.yml;
for ((i=25;i<=41;i++)); do
line=$(sed $i"q;d" docker-compose.yml);
newline="#$line";
sed -i $i"s!.*!$newline!" docker-compose.yml;
done
;;
"init")
echo '';
;;
"none")
replace_ipfs_address run.sh;
;;
esac
break;
;;
*)
echo "Wrong input. Try again";
;;
esac
done
params=("NAME" "ADDRESS" "OPERATOR" "DESCRIPTION");
case $INIT_SYSTEM in
"docker")
for i in "${params[@]}"; do
replace_param "$i" "docker-compose.yml";
done
;;
"systemd")
for i in "${params[@]}"; do
replace_param "$i" "mangaloid.service";
done
;;
"init")
for i in "${params[@]}"; do
replace_param "$i" "sysv-run.sh";
done
;;
"none")
for i in "${params[@]}"; do
replace_param "$i" "run.sh";
done
;;
esac
case $INSTALLATION_METHOD in
"docker")
if ! command -v docker-compose; then
echo "docker-compose is not installed. Setup cannot continue";
exit 1;
fi
echo "The docker-compose.yml file is located in ~/.local/mangaloid";
docker-compose up -d;
exit 0;
;;
"pip")
pip install .
location=$(python -c "import os, site; print(os.path.join(site.USER_BASE, 'Scripts' if os.name == 'nt' else 'bin'))");
executable="$location/mangaloid-instance";
;;
"none")
executable="$HOME/.local/mangaloid/run.sh"
;;
esac
case $INIT_SYSTEM in
"systemd")
replace_exec mangaloid.service "$executable";
sed -i "s@%h@$HOME@" mangaloid.service;
sed -i "s@REPLACE_USER@$USER@" mangaloid.service;
echo "Enabling systemd service...";
sudo cp mangaloid.service /etc/systemd/system;
sudo systemctl daemon-reload
sudo systemctl enable --now mangaloid.service;
sudo systemctl status mangaloid.service
;;
"init")
replace_exec sysv-run.sh "$executable";
;;
"none")
echo "You can start the mangaloid instance with ~/.local/mangaloid/run.sh";
;;
esac