set -e
set -x
-if [ "$#" -ne 3 ]; then
- echo 'Need domain name and mail and old server.'
+if [ "$#" -ne 4 ]; then
+ echo 'Need domain name and mail and old server and init state (old, new?).'
+ false
+fi
+if [ ! "$4" = "old" ] && [ ! "$4" = "new" ]; then
+ echo "Need init state to be either 'old' or 'new'"
false
fi
domain="$1"
mail="$2"
old_server="$3"
+init_state="$4"
# Install configs, set up firewall.
echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
geheim_dir=geheim
su -lc "ln -s /home/plom/${dump_dir} /var/www-dump/${dump_dir}" plom
su -lc "ln -s /home/plom/${geheim_dir} /var/www-dump/${geheim_dir}" plom
-# Use upper outcommented instead of lower code if setting up new empty server.
-#su -lc "mkdir ${dump_dir} ${geheim_dir}" plom
-#password_geheim=$(pwgen -1)
-#echo "foo:{PLAIN}${password_geheim}" > /var/www-dump/password_geheim
-#echo "geheim password is: ${password_geheim}"
-cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
-su -lc "./mirror_dir.sh ${old_server} /home/plom/${dump_dir}" plom
-su -lc "./mirror_dir.sh ${old_server} /home/plom/${geheim_dir}" plom
-su -lc "scp plom@${old_server}:/var/www-dump/password_geheim ~" plom
-mv /home/plom/password_geheim /var/www-dump/password_geheim
-rm /home/plom/mirror_dir.sh
+if [ "${init_state}" = "new" ]; then
+ su -lc "mkdir ${dump_dir} ${geheim_dir}" plom
+ password_geheim=$(pwgen -1)
+ echo "foo:{PLAIN}${password_geheim}" > /var/www-dump/password_geheim
+ echo "geheim password is: ${password_geheim}"
+else
+ cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
+ su -lc "./mirror_dir.sh ${old_server} /home/plom/${dump_dir}" plom
+ su -lc "./mirror_dir.sh ${old_server} /home/plom/${geheim_dir}" plom
+ su -lc "scp plom@${old_server}:/var/www-dump/password_geheim ~" plom
+ mv /home/plom/password_geheim /var/www-dump/password_geheim
+ rm /home/plom/mirror_dir.sh
+fi
# Set up redo.
wget http://news.dieweltistgarnichtso.net/bin/archives/redo-sh.tar.gz
cp "${config_tree_prefix}/other_files/url-catcher_customizations.json" /home/plom/url-catcher/customizations.json
systemctl enable url_catcher.service
service url_catcher start
-# Outcomment if setting up new / not migrating.
-cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
-su -lc "./mirror_dir.sh ${old_server} /home/plom/url-catcher/ips" plom
-su -lc "./mirror_dir.sh ${old_server} /home/plom/url-catcher/lists" plom
-rm /home/plom/mirror_dir.sh
+if [ ! "${init_state}" = "new" ]; then
+ cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
+ su -lc "./mirror_dir.sh ${old_server} /home/plom/url-catcher/ips" plom
+ su -lc "./mirror_dir.sh ${old_server} /home/plom/url-catcher/lists" plom
+ rm /home/plom/mirror_dir.sh
+fi
# Set up index.html
cp "${config_tree_prefix}/other_files/dumpsite_index.html" /var/www-dump/index.html
# To use this dir, "git clone --mirror" repo source paths into it as user plom.
# As user plom, touch git-daemon-export-ok files into it to make the repo
# publically available.
-if [ "$init_state" = "new" ]; then
+if [ "${init_state}" = "new" ]; then
mkdir /var/repos
chown plom:plom /var/repos
else
rm -rf /var/www
mkdir /var/www
chown plom:plom /var/www
-if [ "$init_state" = "new" ]; then
+if [ "${init_state}" = "new" ]; then
su -lc "cd /var/repos && git clone --mirror ${old_server}:repos/website" plom
cp "${config_tree_prefix}/other_files/website_hook_post-receive" /var/repos/website.git/hooks/post-receive
fi
chown -R plom:plom "${irclogs_dir}"
mkdir -p "${irclogs_pw_dir}"
chown -R plom:plom "${irclogs_pw_dir}"
-if [ "$init_state" = "new" ]; then
+if [ "${init_state}" = "new" ]; then
su -lc "cd /var/repos && git clone --mirror https://plomlompom.com/repos/clone/plomlombot-irc" plom
su -lc "touch /var/repos/plomlombot-irc.git/git-daemon-export-ok" plom
cp "${config_tree_prefix}/other_files/plomlombot_hook_post-receive" /var/repos/plomlombot-irc.git/hooks/post-receive
fi
-
su -lc "git clone /var/repos/plomlombot-irc.git" plom
cp "${config_tree_prefix}/other_files/plomlombot_daemon.sh" /home/plom/
chown plom:plom /home/plom/plomlombot_daemon.sh
-if [ "$init_state" = "new" ]; then
+if [ "${init_state}" = "new" ]; then
echo 'bot: plomlombog plomlombog #plomlomtest irc.freenode.net foo bar' >> /home/plom/.plomlombot
chown plom:plom /home/plom/.plomlombot
else