#!/bin/sh
#
#    Copyright (C) 2008-2020  Rubén Rodríguez <ruben@trisquel.info>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#

#STAGE-1-DEBOOTSTRAP

VERSION=7
. ./config

CODENAMECAPS=$(echo $CODENAME | /bin/sed -e "s/\b\(.\)/\u\1/g")
POINT_RELEASE=""

# Disable dynamic motd
find -name *motd-news* -delete
sed '/motd-news/d' -i debian/rules

cat << EOF > motd/01-banner
#!/bin/sh
echo "\
   ___        ___               ___        ___       ___        ___        ___
  /\  \      /\  \      ___    /\  \      /\  \     /\__\      /\  \      /\__\\\\
  \ \  \    /  \  \    /\  \  /  \  \    /  \  \   / /  /     /  \  \    / /  /
   \ \  \  / /\ \  \   \ \  \/ /\ \  \  / /\ \  \ / /  /     / /\ \  \  / /  /
   /  \  \/  \ \ \  \  /  \__\ \ \ \  \/ /  \ \  \ /  /  ___/  \ \ \  \/ /  /
  / /\ \__\/\ \ \ \__\/ /\/__/\ \ \ \__\/__/ \ \__\__/  /\__\/\ \ \ \__\/__/
 / /  \/__/_|  \/ /  / /  /\ \ \ \ \/__/\  \ / /  /  \ / /  /\ \ \ \/__/\  \\\\
/ /  /      | |  /  / /__/  \ \ \ \__\ \ \/\/ /  / \  / /  /\ \ \ \__\ \ \  \\\\
\/__/       | |\/__/\ \__\   \ \/ /  /  \    /  / \ \/ /  /  \ \ \/__/  \ \  \\\\
            | |  |   \/__/    \  /  /    \  /  /   \  /  /    \ \__\     \ \__\\\\
             \|__|             \/__/      \/__/     \/__/      \/__/      \/__/
"
EOF

cat << EOF > motd/10-help-text
#!/bin/sh
echo "Documentation: https://trisquel.info/wiki/"
echo "Support forum: https://trisquel.info/forum/"
EOF

chmod 755 motd/*

cat << EOF > etc/legal

  The programs included with the Trisquel GNU/Linux system are free software.
  The exact distribution terms for each program are described in the individual
  files in /usr/share/doc/*/copyright.

  Trisquel GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted
  by applicable law.

EOF

cat << EOF >> share/dot.bashrc
# Trisquel aliases for root
if [ "$TERM" != "dumb" ] && [ -x /usr/bin/dircolors ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
    alias ll='ls -lh'
    alias la='ls -A'
    alias l='ls -CF'
    alias dir='ls --color=auto --format=vertical'
    alias vdir='ls --color=auto --format=long'

    alias grep='grep --color=auto'
    alias egrep='egrep --color=auto'
    alias fgrep='fgrep --color=auto'
    
    alias rm='rm -i'
    [ -f /usr/bin/vim ] && alias vi='vim' || alias vi='vim.tiny'
    [ -f /usr/bin/vim ] || alias vim='vim.tiny'
fi
EOF

cat > etc/issue <<EOF
Trisquel GNU/Linux $REVISION$POINT_RELEASE \n \l

EOF

cat > etc/issue.net <<EOF
Trisquel GNU/Linux $REVISION$POINT_RELEASE
EOF

cat > etc/lsb-release <<EOF
DISTRIB_ID=Trisquel
DISTRIB_RELEASE=$REVISION$POINT_RELEASE
DISTRIB_CODENAME=$CODENAME
DISTRIB_DESCRIPTION="Trisquel GNU/Linux $REVISION$POINT_RELEASE, $CODENAMECAPS"
EOF

cat > etc/os-release <<EOF
NAME="Trisquel GNU/Linux"
VERSION="$REVISION$POINT_RELEASE, $CODENAMECAPS"
ID=trisquel
ID_LIKE=debian
PRETTY_NAME="Trisquel GNU/Linux $CODENAMECAPS ($REVISION$POINT_RELEASE)"
VERSION_ID="$REVISION$POINT_RELEASE"
VERSION_CODENAME="$CODENAME"
UBUNTU_CODENAME="$UPSTREAM"
HOME_URL="https://trisquel.info/"
SUPPORT_URL="https://trisquel.info/wiki"
BUG_REPORT_URL="https://gitlab.trisquel.org/trisquel"
PRIVACY_POLICY_URL="https://trisquel.info/legal"
EOF

cat << EOF > origins/trisquel
Vendor: Trisquel
Vendor-URL: http://trisquel.info/
Bugs: https://gitlab.trisquel.org/trisquel
Parent: Ubuntu
EOF

echo /etc/dpkg/origins/trisquel >> debian/conffiles

sed s/ubuntu/trisquel/ -i debian/rules

changelog "Compiled for Trisquel"
sed -i "1s/(\(.*\))/(1:\1)/" debian/changelog

package

