Sftp upload with lftp/mirror

Posted: November 2nd, 2011 | Author: | Filed under: Linux | No Comments »
lftp -c "open -u USERNAME,PASSWORD sftp://REMOTE_HOST/PATH/TO/ ; mirror -R /LOCAL/PATH/TO/."

phpMyAdmin config.inc.php

Posted: October 15th, 2011 | Author: | Filed under: Linux | No Comments »
<?php

// Load secret generated on postinst
include('/var/lib/phpmyadmin/blowfish_secret.inc.php');

// Load autoconf local config
include('/var/lib/phpmyadmin/config.inc.php');

$i = 0;
$i++;

if (is_readable('/etc/phpmyadmin/config-db.php')) {
    require('/etc/phpmyadmin/config-db.php');
} else {
    error_log('phpmyadmin: Failed to load /etc/phpmyadmin/config-db.php.'
        . ' Check group www-data has read access.');
}

if (!empty($dbname)) {
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    if (empty($dbserver)) $dbserver = 'localhost';
    $cfg['Servers'][$i]['host'] = $dbserver;

    if (!empty($dbport) || $dbserver != 'localhost') {
        $cfg['Servers'][$i]['connect_type'] = 'tcp';
        $cfg['Servers'][$i]['port'] = $dbport;
    }
    $cfg['Servers'][$i]['extension'] = 'mysqli';
    $cfg['Servers'][$i]['controluser'] = $dbuser;
    $cfg['Servers'][$i]['controlpass'] = $dbpass;
    $cfg['Servers'][$i]['pmadb'] = $dbname;
    $cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
    $cfg['Servers'][$i]['relation'] = 'pma_relation';
    $cfg['Servers'][$i]['table_info'] = 'pma_table_info';
    $cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
    $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
    $cfg['Servers'][$i]['column_info'] = 'pma_column_info';
    $cfg['Servers'][$i]['history'] = 'pma_history';
    $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';
    $cfg['Servers'][$i]['tracking'] = 'pma_tracking';
    $cfg['Servers'][$i]['userconfig'] = 'pma_userconfig';
    $cfg['Servers'][$i]['hide_db'] = '^information_schema|mysql|phpmyadmin$';
    $cfg['Servers'][$i]['AllowNoPassword'] = true;
    $cfg['Servers'][$i]['CountTables'] = true;

    $i++;
}

$cfg['DefaultLang'] = 'en';
$cfg['DisplayDatabasesList'] = 1;
$cfg['ServerDefault'] = 1;
$cfg['GZipDump'] = false;
$cfg['BZipDump'] = false;
$cfg['AllowUserDropDatabase'] = true;
$cfg['AllowArbitraryServer'] = true;
$cfg['LoginCookieValidity'] = 60000;
$cfg['LeftFrameDBSeparator'] = '';
$cfg['LeftDisplayTableFilterMinimum'] = 100;
$cfg['UserprefsDisallow'] = array('LeftFrameDBSeparator');
$cfg['ShowPhpInfo'] = true;
$cfg['ShowAll'] = true;
$cfg['MaxRows'] = 100;
$cfg['Order'] = 'ASC';
$cfg['LimitChars'] = 30;
$cfg['PropertiesIconic'] = true;
$cfg['Import']['charset'] = 'utf-8';
$cfg['Import']['ods_col_names'] = true;
$cfg['Export']['quick_export_onserver'] = true;
$cfg['Export']['quick_export_onserver_overwrite'] = true;
$cfg['Export']['charset'] = 'utf-8';
$cfg['Export']['sql_include_comments'] = false;
$cfg['Export']['sql_drop_table'] = true;
$cfg['Export']['sql_utc_time'] = false;
$cfg['Export']['csv_columns'] = true;
$cfg['Export']['excel_columns'] = true;
$cfg['Export']['htmlword_columns'] = true;
$cfg['Export']['ods_columns'] = true;
$cfg['Export']['texytext_columns'] = true;

Managing apache folder

Posted: September 8th, 2011 | Author: | Filed under: Development, Linux | No Comments »

The goal here is to allow apache process as well as multiple developers to have read and write permission to all apache files.

What I’m currently doing is:
- Add a new group “dev”

addgroup dev

- Add www-data (or whatever your apache runner user is) to the group “dev”

adduser www-data dev

- Add all developers to the group “dev”

adduser vincent dev
adduser anotherdev dev

- Change apache user “www-data” and all developers’ default group to “dev”

vim /etc/passwd
# each line is a user:
# username:x:userid:groupid:userinfo:script
# now change groupid from the default user group to the groupid of "dev"

- Change umask to 002 (all developers on ssh, all developers on sftp, and www-data)

vim /etc/profile
# change umask to 002
vim /etc/ssh/sshd_config
# change Subsystem to:
Subsystem sftp /usr/lib/openssh/sftp-server -u 0002
vim /etc/apache2/envvars
# add
umask 002

- Change all apache folders to www-data:dev, 775 and files to www-data:dev, 664

chown www-data:dev /home/www-data -R
chmod 775 /home/www-data
find /home/www-data/* -type d -exec chmod 775 {} \;
find /home/www-data/* -type f -exec chmod 664 {} \;

Learn Vim Progressively

Posted: August 30th, 2011 | Author: | Filed under: Development, Linux | No Comments »

Source


Keep SSH session alive without sudo

Posted: July 24th, 2011 | Author: | Filed under: Linux | No Comments »
vim ~/.ssh/config

# this example keep the session alive for 60sec x 480 = 8hours
ServerAliveInterval 60 #seconds
ServerAliveCountMax 480 #times of keep-alive signals to send

SSH without password, and key only login

Posted: July 21st, 2011 | Author: | Filed under: Linux | No Comments »
# create rsa key, skip if already done
local> ssh-keygen -t rsa

# create .ssh/ in home
local> ssh USER@REMOTEHOST mkdir ~/.ssh

# cat local public key, pipe over to ssh, take the piped local key append into remote ~/.ssh/authorized_keys
local> cat ~/.ssh/id_rsa.pub | ssh USER@REMOTEHOST 'cat >> ~/.ssh/authorized_keys'

# now on remote
remote> sudo vim /etc/ssh/sshd_config
# add the following
PermitRootLogin no # disable ssh as root
PubkeyAuthentication yes # use key authentication
PasswordAuthentication no # disable password authentication

Production Server with Rails and Phusion Passenger

Posted: June 21st, 2011 | Author: | Filed under: Linux, Ruby, System | No Comments »

First you need to install RVM, ruby, rubygem, rails, with LAMP already installed too.

rvmsudo passenger-install-apache2-module

# to find out where apache config file is
apachectl -V | grep SERVER_CONFIG_FILE

# load modules in Apache config (this may vary)
LoadModule passenger_module /home/vincent/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /home/vincent/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7
PassengerRuby /home/vincent/.rvm/wrappers/ruby-1.9.2-p180/ruby

# now this is an exmple of apache virtualhost
<VirtualHost *:80>
        DocumentRoot /home/www-data/depot/public
        ServerName appname.myserver.com
        <Directory /home/www-data/depot/public>
                AllowOverride all
                Options -MultiViews
        </Directory>

        # Speeds up spawn time tremendously -- if your app is compatible.
        # RMagick seems to be incompatible with smart spawning
        RailsSpawnMethod smart

        # Keep the application instances alive longer. Default is 300 (seconds)
        PassengerPoolIdleTime 1000

        # Keep the spawners alive, which speeds up spawning a new Application
        # listener after a period of inactivity at the expense of memory.
        RailsAppSpawnerIdleTime 0

        # Additionally keep a copy of the Rails framework in memory. If you're
        # using multiple apps on the same version of Rails, this will speed up
        # the creation of new RailsAppSpawners. This isn't necessary if you're
        # only running one or 2 applications, or if your applications use
        # different versions of Rails.
        RailsFrameworkSpawnerIdleTime 0

        # Just in case you're leaking memory, restart a listener
        # after processing 5000 requests
        PassengerMaxRequests 5000

        # only check for restart.txt et al up to once every 5 seconds,
        # instead of once per processed request
        PassengerStatThrottleRate 5
</VirtualHost>

Create the database needed for the new app, update config/database.yml content to allow app to connect to database on the production server.

Once the new rails app is uploaded to the server:

# install/update bundle
cd appfolder/
bundle install

# now setup database table and data
cd appfolder/
rake db:setup RAILS_ENV=production

Next you use a2ensite and /etc/init.d/apache restart to reload the new site.


Few bash scripts

Posted: February 1st, 2011 | Author: | Filed under: Development, Linux, System | No Comments »

Perl rename (copied out from ubuntu dist)

#!/usr/bin/perl -w
use strict;

use Getopt::Long;
Getopt::Long::Configure('bundling');

my ($verbose, $no_act, $force, $op);

die "Usage: rename [-v] [-n] [-f] perlexpr [filenames]\n"
    unless GetOptions(
        'v|verbose' => \$verbose,
        'n|no-act'  => \$no_act,
        'f|force'   => \$force,
    ) and $op = shift;

$verbose++ if $no_act;

if (!@ARGV) {
    print "reading filenames from STDIN\n" if $verbose;
    @ARGV = <STDIN>;
    chop(@ARGV);
}

for (@ARGV) {
    my $was = $_;
    eval $op;
    die $@ if $@;
    next if $was eq $_; # ignore quietly
    if (-e $_ and !$force)
    {
        warn  "$was not renamed: $_ already exists\n";
    }
    elsif ($no_act or rename $was, $_)
    {
        print "$was renamed as $_\n" if $verbose;
    }
    else
    {
        warn  "Can't rename $was $_: $!\n";
    }
}

Capitalize all filenames in current folder (depend on perl rename)

rename 'y/A-Z/a-z/' *
rename 's/\b((?!(a|of|that|to)\b)[a-z]+)/\u$1/g' *

Turn everything to lowercase (depend on perl rename)

rename 'y/A-Z/a-z/' *

Turn everything to uppercase (depend on perl rename)

rename 'y/a-z/A-Z/' *

SVN Synchorize (auto add and delete all files recursively, also propset Id Revision keywords)

find . -name "._*" | xargs rm -Rf
svn st | grep "^?" | awk '{ print $2}' | while read f; do svn add "$f"; svn propset svn:keywords "Id Revision" "$f"; done;
svn st | grep "^!" | awk '{ print $2}' | while read f; do svn delete "$f"; done;

SVN deploy (create a “deploy” folder with all the modified and added files from a specified revision to HEAD, retaining folder structure)
Example: deploy 815 (will copy everything to ./deploy folder from revision 815 onwards)

svn diff -r $1:HEAD --summarize | grep "^A\|^M" | awk '{ print $2}' | while read f; do mkdir -p `dirname deploy/"$f"`; cp "$f" deploy/"$f"; done

Alias for dir, list just the directories and symbolic links in a directory.

alias dir='ls -Lla|grep ^d'

Svn log by revision and username
example: svn 1000:head vincent

#!/bin/bash
svn log -r $1 | sed -n "/"$2"/,/-----$/ p"

Oblivion Scheme

Posted: December 23rd, 2010 | Author: | Filed under: Linux | 1 Comment »
<style>
* {
    margin: 0;
    padding: 0;
}

div {
    float: left;
    width: 100px;
    height: 75px;
    margin: 10px;
    text-align: center;
}

#wrapper {
    float: none;
    width: 360px;
    margin: 0 auto;
}

#butter1 { background-color:  #fce94f }
#butter2 { background-color:  #edd400 }
#butter3 { background-color:  #c4a000 }

#chameleon1 { background-color:  #8ae234 }
#chameleon2 { background-color:  #73d216 }
#chameleon3 { background-color:  #4e9a06 }

#orange1 { background-color:  #fcaf3e }
#orange2 { background-color:  #f57900 }
#orange3 { background-color:  #ce5c00 }

#skyblue1 { background-color:  #729fcf }
#skyblue2 { background-color:  #3465a4 }
#skyblue3 { background-color:  #204a87 }

#plum1 { background-color:  #ad7fa8 }
#plum2 { background-color:  #75507b }
#plum3 { background-color:  #5c3566 }

#chocolate1 { background-color:  #e9b96e }
#chocolate2 { background-color:  #c17d11 }
#chocolate3 { background-color:  #8f5902 }

#scarletred1 { background-color:  #ef2929 }
#scarletred2 { background-color:  #cc0000 }
#scarletred3 { background-color:  #a40000 }

#aluminium1 { background-color:  #eeeeec }
#aluminium2 { background-color:  #d3d7cf }
#aluminium3 { background-color:  #babdb6 }
#aluminium4 { background-color:  #888a85 }
#aluminium5 { background-color:  #555753 }
#aluminium6 { background-color:  #2e3436 }
</style>

<div id="butter1"></div>
<div id="butter2"></div>
<div id="butter3"></div>
<div id="chameleon1"></div>
<div id="chameleon2"></div>
<div id="chameleon3"></div>
<div id="orange1"></div>
<div id="orange2"></div>
<div id="orange3"></div>
<div id="skyblue1"></div>
<div id="skyblue2"></div>
<div id="skyblue3"></div>
<div id="plum1"></div>
<div id="plum2"></div>
<div id="plum3"></div>
<div id="chocolate1"></div>
<div id="chocolate2"></div>
<div id="chocolate3"></div>
<div id="scarletred1"></div>
<div id="scarletred2"></div>
<div id="scarletred3"></div>
<div id="aluminium1"></div>
<div id="aluminium2"></div>
<div id="aluminium3"></div>
<div id="aluminium4"></div>
<div id="aluminium5"></div>
<div id="aluminium6"></div>

Bash command wallpaper

Posted: September 19th, 2010 | Author: | Filed under: Linux | 2 Comments »

Note: Found on reddit.com


Subversion-tools

Posted: August 21st, 2010 | Author: | Filed under: Linux | No Comments »
sudo apt-get install subversion-tools
# svn-backup-dumps: incremental dumpfile-based backup script
# svn-clean: Remove unversioned files from a working copy
# svn-fast-backup: rsync-based backup script for FSFS repositories
# svn-hot-backup: backup script, primarily for BDB repositories
# svn_apply_autoprops: Apply property settings from .subversion/config file to an existing repository
# svn2cl: Generate GNU-style changelog from repository history
# svnmerge: Maintain merge history between two related branches
# svnwrap: Set umask to 002 before calling svn or svnserve
# several example hook scripts: commit-access-control, commit-email, log-police, mailer, svnperms, verify-po

Sass and Haml

Posted: August 17th, 2010 | Author: | Filed under: Linux | No Comments »
sudo apt-get install ruby rubygems1.8
sudo su
gem install haml-edge
vim /etc/environment
# add to PATH
/var/lib/gems/1.8/bin
# add sass watch to scss
sass --watch style.scss:style.css

Make your own mini ubuntu server

Posted: August 16th, 2010 | Author: | Filed under: Linux | No Comments »
# https://help.ubuntu.com/community/Installation/MinimalCD
sudo apt-get install build-essential vim
sudo mount /dev/cdrom /media/cdrom
sudo ./media/cdrom/VBoxLinuxAdditions-amd64.run
sudo dd if=/dev/zero of=/mnt/swap bs=1M count=2000
sudo mkswap /mnt/swap
sudo swapon /mnt/swap
sudo vim /etc/fstab
# /mnt/swap none swap sw 0 0
sudo vim /etc/sysctl.conf
# vm.swappiness=10
sudo apt-get install localepurge
sudo localepurge

Getting Ubuntu works with proxy

Posted: July 15th, 2010 | Author: | Filed under: Linux | No Comments »

This is a problem in Lucid Lynx and potentially also in other versions. If you need a proxy for your network to work, here is the things you need to do.

Source: http://www.uluga.ubuntuforums.org/showthread.php?t=1468738

1) System -> Preferences -> Network proxy

Manual proxy configuration, Use the same proxy for all protocols
HTTP proxy: http://your.proxy.address/ Port: 8081

Click “Apply System-Wide”

2) Synaptic Package Manager

Preferences -> Network tab
Manual config
HTTP proxy: your.proxy.address Port: 8081
FTP proxy: your.proxy.address Port: 8081

3) gksu gedit ~/.bashrc & # add, the following lines at the end:

export https_proxy=https://your.proxy.address:8081
export http_proxy=http://your.proxy.address:8081
export ftp_proxy=ftp://your.proxy.address:8081

4) gksu gedit /etc/wgetrc & # Uncomment or add the lines

https_proxy = https://your.proxy.address:8081/
http_proxy = http://your.proxy.address:8081/
ftp_proxy  = ftp://your.proxy.address:8081/
use_proxy = on

5) gksu gedit /etc/apt/apt.conf & # Add or modify the lines

Acquire::https::proxy "https://your.proxy.address:8081/";
Acquire::http::proxy "http://your.proxy.address:8081/";
Acquire::ftp::proxy "ftp://your.proxy.address:8081/";

Regular Expression Tester

Posted: July 13th, 2010 | Author: | Filed under: Linux | Tags: | No Comments »

http://www.gethifi.com/tools/regex


Netbean Fonts & Colors Profile – Oblivion Revival

Posted: June 7th, 2010 | Author: | Filed under: Linux | 32 Comments »

*update 2011-02-10
A IntelliJ/PhpStorm port of this is released here

*update 2010-08-27
Updated the color per Conrad’s request

Made this based on the Oblivion color scheme on gEdit, it colors PHP/CSS/Javascript/HTML/etc in Netbeans, should work in all Netbean 6 versions.

PHP

HTML

JavaScript

CSS

Download: oblivion_revival
Use the Import function in options to import this color scheme.
Tested under Netbeans 6.9. Remember to choose font & color in your options to enable this.


Ubuntu Start

Posted: May 19th, 2010 | Author: | Filed under: Linux | Tags: | No Comments »

https://launchpad.net/ubuntustart


Advanced SVN – Give SVN a web interface

Posted: May 3rd, 2010 | Author: | Filed under: Linux | 1 Comment »

Install required applications

To do this we will need subversion, libapache2-svn, and of course LAMP stack lamp-server.

# Install lamp-server
sudo apt-get install lamp-server^

# Optional: phpmyadmin and mods for apache
sudo apt-get install libapache2-mod-auth-mysql phpmyadmin
sudo a2enmod vhost_alias rewrite

# Install subversion
sudo apt-get install subversion subversion-tools

# Install libapache2-svn
sudo apt-get install libapache2-svn

Now some more preparation to do.

# SSL
sudo a2enmod ssl

# Regenerate self-signed ssl key if you want
sudo make-ssl-cert generate-default-snakeoil --force-overwrite

Users, folders and groups

Next step we need to add svn usergroups, but not before we fix show all users.

Launch gconf-editor, check “showall” in /apps/gnome-system-tools/users.

Then run Users and Groups in System -> Administration. In Manage Groups, click Add. Name the new group subversion, add yourself and www-data to the member. Log out and log in to activate this.

*Note: all your team members need to be added into subversion group.

The repository

Now, time to create the repository.

sudo mkdir /home/svn
sudo mkdir /home/svn/NEWPROJECTNAME
sudo svnadmin create /home/svn/NEWPROJECTNAME
sudo chown -R www-data:subversion /home/svn/NEWPROJECTNAME
sudo chmod -R 765 /home/svn/NEWPROJECTNAME

# If files under NEWPROJECTNAME/ don't have all group access repeat the previous command again.

Now time to tell apache to set up the access to this repository:

# Add the following content to /etc/apache2/mods-available/dav_svn.conf to make all your repository available. Or add them to each website in /etc/apache2/sites-available

<Location /svn>
 DAV svn
 SVNParentPath /home/svn
 SVNListParentPath On
 AuthType Basic
 AuthName "Subversion Repository"
 AuthUserFile /etc/apache2/dav_svn.passwd
 <LimitExcept GET PROPFIND OPTIONS REPORT>
 Require valid-user
 </LimitExcept>
</Location>

# Restart apache2 after adding the content above
sudo /etc/init.d/apache2 restart

Password protection

# Now, creating the password file.
sudo htpasswd -c /etc/apache2/dav_svn.passwd SVNUSERNAME

# To add more users:
sudo htpasswd /etc/apache2/dav_svn.passwd ANOTHERUSERNAME

# Then you can access to your repository with:
svn co https://hostname/svn/PROJECTNAME PROJECTNAME --username SVNUSERNAME

How to edit grub2 boot order in Lucid Lynx

Posted: May 3rd, 2010 | Author: | Filed under: Linux | No Comments »

As everyone knows the new Ubuntu Lucid Lynx is using Grub2 instead Grub1, the setting up process has changed quite a bit.

Now if you have various boot entries and want to add, remove or re-order the boot list, you won’t find /etc/grub/menu.lst. Instead the info is stored in /boot/grub/grub.cfg. But wait, you are not supposed to edit this grub.cfg. Instead you need to go to /etc/grub.d/ folder…

In /etc/grub.d/ folder you will find a list of executables like:

  • 00_header
  • 05_debian_theme
  • 10_linux
  • 20_memory_test
  • 30_os-prober
  • 40_custom

And your boot list will be order by the numbers. In fact, 10_linux gives you the 2 lines of linux (normal and recovery mode), 20_memory_test gives you 2 lines of memory test, 30_os-probers will list whatever other systems you have on your harddisk, and 40_custom is the extra bits you can add/remove.

So, if you want to move your other OS (for example, Windows) to first, then Ubuntu, and remove memory test from the list, you delete file 20_memory_test, and rename the rest files to like this:

  • 00_header
  • 05_debian_theme
  • 10_os-prober
  • 20_linux
  • 30_custom

Now all you need to do is sudo update-grub which update your /boot/grub/grub.cfg and boot list accordingly.


xorg.conf for ATI

Posted: May 12th, 2009 | Author: | Filed under: Linux | No Comments »

This is for ATI Fire GL 5700, but most of them should be fine for any ATI card. In Ubuntu Jaunty this card scores 5000fps in glxgears -info.

Section "ServerLayout"
        Identifier     "aticonfig Layout"
        Screen      0  "aticonfig-Screen[0]-0" 0 0
        Option      "AIGLX" "on"
EndSection

Section "Files"
EndSection

Section "Module"
        Load  "glx"
EndSection

Section "Monitor"
        Identifier   "aticonfig-Monitor[0]-0"
        Option      "VendorName" "ATI Proprietary Driver"
        Option      "ModelName" "Generic Autodetecting Monitor"
        Option      "DPMS" "true"
EndSection

Section "Device"
        Identifier  "aticonfig-Device[0]-0"
        Driver      "fglrx"
        Option      "XAANoOffscreenPixmaps" "on"
        Option      "TexturedVideo" "on"
        Option      "VideoOverlay" "off"
        Option      "OpenGLOverlay" "off"
        Option      "Textured2D" "on"
        Option      "UseFastTLS" "1"
        Option      "BackingStore" "on"
        BusID       "PCI:1:0:0"
EndSection

Section "Screen"
        Identifier "aticonfig-Screen[0]-0"
        Device     "aticonfig-Device[0]-0"
        Monitor    "aticonfig-Monitor[0]-0"
        DefaultDepth     24
        SubSection "Display"
                Viewport   0 0
                Depth     24
        EndSubSection
EndSection

Section "DRI"
        Group        "Video"
        Mode         0666
EndSection

Section "Extensions"
        Option      "RENDER" "Enable"
        Option      "DAMAGE" "Enable"
        Option      "Composite" "Enable"
EndSection