-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathinstall.sh
executable file
·90 lines (73 loc) · 2.58 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
#!/bin/sh
set -ex
# Install script for a system smileycoin daemon
# Copyright 2018 Jamie Lentin ([email protected])
# This script will install smileycoin globally, create a systemd service for
# it and start the daemon.
#
# It is tested on Debian, but should hopefully work on anything systemd-based.
PROJECT_PATH="${PROJECT_PATH-$(dirname "$(readlink -f "$0")")}" # The full project path, e.g. /srv/tutor-web.beta
PROJECT_NAME="${PROJECT_NAME-$(basename ${PROJECT_PATH})}" # The project directory name, e.g. tutor-web.beta
PROJECT_MODE="${PROJECT_MODE-development}" # The project mode, development or production
SMLY_BIN="${SMLY_BIN-${PROJECT_PATH}/src/smileycoind}"
BINDIR="/usr/local/bin"
TARGETDATA="/var/local/smly"
TARGETCONF="${TARGETDATA}/smileycoin.conf"
TARGETUSER="smly"
TARGETGROUP="nogroup"
# ---------------------------
systemctl | grep -q "smly.service" && systemctl stop smly.service
# The visible smileycoind should be a wrapper to set user/datadir
cat <<EOF > "${BINDIR}/smileycoind"
#!/bin/sh
sudo -u${TARGETUSER} "${SMLY_BIN}" -datadir="${TARGETDATA}" "\$@"
EOF
chown root:root "${BINDIR}/smileycoind"
chmod a+rwx "${BINDIR}/smileycoind"
cat <<EOF > "${BINDIR}/smileycoin-cli"
#!/bin/sh
exec "${PROJECT_PATH}/src/smileycoin-cli" -datadir="${TARGETDATA}" "\$@"
EOF
chown root:root "${BINDIR}/smileycoin-cli"
chmod a+rwx "${BINDIR}/smileycoin-cli"
# install command completion
cp contrib/smileycoin-cli-completion /usr/share/bash-completion/completions/smileycoin-cli
cat <<EOF > "${BINDIR}/smileycoin-walletunlock"
#!/bin/bash
echo -n "Passphrase: "
read -s PASSWD
echo
TIMEOUT="\${1-600}"
exec "${BINDIR}/smileycoin-cli" walletpassphrase "\${PASSWD}" "\${TIMEOUT}"
EOF
chown root:root "${BINDIR}/smileycoin-walletunlock"
chmod a+rwx "${BINDIR}/smileycoin-walletunlock"
grep -qE "^${TARGETUSER}:" /etc/passwd || adduser --system \
--home "${TARGETDATA}" --no-create-home \
--disabled-password \
${TARGETUSER}
mkdir -p "${TARGETDATA}"
chown -R ${TARGETUSER}:${TARGETGROUP} "${TARGETDATA}"
RPCPASS="$(xxd -ps -l 22 /dev/urandom)"
[ -e "${TARGETCONF}" ] || cat <<EOF > "${TARGETCONF}"
rpcuser=smileycoinrpc
rpcpassword=${RPCPASS}
EOF
cat <<EOF > /etc/systemd/system/smly.service
[Unit]
Description=SMLYcoin
After=network.target
[Service]
ExecStart=${SMLY_BIN} -datadir=${TARGETDATA} --server -printtoconsole -algo=skein
User=${TARGETUSER}
Group=${TARGETGROUP}
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable smly.service
systemctl start smly.service
groupadd -f smly-users
cat <<EOF > /etc/sudoers.d/smly
%smly-users ALL=(smly) ${SMLY_BIN}
EOF