-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmauto.sh
executable file
·83 lines (81 loc) · 2.49 KB
/
mauto.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
#!/bin/sh
#
# Copyright 2018 Chrisdigity
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# #####################################################################
#
# Mochimo Autostart - v1.3.2 by Chrisdigity
#
# Prerequisites: mochimo node (https://github.com/mochimodev/mochimo)
# tmux (sudo apt install tmux)
#
# To install this script...
# - Verify the variable 'dmochi' points to your mochimo/bin directory
# - Verify the variable 'mochi' executes the desired command
#
# - For Desktop Environment (Ubuntu);
# Search -> Startup Applications -> Add button
# Give it a name (and comment if you wish)
# Command: gnome-terminal -x sh -c '~/mochitoolkit/mauto.sh;exec bash'
#
# - For Server Environment (Ubuntu);
# Add a '#' to the start of line 73: 'tmux attach -t mochimo'
# Open '/etc/rc.local' with your favourite editor
# `nano /etc/rc.local`
# Add the next line before 'exit 0' in '/etc/rc.local', replacing
# <username> with the user you wish to use to start the mochimo node
# `sh -c ~/mochitoolkit/mauto.sh <username>`
#
# *To access the node after login type
# `tmux attach -t mochimo`
#
############
# Variables
dmochi="$HOME/mochimo/bin" # mochimo bin directory (MUST BE FULL PATH)
mochi="./gomochi d" # start command
network=0 # network connectivity
##########
# Execute
if ! $(tmux has-session -t mochimo) # Check mochimo node
then
printf "Network connectivity check... "
if [ $network -eq 0 ]
then
for i in {1..20}
do
sleep 3
if ping -c1 google.com >/dev/null 2>&1
then
printf "OK\n"
network=1
break
fi
done
else
printf "SKIP\n"
fi
if [ $network -eq 1 ]
then
tmux new -s mochimo -c $dmochi -d "$mochi" # Start mochimo node
tmux attach -t mochimo # Attach to session
else
printf "Timeout!\n"
exit 1
fi
else
echo "A Mochimo session already exists"
echo "Try: tmux attach -t mochimo"
fi
exit 0