<commit_before>#!/bin/bash
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright Clairvoyant 2016
#
# $Id:$
#
# Program
#     Does something.
#
# EXIT CODE:
#     0 = success
#     1 = print_help function (or incorrect commandline)
#     2 = ERROR: Must be root.
#
AUTHOR="<NAME> <<EMAIL>>"
VERSION=YYYYMMDD
#
if [ $DEBUG ]; then set -x; fi
#
##### START CONFIG ###################################################

##### STOP CONFIG ####################################################
PATH=/usr/bin:/usr/sbin:/bin:/sbin
FSTYPE=xfs
FSMOUNTOPT=noatime

# Function to print the help screen.
print_help () {
  printf "Usage:  $1 --mountpoint <mountpoint>\n"
  printf "\n"
  printf "         -m|--mountpoint       Mountpoint of the unencrypted filesystem.\n"
  printf "        [-h|--help]\n"
  printf "        [-v|--version]\n"
  printf "\n"
  printf "   ex.  $1 --navpass \"<PASSWORD>\" --mountpoint /data/2\n"
  exit 1
}

# Function to check for root priviledges.
check_root () {
  if [[ `/usr/bin/id | awk -F= '{print $2}' | awk -F"(" '{print $1}' 2>/dev/null` -ne 0 ]]; then
    printf "You must have root priviledges to run this program.\n"
    exit 2
  fi
}

## If the variable DEBUG is set, then turn on tracing.
## http://www.research.att.com/lists/ast-users/2003/05/msg00009.html
#if [ $DEBUG ]; then
#  # This will turn on the ksh xtrace option for mainline code
#  set -x
#
#  # This will turn on the ksh xtrace option for all functions
#  typeset +f |
#  while read F junk
#  do
#    typeset -ft $F
#  done
#  unset F junk
#fi

# Process arguments.
while [[ $1 = -* ]]; do
  case $1 in
    -m|--mountpoint)
      shift
      MOUNTPOINT=$1
      ;;
    -h|--help)
      print_help "$(basename $0)"
      ;;
    -v|--version)
      printf "\tProgram\n"
      printf "\tVersion: $VERSION\n"
      printf "\tWritten by: $AUTHOR\n"
      exit 0
      ;;
    *)
      print_help "$(basename $0)"
      ;;
  esac
  shift
done

# Check to see if we have no parameters.
if [[ -z "$MOUNTPOINT" ]]; then print_help "$(basename $0)"; fi

# Lets not bother continuing unless we have the privs to do something.
check_root

# main
if [ ! -f /etc/navencrypt/keytrustee/clientname ]; then
  printf "** WARNING: This host is not yet registered.  Skipping..."
  exit 3
fi
if ! mountpoint -q ${MOUNTPOINT}; then
  printf "** ERROR: ${MOUNTPOINT} is not a mountpoint. Exiting..."
  exit 4
fi
if [ -d ${MOUNTPOINT}tmp ]; then
  printf "** ERROR: ${MOUNTPOINT}tmp exists.  Is another move process running?  Exiting..."
  exit 5
fi

ESCMOUNTPOINT=$(echo $MOUNTPOINT | sed -e 's|/|\\/|g')
FULLDEVICE=$(mount | awk "\$3~/${ESCMOUNTPOINT}\$/{print \$1}")
ESCFULLDEVICE=$(echo $FULLDEVICE | sed -e 's|/|\\/|g')
# Find the parent device (ie not the partition).
DEVICE=$(echo $FULLDEVICE | sed -e 's|[0-9]$||')
if [ ! -b $DEVICE ]; then
  DEVICE=$(echo $DEVICE | sed -e 's|.$||')
  if [ ! -b $DEVICE ]; then
    printf "** ERROR: ${DEVICE} does not exist. Exiting..."
    exit 6
  fi
fi
# Check to make sure we do not wipe a LVM.
if ! echo $DEVICE | grep -q ^/dev/sd ;then
  printf "** ERROR: ${DEVICE} is not an sd device. Exiting..."
  exit 7
fi
# Add a check to make sure there is not another partition on the device (ie rootfs on sda1 with data on sda2).
# Add a check to make sure there is enough space in /data<commit_msg>Add a check to make sure there is enough space.<commit_after>#!/bin/bash
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright Clairvoyant 2016
#
# $Id:$
#
# Program
#     Does something.
#
# EXIT CODE:
#     0 = success
#     1 = print_help function (or incorrect commandline)
#     2 = ERROR: Must be root.
#
AUTHOR="<NAME> <<EMAIL>>"
VERSION=YYYYMMDD
#
if [ $DEBUG ]; then set -x; fi
#
##### START CONFIG ###################################################

##### STOP CONFIG ####################################################
PATH=/usr/bin:/usr/sbin:/bin:/sbin
FSTYPE=xfs
FSMOUNTOPT=noatime

# Function to print the help screen.
print_help () {
  printf "Usage:  $1 --mountpoint <mountpoint>\n"
  printf "\n"
  printf "         -m|--mountpoint       Mountpoint of the unencrypted filesystem.\n"
  printf "        [-h|--help]\n"
  printf "        [-v|--version]\n"
  printf "\n"
  printf "   ex.  $1 --navpass \"<PASSWORD>\" --mountpoint /data/2\n"
  exit 1
}

# Function to check for root priviledges.
check_root () {
  if [[ `/usr/bin/id | awk -F= '{print $2}' | awk -F"(" '{print $1}' 2>/dev/null` -ne 0 ]]; then
    printf "You must have root priviledges to run this program.\n"
    exit 2
  fi
}

## If the variable DEBUG is set, then turn on tracing.
## http://www.research.att.com/lists/ast-users/2003/05/msg00009.html
#if [ $DEBUG ]; then
#  # This will turn on the ksh xtrace option for mainline code
#  set -x
#
#  # This will turn on the ksh xtrace option for all functions
#  typeset +f |
#  while read F junk
#  do
#    typeset -ft $F
#  done
#  unset F junk
#fi

# Process arguments.
while [[ $1 = -* ]]; do
  case $1 in
    -m|--mountpoint)
      shift
      MOUNTPOINT=$1
      ;;
    -h|--help)
      print_help "$(basename $0)"
      ;;
    -v|--version)
      printf "\tProgram\n"
      printf "\tVersion: $VERSION\n"
      printf "\tWritten by: $AUTHOR\n"
      exit 0
      ;;
    *)
      print_help "$(basename $0)"
      ;;
  esac
  shift
done

# Check to see if we have no parameters.
if [[ -z "$MOUNTPOINT" ]]; then print_help "$(basename $0)"; fi

# Lets not bother continuing unless we have the privs to do something.
check_root

# main
if [ ! -f /etc/navencrypt/keytrustee/clientname ]; then
  printf "** WARNING: This host is not yet registered.  Skipping..."
  exit 3
fi
if ! mountpoint -q ${MOUNTPOINT}; then
  printf "** ERROR: ${MOUNTPOINT} is not a mountpoint. Exiting..."
  exit 4
fi
if [ -d ${MOUNTPOINT}tmp ]; then
  printf "** ERROR: ${MOUNTPOINT}tmp exists.  Is another move process running?  Exiting..."
  exit 5
fi

ESCMOUNTPOINT=$(echo $MOUNTPOINT | sed -e 's|/|\\/|g')
FULLDEVICE=$(mount | awk "\$3~/${ESCMOUNTPOINT}\$/{print \$1}")
ESCFULLDEVICE=$(echo $FULLDEVICE | sed -e 's|/|\\/|g')
# Find the parent device (ie not the partition).
DEVICE=$(echo $FULLDEVICE | sed -e 's|[0-9]$||')
if [ ! -b $DEVICE ]; then
  DEVICE=$(echo $DEVICE | sed -e 's|.$||')
  if [ ! -b $DEVICE ]; then
    printf "** ERROR: ${DEVICE} does not exist. Exiting..."
    exit 6
  fi
fi
# Check to make sure we do not wipe a LVM.
if ! echo $DEVICE | grep -q ^/dev/sd ;then
  printf "** ERROR: ${DEVICE} is not an sd device. Exiting..."
  exit 7
fi
# Add a check to make sure there is not another partition on the device (ie rootfs on sda1 with data on sda2).
# Add a check to make sure there is enough space in /data
_USED=$(df $MOUNTPOINT | awk '$3~/^[0-9]/{print $3}')
_FREE=$(df ${MOUNTPOINT}/.. | awk '$4~/^[0-9]/{print $4}')
if [ "$_FREE" -lt "$_USED" ]; then
  printf "** ERROR: $(realpath ${MOUNTPOINT}/..) does not have enough space for data in ${MOUNTPOINT}. Exiting..."
  exit 9
fi
{'fraction_non_alphanumeric': 0.1714826498422713, 'fraction_numerical': 0.013501577287066246, 'mean_word_length': 3.013164556962025, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2473655', 'n_tokens_mistral': 2745, 'n_tokens_neox': 2647, 'n_words': 972}