<commit_before>#!/bin/bash

PREFIX=/opt/beehive
MOUNT_BASE=$PREFIX/mnt

# mount a bee!
APP_NAME=[[APP_NAME]]
MOUNT_LOCATION=$MOUNT_BASE/$APP_NAME
LOOP_DEVICE=/dev/$APP_NAME
MOUNT_FILE=[[BEE_IMAGE]]

echo "mount $MOUNT_FILE $MOUNT_LOCATION -t squashfs -o ro -o loop=$LOOP_DEVICE" > /tmp/out
OUT=$(mount $MOUNT_FILE $MOUNT_LOCATION -t squashfs -o ro -o loop=$LOOP_DEVICE)

echo "path $MOUNT_LOCATION"<commit_msg>Added chrooted user for mount-bee Added bind mounting and umounting for apps in mount-bee script<commit_after>#!/bin/bash

PREFIX=/opt/beehive
MOUNT_BASE=$PREFIX/mnt

# mount a bee!
APP_NAME=[[APP_NAME]]
MOUNT_LOCATION=$MOUNT_BASE/$APP_NAME
LOOP_DEVICE=/dev/$APP_NAME
MOUNT_FILE=[[BEE_IMAGE]]

# Unmount the device if it's already mounted
MOUNTED=$(mount | grep $APP_NAME | awk '{a[i++]=$3} END {for (j=i-1; j>=0;) print a[j--] }')
for i in $MOUNTED; do
  sudo umount $i -f >/dev/null 2>&1
done
sudo umount $LOOP_DEVICE >/dev/null 2>&1


if [ ! -e $LOOP_DEVICE ]; then
  mknod -m 600 $LOOP_DEVICE b 7 0
fi

mkdir -p $MOUNT_LOCATION

# Create chroot user
CHROOT_USER="[[APP_NAME]]"

if [ $(sudo cat /etc/passwd | grep $CHROOT_USER | grep -v "#" | wc -l) -eq 0 ]; then
  useradd -s /bin/sh -d $MOUNT_LOCATION/./ -c "$APP_NAME user" -g users $CHROOT_USER;
else
  echo "";
fi

chown -R $CHROOT_USER $MOUNT_LOCATION
chmod 700 $MOUNT_LOCATION

# Mount it!
mount $MOUNT_FILE $MOUNT_LOCATION -t squashfs -o ro -o loop=$LOOP_DEVICE

# Bind mount the system
mount --bind /bin $MOUNT_LOCATION/bin -o ro
mount --bind /etc $MOUNT_LOCATION/etc -o ro
mount --bind /usr $MOUNT_LOCATION/usr -o ro
mount --bind /lib $MOUNT_LOCATION/lib -o ro
mount --bind /dev $MOUNT_LOCATION/dev -o ro
mount -t proc /proc $MOUNT_LOCATION/proc
mount --bind /tmp $MOUNT_LOCATION/tmp -o rw

# If there is a lib64 directory 
if [ -d /lib64 ]; then
  sudo mount --bind /lib64 $MOUNT_LOCATION/lib64 -o ro
fi

sudo /usr/sbin/chroot $MOUNT_LOCATION /usr/bin/env -i \
         HOME=$MOUNT_LOCATION \
         TERM=$TERM PS1='\u:\w\$ ' \
         HI="hi" \
       	/bin/bash --login -c "echo 'Welcome!'";


echo "app_name [[APP_NAME]]"
echo "path $MOUNT_LOCATION"
{'fraction_non_alphanumeric': 0.14513856270549555, 'fraction_numerical': 0.011742602160638797, 'mean_word_length': 3.7865168539325844, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5287659', 'n_tokens_mistral': 903, 'n_tokens_neox': 854, 'n_words': 238}