debian-software 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2017 Igor Pečovnik, igor.pecovnik@gma**.com
  4. #
  5. # This file is licensed under the terms of the GNU General Public
  6. # License version 2. This program is licensed "as is" without any
  7. # warranty of any kind, whether express or implied.
  8. # Functions:
  9. # check_status
  10. # choose_webserver
  11. # server_conf
  12. # install_packet
  13. # alive_port
  14. # alive_process
  15. # install_basic
  16. # create_ispconfig_configuration
  17. # check_if_installed
  18. # install_cups
  19. # install_samba
  20. # install_ncp
  21. # install_omv
  22. # install_tvheadend
  23. # install_docker
  24. # install_urbackup
  25. # install_transmission
  26. # install_transmission_seed_orangepi_torrents
  27. # install_hassio
  28. # install_openhab
  29. # install_syncthing
  30. # install_plex_media_server
  31. # install_emby_server
  32. # install_radarr
  33. # install_sonarr
  34. # install_vpn_server
  35. # install_vpn_client
  36. # install_DashNTP
  37. # install_MySQL
  38. # install_MySQLDovecot
  39. # install_Virus
  40. # install_hhvm
  41. # install_phpmyadmin
  42. # install_apache
  43. # install_nginx
  44. # install_PureFTPD
  45. # install_Bind
  46. # install_Stats
  47. # install_Jailkit
  48. # install_Fail2BanDovecot
  49. # install_Fail2BanRulesDovecot
  50. # install_ISPConfig
  51. #
  52. # load functions, local first
  53. #
  54. if [[ -f debian-config-jobs ]]; then source debian-config-jobs;
  55. elif [[ -f /usr/lib/orangepi-config/jobs.sh ]]; then \
  56. source /usr/lib/orangepi-config/jobs.sh;
  57. else exit 1;
  58. fi
  59. if [[ -f debian-config-submenu ]]; then source debian-config-submenu;
  60. elif [[ -f /usr/lib/orangepi-config/submenu.sh ]]; then \
  61. source /usr/lib/orangepi-config/submenu.sh;
  62. else exit 1;
  63. fi
  64. if [[ -f debian-config-functions ]]; then source debian-config-functions;
  65. elif [[ -f /usr/lib/orangepi-config/functions.sh ]]; then \
  66. source /usr/lib/orangepi-config/functions.sh;
  67. else exit 1;
  68. fi
  69. if [[ -f debian-config-functions-network ]]; then source debian-config-functions-network;
  70. elif [[ -f /usr/lib/orangepi-config/functions-network.sh ]]; then \
  71. source /usr/lib/orangepi-config/functions-network.sh;
  72. else exit 1;
  73. fi
  74. function check_status
  75. {
  76. #
  77. # Check if service is already installed and show it's status
  78. #
  79. dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nLoading install info ... " 5 28
  80. LIST=()
  81. LIST_CONST=26
  82. # Samba
  83. SAMBA_STATUS="$(check_if_installed samba && echo "on" || echo "off" )"
  84. alive_port "Windows compatible file sharing" "445" "boolean"
  85. LIST+=( "Samba" "$DESCRIPTION" "$SAMBA_STATUS" )
  86. # CUPS
  87. CUPS_STATUS="$(check_if_installed cups && echo "on" || echo "off" )"
  88. alive_port "Common UNIX Printing System (CUPS)" "631" "boolean"
  89. LIST+=( "CUPS" "$DESCRIPTION" "$CUPS_STATUS" )
  90. # TV headend
  91. TVHEADEND_STATUS="$(check_if_installed tvheadend && echo "on" || echo "off" )"
  92. alive_port "TV streaming server" "9981"
  93. LIST+=( "TV headend" "$DESCRIPTION" "$TVHEADEND_STATUS" )
  94. # Synthing
  95. SYNCTHING_STATUS="$([[ -f /usr/bin/syncthing ]] && echo "on" || echo "off" )"
  96. alive_port "Personal cloud @syncthing.net" "8384"
  97. LIST+=( "Syncthing" "$DESCRIPTION" "$SYNCTHING_STATUS" )
  98. # Hass.io
  99. HASS_STATUS="$([[ -f /etc/hassio.json ]] && echo "on" || echo "off" )"
  100. alive_port "Home assistant smarthome suite" "8123"
  101. #LIST+=( "Hassio" "$DESCRIPTION" "$HASS_STATUS" )
  102. # OpenHab
  103. OPENHAB_STATUS="$([[ -f /usr/bin/openhab-cli ]] && echo "on" || echo "off" )"
  104. alive_port "Openhab2 smarthome suite" "8080"
  105. LIST+=( "OpenHAB" "$DESCRIPTION" "$OPENHAB_STATUS" )
  106. # VPN
  107. if [[ "$(dpkg --print-architecture)" == "armhf" || "$(dpkg --print-architecture)" == "amd64" ]]; then
  108. # vpn server
  109. VPN_SERVER_STATUS="$([[ -d /usr/local/vpnserver ]] && echo "on" || echo "off" )"
  110. LIST+=( "VPN server" "Softether VPN server" "$VPN_SERVER_STATUS" )
  111. # vpn client
  112. VPN_CLIENT_STATUS="$([[ -d /usr/local/vpnclient ]] && echo "on" || echo "off" )"
  113. LIST+=( "VPN client" "Softether VPN client" "$VPN_CLIENT_STATUS" )
  114. LIST_CONST=$((LIST_CONST + 1))
  115. fi
  116. # NCP
  117. NCP_STATUS="$( [[ -d /var/www/nextcloud ]] && echo "on" || echo "off" )"
  118. alive_port "Nextcloud personal cloud" "443"
  119. [[ "$family" != "Ubuntu" ]] && LIST+=( "NCP" "$DESCRIPTION" "$NCP_STATUS" ) \
  120. && LIST_CONST=$((LIST_CONST + 1))
  121. # OMV
  122. OMV_STATUS="$(check_if_installed openmediavault && echo "on" || echo "off" )"
  123. [[ "$family" != "Ubuntu" ]] && LIST+=( "OMV" "OpenMediaVault NAS solution" "$OMV_STATUS" ) \
  124. && LIST_CONST=$((LIST_CONST + 1))
  125. # Plex media server
  126. PLEX_STATUS="$((check_if_installed plexmediaserver || check_if_installed plexmediaserver-installer) \
  127. && echo "on" || echo "off" )"
  128. alive_port "Plex media server" "32400"
  129. LIST+=( "Plex" "$DESCRIPTION" "$PLEX_STATUS" )
  130. # Emby server
  131. AMBY_STATUS="$((check_if_installed emby-server) \
  132. && echo "on" || echo "off" )"
  133. alive_port "Emby server" "8096"
  134. LIST+=( "Emby" "$DESCRIPTION" "$AMBY_STATUS" )
  135. # Radarr
  136. RADARR_STATUS="$([[ -d /opt/Radarr ]] && echo "on" || echo "off" )"
  137. alive_port "Movies downloading server" "7878"
  138. LIST+=( "Radarr" "$DESCRIPTION" "$RADARR_STATUS" )
  139. # Sonarr
  140. SONARR_STATUS="$([[ -d /opt/NzbDrone ]] && echo "on" || echo "off" )"
  141. alive_port "TV shows downloading server" "8989"
  142. LIST+=( "Sonarr" "$DESCRIPTION" "$SONARR_STATUS" )
  143. # MINIdlna
  144. MINIDLNA_STATUS="$(check_if_installed minidlna && echo "on" || echo "off" )"
  145. alive_port "Lightweight DLNA/UPnP-AV server" "8200" "boolean"
  146. LIST+=( "Minidlna" "$DESCRIPTION" "$MINIDLNA_STATUS" )
  147. # Pi hole
  148. PI_HOLE_STATUS="$([[ -d /etc/pihole ]] && echo "on" || echo "off" )"
  149. alive_process "Ad blocker" "pihole-FTL"
  150. LIST+=( "Pi hole" "$DESCRIPTION" "$PI_HOLE_STATUS" )
  151. # Transmission
  152. TRANSMISSION_STATUS="$(check_if_installed transmission-daemon && echo "on" || echo "off" )"
  153. alive_port "Torrent download server" "9091"
  154. #LIST+=( "Transmission" "$DESCRIPTION" "$TRANSMISSION_STATUS" )
  155. # UrBackup
  156. URBACKUP_STATUS="$((check_if_installed urbackup-server || check_if_installed urbackup-server-dbg) \
  157. && echo "on" || echo "off" )"
  158. alive_port "Client/server backup system" "55414"
  159. LIST+=( "UrBackup" "$DESCRIPTION" "$URBACKUP_STATUS" )
  160. # Docker
  161. DOCKER_STATUS="$((check_if_installed docker-ce) && echo "on" || echo "off" )"
  162. LIST+=( "Docker" "Run applications by using containers" "$DOCKER_STATUS")
  163. # Mayan EDMS docker install
  164. if [[ "$DOCKER_STATUS" == "on" ]]; then
  165. curl --output /dev/null --silent --head --fail http://localhost/authentication/login/?next=
  166. MAYAN_STATUS=$([[ $? -eq 0 ]] && echo "on" || echo "off")
  167. else
  168. MAYAN_STATUS="off"
  169. fi
  170. #LIST+=( "Mayan EDMS" "Electronic vault for your documents" "$MAYAN_STATUS")
  171. # ISPconfig
  172. alive_port "SMTP mail, IMAP, POP3 & LAMP/LEMP web server" "8080" "ssl"
  173. ISPCONFIG_STATUS="$([[ -d /usr/local/ispconfig ]] && echo "on" || echo "off" )"
  174. LIST+=( "ISPConfig" "$DESCRIPTION" "$ISPCONFIG_STATUS" )
  175. # PHPmyadmin
  176. # TODO: fix phpmyadmin installer before uncommenting this section
  177. # if [[ $ISPCONFIG_STATUS == on ]]; then
  178. # LIST_CONST=$((LIST_CONST + 1))
  179. # alive_port "MYSQL administration" "8081" "" "/phpmyadmin"
  180. # PHPMYADMIN_STATUS="on"
  181. # LIST+=( "PHPmyadmin" "$DESCRIPTION" "$PHPMYADMIN_STATUS" )
  182. # fi
  183. }
  184. function choose_webserver
  185. {
  186. #
  187. # Target web server selection
  188. #
  189. check_if_installed openmediavault
  190. case $? in
  191. 0)
  192. # OMV installed, prevent switching from nginx to apache which would trash OMV installation
  193. server="nginx"
  194. ;;
  195. *)
  196. dialog --title "Choose a webserver" --backtitle "$BACKTITLE" --yes-label "Apache" --no-label "Nginx" \
  197. --yesno "\nChoose a web server which you are familiar with. They both work almost the same." 8 70
  198. response=$?
  199. case $response in
  200. 0) server="apache";;
  201. 1) server="nginx";;
  202. 255) exit;;
  203. esac
  204. ;;
  205. esac
  206. }
  207. function server_conf
  208. {
  209. #
  210. # Add some required date for installation
  211. #
  212. if [[ "$(curl -s ipinfo.io/ip)" != "$serverIP" ]]; then
  213. table="\Z2Application Protocol Port\n
  214. \Z0----------------------------------\n
  215. FTP TCP 20\n
  216. FTP TCP 21\n
  217. SSH/SFTP TCP 22\n
  218. Mail (SMTP) TCP 25\n
  219. DNS TCP 53\n
  220. Web (HTTP) TCP 80\n
  221. Mail (POP3) TCP 110\n
  222. Mail (IMAP) TCP 143\n
  223. Web (HTTPS) TCP 443\n
  224. Mail (SMTPS) TCP 465\n
  225. Mail (SMTP) TCP 587\n
  226. Mail (IMAPS) TCP 993\n
  227. Mail (POP3S) TCP 995\n
  228. Database TCP 3306\n
  229. Chat (XMPP) TCP 5222\n
  230. ISPConfig TCP 8080\n
  231. ISPConfig TCP 8081\n
  232. ISPConfig TCP 10000\n
  233. DNS UDP 53\n
  234. Database UDP 3306\n
  235. ";
  236. dialog --colors --title "Warning" --msgbox "\nYour internal and external IP addresses are different which seems that you are behind a router. \n\nMake sure \Z1$serverIP\Z0 is a static IP address. Then forward external ports to those services which you plan to use.\n\n\n$table" 38 38
  237. fi
  238. #
  239. HOSTNAMEFQDN=$(\
  240. dialog --title "Server configuration" \
  241. --ok-label "Install" \
  242. --backtitle "$BACKTITLE" \
  243. --inputbox "\nSet FQDN for $serverIP:" 10 50 \
  244. "$(hostname).example.com" \
  245. 3>&1 1>&2 2>&3 3>&- \
  246. )
  247. # create random password for mysql
  248. MYSQL_PASS=$(< /dev/urandom tr -dc A-Z-a-z-0-9 | head -c16)
  249. }
  250. install_packet ()
  251. {
  252. #
  253. # Install missing packets
  254. #
  255. i=0
  256. j=1
  257. IFS=" "
  258. declare -a PACKETS=($1)
  259. #skupaj=$(apt-get -s -y -qq install $1 | wc -l)
  260. skupaj=${#PACKETS[@]}
  261. while [[ $i -lt $skupaj ]]; do
  262. procent=$(echo "scale=2;($j/$skupaj)*100"|bc)
  263. x=${PACKETS[$i]}
  264. if [ $(dpkg-query -W -f='${Status}' $x 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
  265. printf '%.0f\n' $procent | dialog \
  266. --backtitle "$BACKTITLE" \
  267. --title "Installing" \
  268. --gauge "\n$2\n\n$x" 10 70
  269. if [ "$(DEBIAN_FRONTEND=noninteractive apt-get -qq -y install $x >${TEMP_DIR}/install.log 2>&1 || echo 'Installation failed' \
  270. | grep 'Installation failed')" != "" ]; then
  271. echo -e "[\e[0;31m error \x1B[0m] Installation failed"
  272. tail ${TEMP_DIR}/install.log
  273. exit
  274. fi
  275. fi
  276. i=$[$i+1]
  277. j=$[$j+1]
  278. done
  279. echo ""
  280. }
  281. alive_port ()
  282. {
  283. #
  284. # Displays URL to the service $1 on port $2 or just that is active if $3 = boolean $4 = path
  285. #
  286. if [[ -n $(netstat -lnt | awk '$6 == "LISTEN" && $4 ~ ".'$2'"') ]]; then
  287. if [[ $3 == boolean ]]; then
  288. DESCRIPTION="$1 is \Z1active\Z0";
  289. elif [[ $3 == ssl ]]; then
  290. DESCRIPTION="Active on https://${serverIP}:\Z1$2\Z0$4";
  291. else
  292. DESCRIPTION="Active on http://${serverIP}:\Z1$2\Z0$4";
  293. fi
  294. else
  295. DESCRIPTION="$1";
  296. fi
  297. }
  298. alive_process ()
  299. {
  300. #
  301. # check if process name $2 is running. Display it's name $1 or $1 is active if active
  302. #
  303. if pgrep -x "$2" > /dev/null 2>&1; then DESCRIPTION="$1 is \Z1active\Z0"; else DESCRIPTION="$1"; fi
  304. }
  305. install_basic (){
  306. #
  307. # Set hostname, FQDN, add to sources list
  308. #
  309. IFS=" "
  310. set ${HOSTNAMEFQDN//./ }
  311. HOSTNAMESHORT="$1"
  312. cp /etc/hosts /etc/hosts.backup
  313. cp /etc/hostname /etc/hostname.backup
  314. # create new
  315. echo "127.0.0.1 localhost.localdomain localhost" > /etc/hosts
  316. echo "${serverIP} ${HOSTNAMEFQDN} ${HOSTNAMESHORT} #ispconfig " >> /etc/hosts
  317. echo "$HOSTNAMESHORT" > /etc/hostname
  318. /etc/init.d/hostname.sh start >/dev/null 2>&1
  319. hostnamectl set-hostname $HOSTNAMESHORT
  320. if [[ $family == "Ubuntu" ]]; then
  321. # set hostname in Ubuntu
  322. hostnamectl set-hostname $HOSTNAMESHORT
  323. # disable AppArmor
  324. if [[ -n $(service apparmor status 2> /dev/null | grep -w active | grep -w running) ]]; then
  325. service apparmor stop
  326. update-rc.d -f apparmor remove
  327. apt-get -y -qq remove apparmor apparmor-utils
  328. fi
  329. else
  330. grep -q "contrib" /etc/apt/sources.list || sed -i 's|main|main contrib|' /etc/apt/sources.list
  331. grep -q "non-free" /etc/apt/sources.list || sed -i 's|contrib|contrib non-free|' /etc/apt/sources.list
  332. grep -q "deb http://ftp.debian.org/debian jessie-backports main" /etc/apt/sources.list || echo "deb http://ftp.debian.org/debian jessie-backports main" >> /etc/apt/sources.list
  333. debconf-apt-progress -- apt-get update
  334. fi
  335. }
  336. create_ispconfig_configuration (){
  337. #
  338. # ISPConfig autoconfiguration
  339. #
  340. cat > ${TEMP_DIR}/isp.conf.php <<EOF
  341. <?php
  342. \$autoinstall['language'] = 'en'; // de, en (default)
  343. \$autoinstall['install_mode'] = 'standard'; // standard (default), expert
  344. \$autoinstall['hostname'] = '$HOSTNAMEFQDN'; // default
  345. \$autoinstall['mysql_hostname'] = 'localhost'; // default: localhost
  346. \$autoinstall['mysql_root_user'] = 'root'; // default: root
  347. \$autoinstall['mysql_root_password'] = '$MYSQL_PASS';
  348. \$autoinstall['mysql_database'] = 'dbispconfig'; // default: dbispcongig
  349. \$autoinstall['mysql_charset'] = 'utf8'; // default: utf8
  350. \$autoinstall['mysql_port'] = '3306'; // default: 3306
  351. \$autoinstall['configure_jailkit'] = 'y'; // y (default), n
  352. \$autoinstall['configure_firewall'] = 'y'; // y (default), n
  353. \$autoinstall['configure_$server'] = 'y'; // y (default), n
  354. \$autoinstall['configure_dns'] = 'y'; // y (default), n
  355. \$autoinstall['http_server'] = '$server'; // y (default), n
  356. \$autoinstall['ispconfig_port'] = '8080'; // default: 8080
  357. \$autoinstall['ispconfig_admin_password'] = '1234'; // default: 1234
  358. \$autoinstall['ispconfig_use_ssl'] = 'y'; // y (default), n
  359. /* SSL Settings */
  360. \$autoinstall['ssl_cert_country'] = 'AU';
  361. \$autoinstall['ssl_cert_state'] = 'Some-State';
  362. \$autoinstall['ssl_cert_locality'] = 'Chicago';
  363. \$autoinstall['ssl_cert_organisation'] = 'Internet Widgits Pty Ltd';
  364. \$autoinstall['ssl_cert_organisation_unit'] = 'IT department';
  365. \$autoinstall['ssl_cert_common_name'] = \$autoinstall['hostname'];
  366. \$autoinstall['ssl_cert_email'] = 'joe@lamer.com';
  367. ?>
  368. EOF
  369. }
  370. install_cups ()
  371. {
  372. #
  373. # Install printer system
  374. #
  375. #debconf-apt-progress -- apt-get update
  376. #debconf-apt-progress -- apt-get -y install cups lpr cups-filters
  377. apt-get update >/dev/null 2>&1
  378. apt-get -y install cups lpr cups-filters >/dev/null 2>&1
  379. # cups-filters if jessie
  380. sed -e 's/Listen localhost:631/Listen 631/g' -i /etc/cups/cupsd.conf
  381. sed -e 's/<Location \/>/<Location \/>\nallow $SUBNET/g' -i /etc/cups/cupsd.conf
  382. sed -e 's/<Location \/admin>/<Location \/admin>\nallow $SUBNET/g' -i /etc/cups/cupsd.conf
  383. sed -e 's/<Location \/admin\/conf>/<Location \/admin\/conf>\nallow $SUBNET/g' -i /etc/cups/cupsd.conf
  384. service cups restart
  385. service samba restart | service smbd restart >/dev/null 2>&1
  386. }
  387. install_samba ()
  388. {
  389. #
  390. # install Samba file sharing
  391. #
  392. local SECTION="Samba"
  393. SMBUSER=$(whiptail --inputbox "What is your samba username?" 8 78 $SMBUSER --title "$SECTION" 3>&1 1>&2 2>&3)
  394. exitstatus=$?; if [ $exitstatus = 1 ]; then exit 1; fi
  395. SMBPASS=$(whiptail --inputbox "What is your samba password?" 8 78 $SMBPASS --title "$SECTION" 3>&1 1>&2 2>&3)
  396. exitstatus=$?; if [ $exitstatus = 1 ]; then exit 1; fi
  397. SMBGROUP=$(whiptail --inputbox "What is your samba group?" 8 78 $SMBGROUP --title "$SECTION" 3>&1 1>&2 2>&3)
  398. exitstatus=$?; if [ $exitstatus = 1 ]; then exit 1; fi
  399. #
  400. debconf-apt-progress -- apt-get update
  401. debconf-apt-progress -- apt-get -y install samba samba-common-bin samba-vfs-modules
  402. useradd $SMBUSER
  403. echo -ne "$SMBPASS\n$SMBPASS\n" | passwd $SMBUSER >/dev/null 2>&1
  404. echo -ne "$SMBPASS\n$SMBPASS\n" | smbpasswd -a -s $SMBUSER >/dev/null 2>&1
  405. service samba stop | service smbd stop >/dev/null 2>&1
  406. cp /etc/samba/smb.conf /etc/samba/smb.conf.stock
  407. cat > /etc/samba/smb.conf.tmp << EOF
  408. [global]
  409. workgroup = SMBGROUP
  410. server string = %h server
  411. hosts allow = SUBNET
  412. log file = /var/log/samba/log.%m
  413. max log size = 1000
  414. syslog = 0
  415. panic action = /usr/share/samba/panic-action %d
  416. load printers = yes
  417. printing = cups
  418. printcap name = cups
  419. min receivefile size = 16384
  420. write cache size = 524288
  421. getwd cache = yes
  422. socket options = TCP_NODELAY IPTOS_LOWDELAY
  423. [printers]
  424. comment = All Printers
  425. path = /var/spool/samba
  426. browseable = no
  427. public = yes
  428. guest ok = yes
  429. writable = no
  430. printable = yes
  431. printer admin = SMBUSER
  432. [print$]
  433. comment = Printer Drivers
  434. path = /etc/samba/drivers
  435. browseable = yes
  436. guest ok = no
  437. read only = yes
  438. write list = SMBUSER
  439. [ext]
  440. comment = Storage
  441. path = /ext
  442. browseable = yes
  443. writable = yes
  444. public = no
  445. valid users = SMBUSER
  446. force create mode = 0644
  447. EOF
  448. sed -i "s/SMBGROUP/$SMBGROUP/" /etc/samba/smb.conf.tmp
  449. sed -i "s/SMBUSER/$SMBUSER/" /etc/samba/smb.conf.tmp
  450. sed -i "s/SUBNET/$SUBNET/" /etc/samba/smb.conf.tmp
  451. dialog --backtitle "$BACKTITLE" --title "Review samba configuration" --no-collapse --editbox /etc/samba/smb.conf.tmp 30 0 2> /etc/samba/smb.conf.tmp.out
  452. if [[ $? = 0 ]]; then
  453. mv /etc/samba/smb.conf.tmp.out /etc/samba/smb.conf
  454. install -m 755 -g $SMBUSER -o $SMBUSER -d /ext
  455. echo -ne "$SMBPASS\n$SMBPASS\n" | smbpasswd -a -s $SMBUSER >/dev/null 2>&1
  456. service smbd stop >/dev/null 2>&1
  457. sleep 3
  458. service smbd start >/dev/null 2>&1
  459. fi
  460. }
  461. install_ncp (){
  462. curl -sSL https://raw.githubusercontent.com/nextcloud/nextcloudpi/master/install.sh > ${TEMP_DIR}/install.sh
  463. curl -sSL https://raw.githubusercontent.com/nextcloud/nextcloudpi/master/etc/ncp.cfg > ${TEMP_DIR}/ncp.cfg
  464. local DEBIAN_RELEASE=$(awk '{if ($1 == "\"release\":" ) {print $2}}' ${TEMP_DIR}/ncp.cfg | sed 's/[", ]//g')
  465. sed "s/check_distro etc\/ncp.cfg/[[ \$(lsb_release -cs) == \"${DEBIAN_RELEASE}\" ]] /" -i ${TEMP_DIR}/install.sh
  466. bash ${TEMP_DIR}/install.sh
  467. }
  468. install_omv (){
  469. #
  470. # Install OpenMediaVault on Debian
  471. #
  472. if [ -f /etc/orangepi-release ]; then
  473. . /etc/orangepi-release
  474. fi
  475. # Don't allow installation on Ubuntu
  476. if [[ "$family" == "Ubuntu" ]]; then
  477. dialog --backtitle "$BACKTITLE" --title "Dependencies not met" --msgbox "\nOpenMediaVault can only be installed on Debian." 7 52
  478. sleep 5
  479. exit 1
  480. fi
  481. # Warning / Notice before install
  482. case $distribution in
  483. wheezy|jessie)
  484. dialog --backtitle "$BACKTITLE" --title "OMV3 is End of Life" --msgbox "\nUpgrade to a supported OS : Debian Stretch or Buster." 7 52
  485. sleep 5
  486. exit 1
  487. ;;
  488. esac
  489. # Download OMV install script
  490. wgeturl="https://github.com/OpenMediaVault-Plugin-Developers/installScript/raw/master/install"
  491. fancy_wget "$wgeturl" "-O ${TEMP_DIR}/omv_install.sh"
  492. # Remove Crony on Stretch since OMV4 depends on NTP
  493. if [[ "$distribution" == "stretch" ]]; then
  494. apt-get -y -qq remove chrony
  495. fi
  496. # Execute install script
  497. echo "Now installing OpenMediaVault. Be patient, it will take several minutes..."
  498. bash ${TEMP_DIR}/omv_install.sh &>> /var/log/omv_install.log
  499. # Board Specific Tweak
  500. echo "Now applying board tweak if required..."
  501. # Hardkernel Cloudshell 1 and 2 fixes, read the whole thread for details:
  502. # https://forum.openmediavault.org/index.php/Thread/17855
  503. lsusb | grep -q -i "05e3:0735" && sed -i "/exit 0/i echo 20 > /sys/class/block/sda/queue/max_sectors_kb" /etc/rc.local
  504. case ${BOARD} in
  505. odroidxu4)
  506. HMP_Fix='; taskset -c -p 4-7 $i '
  507. apt install -y i2c-tools
  508. /usr/sbin/i2cdetect -y 1 | grep -q "60: 60"
  509. if [ $? -eq 0 ]; then
  510. add-apt-repository -y ppa:kyle1117/ppa
  511. sed -i 's/jessie/xenial/' /etc/apt/sources.list.d/kyle1117-ppa-jessie.list
  512. apt install -y -q cloudshell-lcd odroid-cloudshell cloudshell2-fan &
  513. lsusb -v | awk -F"__" '/RANDOM_/ {print $2}' | head -n1 | while read ; do
  514. echo "ATTRS{idVendor}==\"152d\", ATTRS{idProduct}==\"0561\", KERNEL==\"sd*\", ENV{DEVTYPE}==\"disk\", SYMLINK=\"disk/by-id/\$env{ID_BUS}-CloudShell2-${REPLY}-\$env{ID_MODEL}\"" >> /etc/udev/rules.d/99-cloudshell2.rules
  515. echo "ATTRS{idVendor}==\"152d\", ATTRS{idProduct}==\"0561\", KERNEL==\"sd*\", ENV{DEVTYPE}==\"partition\", SYMLINK=\"disk/by-id/\$env{ID_BUS}-CloudShell2-${REPLY}-\$env{ID_MODEL}-part%n\"" >> /etc/udev/rules.d/99-cloudshell2.rules
  516. done
  517. fi
  518. ;;
  519. helios4)
  520. # Make mdadm display fault events on Fault LED
  521. # NOTE : this is not a permanent approach need to be improved via some OMV core code change
  522. if [ -f /usr/sbin/mdadm-fault-led.sh ]; then
  523. if [[ "$distribution" == "stretch" ]]; then
  524. sed -i -e "/HOMEHOST/a \\\n# Trigger Fault Led script when an event is detected\\nPROGRAM \/usr\/sbin\/mdadm-fault-led.sh" /usr/share/openmediavault/mkconf/mdadm
  525. /usr/sbin/omv-mkconf mdadm
  526. elif [[ "$distribution" == "buster" ]]; then
  527. cat <<EOF > /srv/salt/omv/deploy/mdadm/25faultled.sls
  528. mdadm_add_program_config:
  529. cmd.run:
  530. - name: "echo -e '\n# Trigger Fault Led script when an event is detected\nPROGRAM /usr/sbin/mdadm-fault-led.sh' >> /etc/mdadm/mdadm.conf"
  531. EOF
  532. /usr/sbin/omv-salt deploy run mdadm
  533. fi
  534. fi
  535. ;;
  536. esac
  537. }
  538. install_tvheadend ()
  539. {
  540. #
  541. # TVheadend https://tvheadend.org/ unofficial port https://tvheadend.org/boards/5/topics/21528
  542. #
  543. if [[ "$family" == "Ubuntu" ]]; then
  544. apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 26F4EF8440618B66 >/dev/null 2>&1
  545. add-apt-repository -y ppa:mamarley/tvheadend-git-stable >/dev/null 2>&1
  546. debconf-apt-progress -- apt-get update
  547. debconf-apt-progress -- apt-get -y install libssl-doc libssl1.0.0 zlib1g-dev tvheadend xmltv-util
  548. else
  549. if [ ! -f /etc/apt/sources.list.d/tvheadend.list ]; then
  550. echo "deb https://www.deb-multimedia.org ${distribution} main non-free" >> /etc/apt/sources.list.d/tvheadend.list
  551. apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 5C808C2B65558117 >/dev/null 2>&1
  552. fi
  553. URL="https://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u9_"$(dpkg --print-architecture)".deb"
  554. fancy_wget "$URL" "-O ${TEMP_DIR}/package.deb"
  555. dpkg -i ${TEMP_DIR}/package.deb >/dev/null 2>&1
  556. debconf-apt-progress -- apt-get update
  557. debconf-apt-progress -- apt-get -y install libssl-doc zlib1g-dev tvheadend xmltv-util
  558. fi
  559. }
  560. install_docker ()
  561. {
  562. #echo "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/${family,,} $distribution edge" >\
  563. # /etc/apt/sources.list.d/docker.list
  564. #curl -fsSL "https://download.docker.com/linux/${family,,}/gpg" | apt-key add -qq - > /dev/null 2>&1
  565. echo "deb [arch=$(dpkg --print-architecture)] https://mirrors.aliyun.com/docker-ce/linux/${family,,} $distribution edge" >\
  566. /etc/apt/sources.list.d/docker.list
  567. curl -fsSL "https://mirrors.aliyun.com/docker-ce/linux/${family,,}/gpg" | apt-key add -qq - > /dev/null 2>&1
  568. debconf-apt-progress -- apt-get update
  569. debconf-apt-progress -- apt-get install -y -qq --no-install-recommends docker-ce
  570. }
  571. install_urbackup ()
  572. {
  573. #
  574. # Client/server backup system https://www.urbackup.org/
  575. #
  576. if [ "$(dpkg --print-architecture | grep arm64)" == "arm64" ]; then local arch=armhf; else local arch=$(dpkg --print-architecture); fi
  577. PREFIX="https://hndl.urbackup.org/Server/latest/"
  578. URL="https://hndl.urbackup.org/Server/latest/"$(wget -q $PREFIX -O - | html2text -width 120 | grep deb | awk ' { print $3 }' | grep $arch)
  579. fancy_wget "$URL" "-O ${TEMP_DIR}/package.deb"
  580. dpkg -i ${TEMP_DIR}/package.deb >/dev/null 2>&1
  581. apt-get -yy -f install
  582. }
  583. install_transmission ()
  584. {
  585. #
  586. # transmission
  587. #
  588. install_packet "debconf-utils unzip build-essential html2text apt-transport-https" "Downloading dependencies"
  589. install_packet "transmission-cli transmission-common transmission-daemon" "Install torrent server"
  590. service transmission-daemon stop
  591. local A=(${serverIP//./ })
  592. local servernetwork="${A[0]}.${A[1]}.*.*"
  593. sed "s/\"rpc-whitelist\": \"127.0.0.1.*/\"rpc-whitelist\": \"127.0.0.1,$servernetwork\",/" -i /etc/transmission-daemon/settings.json
  594. service transmission-daemon start
  595. # systemd workaround
  596. # https://forum.armbian.com/index.php?/topic/4017-programs-does-not-start-automatically-at-boot/
  597. sed -e 's/exit 0//g' -i /etc/rc.local
  598. cat >> /etc/rc.local <<"EOF"
  599. service transmission-daemon restart
  600. exit 0
  601. EOF
  602. }
  603. install_transmission_seed_orangepi_torrents ()
  604. {
  605. #
  606. # seed our torrents
  607. #
  608. # adjust network buffers if necessary
  609. rmem_recommended=4194304
  610. wmem_recommended=1048576
  611. rmem_actual=$(sysctl net.core.rmem_max | awk -F" " '{print $3}')
  612. if [ ${rmem_actual} -lt ${rmem_recommended} ]; then
  613. grep -q net.core.rmem_max /etc/sysctl.conf && \
  614. sed -i "s/net.core.rmem_max =.*/net.core.rmem_max = ${rmem_recommended}/" /etc/sysctl.conf || \
  615. echo "net.core.rmem_max = ${rmem_recommended}" >> /etc/sysctl.conf
  616. fi
  617. wmem_actual=$(sysctl net.core.wmem_max | awk -F" " '{print $3}')
  618. if [ ${wmem_actual} -lt ${wmem_recommended} ]; then
  619. grep -q net.core.wmem_max /etc/sysctl.conf && \
  620. sed -i "s/net.core.wmem_max =.*/net.core.wmem_max = ${wmem_recommended}/" /etc/sysctl.conf || \
  621. echo "net.core.wmem_max = ${wmem_recommended}" >> /etc/sysctl.conf
  622. fi
  623. /sbin/sysctl -p >/dev/null 2>&1
  624. # create cron job for daily sync with official Armbian torrents
  625. cat > /etc/cron.daily/seed-armbian-torrent <<"EOF"
  626. #!/bin/bash
  627. #
  628. # armbian torrents auto update
  629. #
  630. # download latest torrent pack
  631. TEMP_DIR=$(mktemp -d || exit 1)
  632. chmod 700 ${TEMP_DIR}
  633. trap "rm -rf \"${TEMP_DIR}\" ; exit 0" 0 1 2 3 15
  634. wget -qO- -O ${TEMP_DIR}/armbian-torrents.zip https://dl.armbian.com/torrent/all-torrents.zip
  635. # test zip for corruption
  636. unzip -t ${TEMP_DIR}/armbian-torrents.zip >/dev/null 2>&1
  637. [[ $? -ne 0 ]] && echo "Error in zip" && exit
  638. # extract zip
  639. unzip -o ${TEMP_DIR}/armbian-torrents.zip -d ${TEMP_DIR}/torrent-tmp >/dev/null 2>&1
  640. # create list of current active torrents
  641. transmission-remote -n 'transmission:transmission' -l | sed '1d; $d' > ${TEMP_DIR}/torrent-tmp/active.torrents
  642. # loop and add/update torrent files
  643. for f in ${TEMP_DIR}/torrent-tmp/*.torrent; do
  644. transmission-remote -n 'transmission:transmission' -a $f > /dev/null 2>&1
  645. # remove added from the list
  646. pattern="${f//.torrent}"; pattern="${pattern##*/}";
  647. sed -i "/$pattern/d" ${TEMP_DIR}/torrent-tmp/active.torrents
  648. done
  649. # remove old armbian torrents
  650. while read i; do
  651. [[ $i == *Armbian_* || $i == *gcc-linaro-* || $i == *tar.lz4 ]] && transmission-remote -n 'transmission:transmission' -t $(echo "$i" | awk '{print $1}';) --remove-and-delete
  652. done < ${TEMP_DIR}/torrent-tmp/active.torrents
  653. # remove temporally files and direcotories
  654. EOF
  655. chmod +x /etc/cron.daily/seed-armbian-torrent
  656. /etc/cron.daily/seed-armbian-torrent &
  657. }
  658. install_hassio ()
  659. {
  660. #
  661. # Install Home assistant smart home suite hass.io / Docker instance by using official installer
  662. #
  663. local arch=$(dpkg --print-architecture)
  664. case $arch in
  665. armhf)
  666. local machine=raspberrypi2
  667. ;;
  668. arm64)
  669. local machine=raspberrypi4-64
  670. ;;
  671. amd64)
  672. local machine=intel-nuc
  673. ;;
  674. *)
  675. exit 1
  676. ;;
  677. esac
  678. if [ $? == 0 ]; then
  679. install_docker
  680. debconf-apt-progress -- apt-get update
  681. debconf-apt-progress -- apt-get install -y apparmor-utils apt-transport-https avahi-daemon ca-certificates \
  682. dbus jq network-manager socat software-properties-common
  683. #curl -sL "https://raw.githubusercontent.com/home-assistant/supervised-installer/master/installer.sh" | \
  684. #bash -s -- -m ${machine}
  685. curl -sL "https://gitee.com/leeboby/supervised-installer/raw/master/installer.sh" | \
  686. bash -s -- -m ${machine}
  687. dialog --backtitle "$BACKTITLE" --title "Please wait" \
  688. --msgbox "\nIt can take several minutes before Home Assistant UI becomes available! " 7 75
  689. fi
  690. }
  691. install_openhab ()
  692. {
  693. #
  694. # Install Openhab2 smart home suite openhab.org
  695. #
  696. # Install ZuluJDK
  697. #
  698. # test below
  699. #
  700. # sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0xB1998361219BD9C9
  701. # sudo apt-add-repository 'deb http://repos.azulsystems.com/ubuntu stable main'
  702. # apt install zulu-embedded-8
  703. local jdkArch=$(dpkg --print-architecture)
  704. case $jdkArch in
  705. armhf)
  706. URL="https://cdn.azul.com/zulu-embedded/bin/zulu8.40.0.178-ca-jdk1.8.0_222-linux_aarch32hf.tar.gz"
  707. ;;
  708. arm64)
  709. URL="https://cdn.azul.com/zulu-embedded/bin/zulu8.40.0.178-ca-jdk1.8.0_222-linux_aarch64.tar.gz"
  710. ;;
  711. amd64)
  712. URL="https://cdn.azul.com/zulu/bin/zulu8.42.0.21-ca-jdk8.0.232-linux_x64.tar.gz"
  713. ;;
  714. *)
  715. URL="https://cdn.azul.com/zulu/bin/zulu8.42.0.21-ca-jdk8.0.232-linux_i686.tar.gz"
  716. esac
  717. fancy_wget "$URL" "-O ${TEMP_DIR}/zulu8.tar.gz"
  718. mkdir -p /opt/jdk
  719. tar -xpzf ${TEMP_DIR}/zulu8.tar.gz -C /opt/jdk
  720. jdkBin=$(find /opt/jdk/*/bin ... -print -quit)
  721. jdkLib=$(find /opt/jdk/*/lib ... -print -quit)
  722. update-alternatives --remove-all java >/dev/null 2>&1
  723. update-alternatives --remove-all javac >/dev/null 2>&1
  724. update-alternatives --install /usr/bin/java java "$jdkBin"/java 1083000 >/dev/null 2>&1
  725. update-alternatives --install /usr/bin/javac javac "$jdkBin"/javac 1083000 >/dev/null 2>&1
  726. echo "$jdkLib"/"$jdkArch" > /etc/ld.so.conf.d/java.conf
  727. echo "$jdkLib"/"$jdkArch"/jli >> /etc/ld.so.conf.d/java.conf
  728. ldconfig >/dev/null 2>&1
  729. wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | apt-key add - >/dev/null 2>&1
  730. echo 'deb https://dl.bintray.com/openhab/apt-repo2 stable main' | tee /etc/apt/sources.list.d/openhab2.list >/dev/null 2>&1
  731. debconf-apt-progress -- apt-get update
  732. debconf-apt-progress -- apt-get install -y openhab2
  733. systemctl daemon-reload >/dev/null 2>&1
  734. systemctl enable openhab2.service >/dev/null 2>&1
  735. systemctl start openhab2.service >/dev/null 2>&1
  736. # addons seems broken
  737. # apt-get install -y openhab2-addons
  738. sed -i 's|EXTRA_JAVA_OPTS=""|EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0:/dev/ttyS0:/dev/ttyS2:/dev/ttyACM0:/dev/ttyAMA0"|' /etc/default/openhab2
  739. service openhab2 restart >/dev/null 2>&1
  740. dialog --backtitle "$BACKTITLE" --title "Please wait" --msgbox \
  741. "\nIt can take several minutes before OpenHAB UI becomes available! " 7 68
  742. }
  743. install_syncthing ()
  744. {
  745. #
  746. # Install Personal cloud https://syncthing.net/
  747. #
  748. curl -s https://syncthing.net/release-key.txt | apt-key add - >/dev/null 2>&1
  749. echo "deb https://apt.syncthing.net/ syncthing stable" | tee /etc/apt/sources.list.d/syncthing.list >/dev/null 2>&1
  750. debconf-apt-progress -- apt-get update
  751. debconf-apt-progress -- apt-get -y install syncthing
  752. # increase open file limit
  753. if !(grep -qs "fs.inotify.max_user_watches=204800" "/etc/sysctl.conf");then
  754. echo -e "fs.inotify.max_user_watches=204800" | tee -a /etc/sysctl.conf
  755. fi
  756. add_choose_user
  757. mv /lib/systemd/system/syncthing@.service /lib/systemd/system/syncthing@${CHOSEN_USER}.service
  758. # create startup files
  759. systemctl enable syncthing@${CHOSEN_USER}.service >/dev/null 2>&1
  760. systemctl start syncthing@${CHOSEN_USER}.service >/dev/null 2>&1
  761. systemctl stop syncthing@${CHOSEN_USER}.service >/dev/null 2>&1
  762. systemctl start syncthing@${CHOSEN_USER}.service >/dev/null 2>&1
  763. # wait until config file is created
  764. while :
  765. do
  766. if [[ -f /home/${CHOSEN_USER}/.config/syncthing/config.xml ]]; then break; fi
  767. sleep 1
  768. done
  769. # change to server IP
  770. sed -i "s/127.0.0.1/${serverIP}/" /home/${CHOSEN_USER}/.config/syncthing/config.xml
  771. systemctl restart syncthing@${CHOSEN_USER}.service >/dev/null 2>&1
  772. dialog --backtitle "$BACKTITLE" --title "Please wait" --msgbox "\nIt can take several minutes before Syncthing UI becomes available! " 7 70
  773. }
  774. install_plex_media_server ()
  775. {
  776. #
  777. # Plex Media server
  778. #
  779. echo -e "deb https://downloads.plex.tv/repo/deb public main" > /etc/apt/sources.list.d/plex.list
  780. wget -q -O - https://downloads.plex.tv/plex-keys/PlexSign.key | apt-key add - >/dev/null 2>&1
  781. debconf-apt-progress -- apt-get update
  782. debconf-apt-progress -- apt-get -y install plexmediaserver
  783. }
  784. install_emby_server ()
  785. {
  786. #
  787. # Emby server
  788. #
  789. ARCH=$(dpkg --print-architecture)
  790. #URL=$(curl -s https://api.github.com/repos/MediaBrowser/Emby.Releases/releases/latest | grep "/emby-server-deb.*${ARCH}.deb" | cut -d : -f 2,3 | tr -d \")
  791. #URL=https://gitee.com/leeboby/embyreleases/raw/master/emby-server-deb_4.5.2.0_${ARCH}.deb
  792. #fancy_wget "$URL" "-O ${TEMP_DIR}/emby.deb"
  793. git clone https://gitee.com/leeboby/embyreleases.git /tmp/emby >/dev/null 2>&1
  794. dpkg -i /tmp/emby/emby-server-deb_4.5.2.0_${ARCH}.deb >/dev/null 2>&1
  795. apt-get -yy -f install
  796. rm -rf /tmp/emby
  797. }
  798. install_radarr ()
  799. {
  800. #
  801. # Automatically downloading movies
  802. #
  803. debconf-apt-progress -- apt-get update
  804. debconf-apt-progress -- apt-get -y install mono-devel mediainfo libmono-cil-dev
  805. #wgeturl=$(curl -s "https://api.github.com/repos/Radarr/Radarr/releases" | grep 'linux.tar.gz' | grep 'browser_download_url' | head -1 | cut -d \" -f 4)
  806. #fancy_wget "$wgeturl" "-O ${TEMP_DIR}/radarr.tgz"
  807. git clone -b radarr https://gitee.com/leeboby/software.git /tmp/radarr >/dev/null 2>&1
  808. cp /tmp/radarr/Radarr*linux.tar.gz /tmp/radarr/radarr.tgz
  809. tar xf /tmp/radarr/radarr.tgz -C /opt
  810. cat << _EOF_ > /etc/systemd/system/radarr.service
  811. [Unit]
  812. Description=Radarr Daemon
  813. After=network.target
  814. [Service]
  815. User=root
  816. Type=simple
  817. ExecStart=/usr/bin/mono --debug /opt/Radarr/Radarr.exe -nobrowser
  818. [Install]
  819. WantedBy=multi-user.target
  820. _EOF_
  821. systemctl enable radarr >/dev/null 2>&1
  822. systemctl start radarr
  823. }
  824. install_sonarr ()
  825. {
  826. #
  827. # Automatically downloading TV shows
  828. #
  829. if [ "$(dpkg --print-architecture | grep arm64)" == "arm64" ]; then
  830. debconf-apt-progress -- apt-get update
  831. debconf-apt-progress -- apt-get -y install mono-complete mediainfo
  832. fancy_wget "https://update.sonarr.tv/v2/develop/mono/NzbDrone.develop.tar.gz" "-O ${TEMP_DIR}/sonarr.tgz"
  833. tar xf ${TEMP_DIR}/sonarr.tgz -C /opt
  834. else
  835. apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 0xA236C58F409091A18ACA53CBEBFF6B99D9B78493 >/dev/null 2>&1
  836. echo -e "deb http://apt.sonarr.tv/ master main" | sudo tee /etc/apt/sources.list.d/sonarr.list
  837. debconf-apt-progress -- apt-get update
  838. debconf-apt-progress -- apt-get -y install nzbdrone
  839. fi
  840. cat << _EOF_ > /etc/systemd/system/sonarr.service
  841. [Unit]
  842. Description=Sonarr (NzbDrone) Daemon
  843. After=network.target
  844. [Service]
  845. User=root
  846. Type=simple
  847. ExecStart=/usr/bin/mono --debug /opt/NzbDrone/NzbDrone.exe -nobrowser
  848. [Install]
  849. WantedBy=multi-user.target
  850. _EOF_
  851. systemctl enable sonarr >/dev/null 2>&1
  852. systemctl start sonarr
  853. }
  854. install_vpn_server ()
  855. {
  856. #
  857. # Script downloads latest stable
  858. #
  859. cd ${TEMP_DIR}
  860. #PREFIX="https://www.softether-download.com/files/softether/"
  861. install_packet "debconf-utils unzip build-essential html2text apt-transport-https" "Downloading basic packages"
  862. #URL=$(wget -q $PREFIX -O - | html2text | grep rtm | awk ' { print $(NF) }' | tail -1)
  863. #SUFIX="${URL/-tree/}"
  864. #if [ "$(dpkg --print-architecture | grep armhf)" != "" ]; then
  865. #DLURL=$PREFIX$URL"/Linux/SoftEther_VPN_Server/32bit_-_ARM_EABI/softether-vpnserver-$SUFIX-linux-arm_eabi-32bit.tar.gz"
  866. #else
  867. #install_packet "gcc-multilib" "Install libraries"
  868. #DLURL=$PREFIX$URL"/Linux/SoftEther_VPN_Server/32bit_-_Intel_x86/softether-vpnserver-$SUFIX-linux-x86-32bit.tar.gz"
  869. #fi
  870. #wget -q $DLURL -O - | tar -xz
  871. git clone -b vpnserver --depth=1 https://gitee.com/leeboby/software.git /tmp/vpnserver >/dev/null 2>&1
  872. cd /tmp/vpnserver
  873. tar -zxf *.tar.gz
  874. cd vpnserver
  875. make i_read_and_agree_the_license_agreement | dialog --backtitle "$BACKTITLE" --title "Compiling SoftEther VPN" --progressbox $TTY_Y $TTY_X
  876. cd ..
  877. cp -R vpnserver /usr/local
  878. cd /usr/local/vpnserver/
  879. chmod 600 *
  880. chmod 700 vpncmd
  881. chmod 700 vpnserver
  882. if [[ -d /run/systemd/system/ ]]; then
  883. cat <<EOT >/lib/systemd/system/ethervpn.service
  884. [Unit]
  885. Description=VPN service
  886. [Service]
  887. Type=oneshot
  888. ExecStart=/usr/local/vpnserver/vpnserver start
  889. ExecStop=/usr/local/vpnserver/vpnserver stop
  890. RemainAfterExit=yes
  891. [Install]
  892. WantedBy=multi-user.target
  893. EOT
  894. systemctl enable ethervpn.service
  895. service ethervpn start
  896. else
  897. cat <<EOT > /etc/init.d/vpnserver
  898. #!/bin/sh
  899. ### BEGIN INIT INFO
  900. # Provides: vpnserver
  901. # Required-Start: \$remote_fs \$syslog
  902. # Required-Stop: \$remote_fs \$syslog
  903. # Default-Start: 2 3 4 5
  904. # Default-Stop: 0 1 6
  905. # Short-Description: Start daemon at boot time
  906. # Description: Enable Softether by daemon.
  907. ### END INIT INFO
  908. DAEMON=/usr/local/vpnserver/vpnserver
  909. LOCK=/var/lock/vpnserver
  910. test -x $DAEMON || exit 0
  911. case "\$1" in
  912. start)
  913. \$DAEMON start
  914. touch \$LOCK
  915. ;;
  916. stop)
  917. \$DAEMON stop
  918. rm \$LOCK
  919. ;;
  920. restart)
  921. \$DAEMON stop
  922. sleep 3
  923. \$DAEMON start
  924. ;;
  925. *)
  926. echo "Usage: \$0 {start|stop|restart}"
  927. exit 1
  928. esac
  929. exit 0
  930. EOT
  931. chmod 755 /etc/init.d/vpnserver
  932. mkdir /var/lock/subsys
  933. update-rc.d vpnserver defaults >> $logfile
  934. /etc/init.d/vpnserver start
  935. fi
  936. }
  937. install_vpn_client ()
  938. {
  939. #
  940. # Script downloads latest stable
  941. #
  942. #cd ${TEMP_DIR}
  943. #PREFIX="https://www.softether-download.com/files/softether/"
  944. install_packet "debconf-utils unzip build-essential html2text apt-transport-https" "Downloading basic packages"
  945. #URL=$(wget -q $PREFIX -O - | html2text | grep rtm | awk ' { print $(NF) }' | tail -1)
  946. #SUFIX="${URL/-tree/}"
  947. #if [ "$(dpkg --print-architecture | grep armhf)" != "" ]; then
  948. # DLURL=$PREFIX$URL"/Linux/SoftEther_VPN_Client/32bit_-_ARM_EABI/softether-vpnclient-$SUFIX-linux-arm_eabi-32bit.tar.gz"
  949. #else
  950. # install_packet "gcc-multilib" "Install libraries"
  951. # DLURL=$PREFIX$URL"/Linux/SoftEther_VPN_Client/32bit_-_Intel_x86/softether-vpnclient-$SUFIX-linux-x86-32bit.tar.gz"
  952. #fi
  953. #wget -q $DLURL -O - | tar -xz
  954. git clone -b vpnclient --depth=1 https://gitee.com/leeboby/software.git /tmp/vpnclient >/dev/null 2>&1
  955. cd /tmp/vpnclient
  956. tar -zxf *.tar.gz
  957. cd vpnclient
  958. make i_read_and_agree_the_license_agreement | dialog --backtitle "$BACKTITLE" --title "Compiling SoftEther VPN vpnclient" --progressbox $TTY_Y $TTY_X
  959. cd ..
  960. cp -R vpnclient /usr/local
  961. cd /usr/local/vpnclient/
  962. chmod 600 *
  963. chmod 700 vpncmd
  964. chmod 700 vpnclient
  965. }
  966. install_DashNTP ()
  967. {
  968. #
  969. # Install DASH and NTP service
  970. #
  971. echo "dash dash/sh boolean false" | debconf-set-selections
  972. dpkg-reconfigure -f noninteractive dash > /dev/null 2>&1
  973. install_packet "ntp ntpdate" "Install DASH and NTP service"
  974. }
  975. install_MySQL ()
  976. {
  977. #
  978. # Maria SQL
  979. #
  980. install_packet "mariadb-client mariadb-server" "SQL client and server"
  981. #Allow MySQL to listen on all interfaces
  982. cp /etc/mysql/my.cnf /etc/mysql/my.cnf.backup
  983. [[ -f /etc/mysql/my.cnf ]] && sed -i 's|bind-address.*|#bind-address = 127.0.0.1|' /etc/mysql/my.cnf
  984. [[ -f /etc/mysql/mariadb.conf.d/50-server.cnf ]] && sed -i 's|bind-address.*|#bind-address = 127.0.0.1|' /etc/mysql/mariadb.conf.d/50-server.cnf
  985. SECURE_MYSQL=$(expect -c "
  986. set timeout 3
  987. spawn mysql_secure_installation
  988. expect \"Enter current password for root (enter for none):\"
  989. send \"\r\"
  990. expect \"root password?\"
  991. send \"y\r\"
  992. expect \"New password:\"
  993. send \"$MYSQL_PASS\r\"
  994. expect \"Re-enter new password:\"
  995. send \"$MYSQL_PASS\r\"
  996. expect \"Remove anonymous users?\"
  997. send \"y\r\"
  998. expect \"Disallow root login remotely?\"
  999. send \"y\r\"
  1000. expect \"Remove test database and access to it?\"
  1001. send \"y\r\"
  1002. expect \"Reload privilege tables now?\"
  1003. send \"y\r\"
  1004. expect eof
  1005. ")
  1006. #
  1007. # Execution mysql_secure_installation
  1008. #
  1009. echo "${SECURE_MYSQL}" >> /dev/null
  1010. # ISP config exception
  1011. mkdir -p /etc/mysql/mariadb.conf.d/
  1012. cat > /etc/mysql/mariadb.conf.d/99-ispconfig.cnf<<"EOF"
  1013. [mysqld]
  1014. sql-mode="NO_ENGINE_SUBSTITUTION"
  1015. EOF
  1016. service mysql restart >> /dev/null
  1017. }
  1018. install_MySQLDovecot ()
  1019. {
  1020. #
  1021. # Install Postfix, Dovecot, Saslauthd, rkhunter, binutils
  1022. #
  1023. echo "postfix postfix/main_mailer_type select Internet Site" | debconf-set-selections
  1024. echo "postfix postfix/mailname string $HOSTNAMEFQDN" | debconf-set-selections
  1025. install_packet "postfix postfix-mysql postfix-doc openssl getmail4 rkhunter binutils dovecot-imapd dovecot-pop3d dovecot-mysql \
  1026. dovecot-sieve sudo libsasl2-modules dovecot-lmtpd" "postfix, dovecot, saslauthd, rkhunter, binutils"
  1027. #Uncommenting some Postfix configuration files
  1028. cp /etc/postfix/master.cf /etc/postfix/master.cf.backup
  1029. sed -i 's|#submission inet n - - - - smtpd|submission inet n - - - - smtpd|' /etc/postfix/master.cf
  1030. sed -i 's|# -o syslog_name=postfix/submission| -o syslog_name=postfix/submission|' /etc/postfix/master.cf
  1031. sed -i 's|# -o smtpd_tls_security_level=encrypt| -o smtpd_tls_security_level=encrypt|' /etc/postfix/master.cf
  1032. sed -i 's|# -o smtpd_sasl_auth_enable=yes| -o smtpd_sasl_auth_enable=yes|' /etc/postfix/master.cf
  1033. sed -i 's|# -o smtpd_client_restrictions=permit_sasl_authenticated,reject| -o smtpd_client_restrictions=permit_sasl_authenticated,reject|' /etc/postfix/master.cf
  1034. sed -i 's|# -o smtpd_sasl_auth_enable=yes| -o smtpd_sasl_auth_enable=yes|' /etc/postfix/master.cf
  1035. sed -i 's|# -o smtpd_sasl_auth_enable=yes| -o smtpd_sasl_auth_enable=yes|' /etc/postfix/master.cf
  1036. sed -i 's|# -o smtpd_sasl_auth_enable=yes| -o smtpd_sasl_auth_enable=yes|' /etc/postfix/master.cf
  1037. sed -i 's|#smtps inet n - - - - smtpd|smtps inet n - - - - smtpd|' /etc/postfix/master.cf
  1038. sed -i 's|# -o syslog_name=postfix/smtps| -o syslog_name=postfix/smtps|' /etc/postfix/master.cf
  1039. sed -i 's|# -o smtpd_tls_wrappermode=yes| -o smtpd_tls_wrappermode=yes|' /etc/postfix/master.cf
  1040. service postfix restart >> /dev/null
  1041. }
  1042. install_Virus ()
  1043. {
  1044. #
  1045. # Install Amavisd-new, SpamAssassin, And ClamAV
  1046. #
  1047. packets="amavisd-new spamassassin clamav clamav-daemon unzip bzip2 arj p7zip unrar-free rpm nomarch lzop \
  1048. cabextract apt-listchanges libnet-ldap-perl libauthen-sasl-perl clamav-docs daemon libio-string-perl libio-socket-ssl-perl \
  1049. libnet-ident-perl zip libnet-dns-perl postgrey"
  1050. if [[ $distribution != "bionic" ]] && [[ $distribution != "buster" ]]; then
  1051. packets=$packets" zoo"
  1052. fi
  1053. if [[ $distribution != "buster" ]]; then packets=$packets" ripole"; fi
  1054. install_packet "$packets" "amavisd, spamassassin, clamav"
  1055. sed -i "s/^AllowSupplementaryGroups.*/AllowSupplementaryGroups true/" /etc/clamav/clamd.conf
  1056. service spamassassin stop >/dev/null 2>&1
  1057. systemctl disable spamassassin >/dev/null 2>&1
  1058. # amavisd-new program has currently a bug in Ubuntu 18.04
  1059. if [[ $distribution == bionic ]]; then
  1060. cd ${TEMP_DIR}
  1061. wget -q https://git.ispconfig.org/ispconfig/ispconfig3/raw/stable-3.1/helper_scripts/ubuntu-amavisd-new-2.11.patch
  1062. cd /usr/sbin
  1063. cp -pf amavisd-new amavisd-new_bak
  1064. patch --silent < ${TEMP_DIR}/ubuntu-amavisd-new-2.11.patch >> /dev/null 2>&1
  1065. fi
  1066. freshclam >> /var/log/ispconfig_config.log
  1067. service clamav-daemon start >/dev/null 2>&1
  1068. }
  1069. install_hhvm ()
  1070. {
  1071. #
  1072. # Install HipHop Virtual Machine
  1073. #
  1074. apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xB4112585D386EB94 >/dev/null 2>&1
  1075. add-apt-repository https://dl.hhvm.com/"${family,,}" >/dev/null 2>&1
  1076. debconf-apt-progress -- apt-get update
  1077. install_packet "hhvm" "HipHop Virtual Machine"
  1078. }
  1079. install_phpmyadmin ()
  1080. {
  1081. #
  1082. # Phpmyadmin unattended installation
  1083. #
  1084. if [[ "$family" != "Ubuntu" ]]; then
  1085. debconf-apt-progress -- apt-get update
  1086. DEBIAN_FRONTEND=noninteractive debconf-apt-progress -- apt-get -y install phpmyadmin
  1087. else
  1088. debconf-set-selections <<< "phpmyadmin phpmyadmin/internal/skip-preseed boolean true"
  1089. debconf-set-selections <<< "phpmyadmin phpmyadmin/reconfigure-webserver multiselect true"
  1090. debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install boolean false"
  1091. echo "phpmyadmin phpmyadmin/internal/skip-preseed boolean true" | debconf-set-selections
  1092. echo "phpmyadmin phpmyadmin/reconfigure-webserver multiselect" | debconf-set-selections
  1093. echo "phpmyadmin phpmyadmin/dbconfig-install boolean false" | debconf-set-selections
  1094. debconf-apt-progress -- apt-get update
  1095. debconf-apt-progress -- apt-get install -y phpmyadmin
  1096. fi
  1097. # Apache2 needs additional hack
  1098. WWW_RECONFIG=$(expect -c "
  1099. set timeout 3
  1100. spawn dpkg-reconfigure -f readline phpmyadmin
  1101. expect \"Reinstall database for phpmyadmin?\"
  1102. send \"No\r\"
  1103. expect \"Web server to reconfigure automatically:\"
  1104. send \"1\r\"
  1105. expect eof
  1106. ")
  1107. echo "${WWW_RECONFIG}" >> /dev/null
  1108. }
  1109. install_apache ()
  1110. {
  1111. #
  1112. # Install Apache2, PHP5, FCGI, suExec, Pear and mcrypt
  1113. #
  1114. local pkg="apache2 apache2-doc apache2-utils libapache2-mod-fcgid php-pear mcrypt imagemagick libruby libapache2-mod-python memcached"
  1115. local pkg_xenial="libapache2-mod-php php7.0 php7.0-common php7.0-gd php7.0-mysql php7.0-imap php7.0-cli php7.0-cgi \
  1116. apache2-suexec-pristine php-auth php7.0-mcrypt php7.0-curl php7.0-intl php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy \
  1117. php7.0-xmlrpc php7.0-xsl php-memcache php-imagick php-gettext php7.0-zip php7.0-mbstring php7.0-opcache php-apcu \
  1118. libapache2-mod-fastcgi php7.0-fpm"
  1119. local pkg_bionic="apache2 apache2-doc apache2-utils libapache2-mod-php php7.2 php7.2-common php7.2-gd php7.2-mysql php7.2-imap \
  1120. phpmyadmin php7.2-cli php7.2-cgi libapache2-mod-fcgid apache2-suexec-pristine php-pear mcrypt imagemagick libruby libapache2-mod-python \
  1121. php7.2-curl php7.2-intl php7.2-pspell php7.2-recode php7.2-sqlite3 php7.2-tidy php7.2-xmlrpc php7.2-xsl memcached php-memcache \
  1122. php-imagick php-gettext php7.2-zip php7.2-mbstring php-soap php7.2-soap php7.2-fpm php-apcu certbot"
  1123. local pkg_stretch="libapache2-mod-php php7.0 php7.0-common php7.0-gd php7.0-mysql php7.0-imap php7.0-cli php7.0-cgi libapache2-mod-fcgid \
  1124. apache2-suexec-pristine php7.0-mcrypt libapache2-mod-python php7.0-curl php7.0-intl php7.0-pspell php7.0-recode php7.0-sqlite3 \
  1125. php7.0-tidy php7.0-xmlrpc php7.0-xsl php-memcache php-imagick php-gettext php7.0-zip php7.0-mbstring libapache2-mod-passenger \
  1126. php7.0-soap php7.0-fpm php7.0-opcache php-apcu certbot"
  1127. local pkg_jessie="apache2.2-common apache2-mpm-prefork libexpat1 ssl-cert libapache2-mod-php5 php5 php5-common php5-gd php5-mysql \
  1128. php5-imap php5-cli php5-cgi libapache2-mod-fcgid apache2-suexec php-pear php-auth php5-mcrypt mcrypt php5-imagick libapache2-mod-python \
  1129. php5-curl php5-intl php5-memcache php5-memcached php5-pspell php5-recode php5-sqlite php5-tidy php5-xmlrpc php5-xsl \
  1130. libapache2-mod-passenger php5-xcache libapache2-mod-fastcgi php5-fpm"
  1131. local pkg_buster="apache2 apache2-doc apache2-utils libapache2-mod-php php7.3 php7.3-common php7.3-gd php7.3-mysql php7.3-imap \
  1132. php7.3-cli php7.3-cgi libapache2-mod-fcgid apache2-suexec-pristine php-pear mcrypt imagemagick libruby libapache2-mod-python \
  1133. php7.3-curl php7.3-intl php7.3-pspell php7.3-recode php7.3-sqlite3 php7.3-tidy php7.3-xmlrpc php7.3-xsl memcached php-memcache \
  1134. php-imagick php-gettext php7.3-zip php7.3-mbstring php-soap php7.3-soap php7.3-fpm php-apcu certbot"
  1135. local temp="pkg_${distribution}"
  1136. install_packet "${pkg} ${!temp}" "Apache for $family $distribution"
  1137. # fix HTTPOXY vulnerability
  1138. cat <<EOT > /etc/apache2/conf-available/httpoxy.conf
  1139. <IfModule mod_headers.c>
  1140. RequestHeader unset Proxy early
  1141. </IfModule>
  1142. EOT
  1143. a2enmod actions proxy_fcgi setenvif fastcgi alias httpoxy suexec rewrite ssl actions include dav_fs dav auth_digest cgi headers >/dev/null 2>&1
  1144. case $distribution in
  1145. jessie)
  1146. a2enconf php5-fpm >/dev/null 2>&1
  1147. ;;
  1148. xenial)
  1149. a2enconf php7.0-fpm >/dev/null 2>&1
  1150. ;;
  1151. stretch)
  1152. a2enconf php7.0-fpm >/dev/null 2>&1
  1153. ;;
  1154. bionic)
  1155. a2enconf php7.2-fpm >/dev/null 2>&1
  1156. ;;
  1157. buster)
  1158. a2enconf php7.3-fpm >/dev/null 2>&1
  1159. ;;
  1160. esac
  1161. service apache2 restart >> /dev/null
  1162. }
  1163. install_nginx ()
  1164. {
  1165. #
  1166. # Install NginX, PHP5, FCGI, suExec, Pear, And mcrypt
  1167. #
  1168. local pkg="nginx php-pear memcached fcgiwrap"
  1169. local pkg_xenial="php7.0-fpm php7.0-opcache php7.0-fpm php7.0 php7.0-common php7.0-gd php7.0-mysql php7.0-imap php7.0-cli php7.0-cgi \
  1170. php7.0-mcrypt mcrypt imagemagick libruby php7.0-curl php7.0-intl php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy \
  1171. php7.0-xmlrpc php7.0-xsl php-memcache php-imagick php-gettext php7.0-zip php7.0-mbstring php-apcu letsencrypt"
  1172. local pkg_stretch="php7.0-fpm php7.0-opcache php7.0-fpm php7.0 php7.0-common php7.0-gd php7.0-mysql php7.0-imap php7.0-cli php7.0-cgi \
  1173. php7.0-mcrypt mcrypt imagemagick libruby php7.0-curl php7.0-intl php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy \
  1174. php7.0-xmlrpc php7.0-xsl php-memcache php-imagick php-gettext php7.0-zip php7.0-mbstring php-apcu letsencrypt"
  1175. local pkg_jessie="php5-fpm php5-mysql php5-curl php5-gd php5-intl php5-imagick php5-imap php5-mcrypt php5-memcache \
  1176. php5-memcached php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php-apc"
  1177. local pkg_bionic="php7.2-fpm php7.2-opcache php7.2-fpm php7.2 php7.2-common php7.2-gd php7.2-mysql php7.2-imap php7.2-cli php7.2-cgi \
  1178. imagemagick libruby php7.2-curl php7.2-intl php7.2-pspell php7.2-recode php7.2-sqlite3 php7.2-tidy \
  1179. php7.2-xmlrpc php7.2-xsl php-memcache php-imagick php-gettext php7.2-zip php7.2-mbstring php-apcu letsencrypt"
  1180. local pkg_buster="php7.3-fpm php7.3-opcache php7.3-fpm php7.3 php7.3-common php7.3-gd php7.3-mysql php7.3-imap php7.3-cli php7.3-cgi \
  1181. imagemagick libruby php7.3-curl php7.3-intl php7.3-pspell php7.3-recode php7.3-sqlite3 php7.3-tidy \
  1182. php7.3-xmlrpc php7.3-xsl php-memcache php-imagick php-gettext php7.3-zip php7.3-mbstring php-apcu letsencrypt"
  1183. local temp="pkg_${distribution}"
  1184. install_packet "${pkg} ${!temp}" "Nginx for $family $distribution"
  1185. case $distribution in
  1186. jessie)
  1187. phpenmod mcrypt mbstring
  1188. debconf-apt-progress -- apt-get update
  1189. debconf-apt-progress -- apt-get install -y python-certbot -t jessie-backports
  1190. service php5-fpm reload >> /dev/null
  1191. ;;
  1192. xenial)
  1193. phpenmod mcrypt mbstring
  1194. tz=$(cat /etc/timezone | sed 's/\//\\\//g')
  1195. sed -i "s/^cgi.fix_pathinfo=.*/cgi.fix_pathinfo=0/" /etc/php/7.0/fpm/php.ini
  1196. sed -i "s/^date.timezone=.*/date.timezone=""$tz""/" /etc/php/7.0/fpm/php.ini
  1197. service php7.0-fpm reload >> /dev/null
  1198. ;;
  1199. stretch)
  1200. tz=$(cat /etc/timezone | sed 's/\//\\\//g')
  1201. sed -i "s/^cgi.fix_pathinfo=.*/cgi.fix_pathinfo=0/" /etc/php/7.0/fpm/php.ini
  1202. sed -i "s/^date.timezone=.*/date.timezone=""$tz""/" /etc/php/7.0/fpm/php.ini
  1203. service php7.0-fpm reload >> /dev/null
  1204. phpenmod mcrypt mbstring
  1205. ;;
  1206. bionic)
  1207. tz=$(cat /etc/timezone | sed 's/\//\\\//g')
  1208. sed -i "s/^cgi.fix_pathinfo=.*/cgi.fix_pathinfo=0/" /etc/php/7.2/fpm/php.ini
  1209. sed -i "s/^date.timezone=.*/date.timezone=""$tz""/" /etc/php/7.2/fpm/php.ini
  1210. service php7.2-fpm reload >> /dev/null
  1211. phpenmod mbstring
  1212. ;;
  1213. buster)
  1214. tz=$(cat /etc/timezone | sed 's/\//\\\//g')
  1215. sed -i "s/^cgi.fix_pathinfo=.*/cgi.fix_pathinfo=0/" /etc/php/7.3/fpm/php.ini
  1216. sed -i "s/^date.timezone=.*/date.timezone=""$tz""/" /etc/php/7.3/fpm/php.ini
  1217. service php7.3-fpm reload >> /dev/null
  1218. phpenmod mbstring
  1219. ;;
  1220. esac
  1221. }
  1222. install_PureFTPD ()
  1223. {
  1224. #
  1225. # Install PureFTPd and Quota
  1226. #
  1227. install_packet "pure-ftpd-common pure-ftpd-mysql quota quotatool" "pureFTPd and Quota"
  1228. sed -i 's/VIRTUALCHROOT=false/VIRTUALCHROOT=true/' /etc/default/pure-ftpd-common
  1229. echo 1 > /etc/pure-ftpd/conf/TLS
  1230. mkdir -p /etc/ssl/private/
  1231. openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -subj "/C=GB/ST=GB/L=GB/O=GB/OU=GB/CN=$(hostname -f)/emailAddress=joe@joe.com" -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem >/dev/null 2>&1
  1232. chmod 600 /etc/ssl/private/pure-ftpd.pem
  1233. /etc/init.d/pure-ftpd-mysql restart >/dev/null 2>&1
  1234. local temp=$(cat /etc/fstab | grep "/ " | tail -1 | awk '{print $4}')
  1235. sed -i "s/$temp/$temp,usrjquota=quota.user,grpjquota=quota.group,jqfmt=vfsv0/" /etc/fstab
  1236. mount -o remount / >/dev/null 2>&1
  1237. quotacheck -avugm >/dev/null 2>&1
  1238. quotaon -avug >/dev/null 2>&1
  1239. }
  1240. install_Bind ()
  1241. {
  1242. #
  1243. # Install BIND DNS Server
  1244. #
  1245. install_packet "bind9 dnsutils haveged" "Install BIND DNS Server"
  1246. systemctl enable haveged >/dev/null 2>&1
  1247. systemctl start haveged >/dev/null 2>&1
  1248. }
  1249. install_Stats ()
  1250. {
  1251. #
  1252. # Install Vlogger, Webalizer, And AWstats
  1253. #
  1254. install_packet "vlogger webalizer awstats geoip-database libclass-dbi-mysql-perl" "vlogger, webalizer, awstats"
  1255. sed -i "s/MAILTO=root/#MAILTO=root/" /etc/cron.d/awstats
  1256. sed -i "s/*/10 * * * * www-data/#*/10 * * * * www-data/" /etc/cron.d/awstats
  1257. sed -i "s/10 03 * * * www-data/#10 03 * * * www-data/" /etc/cron.d/awstats
  1258. }
  1259. install_Jailkit()
  1260. {
  1261. #
  1262. debconf-apt-progress -- apt-get update
  1263. debconf-apt-progress -- apt-get install -y build-essential autoconf automake libtool flex bison debhelper binutils
  1264. cd ${TEMP_DIR}
  1265. wget -q https://olivier.sessink.nl/jailkit/jailkit-2.19.tar.gz -O - | tar -xz && cd jailkit-2.19
  1266. echo 5 > debian/compat
  1267. ./debian/rules binary > /dev/null 2>&1
  1268. dpkg -i ../jailkit_2.19-1_*.deb > /dev/null 2>&1
  1269. }
  1270. install_Fail2BanDovecot()
  1271. {
  1272. #
  1273. # Install fail2ban
  1274. #
  1275. install_packet "fail2ban ufw" "Install fail2ban and UFW Firewall"
  1276. if [[ $distribution == "stretch" ]]; then
  1277. cat > /etc/fail2ban/jail.local <<"EOF"
  1278. [pure-ftpd]
  1279. enabled = true
  1280. port = ftp
  1281. filter = pure-ftpd
  1282. logpath = /var/log/syslog
  1283. maxretry = 3
  1284. [dovecot]
  1285. enabled = true
  1286. filter = dovecot
  1287. logpath = /var/log/mail.log
  1288. maxretry = 5
  1289. [postfix-sasl]
  1290. enabled = true
  1291. port = smtp
  1292. filter = postfix-sasl
  1293. logpath = /var/log/mail.log
  1294. maxretry = 3
  1295. EOF
  1296. else
  1297. cat > /etc/fail2ban/jail.local <<"EOF"
  1298. [pureftpd]
  1299. enabled = true
  1300. port = ftp
  1301. filter = pureftpd
  1302. logpath = /var/log/syslog
  1303. maxretry = 3
  1304. [dovecot-pop3imap]
  1305. enabled = true
  1306. filter = dovecot-pop3imap
  1307. action = iptables-multiport[name=dovecot-pop3imap, port="pop3,pop3s,imap,imaps", protocol=tcp]
  1308. logpath = /var/log/mail.log
  1309. maxretry = 5
  1310. [sasl]
  1311. enabled = true
  1312. port = smtp
  1313. filter = postfix-sasl
  1314. logpath = /var/log/mail.log
  1315. maxretry = 3
  1316. EOF
  1317. fi
  1318. }
  1319. install_Fail2BanRulesDovecot()
  1320. {
  1321. #
  1322. # Dovecot rules
  1323. #
  1324. cat > /etc/fail2ban/filter.d/pureftpd.conf <<"EOF"
  1325. [Definition]
  1326. failregex = .*pure-ftpd: \(.*@<HOST>\) \[WARNING\] Authentication failed for user.*
  1327. ignoreregex =
  1328. EOF
  1329. cat > /etc/fail2ban/filter.d/dovecot-pop3imap.conf <<"EOF"
  1330. [Definition]
  1331. failregex = (?: pop3-login|imap-login): .*(?:Authentication failure|Aborted login \(auth failed|Aborted login \(tried to use disabled|Disconnected \(auth failed|Aborted login \(\d+ authentication attempts).*rip=(?P<host>\S*),.*
  1332. ignoreregex =
  1333. EOF
  1334. # Add the missing ignoreregex line
  1335. echo "ignoreregex =" >> /etc/fail2ban/filter.d/postfix-sasl.conf
  1336. service fail2ban restart >> /dev/null
  1337. }
  1338. install_ISPConfig (){
  1339. #
  1340. # Install ISPConfig 3
  1341. #
  1342. cd ${TEMP_DIR}
  1343. wget -q https://www.ispconfig.org/downloads/ISPConfig-3-stable.tar.gz -O - | tar -xz
  1344. cd ${TEMP_DIR}/ispconfig3_install/install/
  1345. php -q install.php --autoinstall=${TEMP_DIR}/isp.conf.php &>> /var/log/ispconfig_config.log
  1346. dialog --colors --backtitle "$BACKTITLE" --no-collapse --title " Auto updating SSL certificate " --clear --yesno "\nDo you want to secure ISPConfig control panel and all services with free Let's Encrypt SSL certificate?" 8 80
  1347. if [[ $? == 0 ]]; then
  1348. dialog --colors --backtitle "$BACKTITLE" --no-collapse --title " Instructions " --clear --msgbox "\n1. Access admin panel with your browser: \Z1https://$serverIP:8080\Z0\n\nUsername: \Z1admin\Z0\nPassword: \Z11234\Z0 \n\n\n2. Go to Sites > Website > \Z1Add new website\Z0\n\nDomain: \Z1$(hostname -f)\Z0\nAuto-Subdomain: \Z1None\Z0\nSSL: \Z1enable\Z0\nLet's Encrypt SSL: \Z1enable\Z0\n\n\n3. Go to Tools > \Z1Password and language\Z0\n\nChange ISPConfig control panel password.\n\nSave and Logout. \n\n\n4. Wait until SSL is not working here: \Z1https://$(hostname -f)\Z0 \n\nIt can take up to a few minutes.\n\n\n5. Proceed with install (\Z1Press ENTER\Z0):" 33 80
  1349. curl -sSL https://github.com/ahrasis/LE4ISPC/archive/master.zip > master.zip 2> /dev/null
  1350. unzip -qq master.zip
  1351. bash LE4ISPC-master/${server}/le4ispc.sh 2>&1
  1352. fi
  1353. }
  1354. #
  1355. # Main choices
  1356. #
  1357. # check for root
  1358. #
  1359. if [[ $EUID != 0 ]]; then
  1360. dialog --title "Warning" --infobox "\nThis script requires root privileges.\n\nExiting ..." 7 41
  1361. sleep 3
  1362. exit
  1363. fi
  1364. # nameserver backup
  1365. if [ -d /etc/resolvconf/resolv.conf.d ]; then
  1366. echo 'nameserver 8.8.8.8' > /etc/resolvconf/resolv.conf.d/head
  1367. resolvconf -u &> /dev/null
  1368. fi
  1369. # Create a safe temporary directory
  1370. TEMP_DIR=$(mktemp -d || exit 1)
  1371. chmod 700 ${TEMP_DIR}
  1372. trap "rm -rf \"${TEMP_DIR}\" ; exit 0" 0 1 2 3 15
  1373. # Install basic stuff, we have to wait for other apt tasks to finish
  1374. # (eg unattended-upgrades)
  1375. i=0
  1376. tput sc
  1377. while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
  1378. case $(($i % 4)) in
  1379. 0 ) j="-" ;;
  1380. 1 ) j="\\" ;;
  1381. 2 ) j="|" ;;
  1382. 3 ) j="/" ;;
  1383. esac
  1384. tput rc
  1385. echo -en "\r[$j] Waiting for other software managers to finish..."
  1386. sleep 0.5
  1387. ((i=i+1))
  1388. done
  1389. apt-get -qq -y --no-install-recommends install curl debconf-utils html2text apt-transport-https dialog whiptail lsb-release bc expect > /dev/null
  1390. # gather some info
  1391. #
  1392. TTY_X=$(($(stty size | awk '{print $2}')-6)) # determine terminal width
  1393. TTY_Y=$(($(stty size | awk '{print $1}')-6)) # determine terminal height
  1394. distribution=$(lsb_release -cs)
  1395. family=$(lsb_release -is)
  1396. DEFAULT_ADAPTER=$(ip -4 route ls | grep default | tail -1 | grep -Po '(?<=dev )(\S+)')
  1397. serverIP=$(ip -4 addr show dev $DEFAULT_ADAPTER | awk '/inet/ {print $2}' | cut -d'/' -f1)
  1398. set ${serverIP//./ }
  1399. SUBNET="$1.$2.$3."
  1400. hostnamefqdn=$(hostname -f)
  1401. mysql_pass=""
  1402. BACKTITLE="Softy - Orange Pi post deployment scripts, http://www.orangepi.org"
  1403. SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  1404. #check_status
  1405. # main dialog routine
  1406. #
  1407. DIALOG_CANCEL=1
  1408. DIALOG_ESC=255
  1409. while true; do
  1410. # prepare menu items
  1411. check_status
  1412. LISTLENGTH="$((${#LIST[@]}/2))"
  1413. exec 3>&1
  1414. selection=$(dialog --backtitle "$BACKTITLE" --title "Installing to $family $distribution" --colors --clear --cancel-label \
  1415. "Cancel" --ok-label "Install" --checklist "\nChoose what you want to install:\n " $LIST_CONST 71 18 "${LIST[@]}" 2>&1 1>&3)
  1416. exit_status=$?
  1417. exec 3>&-
  1418. case $exit_status in
  1419. $DIALOG_ESC | $DIALOG_CANCEL)
  1420. clear
  1421. exit 1
  1422. ;;
  1423. esac
  1424. # cycle through all install options
  1425. i=0
  1426. if ! is_package_manager_running; then
  1427. while [ "$i" -lt "$LISTLENGTH" ]; do
  1428. if [[ "$selection" == *Samba* && "$SAMBA_STATUS" != "on" ]]; then
  1429. install_samba
  1430. selection=${selection//Samba/}
  1431. fi
  1432. if [[ "$selection" == *CUPS* && "$CUPS_STATUS" != "on" ]]; then
  1433. install_cups
  1434. selection=${selection//CUPS/}
  1435. fi
  1436. if [[ "$selection" == *headend* && "$TVHEADEND_STATUS" != "on" ]]; then
  1437. install_tvheadend
  1438. selection=${selection//\"TV headend\"/}
  1439. fi
  1440. if [[ "$selection" == *Minidlna* && "$MINIDLNA_STATUS" != "on" ]]; then
  1441. install_packet "minidlna" "Install lightweight DLNA/UPnP-AV server"
  1442. selection=${selection//Minidlna/}
  1443. fi
  1444. if [[ "$selection" == *ISPConfig* && "$ISPCONFIG_STATUS" != "on" ]]; then
  1445. debconf-apt-progress -- apt-get update
  1446. server_conf
  1447. if [[ "$MYSQL_PASS" == "" ]]; then
  1448. dialog --msgbox "Mysql password can't be blank. Exiting..." 7 70
  1449. exit
  1450. fi
  1451. if [[ "$(echo $HOSTNAMEFQDN | grep -P '(?=^.{1,254}$)(^(?>(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)')" == "" ]]; then
  1452. dialog --msgbox "Invalid FQDN. Exiting..." 7 70
  1453. exit
  1454. fi
  1455. choose_webserver; install_basic; install_DashNTP; install_MySQL; install_MySQLDovecot; install_Virus; install_$server;
  1456. install_phpmyadmin
  1457. [[ -z "$(dpkg --print-architecture | grep arm)" ]] && install_hhvm
  1458. create_ispconfig_configuration;install_PureFTPD;install_Stats;install_Bind;
  1459. install_Jailkit; install_Fail2BanDovecot; install_Fail2BanRulesDovecot;
  1460. install_ISPConfig
  1461. selection=${selection//ISPConfig/}
  1462. fi
  1463. if [[ "$selection" == *Syncthing* && "$SYNCTHING_STATUS" != "on" ]]; then
  1464. install_syncthing
  1465. selection=${selection//Syncthing/}
  1466. fi
  1467. if [[ "$selection" == *Hassio* && "$HASS_STATUS" != "on" ]]; then
  1468. install_hassio
  1469. selection=${selection//Hassio/}
  1470. fi
  1471. if [[ "$selection" == *OpenHAB* && "$OPENHAB_STATUS" != "on" ]]; then
  1472. install_openhab
  1473. selection=${selection//OpenHAB/}
  1474. fi
  1475. if [[ "$selection" == *server* && "$VPN_SERVER_STATUS" != "on" ]]; then
  1476. install_vpn_server
  1477. selection=${selection//\"VPN server\"/}
  1478. fi
  1479. if [[ "$selection" == *client* && "$VPN_CLIENT_STATUS" != "on" ]]; then
  1480. install_vpn_client
  1481. selection=${selection//\"VPN client\"/}
  1482. fi
  1483. if [[ "$selection" == *NCP* && "$NCP_STATUS" != "on" ]]; then
  1484. install_ncp
  1485. selection=${selection//NCP/}
  1486. fi
  1487. if [[ "$selection" == *OMV* && "$OMV_STATUS" != "on" ]]; then
  1488. install_omv
  1489. selection=${selection//OMV/}
  1490. fi
  1491. if [[ "$selection" == *Plex* && "$PLEX_STATUS" != "on" ]]; then
  1492. install_plex_media_server
  1493. selection=${selection//Plex/}
  1494. fi
  1495. if [[ "$selection" == *Emby* && "$EMBY_STATUS" != "on" ]]; then
  1496. install_emby_server
  1497. selection=${selection//Emby/}
  1498. fi
  1499. if [[ "$selection" == *Radarr* && "$RADARR_STATUS" != "on" ]]; then
  1500. install_radarr
  1501. selection=${selection//Radarr/}
  1502. fi
  1503. if [[ "$selection" == *Sonarr* && "$SONARR_STATUS" != "on" ]]; then
  1504. install_sonarr
  1505. selection=${selection//Sonarr/}
  1506. fi
  1507. if [[ "$selection" == *hole* && "$PI_HOLE_STATUS" != "on" ]]; then
  1508. #curl -L "https://install.pi-hole.net" | bash
  1509. export PIHOLE_SKIP_OS_CHECK=true
  1510. curl -L "https://gitee.com/leeboby/pi-hole/raw/master/automated%20install/basic-install.sh" | bash
  1511. selection=${selection//\"Pi hole\"/}
  1512. fi
  1513. if [[ "$selection" == *Docker* && "$DOCKER_STATUS" != "on" ]]; then
  1514. install_docker
  1515. selection=${selection//Docker/}
  1516. fi
  1517. if [[ "$selection" == *Transmission* && "$TRANSMISSION_STATUS" != "on" ]]; then
  1518. install_transmission
  1519. selection=${selection//Transmission/}
  1520. dialog --title "Seed Armbian torrents" --backtitle "$BACKTITLE" --yes-label "Yes" --no-label "No" --yesno "\
  1521. \nDo you want to help the community and seed armbian torrent files? It will ensure faster downloads for everyone.\
  1522. \n\nApproximately 400GB disk space is required." 11 44
  1523. if [[ $? = 0 ]]; then
  1524. install_transmission_seed_orangepi_torrents
  1525. fi
  1526. fi
  1527. if [[ "$selection" == *UrBackup* && "$URBACKUP_STATUS" != "on" ]]; then
  1528. install_urbackup
  1529. selection=${selection//UrBackup/}
  1530. fi
  1531. if [[ "$selection" == *Mayan* && "$MAYAN_STATUS" != "on" ]]; then
  1532. if [[ "$DOCKER_STATUS" == "off" ]]; then
  1533. install_docker
  1534. fi
  1535. curl -fsSL https://get.mayan-edms.com | bash
  1536. selection=${selection//Mayan/}
  1537. fi
  1538. i=$[$i+1]
  1539. done
  1540. fi
  1541. # reread statuses
  1542. check_status
  1543. done