create remove and purge script

rename install script
This commit is contained in:
6543 2018-03-14 22:51:31 +01:00
parent d18455849c
commit 1841508b68
5 changed files with 188 additions and 10 deletions

View File

@ -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 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 git clone https://github.com/6543/ipfs_daemon
cd 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

78
install Executable file
View File

@ -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 -`

44
ipfs.initd Executable file → Normal file
View File

@ -33,6 +33,26 @@ ipfs_start() {
fi fi
} # ipfs_start } # 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 <comands>
[ "$line" == "exit" ] || sudo -E -u ipfs ipfs $line
[ "$?" == "1" ] && {
echo "command failed"
echo "use 'help' to show subcomands"
echo "use '<subcmd> --help' for more information"
echo "use 'exit' to leave the console"
}
done
} # ipfs_console

case "$1" in case "$1" in
start) start)
if [ -s $IPFS_PID_FILE ] && kill -0 $(cat $IPFS_PID_FILE) >/dev/null 2>&1; then 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 ipfs_start
;; ;;
stop) stop)
log_daemon_msg "Stopping ipfs daemon" "ipfs" log_daemon_msg "Stopping ipfs daemon" "ipfs"
start-stop-daemon --stop --quiet --oknodo --pidfile $IPFS_PID_FILE start-stop-daemon --stop --quiet --oknodo --pidfile $IPFS_PID_FILE
log_end_msg $? og_end_msg $?
rm -f $IPFS_PID_FILE 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) restart)
log_daemon_msg "Restarting rsync daemon" "ipfs" log_daemon_msg "Restarting rsync daemon" "ipfs"
if [ -s $IPFS_PID_FILE ] && kill -0 $(cat $IPFS_PID_FILE) >/dev/null 2>&1; then if [ -s $IPFS_PID_FILE ] && kill -0 $(cat $IPFS_PID_FILE) >/dev/null 2>&1; then
@ -65,7 +97,7 @@ case "$1" in
exit $? exit $?
;; ;;
*) *)
echo "Usage: /etc/init.d/ipfs {start|stop|restart|status}" echo "Usage: /etc/init.d/ipfs {start|stop|restart|status|console}"
exit 1 exit 1
esac esac



31
purge Executable file
View File

@ -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

22
remove Executable file
View File

@ -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
}