shinobi-v5-install.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #!/usr/bin/env bash
  2. if [ "$VERBOSE" == "yes" ]; then set -x; fi
  3. if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; fi
  4. YW=$(echo "\033[33m")
  5. RD=$(echo "\033[01;31m")
  6. BL=$(echo "\033[36m")
  7. GN=$(echo "\033[1;92m")
  8. CL=$(echo "\033[m")
  9. RETRY_NUM=10
  10. RETRY_EVERY=3
  11. NUM=$RETRY_NUM
  12. CM="${GN}✓${CL}"
  13. CROSS="${RD}✗${CL}"
  14. BFR="\\r\\033[K"
  15. HOLD="-"
  16. set -o errexit
  17. set -o errtrace
  18. set -o nounset
  19. set -o pipefail
  20. shopt -s expand_aliases
  21. alias die='EXIT=$? LINE=$LINENO error_exit'
  22. trap die ERR
  23. silent() { "$@" > /dev/null 2>&1; }
  24. function error_exit() {
  25. trap - ERR
  26. local reason="Unknown failure occurred."
  27. local msg="${1:-$reason}"
  28. local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
  29. echo -e "$flag $msg" 1>&2
  30. exit $EXIT
  31. }
  32. function msg_info() {
  33. local msg="$1"
  34. echo -ne " ${HOLD} ${YW}${msg}..."
  35. }
  36. function msg_ok() {
  37. local msg="$1"
  38. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  39. }
  40. function msg_error() {
  41. local msg="$1"
  42. echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
  43. }
  44. msg_info "Setting up Container OS "
  45. sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
  46. locale-gen >/dev/null
  47. while [ "$(hostname -I)" = "" ]; do
  48. echo 1>&2 -en "${CROSS}${RD} No Network! "
  49. sleep $RETRY_EVERY
  50. ((NUM--))
  51. if [ $NUM -eq 0 ]; then
  52. echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
  53. exit 1
  54. fi
  55. done
  56. msg_ok "Set up Container OS"
  57. msg_ok "Network Connected: ${BL}$(hostname -I)"
  58. set +e
  59. alias die=''
  60. if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else
  61. msg_error "Internet NOT Connected"
  62. read -r -p "Would you like to continue anyway? <y/N> " prompt
  63. if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then
  64. echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}"
  65. else
  66. echo -e " 🖧 Check Network Settings"
  67. exit 1
  68. fi
  69. fi
  70. RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs)
  71. if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi
  72. alias die='EXIT=$? LINE=$LINENO error_exit'
  73. set -e
  74. msg_info "Updating Container OS"
  75. $STD apt-get update --fix-missing
  76. $STD apt-get -y upgrade
  77. msg_ok "Updated Container OS"
  78. ubuntuversion=$(lsb_release -r | awk '{print $2}' | cut -d . -f1)
  79. if [ "$ubuntuversion" = "18" ] || [ "$ubuntuversion" -le "18" ]; then
  80. apt install sudo wget -y
  81. sudo apt install -y software-properties-common
  82. sudo add-apt-repository universe -y
  83. apt update -y
  84. apt update --fix-missing -y
  85. fi
  86. msg_info "Installing Dependencies"
  87. $STD apt-get install -y curl sudo git mc
  88. $STD apt-get install -y make zip net-tools
  89. $STD apt-get install -y gcc g++ cmake
  90. msg_ok "Installed Dependencies"
  91. msg_info "Setting up Node.js Repository"
  92. $STD bash <(curl -fsSL https://deb.nodesource.com/setup_18.x)
  93. msg_ok "Set up Node.js Repository"
  94. msg_info "Installing Node.js"
  95. $STD apt-get install -y nodejs
  96. msg_ok "Installed Node.js"
  97. msg_info "Installing FFMPEG"
  98. $STD apt-get install -y ffmpeg
  99. msg_ok "Installed FFMPEG"
  100. msg_info "Clonning Shinobi"
  101. cd /opt
  102. $STD git clone https://gitlab.com/Shinobi-Systems/Shinobi.git -b master Shinobi
  103. cd Shinobi
  104. gitVersionNumber=$(git rev-parse HEAD)
  105. theDateRightNow=$(date)
  106. touch version.json
  107. chmod 777 version.json
  108. echo '{"Product" : "'"Shinobi"'" , "Branch" : "'"master"'" , "Version" : "'"$gitVersionNumber"'" , "Date" : "'"$theDateRightNow"'" , "Repository" : "'"https://gitlab.com/Shinobi-Systems/Shinobi.git"'"}' > version.json
  109. msg_ok "Cloned Shinobi"
  110. msg_info "Installing Database"
  111. sqlpass=""
  112. echo "mariadb-server mariadb-server/root_password password $sqlpass" | debconf-set-selections
  113. echo "mariadb-server mariadb-server/root_password_again password $sqlpass" | debconf-set-selections
  114. $STD apt-get install -y mariadb-server
  115. service mysql start
  116. sqluser="root"
  117. mysql -e "source sql/user.sql" || true
  118. mysql -e "source sql/framework.sql" || true
  119. msg_ok "Installed Database"
  120. cp conf.sample.json conf.json
  121. cronKey=$(head -c 1024 < /dev/urandom | sha256sum | awk '{print substr($1,1,29)}')
  122. sed -i -e 's/Shinobi/'"$cronKey"'/g' conf.json
  123. cp super.sample.json super.json
  124. msg_info "Installing Shinobi"
  125. $STD npm i npm -g
  126. $STD npm install --unsafe-perm
  127. $STD npm install pm2@latest -g
  128. chmod -R 755 .
  129. touch INSTALL/installed.txt
  130. ln -s /opt/Shinobi/INSTALL/shinobi /usr/bin/shinobi
  131. node /opt/Shinobi/tools/modifyConfiguration.js addToConfig="{\"cron\":{\"key\":\"$(head -c 64 < /dev/urandom | sha256sum | awk '{print substr($1,1,60)}')\"}}" &>/dev/null
  132. $STD pm2 start camera.js
  133. $STD pm2 start cron.js
  134. $STD pm2 startup
  135. $STD pm2 save
  136. $STD pm2 list
  137. msg_ok "Installed Shinobi"
  138. PASS=$(grep -w "root" /etc/shadow | cut -b6)
  139. echo "export TERM='xterm-256color'" >>/root/.bashrc
  140. if [[ $PASS != $ ]]; then
  141. msg_info "Customizing Container"
  142. chmod -x /etc/update-motd.d/*
  143. touch ~/.hushlogin
  144. GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
  145. mkdir -p $(dirname $GETTY_OVERRIDE)
  146. cat <<EOF >$GETTY_OVERRIDE
  147. [Service]
  148. ExecStart=
  149. ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
  150. EOF
  151. systemctl daemon-reload
  152. systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
  153. msg_ok "Customized Container"
  154. fi
  155. if [[ "${SSH_ROOT}" == "yes" ]]; then
  156. sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config
  157. systemctl restart sshd
  158. fi
  159. msg_info "Cleaning up"
  160. $STD apt-get autoremove
  161. $STD apt-get autoclean
  162. msg_ok "Cleaned"