home · contact · privacy
Fix user setting in postinstall script.
[config] / jessie_postinstall.sh
index 02e0b3ac20f07b37cc2df3fa8a5177f4e5ea3ac1..02e4e23f3acd43562a366dbb9d6f993ac1a03af6 100755 (executable)
@@ -6,11 +6,32 @@ if [ ! "$1" = "thinkpad" ] && [ ! "$1" = "server" ]; then
     echo "Need argument."
     false
 fi
-
 if [ "$1" = "thinkpad" ] && [ ! "$2" = "X200s" ] && [ ! "$2" = "T450s" ]; then
     echo "Need Thinkpad type."
     false
 fi
+if [ "$1" = "server" ] && [ ! "$2" = "personal" ] && [ ! "$2" = "public" ]; then
+    echo "Need server purpose."
+    false
+fi
+if [ "$2" = "personal" ] && [ ! "$3" = "test.plomlompom.com" ] && \
+    [ ! "$3" = "plomlompom.com" ]; then
+    echo "Need server domain"
+    false
+fi
+
+# Some important variables
+if [ "$3" = "plomlompom.com" ]; then
+    hostname="plomlompom"
+elif [ "$3" = "test.plomlompom.com" ]; then
+    hostname="test.plomlompom"
+elif [ "$2" = "public" ]; then
+    hostname="twtxt.plomlompom"
+elif [ "$2" = "X200s" ]; then
+    hostname="X220s"
+elif [ "$2" = "T450s" ]; then
+    hostname="T450s"
+fi
 
 if [ "$1" = "server" ]; then
     # Set root pw.
@@ -35,13 +56,13 @@ rm list_all_packages list_white_unsorted list_white list_black
 echo 'APT::Install-Recommends "false";' >> /etc/apt/apt.conf.d/99mindeps
 echo 'APT::Install-Suggests "false";' >> /etc/apt/apt.conf.d/99mindeps
 
+# Set hostname and FQDN.
+echo $hostname > /etc/hostname
+hostname $hostname
 if [ "$1" = "server" ]; then
-    # Set hostname and FQDN.
-    echo 'plomlompom' > /etc/hostname
-    hostname 'plomlompom'
     echo '127.0.0.1 localhost' > /etc/hosts
-    ip=`hostname -I`
-    echo "$ip plomlompom.com plomlompom" >> /etc/hosts
+    ip=`hostname -I | cut -d " " -f 1`
+    echo "$ip $hostname.com $hostname" >> /etc/hosts
 
     # Call dhclient on startup.
     cat > /etc/systemd/system/dhclient.service << EOF
@@ -55,12 +76,6 @@ ExecStart=/sbin/dhclient eth0
 WantedBy=multi-user.target
 EOF
     systemctl enable /etc/systemd/system/dhclient.service
-elif [ "$1" = "thinkpad" ]; then
-    if [ "$2" = "X200s" ]; then
-        echo 'X200s' > /etc/hostname
-    elif [ "$2" = "T450s" ]; then
-        echo 'T450s' > /etc/hostname
-    fi
 fi
 
 # Package management config, system upgrade.
@@ -70,7 +85,7 @@ echo 'deb http://security.debian.org/ jessie/updates main contrib non-free' \
     >> /etc/apt/sources.list
 echo 'deb http://ftp.debian.org/debian/ jessie-updates main contrib non-free' \
     >> /etc/apt/sources.list
-if [ "$1" = "thinkpad" ]; then
+if [ "$1" = "thinkpad" ] || [ "$2" = "public" ]; then
     echo 'deb http://ftp.debian.org/debian/ jessie-backports main contrib' \
 ' non-free' >> /etc/apt/sources.list
     echo 'deb http://ftp.debian.org/debian/ testing main contrib non-free' \
@@ -142,7 +157,13 @@ config/bin/symlink.sh
 useradd -m -s /bin/bash plom
 rm -rf /home/plom/config
 su - plom -c 'git clone http://github.com/plomlompom/config /home/plom/config'
-su plom -c '/home/plom/config/bin/symlink.sh '$1
+su plom -c '/home/plom/config/bin/symlink.sh '$1' '$2' '$3
+
+# Allow user to sudo.
+if [ "$1" = "thinkpad" ]; then
+    apt-get -y install sudo
+    adduser plom sudo
+fi
 
 # Set up editor.
 mkdir -p .vimbackups
@@ -161,33 +182,47 @@ if [ "$1" = "server" ]; then
     su plom -c 'mkdir -p /home/plom/mail/inbox/{cur,new,tmp}'
     su plom -c 'mkdir -p /home/plom/mail/new_inbox/{cur,new,tmp}'
     sed -i 's/^delete = true$/delete = false/g' \
-        /home/plom/config/dotfiles/user/server/getmail/getmailrc
-    DEBIAN_FRONTEND=noninteractive apt-get -y install getmail4 procmail mutt \
-        postfix maildrop
+        /home/plom/config/dotfiles/user/server/personal/minimal/getmail/getmailrc
+    DEBIAN_FRONTEND=noninteractive apt-get -y install mutt postfix maildrop
     cp config/systemfiles/main.cf /etc/postfix/main.cf
+    sed -i 's/HOSTNAME/'$hostname.com'/g' /etc/postfix/main.cf
     cp config/systemfiles/aliases /etc/aliases
     newaliases
     service postfix restart
+    if [ "$2" = "personal" ]; then
+    apt-get -y install getmail4 procmail
+    fi
 
     # Set up regular system update reminder.
     apt-get -y install cron
     su plom -c "echo '0 18 * * 0 ~/config/bin/simplemail.sh '\
         '~/config/mails/update_reminder' | crontab -"
 
-    # Set up screen/weechat/OTR/bitlbee. Make bitlbee listen only locally.
-    apt-get -y install screen weechat-plugins python-potr bitlbee
-    sed -i 's/^# DaemonInterface/DaemonInterface = 127.0.0.1 '\
+    if [ "$2" = "personal" ]; then
+        # Set up screen/weechat/OTR/bitlbee. Make bitlbee listen only locally.
+        apt-get -y install screen weechat-plugins python-potr bitlbee
+        sed -i 's/^# DaemonInterface/DaemonInterface = 127.0.0.1 '\
 '# DaemonInterface/' /etc/bitlbee/bitlbee.conf
-    sedtest=`grep -E '^DaemonInterface = 127.0.0.1 #' \
-        /etc/bitlbee/bitlbee.conf | wc -l | cut -d ' ' -f 1`
-    if [ 0 -eq $sedtest ]; then
-        false
+        sedtest=`grep -E '^DaemonInterface = 127.0.0.1 #' \
+            /etc/bitlbee/bitlbee.conf | wc -l | cut -d ' ' -f 1`
+        if [ 0 -eq $sedtest ]; then
+            false
+        fi
+        cp config/systemfiles/weechat.service \
+            /etc/systemd/system/weechat.service
+        systemctl enable /etc/systemd/system/weechat.service
+
+        # Send instructions mail.
+        config/bin/simplemail.sh config/mails/server_postinstall_finished
+
+    elif [ "$2" = "public" ]; then
+        # Set up twtxt environment.
+        apt-get -y -t jessie-backports install golang
+        su - plom -c 'git clone '\
+'https://github.com/plomlompom/htwtxt $GOPATH/src/htwtxt'
+        su - plom -c 'go get htwtxt'
+        su - plom -c 'mkdir ~/htwtxt'
     fi
-    cp config/systemfiles/weechat.service  /etc/systemd/system/weechat.service
-    systemctl enable /etc/systemd/system/weechat.service
-
-    # Send instructions mail.
-    config/bin/simplemail.sh config/mails/server_postinstall_finished
 
 elif [ "$1" = "thinkpad" ]; then
     # Set up networking (wifi!).