Wednesday, August 3, 2016

Bash Shell Built Into Windows 10 Anniversary Update 1607 Build 14393.10

After Windows 10 Anniversary Update, you have to enable "Developer mode" on the "Update & Security" page.
Then go to Control Panel -> Program and Features -> Turn Windows Features on or off -> Windows SubSystem for Linux (Beta), and click OK.

Bash Shell is only for 64-bit versions of Windows 10.

Bash Shortcut Keys
There are a number of very useful shortcut keys you can use in the bash shell:

Ctrl + U: Clears the line from the cursor point back to the beginning.
Ctrl + A: Moves the cursor to the beginning of the line.
Ctrl + E: Moves the cursor to the end of the line.
Ctrl + Left / Right: Moves the cursor to one word Left / Right.
Ctrl + R: Allows you to search through the previous commands.

Batch Rename Files
rename –v 's/foo/bar/g' *

Customize command line prompt
function prompt
{
local WHITE="\[\033[1;37m\]"
local GREEN="\[\033[0;32m\]"
local CYAN="\[\033[0;36m\]"
local GRAY="\[\033[0;37m\]"
local BLUE="\[\033[0;34m\]"
export PS1="${GREEN}\u${CYAN}@${BLUE}\h ${CYAN}\w${GRAY}$ "
}
prompt


where
\u refers to the current username
\h refers to the host name
\w refers to the current file path.

or simply uncomment the line force_color_prompt=yes in ~/.bashrc

You can use Docker for Windows as engine and docker client for linux in bash. "Docker for Windows" requires Windows 10 Pro 64-bit and Hyper-V Package.

To install docker client for Linux under bash shell
cd ~/
wget https://get.docker.com/builds/Linux/x86_64/docker-1.12.0.tgz
tar -xzvf docker-1.12.0.tgz
cd docker
./docker -H tcp://0.0.0.0:2375 ps


Or simply add the corresponding variables to ~/.bashrc
export DOCKER_HOST=tcp://0.0.0.0:2375
export PATH=$PATH:~/docker

To detach the docker tty without exiting the shell, use the escape sequence Ctrl-p + Ctrl-q


Install docker-compose and try docker-compose example as per https://docs.docker.com/compose/wordpress/
shell script    Select all
# install dcoker-compose curl -L https://github.com/docker/compose/releases/download/1.8.0/docker-compose-`uname -s`-`uname -m` > ~/docker/docker-compose chmod +x ~/docker/docker-compose docker-compose --version # try docker-compose example on wordpress and mysql images cd $HOME mkdir my-wordpress cd my-wordpress cat > docker-compose.yaml <<EOF version: '2' services: db: image: mysql:5.7 volumes: - "./.data/db:/var/lib/mysql" restart: always environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest links: - db ports: - "8000:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_PASSWORD: wordpress EOF # start the docker-compose example docker-compose up -d # then try browser http://localhost:8000/ # stop the docker-compose example docker-compose down


Swift 3 on Ubuntu (14.04 LTS trusty) for Windows 10 bash shell

You need to download and extract the development snapshot (Ubuntu 14.04) from swift.org and do these under bash shell.
shell script    Select all
# download and extract swift 3 snapshot cd ~/ wget https://swift.org/builds/development/ubuntu1404/swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a/swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a-ubuntu14.04.tar.gz tar xzvf swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a-ubuntu14.04.tar.gz # the latest snapshot 2016-08-23 has libdispatch cd ~/ wget https://swift.org/builds/development/ubuntu1404/swift-DEVELOPMENT-SNAPSHOT-2016-08-23-a/swift-DEVELOPMENT-SNAPSHOT-2016-08-23-a-ubuntu14.04.tar.gz tar xzvf swift-DEVELOPMENT-SNAPSHOT-2016-08-23-a-ubuntu14.04.tar.gz # Swift 3.0 GM Candidate cd ~/ wget https://swift.org/builds/swift-3.0-GM-CANDIDATE/ubuntu1404/swift-3.0-GM-CANDIDATE/swift-3.0-GM-CANDIDATE-ubuntu14.04.tar.gz tar xzvf swift-3.0-GM-CANDIDATE-ubuntu14.04.tar.gz # Swift 3.0.2 Release cd ~/ wget https://swift.org/builds/swift-3.0.2-release/ubuntu1404/swift-3.0.2-RELEASE/swift-3.0.2-RELEASE-ubuntu14.04.tar.gz tar xzvf swift-3.0.2-RELEASE-ubuntu14.04.tar.gz # install and configure clang plus other tools sudo apt-get update sudo apt-get install -y libicu-dev uuid-dev clang-3.6 sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100 sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100 sudo apt-get install -y git build-essential # clears the executable stack flag of shared library sudo apt-get install -y execstack sudo execstack -c ~/swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a-ubuntu14.04/usr/lib/swift/linux/libFoundation.so sudo execstack -c ~/swift-DEVELOPMENT-SNAPSHOT-2016-08-23-a-ubuntu14.04/usr/lib/swift/linux/libFoundation.so sudo execstack -c ~/swift-3.0-GM-CANDIDATE-ubuntu14.04/usr/lib/swift/linux/libFoundation.so sudo execstack -c ~/swift-3.0.2-RELEASE-ubuntu14.04/usr/lib/swift/linux/libFoundation.so # add path in ~/.bashrc export PATH=$PATH:~/swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a-ubuntu14.04/usr/bin export PATH=$PATH:~/swift-DEVELOPMENT-SNAPSHOT-2016-08-23-a-ubuntu14.04/usr/bin export PATH=$PATH:~/swift-3.0-GM-CANDIDATE-ubuntu14.04/usr/bin export PATH=$PATH:~/swift-3.0.2-RELEASE-ubuntu14.04/usr/bin # test Foundation, libdispatch and swiftc compile cat > hello.swift <<EOF import Foundation let device = "WIN10" print("Hello from Swift on \(device)") //print("\(TimeZone.defaultTimeZone().name) \(NSDate())") // for old snapshot 2016-08-04 //print("\(NSTimeZone.defaultTimeZone().abbreviation()!) \(NSDate())") // for old snapshot 2016-08-23 print("\(NSTimeZone.default.abbreviation()!) \(NSDate())") // for Swift 3.0 GM Candidate // Test libdispatch import Dispatch var my_dispatch_group = DispatchGroup() let concurrentQueue = DispatchQueue(label: "myqueuename", attributes: DispatchQueue.Attributes.concurrent) for a in 1...20 { my_dispatch_group.enter() let block = DispatchWorkItem { print("do something at \(a)") } my_dispatch_group.leave() my_dispatch_group.notify(queue: concurrentQueue, work:block) } let item = DispatchWorkItem { print("PROGRAM ENDED \(NSTimeZone.default.abbreviation()!) \(NSDate())") } my_dispatch_group.notify(queue: DispatchQueue.global(qos:.userInitiated), work:item) print("press enter to exit") let _ = readLine(strippingNewline: true) EOF swiftc hello.swift ./hello # test Swift Package Manager mkdir -p $HOME/test1 cd $HOME/test1 swift package init swift test


Install node.js and mongo shell for Ubuntu
shell script    Select all
# download and extract node.js cd ~/ wget https://nodejs.org/dist/v4.4.7/node-v4.4.7-linux-x64.tar.xz tar xpvf node-v4.4.7-linux-x64.tar.xz # add path in ~/.bashrc export PATH=$PATH:~/node-v4.4.7-linux-x64/bin node --version npm --version # install mongo shell for version 3.2.8 # please refer to instructions here https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list sudo apt-get update sudo apt-get install -y mongodb-org-shell=3.2.8 # if you follow the previous post on nodeapi.zip example # you need to install mongodb server on the Windows platform # in order to test that example.


File System Access

Ubuntu filesystem from Windows Explorer
C:\Users\%USERNAME%\AppData\Local\Lxss\rootfs
Ubuntu 16.04 filesystem from Windows Explorer, Fall Creators Update (2017 Oct)
C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\

Windows filesystem from Ubuntu bash
/mnt/c/
/mnt/d/

#edit ~/.bashrc
#add export LS_COLORS=$LS_COLORS:'di=1;44:' ; # dir white on blue background


To upgrade to Ubuntu 16.04 after Windows 10's Creators Update (2017 April)
open the Bash shell and run the following command:


sudo do-release-upgrade

lsb_release -a

However, lxrun /uninstall then lxrun /install is faster.


The lastest installtion of WSL is documented at https://docs.microsoft.com/en-us/windows/wsl/install-win10
where different and multiple distros can be installed via Microsoft Store since Fall Creators Update (2017 Oct).


Installation of Swift 3.1.1 in Ubuntu 16.04
shell script    Select all
# Install related packages and set LLVM 3.8 as the compiler sudo apt-get -q update && sudo apt-get -q install -y make libc6-dev clang-3.8 curl libedit-dev libicu-dev libssl-dev libxml2 git libcurl4-openssl-dev pkg-config sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.8 100 sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.8 100 curl -fSLO https://swift.org/builds/swift-3.1.1-release/ubuntu1604/swift-3.1.1-RELEASE/swift-3.1.1-RELEASE-ubuntu16.04.tar.gz # Swift 4.0 # https://swift.org/builds/swift-4.0-release/ubuntu1604/swift-4.0-RELEASE/swift-4.0-RELEASE-ubuntu16.04.tar.gz tar xzvf swift-3.1.1-RELEASE-ubuntu16.04.tar.gz export PATH=$PATH:$HOME/swift-3.1.1-RELEASE-ubuntu16.04/usr/bin #test Hello mkdir Hello cd Hello/ swiftc --version swift package init --type=executable swift build ./.build/debug/Hello # test Swift Package Manager mkdir -p $HOME/SessionState cd $HOME/SessionState swift package init --type library cat > $HOME/SessionState/Sources/SessionState.swift <<EOF // SessionState.swift import Foundation import Dispatch public class SessionState { private var storage = [String:Any]() // serial access to internal dictionary // private let syncQueue = DispatchQueue(label:"serializationQueue") // change to concurrent queue private let asyncQueue = DispatchQueue(label:"asyncQueue", attributes:.concurrent, target:nil) private init() {} public static let shared:SessionState = { let instance = SessionState() return instance } () public func set( _ value: Any, forKey key: String) { asyncQueue.sync(flags: .barrier) { // change to barrier queue to have serial write access // syncQueue.sync { storage[key] = value } } public func object (forKey key: String) -> Any? { var result: Any? asyncQueue.sync { result = storage[key] ?? nil } return result } } EOF cat > $HOME/SessionState/Tests/SessionStateTests/SessionStateTests.swift <<EOF //SessionStateTests.swift import XCTest import Dispatch @testable import SessionState class SessionStateTests:XCTestCase { override func setUp() { super.setUp() } override func tearDown() { super.tearDown() } func testConcurrentAccess() { let asyncQueue = DispatchQueue( label: "asyncQueue", attributes: .concurrent, target: nil ) let expect = expectation(description: "Storing value in SessionState shall succeed") let MaxIndex = 2000 for index in 0...MaxIndex { asyncQueue.async { SessionState.shared.set ( index, forKey: String(index) ) } } while SessionState.shared.object(forKey: String(MaxIndex)) as? Int != MaxIndex { //nop } expect.fulfill() waitForExpectations(timeout:10) { (error) in XCTAssertNil(error, "Test expectation failed") } } static var allTests = [ ("testConcurrentAccess", testConcurrentAccess), ] } EOF # build and test swift test # Compile and install Boost sudo apt-get -q install -y build-essential cd $HOME curl -O https://nchc.dl.sourceforge.net/project/boost/boost/1.62.0/boost_1_62_0.tar.bz2 tar xjvf boost_1_62_0.tar.bz2 cd boost_1_62_0/ ./bootstrap.sh --with-libraries=atomic,chrono,date_time,exception,filesystem,graph,iostreams,math,program_options,random,regex,serialization,signals,system,test,thread,wave --prefix=/usr ./b2 -j6 toolset=gcc address-model=64 threading=multi link=static sudo ./b2 install # Compile and install QuantLib cd $HOME curl -O https://jaist.dl.sourceforge.net/project/quantlib/QuantLib/1.10/QuantLib-1.10.tar.gz tar xzvf QuantLib-1.10.tar.gz # QuantLib 1.11 download link # https://jaist.dl.sourceforge.net/project/quantlib/QuantLib/1.11/QuantLib-1.11.tar.gz cd QuantLib-1.10/ ./configure --prefix=/usr --enable-static --disable-examples make -j6 sudo make install # to remove -> sudo make uninstall # test QuantLib cd $HOME cat > $HOME/qlversion.cpp <<EOF #include <iostream> #include <ql/version.hpp> int main() { std::cout << "Current QL Version:" << QL_LIB_VERSION << std::endl; return 0; } EOF g++ qlversion.cpp -o qlversion ./qlversion # Following this instruction to install QuantLib Python # http://quantlib.org/install/linux-python.shtml



Installation of Swift 4 for Cygwin64
shell script    Select all
# first install Cygwin64 in Windows # In Cygwin64 Terminal prompt wget -q https://github.com/tinysun212/swift-windows/releases/download/swift-4.0.3%2Bcygwin.20180212/swift-4.0.3.cygwin.20180212-bin.tar.gz tar zxf swift-4.0.3.cygwin.20180212-bin.tar.gz export PATH=$PATH:$(pwd)/usr/bin swift --version # test git clone https://github.com/apple/example-package-dealer.git cd example-package-dealer swift run Dealer



No comments: