Copy.com Client ohne GUI als Dienst auf Debian Wheezy (x86 und x86_64) installieren – Install-Script v1.1

Copy.com

Changelog

  • 12. Mär 2014 – Init-Script: Fix für „status“

Copy.com ist wie Dropbox ein Dienst, um Daten in der Cloud abzuspeichern. Im Gegensatz zu Dropbox bekommt man hier ganze 15GB kostenlosen Speicher.

5GB Extra-Speicher gibt es mit Einladung/Ref.-Link, meiner lautet: https://copy.com?r=ul6OfL

Um die Installation zu erleichtern, habe ich ein Install-Script in Bash geschrieben, um den Client herunterzuladen, in /opt/copycom_agent zu installieren und einem unpriviligierten Benutzer zuzuweisen. Die Architektur des Systems wird automatisch erkannt.

Das Script installiert zudem ein INIT-Script, um den Client beim hochfahren mitzustarten.
Das Passwort wird NICHT plain-text gespeichert. Es wird eine Initialisierung durchgeführt, die das Passwort verschlüsselt im Anwendungsverzeichnis speichert. Im INIT-Script wird diese Angabe daher nicht mehr benötigt.

Abhängigkeiten
– Copy.com Accunt
– Curl
– Bash

Usage
chmod +x installer.sh
./installer.sh COPY_LOGIN COPY_PASSWD RUNAS

Nach der Installation kann der Service via „service copycom start/stop/restart“ gesteuert werden.

  • COPY_LOGIN ist die E-Mailadresse, mit der sich bei Copy.com eingeloggt werden kann
  • COPY_PASSWD das zugehörige Passwort
  • RUNAS ist der lokale Benutzer (mit Shell), der den Client ausführen soll

Alle Dateien werden in den Ordner „/opt/copycom_anget/data“ synchronisiert, das Anwendungsdaten-Verzeichnis lautet „/opt/copycom_agent/appdata“.

Changelog
v1.1
– Run-as-root Check
– Cleanup Funktion
– Abhängigkeiten überprüfen
– Small fixes

Download

Copy.com Installer v1.1

Der Code

#!/bin/bash
if [[ -z "$1" ]] || [[ -z "$2" ]] || [[ -z "$3" ]]; then
	echo "Usage: $0 COPY_LOGIN COPY_PASSWD RUNAS"
	exit 1
fi
if [ "$(id -u)" != "0" ]; then
    echo "This script must be run as root" 1>&2
    exit 1
fi

cleanup() {
rm -r Copy.tgz copy/ >/dev/null 2>&1
rm -r /opt/copycom_agent >/dev/null 2>&1
update-rc.d copycom remove >/dev/null 2>&1
rm -r /etc/init.d/copycom_agent >/dev/null 2>&1
echo "Cleaning up..."
}

IS64=`arch`
LOGGEDIN=1
USERCHK=`getent passwd ${3} | grep -vi false`
DEPENDS=`which curl`

echo -en "Checking if user ${3} exists and is valid...\t"
if [ -z $USERCHK ] ; then
	echo -e "\e[00;31m ERROR\e[00m"
	exit 1
fi
echo -e "\e[00;32m OK\e[00m"

echo -en "Checking dependencies...\t\t\t"
if [ -z $DEPENDS ] ; then
	echo -e "\e[00;31m ERROR\e[00m"
	exit 1
fi
echo -e "\e[00;32m OK\e[00m"

echo
echo "Downloading latest Copy.com Client:"
curl -# -O https://copy.com/install/linux/Copy.tgz
echo

tar xfvz Copy.tgz >/dev/null 2>&1
if [ "$IS64" == "x86_64" ]; then
	mv copy/x86_64 /opt/copycom_agent
else
	mv copy/x86 /opt/copycom_agent
fi
mkdir /opt/copycom_agent/appdata
mkdir /opt/copycom_agent/data
touch /opt/copycom_agent/appdata/synclog.txt
chown -R ${3}:${3} /opt/copycom_agent

echo -en "Waiting for first login...\t\t\t"
su ${3} -c "/opt/copycom_agent/CopyConsole -data=/opt/copycom_agent/appdata -u=${1} -p=${2} -r=/opt/copycom_agent/data >/dev/null 2>&1 &"
while [ $LOGGEDIN -gt 0 ]; do
        LOGGEDIN=$(cat /opt/copycom_agent/appdata/synclog.txt | grep -i "U-LOGIN-SUCCESS" >/dev/null 2>&1)$?
        RETRY=$(($RETRY+1))
        if [ $RETRY -gt 10 ]; then
			echo -e "\e[00;31m ERROR (wrong user?)\e[00m"
			cleanup
			exit 1
		fi
        sleep 1
done
echo -e "\e[00;32m OK\e[00m"

echo -en "Sending TERMSIG to CopyConsole...\t\t"
kill -15 `pidof CopyConsole` >/dev/null 2>&1
sleep 2
killall CopyConsole >/dev/null 2>&1
echo -e "\e[00;32m OK\e[00m"

echo -en "Installing INIT-script for CopyConsole...\t"
echo "#!/bin/bash
### BEGIN INIT INFO
# Provides:          CopyConsole
# Required-Start:    \$local_fs \$remote_fs \$network
# Required-Stop:     \$local_fs \$remote_fs \$network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start or stop CopyConsole
### END INIT INFO

RUNAS=${3}

start() {
   echo \"Starting CopyConsole...\"
       if [ -x /opt/copycom_agent/CopyConsole ]; then
           HOME=\"/opt/copycom_agent\" start-stop-daemon -b -o -c \$RUNAS -S -u \$RUNAS -x /opt/copycom_agent/CopyConsole -- -daemon -data=/opt/copycom_agent/appdata
       fi
}
 
stop() {
   echo \"Stopping CopyConsole...\"
       if [ -x /opt/copycom_agent/CopyConsole ]; then
           start-stop-daemon -o -c \$RUNAS -K -u \$RUNAS -x /opt/copycom_agent/CopyConsole
       fi
}
 
status() {
       ccpid=\`pgrep -u $RUNAS CopyConsole\`
       if [ -z ccpid ] ; then
           echo \"CopyConsole for user $RUNAS: not running.\"
       else
           echo \"CopyConsole for user $RUNAS: running (pid $ccpid)\"
       fi
}
 
case \"\$1\" in
 
   start)
       start
       ;;
   stop)
       stop
       ;;
   restart|reload|force-reload)
       stop
       start
       ;;
   status)
       status
       ;;
   *)
       echo \"Usage: copycom {start|stop|reload|force-reload|restart|status}\"
       exit 1
 
esac
 
exit 0" > /etc/init.d/copycom
chmod +x /etc/init.d/copycom
update-rc.d copycom defaults >/dev/null 2>&1
if [ $? -ne 0 ] ; then
	echo -e "\e[00;31m ERROR\e[00m"
	cleanup
	exit 1
fi
echo -e "\e[00;32m OK\e[00m"
echo -en "Starting CopyConsole service...\t\t\t"
/etc/init.d/copycom start >/dev/null 2>&1
if [ $? -ne 0 ] ; then
	echo -e "\e[00;31m ERROR\e[00m"
	cleanup
	exit 1
fi
echo -e "\e[00;32m OK\e[00m"

20 Antworten auf “Copy.com Client ohne GUI als Dienst auf Debian Wheezy (x86 und x86_64) installieren – Install-Script v1.1

  1. Frank

    Hi Andre

    OK The script stalled – I think due to out of memory problems, I’m using a fairly low powered old pc as a server. On restart the service does not restart – I guess this is because of the error above. I tried running the service using start service – got a unable to set gid to 0

    OK tried running as root – i.e. sudo start

    Checked running processes – nothing

    Reinstalled via script – nothing running as process

    Had small brainwave – created user CopyConsole with same rights as root. Re-installed using script – this stops the
    Installing INIT-script for CopyConsole… pgrep: Invalid username: CopyConsole

    Restarted as seems all OK, copycom is showing in my upstart list in webmin but shows as not running. Tried starting it – won’t start.

    So it seems that reinstalling won’t force it to restart something has gone very wrong.

    Sorry

    Frank

    1. André P. Autor

      Sorry for my very late reply. I think I should escape the passwords before passing them to the script. I guess that is the problem here. I will check that later, because I am very busy at this moment.

  2. frank

    Hi Andre

    Thank you so much :)

    This worked like a dream. I get one message that I’m not sure I should worry about – as it all seems to be working.

    This is it
    Installing INIT-script for CopyConsole… pgrep: Invalid username: CopyConsole
    It then says ‚OK‘

    Thank you again.

    Frank

    1. André P. Autor

      Hi Frank,

      Nice to hear that you were lucky with the script. I will have a look at your error message tomorrow morning! Hope you didn’t run into problems so far.

      André

  3. frank

    Sorry I’ve checked the actual script more carefully and I can now see where the appdata and data directories are ’set‘.

    I’ve tried editing the script to force the data folder into my users folder but this doesn’t work – ie I get a ‚wrong user‘ message.
    Any ideas

    many thanks

    Frank

  4. frank

    This is exactly what I was looking for. However I have a problem

    I managed – after some fiddling – to get the installer script to install and start the service. However it insists on syncing to a folder in opt. I’ve checked the script but I can’t see where it sets the sync folder. This may be something to do with the fact that the user home folder sits in a logical volume on a usb disk. But if I can’t see the synced data on the server via user shares then several things fail.

    Is there a way of forcing a destination for sync.

    Many thanks

    Frank

  5. David

    Yes I’ve got a raspberry Pi running as a media server.
    I wanted to sync my media files to copy.com, but their app does not work very well (keeps stopping!), and I wanted it to run as a daemon in the background as well, so your script was ideal for me.

    Thank you anyway

    David

  6. David

    OK, the /bin/bash^M error suggests that you have written this on a Windows operating system and not linux, as ^M is a carriage return character, and not a line feed character.
    I’ve now corrected that, but still no luck….
    —————————-
    $ ./installer.sh my_copy_email my_copy_password pi
    Checking if user pi exists and is valid… OK
    Checking dependencies… OK
    Downloading latest Copy.com Client:
    ######################################################################## 100.0%
    Waiting for first login… ERROR (wrong user?)
    Cleaning up…
    pi@emoncmspi ~ $
    —————————-
    I have checked that I used the correct copy.com login details…..

    David

    1. André P. Autor

      David, you are running this on an ARM CPU, which is not compatible to x86. If you want to, I can try to insert a check for ARM and the latest beta client. But I cannot check this since I have got no raspberry here. André

      1. kfz versicherungs prozente tabelle

        Jepp, det svarte pÃ¥ det meste. Takk for svar!Kommer til Ã¥ lese SS-boken denne uken. Tror uansett jeg kommer til Ã¥ basere meg pÃ¥ oppsettet Synøve hadde som eks. i sitt innlegg:A: Knebøy, skulderpress, markløftB: Knebøy, benkpress, power cleanDet passer veldig med det jeg trener nÃ¥ (samme øvelser, bare at nÃ¥ trener jeg voldsomt(!!) ustrukturert…).Første blir Ã¥ gÃ¥ til innkjøp av notatblokk + penn… :p

  7. David

    I’ve just read your guide again!! (sorry my fault)
    but it still doesn’t work.
    ————————-
    $ chmod +x installer.sh
    $ ./installer.sh my_copy_email my_copy_password pi
    -bash: ./installer.sh: /bin/bash^M: bad interpreter: No such file or directory
    ————————-

    David

  8. David

    Sorry André
    I’ve tried to run the installer but it’s creating an error;
    ——————————————
    pi@emoncmspi ~ $ sudo bash installer.sh
    installer.sh: line 11: syntax error near unexpected token `$'{\r“
    ’nstaller.sh: line 11: `cleanup() {
    pi@emoncmspi ~ $
    ——————————————
    I’ve tried setting executable permission –
    pi@emoncmspi ~ $ chmod +x installer.sh
    ..but still errors.

    David

  9. David

    André thanks for sharing this.
    Could I ask a few questions please;
    1) Where should I install the script please?
    2) How do you call the start/stop/status commands?
    3) I see Copy.com are releasing a specific Raspberry Pi client – http://bit.ly/178OOCk but are you using the full linux client instead?

    David

    1. André P. Autor

      Hi David,
      1: You can save the script in your root folder, i.e. /root. Also every other location (except in /opt/copycom_agent ;) ) is fine. But it is important to run it as root!
      2: Since the installer just adds a simple Sysinit Script, you can handle it like every other service, too:
      – /etc/init.d/copycom start/stop/restart
      – invoke.rc-d copycom start/stop/restart
      – service copycom start/stop/restart
      I will add a little more information tomorrow morning, including an are-you-root-checker in the script, also a clean-up function.
      3: The Raspberry client is not open-source and will only be compiled for ARM-based computers, I guess. Maybe they will offer a port later? I am using the typical linux client, but only make use of the CopyConsole binary, which was made to run without GUI. The CopyAgent stays untouched.

      Hope I could help!

      André

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.