1
0

lxcbuild 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env bash
  2. CONTAINER_OS=ubuntu
  3. CONTAINER_VERSION=18.04
  4. CONTAINER_NAME=$(basename `git rev-parse --show-toplevel`)
  5. function container_sh {
  6. lxc exec ${CONTAINER_NAME} -- sh -c "${1}"
  7. return $?
  8. }
  9. function container_cmd {
  10. lxc exec ${CONTAINER_NAME} -- ${1}
  11. return $?
  12. }
  13. function container_snap_cmd {
  14. container_sh "cd ~/${CONTAINER_NAME} && ${1}"
  15. return $?
  16. }
  17. [[ ! -z $(which snap) ]] || sudo apt install snapd
  18. [[ ! -z $(which lxd) ]] || sudo snap install lxd
  19. '''container_sh "echo true" || (lxc launch ${CONTAINER_OS}:${CONTIANER_VERSION} ${CONTAINER_NAME} && sleep 5) || (lxd init && lxc launch ${CONTAINER_OS}:${CONTIANER_VERSION} ${CONTAINER_NAME} || sleep 5)
  20. container_sh "apt update && apt upgrade -y && apt dist-upgrade -y"
  21. if [ $? -ne 0 ]; then
  22. echo "Cannot create container ${CONTAINER_OS}:${CONTAINER_VERSION} for ${CONTAINER_NAME}"
  23. exit 1
  24. fi
  25. container_sh "snap list snapcraft"
  26. if [ $? -ne 0 ]; then
  27. container_sh "snap install snapcraft --classic"
  28. fi
  29. container_sh "[ -d ~/${CONTAINER_NAME} ] && rm -rf ~/${CONTAINER_NAME}"
  30. lxc file push ../${CONTAINER_NAME} ${CONTAINER_NAME}/root/ -r
  31. container_snap_cmd "snapcraft --destructive-mode"
  32. if [ $? -eq 0 ]; then'''
  33. FILE=$(container_snap_cmd "ls | grep .snap --max-count=1")
  34. lxc file pull ${CONTAINER_NAME}/root/${CONTAINER_NAME}/${FILE} ./
  35. #fi