apiVersion: batch/v1
kind: Job
metadata:
  name: bbrf-new-BBS_PROJECT_CODE
  labels:
    app: bbrf-new-BBS_PROJECT_CODE
spec:
  ttlSecondsAfterFinished: 100
  template:
    metadata:
      labels:
        app: bbrf-new-BBS_PROJECT_CODE
    spec:
      volumes:
      - name: data-volume
        hostPath: 
          path: /mnt/volume_lon1_01
          type: Directory
      containers:
      - name: bbrf-new-BBS_PROJECT_CODE
        image: smokingcaterpillar/bbs-osintel-github-subs
        volumeMounts:
        - name: data-volume
          mountPath: /optdata
        command: 
        - /bin/sh
        - -c
        - |
          echo bbrf-new v1
          echo Code: BBS_PROJECT_CODE
          echo Id: BBS_PROJECT_ID
          echo List: BBS_PROJECT_LIST
          
          ## BBRF SETUP ##
          echo setting up BBRF...
          cp /optdata/BBS/output/private/bbrs-config.json /root/.bbrf/config.json
          bbrf new BBS_PROJECT_CODE
          bbrf use BBS_PROJECT_CODE
          ## BBRF SETUP ##
          
          mkdir -p /optdata/BBS/output/project-data/BBS_PROJECT_CODE/scope-given/
          
          #copy data from nextcloud shared folder
          cp /optdata/BBS/output/private/nextcloud-https-V7/data/__groupfolders/1/BBS_PROJECT_CODE/* /optdata/BBS/output/project-data/BBS_PROJECT_CODE/scope-given/
          
          echo reading list items
          input="/optdata/BBS/output/project-data/BBS_PROJECT_CODE/scope-given/scope.in.txt"
          while IFS= read -r line
          do
            echo Adding to scope: "$line"
            bbrf inscope add "$line" 
          done < "$input"
          
          
          echo reading list items
          input="/optdata/BBS/output/project-data/BBS_PROJECT_CODE/scope-given/scope.out.txt"
          while IFS= read -r line
          do
            echo Removing from scope: "$line"
            bbrf outscope add "$line" 
          done < "$input"
  
            
          echo all done
      restartPolicy: Never

