From 1841508b6801f4281d5d939cc86aae2eba3318ed Mon Sep 17 00:00:00 2001 From: 6543 Date: Wed, 14 Mar 2018 22:51:31 +0100 Subject: [PATCH] create remove and purge script rename install script --- README.md | 23 +++++++++++++--- install | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ipfs.initd | 44 +++++++++++++++++++++++++----- purge | 31 ++++++++++++++++++++++ remove | 22 +++++++++++++++ 5 files changed, 188 insertions(+), 10 deletions(-) create mode 100755 install mode change 100755 => 100644 ipfs.initd create mode 100755 purge create mode 100755 remove diff --git a/README.md b/README.md index ee61bb5..98f8378 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,26 @@ -# Install IPFS as Daemon +# IPFS as Service / Daemon +## Requirement -used on Debian based Distros +on Debian based Distros install it with: apt-get install -y git wget tar gzip sudo + +## Install + +ipfs will save files in /var/spool/ipfs/ and run as "ipfs" +if you like to change this, +edit Settings section in "./install" before execution + git clone https://github.com/6543/ipfs_daemon cd ipfs_daemon - sudo ./setup-ipfs-daemon + sudo ./install -ipfs save files in /var/spool/ipfs/ +## Remove + + sudo ./remove + +## Purge +to delete all data use: + + sudo ./purge diff --git a/install b/install new file mode 100755 index 0000000..80cb2ca --- /dev/null +++ b/install @@ -0,0 +1,78 @@ +#!/bin/bash +# Licence GPL 3 + +##################### +## S e t t i n g s ## +##################### + +VERSION=0.4.13 +AIM=/usr/local/bin/ipfs +DATA_DIR=/var/spool/ipfs/ +USER=ipfs + +####### ENDE ####### + +[ "`id -u`" != "0" ] && { echo run as root; exit 1; } + +################# +## daemon user ## +################# + +adduser $USER --disabled-password --disabled-login --home $DATA_DIR --system + + +################# +## init skript ## +################# + +cp ipfs.initd /etc/init.d/ipfs +sed -i "s/#GID#/`id -g $USER`/g" /etc/init.d/ipfs +sed -i "s/#UID#/`id -u $USER`/g" /etc/init.d/ipfs +sed -i 's|#DATA#|'${DATA_DIR}'|g' /etc/init.d/ipfs +sed -i 's|#AIM#|'${AIM}'|g' /etc/init.d/ipfs +chmod +x /etc/init.d/ipfs +update-rc.d ipfs defaults + + +################## +## install ipfs ## +################## + +# creat tmp and enter it +cd `mktemp -d` + +# select CPU architecture +ARCH=`uname -m` +case "$ARCH" in + i?86) ARCH=386 ;; + x86_64) ARCH="amd64" ;; + *arm*) ARCH="arm" ;; + *) echo ipfs for $arch not available; exit 1 ;; +esac + +#download ... +wget "https://dist.ipfs.io/go-ipfs/v"$VERSION"/go-ipfs_v"$VERSION"_linux-"$ARCH".tar.gz" + +#extract +tar xzf go-ipfs_* + +#delete old one if exit +[ -f $AIM ] && rm $AIM + +# install new +cp go-ipfs/ipfs $AIM + +#set permissions +chmod 770 $AIM +chown $USER $AIM + +## init ipfs +export "IPFS_PATH=$DATA_DIR" +export "HOME=$DATA_DIR" +sudo -E -u ipfs ipfs init --profile=server +#If you're not running ipfs in a hosted environment, use ipfs init" +sed -i 's/127.0.0.1/0.0.0.0/g' $DATA_DIR/config + +#go back and delete temp +cd - +rm -r `cd -` diff --git a/ipfs.initd b/ipfs.initd old mode 100755 new mode 100644 index 419b147..4cf35a4 --- a/ipfs.initd +++ b/ipfs.initd @@ -33,6 +33,26 @@ ipfs_start() { fi } # ipfs_start +ipfs_console() { + export "IPFS_PATH=$DATA_DIR" + export "HOME=$DATA_DIR" + line= + while [ "$line" != "exit" ] ; do + echo -n 'ipfs:> ' + read line + #parse exit string + [ "$line" == "quit" ] && line=exit + # exec ipfs + [ "$line" == "exit" ] || sudo -E -u ipfs ipfs $line + [ "$?" == "1" ] && { + echo "command failed" + echo "use 'help' to show subcomands" + echo "use ' --help' for more information" + echo "use 'exit' to leave the console" + } + done +} # ipfs_console + case "$1" in start) if [ -s $IPFS_PID_FILE ] && kill -0 $(cat $IPFS_PID_FILE) >/dev/null 2>&1; then @@ -44,11 +64,23 @@ case "$1" in ipfs_start ;; stop) - log_daemon_msg "Stopping ipfs daemon" "ipfs" - start-stop-daemon --stop --quiet --oknodo --pidfile $IPFS_PID_FILE - log_end_msg $? - rm -f $IPFS_PID_FILE - ;; + log_daemon_msg "Stopping ipfs daemon" "ipfs" + start-stop-daemon --stop --quiet --oknodo --pidfile $IPFS_PID_FILE + og_end_msg $? + rm -f $IPFS_PID_FILE + ;; + console) + log_daemon_msg "Restarting rsync daemon" "ipfs" + if [ -s $IPFS_PID_FILE ] && kill -0 $(cat $IPFS_PID_FILE) >/dev/null 2>&1; then + start-stop-daemon --stop --quiet --oknodo --pidfile $IPFS_PID_FILE || true + sleep 1 + else + log_warning_msg "ipfs daemon not running, attempting to start." + rm -f $IPFS_PID_FILE + fi + ipfs_start + ipfs_console + ;; restart) log_daemon_msg "Restarting rsync daemon" "ipfs" if [ -s $IPFS_PID_FILE ] && kill -0 $(cat $IPFS_PID_FILE) >/dev/null 2>&1; then @@ -65,7 +97,7 @@ case "$1" in exit $? ;; *) - echo "Usage: /etc/init.d/ipfs {start|stop|restart|status}" + echo "Usage: /etc/init.d/ipfs {start|stop|restart|status|console}" exit 1 esac diff --git a/purge b/purge new file mode 100755 index 0000000..72188c8 --- /dev/null +++ b/purge @@ -0,0 +1,31 @@ +#!/bin/bash +# Licence GPL 3 + +[ "`id -u`" != "0" ] && { echo run as root; exit 1; } + +############################ +## if daemon skript exist ## +############################ +if [ -f /etc/init.d/ipfs ] ; then + DAEMON=`cat /etc/init.d/ipfs | grep DAEMON= | sed 's/DAEMON=//g'` + IPFS_PID_FILE=`cat /etc/init.d/ipfs | grep IPFS_PID_FILE= | sed 's/IPFS_PID_FILE=//g'` + IPFS_DATA=`cat /etc/init.d/ipfs | grep IPFS_DATA= | sed 's/IPFS_DATA=//g'` + IPFS_UID=`cat /etc/init.d/ipfs | grep IPFS_UID= | sed 's/IPFS_UID=//g'` + IPFS_User=`id $IPFS_UID | cut -d "(" -f 2 | cut -d ")" -f 1` + + [ -f "$DAEMON" ] && rm "$DAEMON" + [ -f "$IPFS_PID_FILE" ] && rm "$DAEMON" + [ -d "$IPFS_DATA" ] && rm -R "$IPFS_DATA" + + sudo deluser $IPFS_User --remove-home + + update-rc.d -f ipfs remove + rm /etc/init.d/ipfs +################################### +## if daemon didnt exist anymore ## +################################### +else +## del if default files/folders found + [ -f "/usr/local/bin/ipfs" ] && rm "/usr/local/bin/ipfs" + [ -d "/var/spool/ipfs/" ] && rm -R "/var/spool/ipfs/" +fi diff --git a/remove b/remove new file mode 100755 index 0000000..86ea8aa --- /dev/null +++ b/remove @@ -0,0 +1,22 @@ +#!/bin/bash +# Licence GPL 3 + +[ "`id -u`" != "0" ] && { echo run as root; exit 1; } + +############################ +## if daemon skript exist ## +############################ +[ -f /etc/init.d/ipfs ] &&{ + DAEMON=`cat /etc/init.d/ipfs | grep DAEMON= | sed 's/DAEMON=//g'` + IPFS_PID_FILE=`cat /etc/init.d/ipfs | grep IPFS_PID_FILE= | sed 's/IPFS_PID_FILE=//g'` + IPFS_UID=`cat /etc/init.d/ipfs | grep IPFS_UID= | sed 's/IPFS_UID=//g'` + IPFS_User=`id $IPFS_UID | cut -d "(" -f 2 | cut -d ")" -f 1` + + [ -f "$DAEMON" ] && rm "$DAEMON" + [ -f "$IPFS_PID_FILE" ] && rm "$DAEMON" + + sudo deluser $IPFS_User --remove-home + + update-rc.d -f ipfs remove + rm /etc/init.d/ipfs +}