Skip to content

Instantly share code, notes, and snippets.

@dagrons
Last active October 4, 2022 08:30
Show Gist options
  • Save dagrons/256a423e7fb8390f934dc191e37fe5a5 to your computer and use it in GitHub Desktop.
Save dagrons/256a423e7fb8390f934dc191e37fe5a5 to your computer and use it in GitHub Desktop.
mal installation
#!/bin/bash
# tested on ubuntu18.04-desktop
set -e
set -x
# confs
VBOX_USER=$(cat /etc/passwd|grep 1000|cut -d ':' -f 1)
VBOX_PASS="1205"
# add pkgs
if ! grep virtualbox /etc/apt/sources.list; then
cat <<-EOF >> /etc/apt/sources.list
deb https://mirrors.tuna.tsinghua.edu.cn/virtualbox/apt/ bionic contrib
EOF
fi
wget -qO- https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo apt-key add -
pip3 install gdown # 用于从google drive下载文件
apt update && apt install -y virtualbox-5.2 docker.io docker-compose npm curl stow nginx python3-pip git
# install virtualbox, import cuckoo-xp
if [ -z "$(grep VBOX /etc/default/virtualbox)" ]; then
echo "VBOX_USER=$VBOX_USER" >> /etc/default/virtualbox
echo "VBOX_PASS=$VBOX_PASS" >> /etc/default/virtualbox
fi
if [[ -z $(vboxmanage list hostonlyifs|grep 'vboxnet0') ]]; then # create hostonlyif vboxnet0
vboxmanage hostonlyif create # create a hostonly interface
fi
vboxmanage hostonlyif ipconfig vboxnet0 --ip 192.168.56.1 # config ip for vboxnet0 on host
su - $VBOX_USER -c "vboxwebsrv --background --host 0.0.0.0" # su - <username> -c "<command>"" # run <command> as <username>
if ! su $VBOX_USER -c "vboxmanage list vms|grep cuckoo1" ; then
[[ "$(md5sum /opt/cuckoo1.ova|awk '{print $1}')" != "c796278348291a96da5dc1acc7fc5e26" ]] && gdown -O /opt/cuckoo1.ova --fuzzy https://drive.google.com/file/d/121Qz8pKKd4tb2RDXdobuV4lILsSw-p0m/view?usp=sharing && chown $VBOX_USER /opt/cuckoo1.ova
[[ "$(md5sum /opt/cuckoo1.ova|awk '{print $1}')" != "c796278348291a96da5dc1acc7fc5e26" ]] && echo "mismatched checksum for cuckoo1.ova" && exit -1
su - $VBOX_USER -c "vboxmanage import /opt/cuckoo1.ova"
su - $VBOX_USER -c "vboxmanage modifyvm cuckoo1 --pae on"
fi
[[ "$1" != "continue" ]] && echo "先创建cuckoo1_infant再继续..." && exit -1
# install docker-cuckoo
if [ ! -d "/opt/docker-cuckoo" ]; then
git clone -b pve https://github.com/dagrons/docker-cuckoo.git /opt/docker-cuckoo
fi
rm /opt/docker-cuckoo/postgres-data/*
sysctl -w net.ipv4.ip_forward=1 # enable ip forward
echo 1 > /proc/sys/net/ipv4/ip_forward
sudo sed -i "s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/" /etc/sysctl.conf # persistent
sysctl -w vm.max_map_count=262144 # increase ulimit for elastic
if [ -z "$(grep vm.max_map_count /etc/sysctl.conf)" ]; then
sed -i "$ a vm.max_map_count=262144" /etc/sysctl.conf # persistent
fi
if [[ ! -e /mnt/cuckoo-storage ]]; then
mkdir /mnt/cuckoo-storage
fi
chown -R $VBOX_USER /mnt/cuckoo-storage && chmod +777 /mnt/cuckoo-storage
cd /opt/docker-cuckoo && chown -R $VBOX_USER cuckoo-tmp # accessible to vbox_user
sed -i "s/url.*/url = http:\/\/192.168.56.1:18083/; s/user.*/user = $VBOX_USER/; s/password.*/password = $VBOX_PASS/" /opt/docker-cuckoo/vbox/conf/virtualbox_websrv.conf # replace external ip for vboxwebsrv # # modify virtualbox_websrv.conf
sed -i "s/80:/81:/" /opt/docker-cuckoo/docker-compose.yml
cd /opt/docker-cuckoo && stow -t / stow
systemctl enable vboxwebsrv load-iptables vboxhostonlynic docker-cuckoo
docker-compose -f docker-compose.yml up -d --force-recreate
reboot
#!/bin/bash
# tested on ubuntu18.04-desktop
set -e
set -x
# clone all projs
if [ ! -d "/opt/mal_v2" ]; then
git clone -b pve https://github.com/dagrons/mal_v2.git /opt/mal_v2
fi
if [ ! -d "/opt/mal_ui" ]; then
git clone https://github.com/dagrons/mal_ui.git /opt/mal_ui
fi
if [ ! -d "/opt/kg" ]; then
git clone https://github.com/dagrons/kg.git /opt/kg
fi
if [ ! -d "/opt/kg_ui" ]; then
git clone https://github.com/dagrons/kg_ui.git /opt/kg_ui
fi
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash # 下载nvm
cat <<EOF >> ~/.bashrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_complete" ] && . "$NVM_DIR/bash_complete"
EOF
echo "export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node/" >> ~/.bashrc && source ~/.bashrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
nvm install node
nvm install lts/erbium && nvm use lts/erbium
npm install -g yarn
# compile
docker build -t kg /opt/kg
# mal_v2
cd /opt/mal_v2 && docker-compose up -d neo4j
[[ "$1" != "continue" ]] && echo "请先初始化neo4j后使用continue选项继续..." && exit -1
cd /opt/mal_v2 && docker-compose up -d --force-recreate
# mal_ui
cd /opt/mal_ui && yarn
yarn build
if [ ! -d "/var/www/html/mal_ui" ]; then
mkdir /var/www/html/mal_ui
fi
cp -r build/* /var/www/html/mal_ui
# kg_ui
cd /opt/kg_ui
if [ ! -d "/var/www/html/kg_ui" ]; then
mkdir /var/www/html/kg_ui
fi
cp -r * /var/www/html/kg_ui
# system prod conf
cd /opt/mal_v2 && stow -t / stow/
systemctl enable mal_v2
ln -s /etc/nginx/sites-available/mal_v2 /etc/nginx/sites-enabled/mal_v2
nginx -t
nginx -s reload
reboot
#!/bin/bash
# tested on ubuntu18.04-desktop
set -e
set -x
# clone all projs
if [ ! -d "/opt/map" ]; then
git clone https://github.com/dagrons/map.git /opt/map
fi
if [ ! -d "/opt/celery_s" ]; then
git clone https://github.com/dagrons/celery_s.git /opt/celery_s
fi
if [ ! -d "/opt/fmap" ]; then
git clone https://github.com/dagrons/fmap.git /opt/fmap
fi
if [ ! -d "/opt/kg" ]; then
git clone https://github.com/dagrons/kg.git /opt/kg
fi
if [ ! -d "/opt/kg_ui" ]; then
git clone https://github.com/dagrons/kg_ui.git /opt/kg_ui
fi
# install requirements for compilation
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash # 下载nvm
cat <<EOF >> ~/.bashrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_complete" ] && . "$NVM_DIR/bash_complete"
EOF
echo "export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node/" >> ~/.bashrc && source ~/.bashrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
nvm install node
nvm install lts/erbium && nvm use lts/erbium
npm install -g yarn
# compile images
docker build -t kg /opt/kg
docker build -t map /opt/map
docker build -t celery_s /opt/celery_s
# map
# compile backend
cd /opt/fmap && docker-compose up -d neo4j
[[ "$1" != "continue" ]] && echo "请先初始化neo4j后使用continue选项继续..." && exit -1
cd /opt/fmap && docker-compose up -d --force-recreate
# mal_ui
# compile frontend
cd /opt/mal_ui && yarn
yarn build
if [ ! -d "/var/www/html/mal_ui" ]; then
mkdir /var/www/html/mal_ui
fi
cp -r build/* /var/www/html/mal_ui
# kg_ui
# compile frontend
cd /opt/kg_ui
if [ ! -d "/var/www/html/kg_ui" ]; then
mkdir /var/www/html/kg_ui
fi
cp -r * /var/www/html/kg_ui
# configure nginx
wget -qO /etc/nginx/sites-enabled/map https://raw.githubusercontent.com/dagrons/mal_v2/pve/stow/etc/nginx/sites-available/mal_v2
ln -s /etc/nginx/sites-available/map /etc/nginx/sites-enabled/map
nginx -t
nginx -s reload
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment