freedombone-utils-setup 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  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 separate_tmp_filesystem {
  100. tmp_filesystem_size_mb=$1
  101. if [ ! -d /tmp ]; then
  102. mkdir -p /tmp
  103. fi
  104. if ! grep -q '/tmp' /etc/fstab; then
  105. mount -t tmpfs -o size=${tmp_filesystem_size_mb}m tmpfs /tmp
  106. echo "tmpfs /tmp tmpfs nodev,nosuid,noexec,nodiratime,size=${tmp_filesystem_size_mb}M 0 0" >> /etc/fstab
  107. fi
  108. }
  109. function remove_bluetooth {
  110. rmmod -f bnep
  111. rmmod -f bluetooth
  112. if [ -f /etc/default/bluetooth ]; then
  113. if grep "BLUETOOTH_ENABLED=" /etc/default/bluetooth; then
  114. sed -i 's|BLUETOOTH_ENABLED=.*|BLUETOOTH_ENABLED=0|g' /etc/default/bluetooth
  115. else
  116. echo "BLUETOOTH_ENABLED=0" >> /etc/default/bluetooth
  117. fi
  118. fi
  119. if ! grep 'blacklist bnep' /etc/modprobe.d/bluetooth.conf; then
  120. echo 'blacklist bnep' >> /etc/modprobe.d/bluetooth.conf
  121. fi
  122. if ! grep 'blacklist btusb' /etc/modprobe.d/bluetooth.conf; then
  123. echo 'blacklist btusb' >> /etc/modprobe.d/bluetooth.conf
  124. fi
  125. if ! grep 'blacklist bluetooth' /etc/modprobe.d/bluetooth.conf; then
  126. echo 'blacklist bluetooth' >> /etc/modprobe.d/bluetooth.conf
  127. fi
  128. update-initramfs -u -k `uname -r` -v
  129. update-rc.d bluetooth remove
  130. }
  131. function running_as_root {
  132. if [[ $EUID != 0 ]] ; then
  133. echo "0"
  134. else
  135. echo "1"
  136. fi
  137. }
  138. function reset_usb_devices {
  139. for xhci in /sys/bus/pci/drivers/?hci-pci ; do
  140. if ! cd $xhci ; then
  141. return
  142. fi
  143. echo "Resetting devices from $xhci..."
  144. for i in ????:??:??.? ; do
  145. echo -n "$i" > unbind
  146. echo -n "$i" > bind
  147. done
  148. done
  149. udevadm control --reload-rules
  150. }
  151. function install_backports_kernel {
  152. # install backports kernel if possible
  153. architecture_type=$(uname -a)
  154. if [[ "$architecture_type" == *"amd64"* ]]; then
  155. apt-get -yq install linux-image-amd64 -t jessie-backports
  156. fi
  157. }
  158. function turn_off_rsys_logging {
  159. sed -i 's|mail,news.none.*|mail,news.none /dev/null|g' /etc/rsyslog.conf
  160. sed -i 's|auth,authpriv.\*.*|auth,authpriv.\* /dev/null|g' /etc/rsyslog.conf
  161. sed -i 's|mail.info.*|mail.info /dev/null|g' /etc/rsyslog.conf
  162. sed -i 's|mail.warn.*|mail.warn /dev/null|g' /etc/rsyslog.conf
  163. sed -i 's|mail.err.*|mail.err /dev/null|g' /etc/rsyslog.conf
  164. sed -i 's|daemon.\*.*|daemon.\* /dev/null|g' /etc/rsyslog.conf
  165. sed -i 's|mail.\*.*|mail.\* /dev/null|g' /etc/rsyslog.conf
  166. sed -i 's|user.\*.*|user.\* /dev/null|g' /etc/rsyslog.conf
  167. sed -i 's|news.none;mail.none.*|news.none;mail.none /dev/null|g' /etc/rsyslog.conf
  168. sed -i 's|\*.\*;auth,authpriv.none.*|\*.\*;auth,authpriv.none /dev/null|g' /etc/rsyslog.conf
  169. sed -i 's|#cron.\*|cron.\*|g' /etc/rsyslog.conf
  170. sed -i 's|cron.\*.*|cron.\* /dev/null|g' /etc/rsyslog.conf
  171. shred -zu /var/log/wtmp*
  172. shred -zu /var/log/debug*
  173. shred -zu /var/log/cron.*
  174. shred -zu /var/log/auth.*
  175. shred -zu /var/log/mail.*
  176. shred -zu /var/log/daemon.*
  177. shred -zu /var/log/user.*
  178. shred -zu /var/log/messages*
  179. }
  180. function initial_setup {
  181. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  182. return
  183. fi
  184. apt-get -yq remove --purge apache*
  185. apt-get -yq dist-upgrade
  186. apt-get -yq install ca-certificates
  187. apt-get -yq install apt-utils
  188. apt-get -yq install cryptsetup libgfshare-bin obnam sshpass wget avahi-daemon
  189. apt-get -yq install avahi-utils avahi-discover connect-proxy openssh-server
  190. apt-get -yq install sudo git dialog build-essential avahi-daemon avahi-utils
  191. apt-get -yq install avahi-discover avahi-autoipd iptables dnsutils net-tools
  192. apt-get -yq install network-manager iputils-ping libnss-mdns libnss-myhostname
  193. apt-get -yq install libnss-gw-name nano man ntp locales locales-all debconf
  194. apt-get -yq install wireless-tools wpasupplicant usbutils cryptsetup zsh
  195. apt-get -yq install pinentry-curses eatmydata iotop bc hostapd haveged
  196. apt-get -yq install cpulimit screen
  197. if [[ $ARCHITECTURE == 'qemu'* || $ARCHITECTURE == 'amd64' || $ARCHITECTURE == 'x86_64' || $ARCHITECTURE == 'i686' || $ARCHITECTURE == 'i386' ]]; then
  198. apt-get -yq install grub2
  199. fi
  200. if [ ! -d $INSTALL_DIR ]; then
  201. mkdir -p $INSTALL_DIR
  202. fi
  203. mark_completed $FUNCNAME
  204. }
  205. function admin_user_sudo {
  206. if ! grep -q "$MY_USERNAME ALL=(ALL) ALL" $rootdir/etc/sudoers; then
  207. echo "$MY_USERNAME ALL=(ALL) ALL" >> $rootdir/etc/sudoers
  208. fi
  209. }
  210. function search_for_attached_usb_drive {
  211. # If a USB drive is attached then search for email,
  212. # gpg, ssh keys and emacs configuration
  213. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  214. return
  215. fi
  216. detect_usb_drive
  217. if [ -b $USB_DRIVE ]; then
  218. if [ ! -d $USB_MOUNT ]; then
  219. echo $'Mounting USB drive'
  220. mkdir $USB_MOUNT
  221. mount $USB_DRIVE $USB_MOUNT
  222. fi
  223. if [ -d $USB_MOUNT/.gnupg ]; then
  224. echo $'Importing GPG keyring'
  225. cp -r $USB_MOUNT/.gnupg /home/$MY_USERNAME
  226. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.gnupg
  227. GPG_KEYS_IMPORTED="yes"
  228. if [ ! -f /home/$MY_USERNAME/.gnupg/secring.gpg ]; then
  229. echo $'GPG files did not copy'
  230. exit 73529
  231. fi
  232. fi
  233. if [ -f $USB_MOUNT/private_key.gpg ]; then
  234. echo $'GPG private key found on USB drive'
  235. MY_GPG_PRIVATE_KEY=$USB_MOUNT/private_key.gpg
  236. fi
  237. if [ -f $USB_MOUNT/public_key.gpg ]; then
  238. echo $'GPG public key found on USB drive'
  239. MY_GPG_PUBLIC_KEY=$USB_MOUNT/public_key.gpg
  240. fi
  241. if [ -f $USB_MOUNT/letsencrypt ]; then
  242. echo $'Copying letsencrypt keys"'
  243. cp -r $USB_MOUNT/letsencrypt /etc
  244. fi
  245. if [ -d $USB_MOUNT/.ssh ]; then
  246. echo $'Importing ssh keys'
  247. cp -r $USB_MOUNT/.ssh /home/$MY_USERNAME
  248. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
  249. # for security delete the ssh keys from the usb drive
  250. if [ ! -f /home/$MY_USERNAME/.ssh/id_rsa ]; then
  251. echo $'ssh files did not copy'
  252. exit 8
  253. fi
  254. fi
  255. if [ -f $USB_MOUNT/.emacs ]; then
  256. echo $'Importing .emacs file'
  257. cp -f $USB_MOUNT/.emacs /home/$MY_USERNAME/.emacs
  258. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs
  259. fi
  260. if [ -d $USB_MOUNT/.emacs.d ]; then
  261. echo $'Importing .emacs.d directory'
  262. cp -r $USB_MOUNT/.emacs.d /home/$MY_USERNAME
  263. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs.d
  264. fi
  265. if [ -d $USB_MOUNT/ssl ]; then
  266. echo $'Importing SSL certificates'
  267. cp -r $USB_MOUNT/ssl/* /etc/ssl
  268. chmod 640 /etc/ssl/certs/*
  269. chmod 400 /etc/ssl/private/*
  270. # change ownership of some certificates
  271. if [ -d /etc/prosody ]; then
  272. chown prosody:prosody /etc/ssl/private/xmpp.*
  273. chown prosody:prosody /etc/ssl/certs/xmpp.*
  274. fi
  275. if [ -d /etc/dovecot ]; then
  276. chown root:dovecot /etc/ssl/certs/dovecot.*
  277. chown root:dovecot /etc/ssl/private/dovecot.*
  278. fi
  279. if [ -f /etc/ssl/private/exim.key ]; then
  280. cp /etc/ssl/private/exim.key /etc/exim4
  281. cp /etc/ssl/certs/exim.crt /etc/exim4
  282. cp /etc/ssl/certs/exim.dhparam /etc/exim4
  283. chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  284. chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  285. fi
  286. fi
  287. if [ -d $USB_MOUNT/personal ]; then
  288. echo $'Importing personal directory'
  289. cp -r $USB_MOUNT/personal /home/$MY_USERNAME
  290. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/personal
  291. fi
  292. else
  293. if [ -d $USB_MOUNT ]; then
  294. umount $USB_MOUNT
  295. rm -rf $USB_MOUNT
  296. fi
  297. echo $'No USB drive attached'
  298. fi
  299. mark_completed $FUNCNAME
  300. }
  301. function mark_admin_user_account {
  302. set_completion_param "Admin user" "$MY_USERNAME"
  303. }
  304. function remove_instructions_from_motd {
  305. sed -i '/## /d' /etc/motd
  306. }
  307. function remove_default_user {
  308. # make sure you don't use the default user account
  309. if [[ $MY_USERNAME == "debian" ]]; then
  310. echo 'Do not use the default debian user account. Create a different user with: adduser [username]'
  311. exit 68
  312. fi
  313. # remove the default debian user to prevent it from becoming an attack vector
  314. if [ -d /home/debian ]; then
  315. userdel -r debian
  316. echo 'Default debian user account removed'
  317. fi
  318. }
  319. function create_completion_file {
  320. if [ ! -f $COMPLETION_FILE ]; then
  321. touch $COMPLETION_FILE
  322. fi
  323. }
  324. function disable_nfs_insecure_locks {
  325. apt-get -yq install nfs-kernel-server
  326. if grep 'insecure_locks' /etc/exports; then
  327. sed -i 's|,insecure_locks||g' /etc/exports
  328. sed -i 's|insecure_locks,||g' /etc/exports
  329. exportfs -a
  330. fi
  331. }
  332. function set_login_umask {
  333. sed -i 's|UMASK\t.*|UMASK\t\t077|g' /etc/login.defs
  334. }
  335. function disable_deferred_execution {
  336. systemctl stop atd
  337. systemctl disable atd
  338. }
  339. function set_shadow_permissions {
  340. chown root:root /etc/shadow
  341. chmod 0000 /etc/shadow
  342. chown root:root /etc/gshadow
  343. chmod 0000 /etc/gshadow
  344. }
  345. function set_max_login_tries {
  346. max_tries=$1
  347. if ! grep ' deny=' /etc/pam.d/common-auth; then
  348. 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
  349. else
  350. sed -i "s| deny=.*| deny=$max_tries|g" /etc/pam.d/common-auth
  351. fi
  352. if ! grep ' deny=' /etc/pam.d/common-account; then
  353. sed -i '/pam_deny.so/a account required\t\t\tpam_tally.so' /etc/pam.d/common-account
  354. else
  355. sed -i "s| deny=.*| deny=$max_tries|g" /etc/pam.d/common-account
  356. fi
  357. }
  358. function limit_user_logins {
  359. # overall max logins
  360. if ! grep '* hard maxsyslogins' /etc/security/limits.conf; then
  361. echo '* hard maxsyslogins 10' >> /etc/security/limits.conf
  362. else
  363. sed -i 's|hard maxsyslogins.*|hard maxsyslogins 10|g' /etc/security/limits.conf
  364. fi
  365. # Max logins for each user
  366. if ! grep '* hard maxlogins' /etc/security/limits.conf; then
  367. echo '* hard maxlogins 2' >> /etc/security/limits.conf
  368. else
  369. sed -i 's|hard maxlogins.*|hard maxlogins 2|g' /etc/security/limits.conf
  370. fi
  371. }
  372. function remove_serial_logins {
  373. if grep 'ttyS' /etc/securetty; then
  374. cp /etc/securetty /etc/securetty_old
  375. sed -i '/ttyS/d' /etc/securetty
  376. fi
  377. }
  378. function set_sticky_bits {
  379. world_writable=$(find / -xdev -type d -perm -002 \! -perm -1000)
  380. for w in $world_writable; do
  381. echo "Setting sticky bit on $w"
  382. chmod +t $w
  383. done
  384. }
  385. function disable_ctrl_alt_del {
  386. ln -sf /dev/null /etc/systemd/system/ctrl-alt-del.target
  387. }
  388. function lockdown_permissions {
  389. # All commands owned by root
  390. if [ -d /root/.cache/yarn ]; then
  391. rm -rf /root/.cache/yarn
  392. fi
  393. if [ -d /usr/local/share/.cache/yarn ]; then
  394. rm -rf /usr/local/share/.cache/yarn
  395. fi
  396. if [ -f /usr/lib/ssl/certs/ssl-cert-snakeoil.pem ]; then
  397. chown root:root /usr/lib/ssl/certs/ssl-cert-snake*
  398. fi
  399. if [ -d /bin ]; then
  400. chown root:root /bin/*
  401. fi
  402. if [ -d /usr/bin ]; then
  403. chown root:root /usr/bin/*
  404. fi
  405. if [ -d /usr/local/bin ]; then
  406. chown root:root /usr/local/bin/*
  407. fi
  408. if [ -d /sbin ]; then
  409. chown root:root /sbin/*
  410. fi
  411. if [ -d /usr/sbin ]; then
  412. chown root:root /usr/sbin/*
  413. fi
  414. if [ -d /usr/local/sbin ]; then
  415. chown root:root /usr/local/sbin/*
  416. fi
  417. if [ -d /usr/share/${PROJECT_NAME} ]; then
  418. chown -R root:root /usr/share/${PROJECT_NAME}
  419. chmod -R +r /usr/share/${PROJECT_NAME}
  420. fi
  421. # All libraries owned by root
  422. if [ -d /lib ]; then
  423. chown -R root:root /lib/*
  424. fi
  425. if [ -d /lib64 ]; then
  426. chown -R root:root /lib64/*
  427. fi
  428. if [ -d /usr/lib ]; then
  429. chown -R root:root /usr/lib/*
  430. fi
  431. if [ -d /usr/lib64 ]; then
  432. chown -R root:root /usr/lib64/*
  433. fi
  434. # sudo permissions
  435. chmod 4755 /usr/bin/sudo
  436. chmod 4755 /usr/lib/sudo/sudoers.so
  437. chown root:root /etc/sudoers
  438. # permissions on email commands
  439. if [ -f /usr/bin/procmail ]; then
  440. chmod 6755 /usr/bin/procmail
  441. fi
  442. if [ -f /usr/sbin/exim ]; then
  443. chmod u+s /usr/sbin/exim
  444. fi
  445. if [ -f /usr/sbin/exim4 ]; then
  446. chmod u+s /usr/sbin/exim4
  447. fi
  448. set_sticky_bits
  449. # Create some directories to correspond with users in passwords file
  450. if [ ! -d /var/spool/lpd ]; then
  451. mkdir /var/spool/lpd
  452. fi
  453. if [ ! -d /var/spool/news ]; then
  454. mkdir /var/spool/news
  455. fi
  456. if [ ! -d /var/spool/uucp ]; then
  457. mkdir /var/spool/uucp
  458. fi
  459. if [ ! -d /var/list ]; then
  460. mkdir /var/list
  461. fi
  462. if [ ! -d /var/lib/gnats ]; then
  463. mkdir /var/lib/gnats
  464. fi
  465. if [ ! -d /var/lib/saned ]; then
  466. mkdir /var/lib/saned
  467. fi
  468. if [ -d /etc/prosody ]; then
  469. chown -R prosody /etc/prosody
  470. chmod -R 700 /etc/prosody/conf.d
  471. fi
  472. if [ -d /var/lib/prosody ]; then
  473. chown -R prosody /var/lib/prosody
  474. fi
  475. }
  476. function disable_core_dumps {
  477. if ! grep '* hard core 0' /etc/security/limits.conf; then
  478. echo '* hard core 0' >> /etc/security/limits.conf
  479. else
  480. sed -i 's|hard core.*|hard core 0|g' /etc/security/limits.conf
  481. fi
  482. }
  483. function dummy_nologin_command {
  484. if [ ! -f /sbin/nologin ]; then
  485. echo '#!/bin/bash' > /sbin/nologin
  486. chmod +x /sbin/nologin
  487. fi
  488. }
  489. function disable_null_passwords {
  490. sed -i 's| nullok_secure||g' /etc/pam.d/common-auth
  491. }
  492. function setup_firewall {
  493. function_check create_completion_file
  494. create_completion_file
  495. function_check configure_firewall
  496. configure_firewall
  497. function_check configure_firewall_ping
  498. configure_firewall_ping
  499. function_check firewall_drop_telnet
  500. firewall_drop_telnet
  501. function_check firewall_drop_spoofed_packets
  502. firewall_drop_spoofed_packets
  503. function_check firewall_rate_limits
  504. firewall_rate_limits
  505. function_check configure_firewall_for_dns
  506. configure_firewall_for_dns
  507. function_check configure_firewall_for_avahi
  508. configure_firewall_for_avahi
  509. function_check global_rate_limit
  510. global_rate_limit
  511. function_check firewall_block_bad_ip_ranges
  512. firewall_block_bad_ip_ranges
  513. }
  514. function setup_utils {
  515. read_config_param "PROJECT_REPO"
  516. write_config_param "PROJECT_REPO" "$PROJECT_REPO"
  517. function_check separate_tmp_filesystem
  518. separate_tmp_filesystem 150
  519. function_check disable_null_passwords
  520. disable_null_passwords
  521. function_check disable_ctrl_alt_del
  522. disable_ctrl_alt_del
  523. function_check dummy_nologin_command
  524. dummy_nologin_command
  525. function_check disable_core_dumps
  526. disable_core_dumps
  527. function_check remove_serial_logins
  528. remove_serial_logins
  529. function_check set_max_login_tries
  530. set_max_login_tries 10
  531. function_check set_shadow_permissions
  532. set_shadow_permissions
  533. function_check remove_bluetooth
  534. remove_bluetooth
  535. function_check disable_nfs_insecure_locks
  536. disable_nfs_insecure_locks
  537. function_check set_login_umask
  538. set_login_umask
  539. function_check disable_deferred_execution
  540. disable_deferred_execution
  541. function_check turn_off_rsys_logging
  542. turn_off_rsys_logging
  543. function_check install_backports_kernel
  544. install_backports_kernel
  545. function_check create_completion_file
  546. create_completion_file
  547. function_check read_configuration
  548. read_configuration
  549. function_check check_system_type
  550. check_system_type
  551. function_check set_default_onion_domains
  552. set_default_onion_domains
  553. function_check locale_setup
  554. locale_setup
  555. function_check parse_args
  556. parse_args
  557. function_check check_domains
  558. check_domains
  559. function_check install_static_network
  560. install_static_network
  561. function_check remove_default_user
  562. remove_default_user
  563. function_check setup_firewall
  564. setup_firewall
  565. function_check create_repo_sources
  566. create_repo_sources
  567. function_check configure_dns
  568. configure_dns
  569. function_check initial_setup
  570. initial_setup
  571. function_check install_tor
  572. install_tor
  573. #function_check resolve_dns_via_tor
  574. #resolve_dns_via_tor
  575. function_check install_command_line_browser
  576. install_command_line_browser
  577. function_check enable_ssh_via_onion
  578. enable_ssh_via_onion
  579. function_check check_date
  580. check_date
  581. function_check install_dynamicdns
  582. install_dynamicdns
  583. function_check randomize_cron
  584. randomize_cron
  585. function_check create_freedns_updater
  586. create_freedns_updater
  587. function_check mark_admin_user_account
  588. mark_admin_user_account
  589. function_check enforce_good_passwords
  590. enforce_good_passwords
  591. function_check change_login_message
  592. change_login_message
  593. function_check enable_zram
  594. enable_zram
  595. function_check random_number_generator
  596. random_number_generator
  597. function_check set_your_domain_name
  598. set_your_domain_name
  599. function_check configure_internet_protocol
  600. configure_internet_protocol
  601. function_check create_git_project
  602. create_git_project
  603. function_check setup_wifi
  604. setup_wifi
  605. function_check configure_ssh
  606. configure_ssh
  607. function_check configure_ssh_onion
  608. configure_ssh_onion
  609. function_check allow_ssh_to_onion_address
  610. allow_ssh_to_onion_address
  611. function_check remove_instructions_from_motd
  612. remove_instructions_from_motd
  613. function_check check_hwrng
  614. check_hwrng
  615. function_check search_for_attached_usb_drive
  616. search_for_attached_usb_drive
  617. function_check regenerate_ssh_keys
  618. regenerate_ssh_keys
  619. function_check create_mirrors
  620. create_mirrors
  621. function_check create_upgrade_script
  622. create_upgrade_script
  623. function_check letsencrypt_renewals
  624. letsencrypt_renewals
  625. function_check install_watchdog_script
  626. install_watchdog_script
  627. function_check install_avahi
  628. install_avahi
  629. function_check create_avahi_onion_domains
  630. create_avahi_onion_domains
  631. #function_check install_atheros_wifi
  632. #install_atheros_wifi
  633. function_check route_outgoing_traffic_through_tor
  634. route_outgoing_traffic_through_tor
  635. function_check upgrade_golang
  636. upgrade_golang
  637. function_check install_tomb
  638. install_tomb
  639. function_check admin_user_sudo
  640. admin_user_sudo
  641. function_check limit_user_logins
  642. limit_user_logins
  643. function_check schedule_stig_tests
  644. schedule_stig_tests
  645. }
  646. function setup_email {
  647. function_check create_completion_file
  648. create_completion_file
  649. function_check install_email
  650. install_email
  651. function_check create_procmail
  652. create_procmail
  653. function_check handle_admin_emails
  654. handle_admin_emails
  655. function_check spam_filtering
  656. spam_filtering
  657. function_check configure_imap
  658. configure_imap
  659. #function_check configure_imap_client_certs
  660. #configure_imap_client_certs
  661. function_check configure_gpg
  662. configure_gpg
  663. function_check refresh_gpg_keys
  664. refresh_gpg_keys
  665. function_check configure_backup_key
  666. configure_backup_key
  667. function_check install_monkeysphere
  668. install_monkeysphere
  669. function_check encrypt_incoming_email
  670. encrypt_incoming_email
  671. function_check encrypt_outgoing_email
  672. encrypt_outgoing_email
  673. function_check email_client
  674. email_client
  675. function_check email_archiving
  676. email_archiving
  677. function_check email_from_address
  678. email_from_address
  679. function_check create_public_mailing_list
  680. #create_public_mailing_list
  681. #function check create_private_mailing_list
  682. #create_private_mailing_list
  683. function_check encrypt_all_email
  684. encrypt_all_email
  685. function_check import_email
  686. import_email
  687. }
  688. function setup_web {
  689. function_check create_completion_file
  690. create_completion_file
  691. function_check install_web_server
  692. install_web_server
  693. function_check install_web_server_access_control
  694. install_web_server_access_control
  695. }
  696. function upgrade_apps {
  697. function_check create_completion_file
  698. create_completion_file
  699. APPS_COMPLETED=()
  700. FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
  701. # for all the app scripts
  702. for filename in $FILES
  703. do
  704. app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
  705. item_in_array "${app_name}" "${APPS_COMPLETED[@]}"
  706. if [[ $? != 0 ]]; then
  707. function_check app_is_installed
  708. if [[ "$(app_is_installed $a)" == "1" ]]; then
  709. echo ''
  710. echo ''
  711. echo $"Upgrading $a"
  712. app_load_variables ${app_name}
  713. APPS_COMPLETED+=("${app_name}")
  714. function_check upgrade_${app_name}
  715. upgrade_${app_name}
  716. fi
  717. fi
  718. done
  719. }
  720. function setup_apps {
  721. is_interactive=$1
  722. function_check create_completion_file
  723. create_completion_file
  724. function_check detect_installable_apps
  725. detect_installable_apps
  726. function_check choose_apps_for_variant
  727. choose_apps_for_variant "$SYSTEM_TYPE"
  728. echo $"System variant: $SYSTEM_TYPE"
  729. echo $'The following apps have been selected'
  730. echo ''
  731. function_check list_chosen_apps
  732. list_chosen_apps
  733. echo ''
  734. function_check upgrade_apps
  735. upgrade_apps
  736. if [[ $is_interactive == "noninteractive" || $is_interactive == "headless" ]]; then
  737. function_check install_apps
  738. install_apps
  739. if [ ! $APP_INSTALLED_SUCCESS ]; then
  740. echo $'One or more apps failed to install'
  741. fi
  742. fi
  743. }
  744. function combine_all_scripts {
  745. combined_filename=$1
  746. # initial variables
  747. cp $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars $combined_filename
  748. # utilities
  749. UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
  750. for f in $UTILS_FILES
  751. do
  752. # this removes the first line, which is #!/bin/bash
  753. tail -n +2 "$f" >> $combined_filename
  754. done
  755. # base system
  756. BASE_SYSTEM_FILES=/usr/share/${PROJECT_NAME}/base/${PROJECT_NAME}-base-*
  757. for f in $BASE_SYSTEM_FILES
  758. do
  759. tail -n +2 "$f" >> $combined_filename
  760. done
  761. # apps
  762. APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
  763. for f in $APP_FILES
  764. do
  765. tail -n +2 "$f" >> $combined_filename
  766. done
  767. }
  768. # NOTE: deliberately no exit 0