This repository has been archived by the owner on Dec 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploadBoxToVagrantCloud.sh
executable file
·70 lines (55 loc) · 2.34 KB
/
uploadBoxToVagrantCloud.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
set -euxo pipefail
# ensure login credentials
vagrant cloud auth login
# create Base VM and ensure Base VM is online
vagrant box update || true
vagrant destroy -f || true
vagrant up
PROJ_ROOT=$(pwd)
BOX_NAME=FACTbox
ACCOUNT=botlabs-dev
BOX_FOLDER=createBoxForVagrantCloud
VAGRANT_BOX_FILE=VagrantBoxFile
VIRTUAL_BOX_NAME=$(vboxmanage list vms | grep FACT | head -n 1 | cut -d '"' -f 2)
VERSION_ORIG=$(curl --silent "https://api.github.com/repos/fkie-cad/FACT_core/releases/latest" | jq -r .tag_name | tr -d "v//")
VERSION=$VERSION_ORIG.$(date +'%Y%m%d')
# print overview
echo "++++++++++++++++++++++++++++++"
echo "Account: " $ACCOUNT
echo "Virtualbox Name:" $VIRTUAL_BOX_NAME
echo "Vagrantbox Name:" $BOX_NAME
echo "Version: " $VERSION
echo "++++++++++++++++++++++++++++++"
# add default ssh Vagrant key
BASH_ADD_VAGRANT_KEY="wget --no-check-certificate https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -O /tmp/authorized_keys;
cat /tmp/authorized_keys >> .ssh/authorized_keys;
chmod 700 .ssh;
chmod 600 .ssh/authorized_keys;
chown -R vagrant:vagrant .ssh;"
# clean VM
BASH_CLEAN_VM="sudo apt-get clean;
sudo dd if=/dev/zero of=/EMPTY bs=1M || true;
sudo rm -f /EMPTY;
echo ''>~/.bash_history && history;"
vagrant ssh -- -t $BASH_ADD_VAGRANT_KEY
vagrant ssh -- -t $BASH_CLEAN_VM
rm -rf $BOX_FOLDER
mkdir -p $BOX_FOLDER
cp $VAGRANT_BOX_FILE $BOX_FOLDER/
cd $BOX_FOLDER
# create box
vagrant package --base $VIRTUAL_BOX_NAME --output $BOX_NAME.box --vagrantfile $VAGRANT_BOX_FILE
# add box locally to Vagrant and start it for debug reasons
#vagrant box add testBox $BOX_NAME.box
#vagrant init testBox
#vagrant up
# upload box
hash=$(sha1sum $BOX_NAME.box | cut -d " " -f 1)
echo "vagrant cloud publish $ACCOUNT/$BOX_NAME $VERSION virtualbox $BOX_NAME.box --box-VERSION $VERSION --force --release -c $hash -C sha1 "
vagrant cloud publish $ACCOUNT/$BOX_NAME $VERSION virtualbox $BOX_NAME.box --box-VERSION $VERSION --force --release -c $hash -C sha1 --short-description "FACT - The Firmware Analysis and Comparison Tool (Release: $VERSION_ORIG)" --description "FACT - The Firmware Analysis and Comparison Tool (Release: $VERSION_ORIG)"
# clean
cd $PROJ_ROOT
vagrant destroy --force
rm -rf $BOX_FOLDER
rm -rf .vagrant