Saturday, June 03, 2017

Nextcloud on Archlinux

Recently I'm trying Nextcloud, which is a fork of Owncloud.

I have to admit that I am not a big fan of PHP apps. When I tested Owncloud several years ago I only felt it's very slow.....As someone recommended Nextcloud a few weeks ago I'd like to give it a try.

The installation doc was well but since it is only for Redhat and Ubuntu. I'd like to add some notes when using Archlinux (with Nginx, PHP-FPM, Mariadb, Redis Server):


  1. The official packages are needed ("pacman -Sy nginx, php-fpm, mariadb, redis")
  2. The AUR package php-smbclient is needed if you want to use the external storage feature with SMB/CIFS
  3. Using memory caching can improve the performance. From the doc you can choose APCu, Memcached and Redis. I am using Redis server since it should be most flexible approach. AUR package php-redis, again, is needed.
  4. Download the latest Nextcloud package. Extract and put it under /var/www
  5. under /etc/php/php.ini, make sure these lines are uncommented:
    zend_extension=opcache.so
    extension=pdo_mysql.so
    extension="smbclient.so"
    extension="redis.so"
  6. Following the official method to setup Nginx 
  7. Enable the services so that they will bring up after a reboot. (systemctl enable xxx)
  8. Using SSL is highly recommended. It's very easy to get one from Let's Encrypt with zero cost.
I will setup a container on my proxmox and evaluate for a while and give a brief review about it  later.

Thursday, September 01, 2016

Eclipse Che setup - on a server with Docker

If you take a look at the official site you'll see the installation is super easy - just a single line:

docker run --rm -t -v /var/run/docker.sock:/var/run/docker.sock eclipse/che start

Of course it is assumed that you have Docker 1.8 or later installed.

If you run it in your desktop or laptop, you can start using it. Just go to "http://localhost:8080" and create a workspace for your development:


Since I am going to install it on my HP N54L server (ArchLinux), I need to put from environment variables:

docker run --rm -t -e CHE_HOST_IP= -v /var/run/docker.sock:/var/run/docker.sock  eclipse/che  stop

Then I can go ot "http://:8080" to enjoy this web IDE.

Another thing I discover is that if you run "docker ps" you will see:

CONTAINER ID        IMAGE                                                                       COMMAND                  CREATED             STATUS              PORTS                                                                                                                       NAMES
6b5cf5c1c0e9        eclipse-che/workspacef2v2k7ltal4gbsxp_machineph3hokyhknjhxa90_che_default   "/home/user/entrypoin"   42 hours ago        Up 42 hours         0.0.0.0:32817->22/tcp, 0.0.0.0:32816->4401/tcp, 0.0.0.0:32815->4403/tcp, 0.0.0.0:32814->4411/tcp, 0.0.0.0:32813->8080/tcp   workspacef2v2k7ltal4gbsxp_machineph3hokyhknjhxa90_che_default
ac63c449f4b8        codenvy/che-server:latest                                                   "/home/user/che/bin/c"   42 hours ago        Up 42 hours         8000/tcp, 0.0.0.0:8080->8080/tcp                                                                                            che-server


Just remember do not stop it by running "docker stop che-server". I did once and when I start the che-server my previous setting, including workpsaces and projects were gone.

Instead, we should run 

docker run --rm -t -e CHE_HOST_IP= -v /var/run/docker.sock:/var/run/docker.sock  eclipse/che  stop

Or simply download the start/stop script from eclipse.org:

curl -sL https://raw.githubusercontent.com/eclipse/che/master/che.sh > che
then run
 ./che start / stop / restart

for my case I need to set the environemnt:
CHE_HOST_IP=je54 ./che  start
CHE_HOST_IP=je54 ./che  stop

Eclipse Che (coding within a browser)

I am not a professional programmer or developer. But I do need to code time to time. 90% of my coding is done with "vi". It's very powerful if the project is small. I also tried atom.io or sublime text, but they are just too powerful that I don't want to invest too much time. Then I found Eclipse Che.

Eclipse was a heavy IDE and I was using it 10 years ago, when I was still a big fans of Java. I put it down for years but when i visit the site again I found there is an interesting project: Eclispe Che - http://eclipse.org/che . Unlike Atom or Sublime Text, it's not a editor or IDE but a development infrastructure. It's not necessary to install it in your PC or laptop, but another server or even in the cloud. Even you install it in your PC you just install a docker container and use a browser to work:



As you can see everything is in docker. For my case I can put it in my HP N54L and then I can code with any computers. The installation is pretty simple, I will show it in the next post.

Monday, August 29, 2016

Wordpress install by wp-cli (Command line only)

Prepare the database (mysql / mariadb)

  • mysql -u -p
  • create database wp_db1;
  • grant all on wp_db1.* to @'%' identified by ;

wp-cli

  • Download wp-cli at http://wp-cli.org/
  • wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
    
  • Move the file to /usr/local/bin (Or set $PATH to the location you want )
  • create the wordpress home (eg. /var/www/wordpress)
  • cd /var/www/wordpress
  • wp core download
  • wp core config --dbname=wp_db1 --dbuser= --dbpass= --dbprefix=wp
  • wp core install --url=""  --title="" --admin_user="<user>" --admin_password="<password>" --admin_email="<email>"</li> </ul> Now you can login WordPress with a browser for further configuration.<br><div> <p> <br></p> </div> <div> <p> <br></p> </div>

Friday, November 06, 2015

Sending Whatsapp Messages from Raspberry Pi

yowsup is the Whatsapp library. It is written in python so we can run even with a Raspberry Pi. After the installation there is a client script that we can send message to other Whatsapp user. 

Reasons to use yowsup:
  1. send messages to mobile device like SMS
  2. the cost is cheap: all we need is just a mobile number ( a number that has not been registered in Whatsapp) and a Raspberry Pi ( I am using Raspberry Pi B2, but any model should be found)
Installation

$ virtualenv2 venv/
New python executable in venv/bin/python2
Also creating executable in venv/bin/python
Installing setuptools, pip, wheel...done.
$ . venv/bin/activate
(venv)$ git clone https://github.com/tgalal/yowsup

Cloning into 'yowsup'...
remote: Counting objects: 6983, done.
remote: Total 6983 (delta 0), reused 0 (delta 0), pack-reused 6983
Receiving objects: 100% (6983/6983), 1.49 MiB | 574.00 KiB/s, done.
Resolving deltas: 100% (4388/4388), done.
Checking connectivity... done.

python setup.py  install

After the setup there will be a script "yowsup-cli"

Registration

Prepare the following information:
    • the phone number           (XXXXXXXX)
    • the country code             (CCC)
    • the mobile country code (mcc)
    • the mobile network code (mnc)

Note that the phone number is in the form of Country Code + Number. And the mcc and mnc can be found at https://en.wikipedia.org/wiki/Mobile_country_code

For example, if you are using Verizon LTE in US, that the mcc and mnc should be 310 and 012 respectively.

Run the command:
./yowsup-cli registration --requestcode sms --phone CCCXXXXXXXX --cc CCC --mcc 310 --mnc 012

INFO:yowsup.common.http.warequest:{"status":"sent","length":6,"method":"sms","retry_after":1805}

status: sent
retry_after: 1805
length: 6
method: sms


If you are lucky enough you will receive a SMS from the mobile phone.

With this WhatsApp code we can run another command:
./yowsup-cli registration --register 800-269 --phone CCCXXXXXXXX --cc CCC
INFO:yowsup.common.http.warequest:{"status":"ok","login":"CCCXXXXXXXX","pw":"kaiaCmXHgRxxxvuOfbbCFHlqbLI=","type":"new","expiration":1478245880,"kind":"free","price":"$1.00","cost":"1.00","currency":"USD","price_expiration":1449782266}

status: ok
kind: free
pw: kaiaCmXHgRxxxvuOfbbCFHlqbLI=
price: $1.00
price_expiration: 1449782266
currency: USD
cost: 1.00
expiration: 1478245880
login: CCCXXXXXXXX
type: new


Note that the line pw: xxxxxxxxxxxxx . That's the password we need to put in a config file.

create a file yowsup-cli.conf with the following content:

cc=CCC # The country code
phone=XXXXXXXX # the phone number
id= # 
password=xxxxxxxxxxx # the password

Finally we can test by sending a message to a Whatsapp user (eg. CCCYYYYYYYY):

./yowsup-cli demos -c yowsup-cli.conf -s YYYYYYY “hello world”


By using the simple command we can send Whatsapp message to another user programmatically. Possible usages are to send alerts when some health check jobs failed, or writing authentication apps that can send the passcode.

Ref:
  • https://github.com/tgalal/yowsup
  • https://en.wikipedia.org/wiki/Mobile_country_code