<commit_before>#!/bin/bash
set -e

CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
KINETIC_DIR="/home/$USER/work/ros-kinetic"

RED='\033[0;31m'
YEL='\033[1;33m'
NC='\033[0m' # No Color

SKIP_UPDATES=0
NO_GPU=1

echo -e "${YEL}CURRENT_DIR: $CURRENT_DIR${NC}"
echo -e "${YEL}KINETIC_DIR: $KINETIC_DIR${NC}"

# Ask for SSH passphrase
if [ -z "$SSH_AUTH_SOCK" ];
then
  ssh-add
fi

if [ ! -f /etc/apt/sources.list.d/ros-latest.list ];
then
  echo -e "${YEL}Configure apt sources.${NC}"
  sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
  sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 0xB01FA116
fi
if [ ! $SKIP_UPDATES -eq 1 ];
then
  echo -e "${YEL}Updating apt.${NC}"
  sudo apt-get update
else
  echo -e "${RED}Updating apt - skipped.${NC}"
fi

echo -e "${YEL}Installing dependencies.${NC}"
sudo apt-get install -y python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential
# FIXME: `python-numpy` not included in OpenCV3 dependencies.
sudo apt-get install -y python-catkin-tools python-numpy

if [ ! -f /etc/ros/rosdep/sources.list.d/20-default.list ];
then
  echo -e "${YEL}Initialising rosdep.${NC}"
  sudo rosdep init
fi

# TODO: Add `/etc/ros/rosdep/local.yaml` with `python-pyassimp`
if [ ! -f /etc/ros/rosdep/local.yaml ];
then
  echo -e "${YEL}Creating rosdep local.yaml.${NC}"
  sudo tee /etc/ros/rosdep/local.yaml << EOF
python-pyassimp:
    debian:
      jessie:
        apt: [python-pyassimp]
EOF
fi
if [ ! -f /etc/ros/rosdep/sources.list.d/10-local.list ];
then
  echo -e "${YEL}Adding rosdep local.yaml.${NC}"
  sudo tee /etc/ros/rosdep/sources.list.d/10-local.list << EOF
yaml file:///etc/ros/rosdep/local.yaml
EOF
fi

if [ ! $SKIP_UPDATES -eq 1 ];
then
  echo -e "${YEL}Updating rosdep.${NC}"
  rosdep update
else
  echo -e "${RED}Updating rosdep - skipped.${NC}"
fi

# Create workspaces given path and rosinstall file.
function workspace {
  DIR="$KINETIC_DIR/$1" # Workspace path
  ROS=$2 # rosinstall file

  if [ -z "$3" ];
  then
    EXT=""
  else
    EXT="$KINETIC_DIR/$3" # Extend workspace
  fi

  echo -e "${YEL}Workspace: $DIR - $ROS${NC}"

  if [ ! -d $DIR ];
  then
    echo -e "${YEL}Creating Catkin workspace.${NC}"
    mkdir -p $DIR
  fi

  echo -e "${YEL}Copying $ROS to workspace.${NC}"
  cp -u $CURRENT_DIR/$ROS $DIR/$ROS

  if [ ! -f $DIR/src/.rosinstall ];
  then
    echo -e "${YEL}Generating ROS workspace.${NC}"
    # FIXME: Using own `.rosinstall` file to avoid broken packages. Could merge my changes.
    #rosinstall_generator desktop_full --rosdistro kinetic --deps --wet-only > kinetic-desktop-full-wet.rosinstall
    #wstool init -j8 src kinetic-desktop-full-wet.rosinstall
    wstool init -j8 $DIR/src $DIR/$ROS
  else
    # Merge in any updates to original rosinstall.
    wstool merge -ky -t $DIR/src $DIR/$ROS
    if [ ! $SKIP_UPDATES -eq 1 ];
    then
      echo -e "${YEL}Updating ROS workspace.${NC}"
      wstool update -j8 -t $DIR/src
    else
      echo -e "${RED}Updating ROS workspace - skipped.${NC}"
    fi
  fi

  echo -e "${YEL}Configuring workspace paths.${NC}"
  catkin config --init -w$DIR #-s$DIR/src -l$DIR/log -b$DIR/build -d$DIR/devel -i$DIR/install

  if [ $NO_GPU -eq 1 ];
  then
    echo -e "${YEL}Disabling CUDA support.${NC}"
    catkin config --cmake-args -DWITH_CUDA=OFF -DBUILD_opencv_gpu=OFF
  fi

  if [ ! -z $EXT ];
  then
    echo -e "${YEL}Extending workspace $EXT.${NC}"
    catkin config --extend $EXT
  #else
  #  echo -e "${YEL}Root workspace.${NC}"
  #  catkin config --no-extend
  fi

  echo -e "${YEL}Installing dependency packages.${NC}"
  rosdep install --from-paths $DIR/src --ignore-src --rosdistro kinetic -y --os $(lsb_release -si | awk '{print tolower($0)}'):$(lsb_release -sc)

  #echo -e "${YEL}Build workspace $DIR? [Y/n]${NC}"
  #read input_variable<commit_msg>Specify workspace when configuring catkin<commit_after>#!/bin/bash
set -e

CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
KINETIC_DIR="/home/$USER/work/ros-kinetic"

RED='\033[0;31m'
YEL='\033[1;33m'
NC='\033[0m' # No Color

SKIP_UPDATES=0
NO_GPU=1

echo -e "${YEL}CURRENT_DIR: $CURRENT_DIR${NC}"
echo -e "${YEL}KINETIC_DIR: $KINETIC_DIR${NC}"

# Ask for SSH passphrase
if [ -z "$SSH_AUTH_SOCK" ];
then
  ssh-add
fi

if [ ! -f /etc/apt/sources.list.d/ros-latest.list ];
then
  echo -e "${YEL}Configure apt sources.${NC}"
  sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
  sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 0xB01FA116
fi
if [ ! $SKIP_UPDATES -eq 1 ];
then
  echo -e "${YEL}Updating apt.${NC}"
  sudo apt-get update
else
  echo -e "${RED}Updating apt - skipped.${NC}"
fi

echo -e "${YEL}Installing dependencies.${NC}"
sudo apt-get install -y python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential
# FIXME: `python-numpy` not included in OpenCV3 dependencies.
sudo apt-get install -y python-catkin-tools python-numpy

if [ ! -f /etc/ros/rosdep/sources.list.d/20-default.list ];
then
  echo -e "${YEL}Initialising rosdep.${NC}"
  sudo rosdep init
fi

# TODO: Add `/etc/ros/rosdep/local.yaml` with `python-pyassimp`
if [ ! -f /etc/ros/rosdep/local.yaml ];
then
  echo -e "${YEL}Creating rosdep local.yaml.${NC}"
  sudo tee /etc/ros/rosdep/local.yaml << EOF
python-pyassimp:
    debian:
      jessie:
        apt: [python-pyassimp]
EOF
fi
if [ ! -f /etc/ros/rosdep/sources.list.d/10-local.list ];
then
  echo -e "${YEL}Adding rosdep local.yaml.${NC}"
  sudo tee /etc/ros/rosdep/sources.list.d/10-local.list << EOF
yaml file:///etc/ros/rosdep/local.yaml
EOF
fi

if [ ! $SKIP_UPDATES -eq 1 ];
then
  echo -e "${YEL}Updating rosdep.${NC}"
  rosdep update
else
  echo -e "${RED}Updating rosdep - skipped.${NC}"
fi

# Create workspaces given path and rosinstall file.
function workspace {
  DIR="$KINETIC_DIR/$1" # Workspace path
  ROS=$2 # rosinstall file

  if [ -z "$3" ];
  then
    EXT=""
  else
    EXT="$KINETIC_DIR/$3" # Extend workspace
  fi

  echo -e "${YEL}Workspace: $DIR - $ROS${NC}"

  if [ ! -d $DIR ];
  then
    echo -e "${YEL}Creating Catkin workspace.${NC}"
    mkdir -p $DIR
  fi

  echo -e "${YEL}Copying $ROS to workspace.${NC}"
  cp -u $CURRENT_DIR/$ROS $DIR/$ROS

  if [ ! -f $DIR/src/.rosinstall ];
  then
    echo -e "${YEL}Generating ROS workspace.${NC}"
    # FIXME: Using own `.rosinstall` file to avoid broken packages. Could merge my changes.
    #rosinstall_generator desktop_full --rosdistro kinetic --deps --wet-only > kinetic-desktop-full-wet.rosinstall
    #wstool init -j8 src kinetic-desktop-full-wet.rosinstall
    wstool init -j8 $DIR/src $DIR/$ROS
  else
    # Merge in any updates to original rosinstall.
    wstool merge -ky -t $DIR/src $DIR/$ROS
    if [ ! $SKIP_UPDATES -eq 1 ];
    then
      echo -e "${YEL}Updating ROS workspace.${NC}"
      wstool update -j8 -t $DIR/src
    else
      echo -e "${RED}Updating ROS workspace - skipped.${NC}"
    fi
  fi

  echo -e "${YEL}Configuring workspace paths.${NC}"
  catkin config --init -w$DIR #-s$DIR/src -l$DIR/log -b$DIR/build -d$DIR/devel -i$DIR/install

  if [ $NO_GPU -eq 1 ];
  then
    echo -e "${YEL}Disabling CUDA support.${NC}"
    catkin config -w$DIR --cmake-args -DWITH_CUDA=OFF -DBUILD_opencv_gpu=OFF
  fi

  if [ ! -z $EXT ];
  then
    echo -e "${YEL}Extending workspace $EXT.${NC}"
    catkin config -w$DIR --extend $EXT
  #else
  #  echo -e "${YEL}Root workspace.${NC}"
  #  catkin config -w$DIR --no-extend
  fi

  echo -e "${YEL}Installing dependency packages.${NC}"
  rosdep install --from-paths $DIR/src --ignore-src --rosdistro kinetic -y --os $(lsb_release -si | awk '{print tolower($0)}'):$(lsb_release -sc)

  #echo -e "${YEL}Build workspace $DIR? [Y/n]${NC}"
  #read input_variable
{'fraction_non_alphanumeric': 0.1693968253968254, 'fraction_numerical': 0.011682539682539683, 'mean_word_length': 3.196057538625466, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '567618', 'n_tokens_mistral': 3220, 'n_tokens_neox': 3047, 'n_words': 782}