freedombone-utils-setup 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Setup functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. if [ ! $PROJECT_NAME ]; then
  31. PROJECT_NAME='freedombone'
  32. fi
  33. DEFAULT_DOMAIN_NAME=
  34. DEFAULT_DOMAIN_CODE=
  35. MY_USERNAME=
  36. if [ ! $SYSTEM_TYPE ]; then
  37. SYSTEM_TYPE="full"
  38. fi
  39. # An optional configuration file which overrides some of these variables
  40. if [ ! $CONFIGURATION_FILE ]; then
  41. CONFIGURATION_FILE="$HOME/${PROJECT_NAME}.cfg"
  42. fi
  43. # Directory where source code is downloaded and compiled
  44. INSTALL_DIR=$HOME/build
  45. # device name for an attached usb drive
  46. USB_DRIVE=/dev/sda1
  47. # Location where the USB drive is mounted to
  48. USB_MOUNT=/mnt/usb
  49. # Number of days to keep backups for
  50. BACKUP_MAX_DAYS=30
  51. # file containing a list of remote locations to backup to
  52. # Format: [username@friendsdomain//home/username] [ssh_password]
  53. # With the only space character being between the server and the password
  54. FRIENDS_SERVERS_LIST=/home/$MY_USERNAME/backup.list
  55. export DEBIAN_FRONTEND=noninteractive
  56. # used to limit CPU usage
  57. CPULIMIT='/usr/bin/cpulimit -l 20 -e'
  58. # command to create a git repository
  59. CREATE_GIT_PROJECT_COMMAND='create-project'
  60. # File which keeps track of what has already been installed
  61. COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
  62. # log file where details of remote backups are stored
  63. REMOTE_BACKUPS_LOG=/var/log/remotebackups.log
  64. # message if something fails to install
  65. CHECK_MESSAGE="Check your internet connection, /etc/network/interfaces and /etc/resolv.conf, then delete $COMPLETION_FILE, run 'rm -fR /var/lib/apt/lists/* && apt-get update --fix-missing' and run this script again. If hash sum mismatches persist then try setting $DEBIAN_REPO to a different mirror and also change /etc/apt/sources.list."
  66. # Default diffie-hellman key length in bits
  67. DH_KEYLENGTH=2048
  68. function detect_usb_drive {
  69. # sets to the highest available drive letter
  70. # which is likely to be the last drive connected
  71. read_config_param USB_DRIVE
  72. partition_number='1'
  73. if [[ "$1" == "nopath" ]]; then
  74. partition_number=''
  75. fi
  76. if [ -b /dev/sdb${partition_number} ]; then
  77. USB_DRIVE=/dev/sdb${partition_number}
  78. fi
  79. if [ -b /dev/sdc${partition_number} ]; then
  80. USB_DRIVE=/dev/sdc${partition_number}
  81. fi
  82. if [ -b /dev/sdd${partition_number} ]; then
  83. USB_DRIVE=/dev/sdd${partition_number}
  84. fi
  85. if [ -b /dev/sde${partition_number} ]; then
  86. USB_DRIVE=/dev/sde${partition_number}
  87. fi
  88. if [ -b /dev/sdf${partition_number} ]; then
  89. USB_DRIVE=/dev/sdf${partition_number}
  90. fi
  91. if [ -b /dev/sdg${partition_number} ]; then
  92. USB_DRIVE=/dev/sdg${partition_number}
  93. fi
  94. if [ -b /dev/sdh${partition_number} ]; then
  95. USB_DRIVE=/dev/sdh${partition_number}
  96. fi
  97. write_config_param USB_DRIVE "$USB_DRIVE"
  98. }
  99. function remove_bluetooth {
  100. rmmod -f bnep
  101. rmmod -f bluetooth
  102. if [ -f /etc/default/bluetooth ]; then
  103. if grep "BLUETOOTH_ENABLED=" /etc/default/bluetooth; then
  104. sed -i 's|BLUETOOTH_ENABLED=.*|BLUETOOTH_ENABLED=0|g' /etc/default/bluetooth
  105. else
  106. echo "BLUETOOTH_ENABLED=0" >> /etc/default/bluetooth
  107. fi
  108. fi
  109. if ! grep 'blacklist bnep' /etc/modprobe.d/bluetooth.conf; then
  110. echo 'blacklist bnep' >> /etc/modprobe.d/bluetooth.conf
  111. fi
  112. if ! grep 'blacklist btusb' /etc/modprobe.d/bluetooth.conf; then
  113. echo 'blacklist btusb' >> /etc/modprobe.d/bluetooth.conf
  114. fi
  115. if ! grep 'blacklist bluetooth' /etc/modprobe.d/bluetooth.conf; then
  116. echo 'blacklist bluetooth' >> /etc/modprobe.d/bluetooth.conf
  117. fi
  118. update-initramfs -u -k `uname -r` -v
  119. update-rc.d bluetooth remove
  120. }
  121. function running_as_root {
  122. if [[ $EUID != 0 ]] ; then
  123. echo "0"
  124. else
  125. echo "1"
  126. fi
  127. }
  128. function reset_usb_devices {
  129. for xhci in /sys/bus/pci/drivers/?hci-pci ; do
  130. if ! cd $xhci ; then
  131. return
  132. fi
  133. echo "Resetting devices from $xhci..."
  134. for i in ????:??:??.? ; do
  135. echo -n "$i" > unbind
  136. echo -n "$i" > bind
  137. done
  138. done
  139. udevadm control --reload-rules
  140. }
  141. function install_backports_kernel {
  142. # install backports kernel if possible
  143. architecture_type=$(uname -a)
  144. if [[ "$architecture_type" == *"amd64"* ]]; then
  145. apt-get -yq install linux-image-amd64 -t jessie-backports
  146. fi
  147. }
  148. function turn_off_rsys_logging {
  149. sed -i 's|mail,news.none.*|mail,news.none /dev/null|g' /etc/rsyslog.conf
  150. sed -i 's|auth,authpriv.\*.*|auth,authpriv.\* /dev/null|g' /etc/rsyslog.conf
  151. sed -i 's|mail.info.*|mail.info /dev/null|g' /etc/rsyslog.conf
  152. sed -i 's|mail.warn.*|mail.warn /dev/null|g' /etc/rsyslog.conf
  153. sed -i 's|mail.err.*|mail.err /dev/null|g' /etc/rsyslog.conf
  154. sed -i 's|daemon.\*.*|daemon.\* /dev/null|g' /etc/rsyslog.conf
  155. sed -i 's|mail.\*.*|mail.\* /dev/null|g' /etc/rsyslog.conf
  156. sed -i 's|user.\*.*|user.\* /dev/null|g' /etc/rsyslog.conf
  157. sed -i 's|news.none;mail.none.*|news.none;mail.none /dev/null|g' /etc/rsyslog.conf
  158. sed -i 's|\*.\*;auth,authpriv.none.*|\*.\*;auth,authpriv.none /dev/null|g' /etc/rsyslog.conf
  159. sed -i 's|#cron.\*|cron.\*|g' /etc/rsyslog.conf
  160. sed -i 's|cron.\*.*|cron.\* /dev/null|g' /etc/rsyslog.conf
  161. shred -zu /var/log/wtmp*
  162. shred -zu /var/log/debug*
  163. shred -zu /var/log/cron.*
  164. shred -zu /var/log/auth.*
  165. shred -zu /var/log/mail.*
  166. shred -zu /var/log/daemon.*
  167. shred -zu /var/log/user.*
  168. shred -zu /var/log/messages*
  169. }
  170. function initial_setup {
  171. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  172. return
  173. fi
  174. apt-get -yq remove --purge apache*
  175. apt-get -yq dist-upgrade
  176. apt-get -yq install ca-certificates
  177. apt-get -yq install apt-utils
  178. apt-get -yq install cryptsetup libgfshare-bin obnam sshpass wget avahi-daemon
  179. apt-get -yq install avahi-utils avahi-discover connect-proxy openssh-server
  180. apt-get -yq install sudo git dialog build-essential avahi-daemon avahi-utils
  181. apt-get -yq install avahi-discover avahi-autoipd iptables dnsutils net-tools
  182. apt-get -yq install network-manager iputils-ping libnss-mdns libnss-myhostname
  183. apt-get -yq install libnss-gw-name nano man ntp locales locales-all debconf
  184. apt-get -yq install wireless-tools wpasupplicant usbutils cryptsetup zsh
  185. apt-get -yq install pinentry-curses eatmydata iotop bc grub2 hostapd haveged
  186. apt-get -yq install cpulimit
  187. if [ ! -d $INSTALL_DIR ]; then
  188. mkdir -p $INSTALL_DIR
  189. fi
  190. mark_completed $FUNCNAME
  191. }
  192. function admin_user_sudo {
  193. if ! grep -q "$MY_USERNAME ALL=(ALL) ALL" $rootdir/etc/sudoers; then
  194. echo "$MY_USERNAME ALL=(ALL) ALL" >> $rootdir/etc/sudoers
  195. fi
  196. }
  197. function search_for_attached_usb_drive {
  198. # If a USB drive is attached then search for email,
  199. # gpg, ssh keys and emacs configuration
  200. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  201. return
  202. fi
  203. detect_usb_drive
  204. if [ -b $USB_DRIVE ]; then
  205. if [ ! -d $USB_MOUNT ]; then
  206. echo $'Mounting USB drive'
  207. mkdir $USB_MOUNT
  208. mount $USB_DRIVE $USB_MOUNT
  209. fi
  210. if [ -d $USB_MOUNT/.gnupg ]; then
  211. echo $'Importing GPG keyring'
  212. cp -r $USB_MOUNT/.gnupg /home/$MY_USERNAME
  213. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.gnupg
  214. GPG_KEYS_IMPORTED="yes"
  215. if [ ! -f /home/$MY_USERNAME/.gnupg/secring.gpg ]; then
  216. echo $'GPG files did not copy'
  217. exit 73529
  218. fi
  219. fi
  220. if [ -f $USB_MOUNT/private_key.gpg ]; then
  221. echo $'GPG private key found on USB drive'
  222. MY_GPG_PRIVATE_KEY=$USB_MOUNT/private_key.gpg
  223. fi
  224. if [ -f $USB_MOUNT/public_key.gpg ]; then
  225. echo $'GPG public key found on USB drive'
  226. MY_GPG_PUBLIC_KEY=$USB_MOUNT/public_key.gpg
  227. fi
  228. if [ -f $USB_MOUNT/letsencrypt ]; then
  229. echo $'Copying letsencrypt keys"'
  230. cp -r $USB_MOUNT/letsencrypt /etc
  231. fi
  232. if [ -d $USB_MOUNT/.ssh ]; then
  233. echo $'Importing ssh keys'
  234. cp -r $USB_MOUNT/.ssh /home/$MY_USERNAME
  235. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
  236. # for security delete the ssh keys from the usb drive
  237. if [ ! -f /home/$MY_USERNAME/.ssh/id_rsa ]; then
  238. echo $'ssh files did not copy'
  239. exit 8
  240. fi
  241. fi
  242. if [ -f $USB_MOUNT/.emacs ]; then
  243. echo $'Importing .emacs file'
  244. cp -f $USB_MOUNT/.emacs /home/$MY_USERNAME/.emacs
  245. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs
  246. fi
  247. if [ -d $USB_MOUNT/.emacs.d ]; then
  248. echo $'Importing .emacs.d directory'
  249. cp -r $USB_MOUNT/.emacs.d /home/$MY_USERNAME
  250. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs.d
  251. fi
  252. if [ -d $USB_MOUNT/ssl ]; then
  253. echo $'Importing SSL certificates'
  254. cp -r $USB_MOUNT/ssl/* /etc/ssl
  255. chmod 640 /etc/ssl/certs/*
  256. chmod 400 /etc/ssl/private/*
  257. # change ownership of some certificates
  258. if [ -d /etc/prosody ]; then
  259. chown prosody:prosody /etc/ssl/private/xmpp.*
  260. chown prosody:prosody /etc/ssl/certs/xmpp.*
  261. fi
  262. if [ -d /etc/dovecot ]; then
  263. chown root:dovecot /etc/ssl/certs/dovecot.*
  264. chown root:dovecot /etc/ssl/private/dovecot.*
  265. fi
  266. if [ -f /etc/ssl/private/exim.key ]; then
  267. cp /etc/ssl/private/exim.key /etc/exim4
  268. cp /etc/ssl/certs/exim.crt /etc/exim4
  269. cp /etc/ssl/certs/exim.dhparam /etc/exim4
  270. chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  271. chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  272. fi
  273. fi
  274. if [ -d $USB_MOUNT/personal ]; then
  275. echo $'Importing personal directory'
  276. cp -r $USB_MOUNT/personal /home/$MY_USERNAME
  277. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/personal
  278. fi
  279. else
  280. if [ -d $USB_MOUNT ]; then
  281. umount $USB_MOUNT
  282. rm -rf $USB_MOUNT
  283. fi
  284. echo $'No USB drive attached'
  285. fi
  286. mark_completed $FUNCNAME
  287. }
  288. function mark_admin_user_account {
  289. set_completion_param "Admin user" "$MY_USERNAME"
  290. }
  291. function remove_instructions_from_motd {
  292. sed -i '/## /d' /etc/motd
  293. }
  294. function remove_default_user {
  295. # make sure you don't use the default user account
  296. if [[ $MY_USERNAME == "debian" ]]; then
  297. echo 'Do not use the default debian user account. Create a different user with: adduser [username]'
  298. exit 68
  299. fi
  300. # remove the default debian user to prevent it from becoming an attack vector
  301. if [ -d /home/debian ]; then
  302. userdel -r debian
  303. echo 'Default debian user account removed'
  304. fi
  305. }
  306. function create_completion_file {
  307. if [ ! -f $COMPLETION_FILE ]; then
  308. touch $COMPLETION_FILE
  309. fi
  310. }
  311. function upgrade_installation {
  312. # TODO
  313. echo ''
  314. }
  315. function disable_nfs_insecure_locks {
  316. apt-get -yq install nfs-kernel-server
  317. if grep 'insecure_locks' /etc/exports; then
  318. sed -i 's|,insecure_locks||g' /etc/exports
  319. sed -i 's|insecure_locks,||g' /etc/exports
  320. exportfs -a
  321. fi
  322. }
  323. function set_login_umask {
  324. sed -i 's|UMASK\t.*|UMASK\t\t077|g' /etc/login.defs
  325. }
  326. function disable_deferred_execution {
  327. systemctl stop atd
  328. systemctl disable atd
  329. }
  330. function set_shadow_permissions {
  331. chown root:root /etc/shadow
  332. chmod 0000 /etc/shadow
  333. chown root:root /etc/gshadow
  334. chmod 0000 /etc/gshadow
  335. }
  336. function set_max_login_tries {
  337. max_tries=$1
  338. if ! grep ' deny=' /etc/pam.d/common-auth; then
  339. sed -i "/pam_deny.so/a auth required\t\t\tpam_tally.so onerr=fail no_lock_time per_user deny=$max_tries" /etc/pam.d/common-auth
  340. else
  341. sed -i "s| deny=.*| deny=$max_tries|g" /etc/pam.d/common-auth
  342. fi
  343. if ! grep ' deny=' /etc/pam.d/common-account; then
  344. sed -i '/pam_deny.so/a account required\t\t\tpam_tally.so' /etc/pam.d/common-account
  345. else
  346. sed -i "s| deny=.*| deny=$max_tries|g" /etc/pam.d/common-account
  347. fi
  348. }
  349. function limit_user_logins {
  350. # overall max logins
  351. if ! grep '* hard maxsyslogins' /etc/security/limits.conf; then
  352. echo '* hard maxsyslogins 10' >> /etc/security/limits.conf
  353. else
  354. sed -i 's|hard maxsyslogins.*|hard maxsyslogins 10|g' /etc/security/limits.conf
  355. fi
  356. # Max logins for each user
  357. if ! grep '* hard maxlogins' /etc/security/limits.conf; then
  358. echo '* hard maxlogins 2' >> /etc/security/limits.conf
  359. else
  360. sed -i 's|hard maxlogins.*|hard maxlogins 2|g' /etc/security/limits.conf
  361. fi
  362. }
  363. function remove_serial_logins {
  364. if grep 'ttyS' /etc/securetty; then
  365. cp /etc/securetty /etc/securetty_old
  366. sed -i '/ttyS/d' /etc/securetty
  367. fi
  368. }
  369. function set_command_file_permissions {
  370. if [ -d /bin ]; then
  371. chown root:root /bin/*
  372. fi
  373. if [ -d /usr/bin ]; then
  374. chown root:root /usr/bin/*
  375. fi
  376. if [ -d /usr/local/bin ]; then
  377. chown root:root /usr/local/bin/*
  378. fi
  379. if [ -d /sbin ]; then
  380. chown root:root /sbin/*
  381. fi
  382. if [ -d /usr/sbin ]; then
  383. chown root:root /usr/sbin/*
  384. fi
  385. if [ -d /usr/local/sbin ]; then
  386. chown root:root /usr/local/sbin/*
  387. fi
  388. }
  389. function setup_firewall {
  390. function_check create_completion_file
  391. create_completion_file
  392. function_check configure_firewall
  393. configure_firewall
  394. function_check configure_firewall_ping
  395. configure_firewall_ping
  396. function_check configure_firewall_for_dns
  397. configure_firewall_for_dns
  398. function_check configure_firewall_for_avahi
  399. configure_firewall_for_avahi
  400. function_check global_rate_limit
  401. global_rate_limit
  402. }
  403. function setup_utils {
  404. read_config_param "PROJECT_REPO"
  405. write_config_param "PROJECT_REPO" "$PROJECT_REPO"
  406. function_check remove_serial_logins
  407. remove_serial_logins
  408. function_check set_max_login_tries
  409. set_max_login_tries 10
  410. function_check set_shadow_permissions
  411. set_shadow_permissions
  412. function_check remove_bluetooth
  413. remove_bluetooth
  414. function_check disable_nfs_insecure_locks
  415. disable_nfs_insecure_locks
  416. function_check set_login_umask
  417. set_login_umask
  418. function_check disable_deferred_execution
  419. disable_deferred_execution
  420. function_check turn_off_rsys_logging
  421. turn_off_rsys_logging
  422. function_check install_backports_kernel
  423. install_backports_kernel
  424. function_check create_completion_file
  425. create_completion_file
  426. function_check read_configuration
  427. read_configuration
  428. function_check check_system_type
  429. check_system_type
  430. function_check upgrade_installation
  431. upgrade_installation
  432. function_check set_default_onion_domains
  433. set_default_onion_domains
  434. function_check locale_setup
  435. locale_setup
  436. function_check parse_args
  437. parse_args
  438. function_check check_domains
  439. check_domains
  440. function_check install_static_network
  441. install_static_network
  442. function_check remove_default_user
  443. remove_default_user
  444. function_check setup_firewall
  445. setup_firewall
  446. function_check create_repo_sources
  447. create_repo_sources
  448. function_check configure_dns
  449. configure_dns
  450. function_check initial_setup
  451. initial_setup
  452. function_check install_tor
  453. install_tor
  454. #function_check resolve_dns_via_tor
  455. #resolve_dns_via_tor
  456. function_check install_command_line_browser
  457. install_command_line_browser
  458. function_check enable_ssh_via_onion
  459. enable_ssh_via_onion
  460. function_check check_date
  461. check_date
  462. function_check install_dynamicdns
  463. install_dynamicdns
  464. function_check randomize_cron
  465. randomize_cron
  466. function_check create_freedns_updater
  467. create_freedns_updater
  468. function_check mark_admin_user_account
  469. mark_admin_user_account
  470. function_check enforce_good_passwords
  471. enforce_good_passwords
  472. function_check change_login_message
  473. change_login_message
  474. function_check enable_zram
  475. enable_zram
  476. function_check random_number_generator
  477. random_number_generator
  478. function_check set_your_domain_name
  479. set_your_domain_name
  480. function_check configure_internet_protocol
  481. configure_internet_protocol
  482. function_check create_git_project
  483. create_git_project
  484. function_check setup_wifi
  485. setup_wifi
  486. function_check configure_ssh
  487. configure_ssh
  488. function_check configure_ssh_onion
  489. configure_ssh_onion
  490. function_check allow_ssh_to_onion_address
  491. allow_ssh_to_onion_address
  492. function_check remove_instructions_from_motd
  493. remove_instructions_from_motd
  494. function_check check_hwrng
  495. check_hwrng
  496. function_check search_for_attached_usb_drive
  497. search_for_attached_usb_drive
  498. function_check regenerate_ssh_keys
  499. regenerate_ssh_keys
  500. function_check create_mirrors
  501. create_mirrors
  502. function_check create_upgrade_script
  503. create_upgrade_script
  504. function_check letsencrypt_renewals
  505. letsencrypt_renewals
  506. function_check install_watchdog_script
  507. install_watchdog_script
  508. function_check install_avahi
  509. install_avahi
  510. function_check create_avahi_onion_domains
  511. create_avahi_onion_domains
  512. #function_check install_atheros_wifi
  513. #install_atheros_wifi
  514. function_check route_outgoing_traffic_through_tor
  515. route_outgoing_traffic_through_tor
  516. function_check upgrade_golang
  517. upgrade_golang
  518. function_check install_tomb
  519. install_tomb
  520. function_check admin_user_sudo
  521. admin_user_sudo
  522. function_check limit_user_logins
  523. limit_user_logins
  524. }
  525. function setup_email {
  526. function_check create_completion_file
  527. create_completion_file
  528. function_check install_email
  529. install_email
  530. function_check create_procmail
  531. create_procmail
  532. function_check handle_admin_emails
  533. handle_admin_emails
  534. function_check spam_filtering
  535. spam_filtering
  536. function_check configure_imap
  537. configure_imap
  538. #function_check configure_imap_client_certs
  539. #configure_imap_client_certs
  540. function_check configure_gpg
  541. configure_gpg
  542. function_check refresh_gpg_keys
  543. refresh_gpg_keys
  544. function_check configure_backup_key
  545. configure_backup_key
  546. function_check install_monkeysphere
  547. install_monkeysphere
  548. function_check encrypt_incoming_email
  549. encrypt_incoming_email
  550. function_check encrypt_outgoing_email
  551. encrypt_outgoing_email
  552. function_check email_client
  553. email_client
  554. function_check email_archiving
  555. email_archiving
  556. function_check email_from_address
  557. email_from_address
  558. function_check create_public_mailing_list
  559. create_public_mailing_list
  560. #function check create_private_mailing_list
  561. #create_private_mailing_list
  562. function_check encrypt_all_email
  563. encrypt_all_email
  564. function_check import_email
  565. import_email
  566. }
  567. function setup_web {
  568. function_check create_completion_file
  569. create_completion_file
  570. function_check install_web_server
  571. install_web_server
  572. function_check install_web_server_access_control
  573. install_web_server_access_control
  574. }
  575. function upgrade_apps {
  576. function_check create_completion_file
  577. create_completion_file
  578. APPS_COMPLETED=()
  579. FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
  580. # for all the app scripts
  581. for filename in $FILES
  582. do
  583. app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
  584. item_in_array "${app_name}" "${APPS_COMPLETED[@]}"
  585. if [[ $? != 0 ]]; then
  586. function_check app_is_installed
  587. if [[ "$(app_is_installed $a)" == "1" ]]; then
  588. app_load_variables ${app_name}
  589. APPS_COMPLETED+=("${app_name}")
  590. function_check upgrade_${app_name}
  591. upgrade_${app_name}
  592. fi
  593. fi
  594. done
  595. }
  596. function setup_apps {
  597. is_interactive=$1
  598. function_check create_completion_file
  599. create_completion_file
  600. function_check detect_installable_apps
  601. detect_installable_apps
  602. function_check choose_apps_for_variant
  603. choose_apps_for_variant "$SYSTEM_TYPE"
  604. echo $"System variant: $SYSTEM_TYPE"
  605. echo $'The following apps have been selected'
  606. echo ''
  607. function_check list_chosen_apps
  608. list_chosen_apps
  609. echo ''
  610. function_check upgrade_apps
  611. upgrade_apps
  612. if [[ $is_interactive == "menuconfig"* ]]; then
  613. ${PROJECT_NAME}-addremove add-all
  614. if [ ! "$?" = "0" ]; then
  615. exit 72524
  616. fi
  617. fi
  618. if [[ $is_interactive == "noninteractive" || $is_interactive == "headless" ]]; then
  619. function_check install_apps
  620. install_apps
  621. if [ ! $APP_INSTALLED_SUCCESS ]; then
  622. echo $'One or more apps failed to install'
  623. fi
  624. fi
  625. }
  626. function combine_all_scripts {
  627. combined_filename=$1
  628. # initial variables
  629. cp $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars $combined_filename
  630. # utilities
  631. UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
  632. for f in $UTILS_FILES
  633. do
  634. # this removes the first line, which is #!/bin/bash
  635. tail -n +2 "$f" >> $combined_filename
  636. done
  637. # base system
  638. BASE_SYSTEM_FILES=/usr/share/${PROJECT_NAME}/base/${PROJECT_NAME}-base-*
  639. for f in $BASE_SYSTEM_FILES
  640. do
  641. tail -n +2 "$f" >> $combined_filename
  642. done
  643. # apps
  644. APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
  645. for f in $APP_FILES
  646. do
  647. tail -n +2 "$f" >> $combined_filename
  648. done
  649. }
  650. # NOTE: deliberately no exit 0