#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   exit 1
fi

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

P=ratpoison
V=1.4.9
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc libICE-dev libXft-dev libXinerama-dev libXrandr-dev libXtst-dev perl5 aterm"
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp 
/usr/local/bin/wget -nc --no-check-certificate \
http://mirror.accum.se/mirror/gnu.org/savannah/$P/$SRC.tar.xz
tar xvf $SRC*xz
cd $SRC
./configure --prefix=/usr/local --localstatedir=/var --with-xterm=aterm 
find . -name Makefile -type f -exec sed -i 's/-g -O2//g' {} \;
make -j6 # 1 secs
make install-strip DESTDIR=/tmp/$P
cd /tmp

# doc
######
mkdir -p $P-doc/usr/local/share/doc/$P-doc
mv $P/usr/local/share/info $P-doc/usr/local/share
mv $P/usr/local/share/man $P-doc/usr/local/share
# put original sample rc here as I use a modified one in main
cp $SRC/doc/sample.ratpoisonrc $P-doc/usr/local/share/doc/$P-doc/

# main
##### doc had too many files start again
rm -rf $P/usr/local/share/doc/$P
mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v 2' > $P/usr/local/share/doc/$P/COPYING
rm -rf $P/usr/local/share/emacs # we don't have it

# config
########
mkdir -p $P/usr/local/share/$P/files
echo '# Copyright (C) 2003, 2004 Shawn Betts
# Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright (is here)
# modified by aus9

# The ESCAPE KEYS = C-t mean... hold down Ctrl and press t....then RELEASE those keys 
# ratpoison should prompt you about help being C-t ?...... help = show all system and user key bindings
# If you made bad input, ratpoison will popup a notification of unbound key for "that-key-name", so you know that key is spare for you to use!

# When you have used 2 bindings to open 2 different applications......I find the easiest thing to do is know your first frame is on 0 (zero) and 
# ratpoison counts frames (workspaces) from zero....pretending I have a terminal on frame 0....and used KB combo to open a web browser on frame 1
#....to get back to that terminal input C-t 0
# be aware that if you kill frame 0....frame 1 automatically become frame 0....etc
# There are too many keys to press if you use keybinding for Next or Previous frame....IMHO

# ratpoison can support mice YMMV
# we have a "run box"  C-t ! ........and if you use it we have a history file ~/.ratpoison_history

# if you have no mouse you can stil use GUI exittc....just use arrows and space bar at the radio button section
# look for the button having a faint dash lines when selected by arror or tab
# autostart an app by removing the # symbol
# exec executable-name
############################# above were comments below are action lines or bindings
# workspace section unlike ESCAPE KEYS...to get to each work space its normal to press Alt + F1 to get to work space 1
exec rpws init 5 -k
# alternative to Alt+F1 etc for work spaces 
bind C-1 exec rpws 1
bind C-2 exec rpws 2
bind C-3 exec rpws 3
bind C-4 exec rpws 4
bind C-5 exec rpws 5
# below are mainly user keybindings
####################################
bind a exec apps
bind BackSpace  exec `aterm -fn 12x24`
# system binding .....C-c executes terminal (defined as aterm)
bind e exec exittc
bind f exec firefox
bind j exec jgmenu
# system binding.... k for kill current active window 
bind m exec `export LANG=C && aterm -fn 10x20 -e mc`
bind p exec pcmanfm
bind z exec `aterm -e nano ~/.ratpoisonrc`
# system binding ?....display all bindings
# system binding 0 ....return to frame 0 
# system binding 1 ....return to frame 1
# system binding ! ...brings up run box top RH corner   '  > $P/usr/local/share/$P/files/.ratpoisonrc 

# tce.install
############# 
mkdir -p  $P/usr/local/tce.installed
echo '#!/bin/sh
echo "ratpoison" > /etc/sysconfig/desktop

# create config as default was stay alive which IMHO was messy
USER=`cat /etc/sysconfig/tcuser`
DIR=/home/$USER  && FILE=$DIR/.ratpoisonrc && SRC=/usr/local/share/ratpoison/files/.ratpoisonrc
[ -f $FILE ] || cp $SRC $DIR/ && chmod 644 $FILE && chown $USER:staff $FILE       ' > $P/usr/local/tce.installed/$P 

chown -R root:staff $P/usr/local/tce.installed
chmod -R 775        $P/usr/local/tce.installed

# submit fixs
chmod 755 $P/usr/local/share/$P/*
chmod 644 $P/usr/local/share/ratpoison/*.c

# TCZ them
###########
LIST2="$P $P-doc "
for Z in $LIST2
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find . -not -type d | cut -c 2- | sort > /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          ratpoison-doc.tcz
Description:    man page or info format doc
Version:        1.4.9
Author:         Shawn Betts & contributors
Original-site:  http://mirror.accum.se/mirror/gnu.org/savannah/ratpoison/
Copying-policy: GPL v 2
Size:           48K
Extension_by:   aus9 @ linuxquestions.org
Tags:           window manager wm
Comments:       $ man ratpoison 
                or
                $ info ratpoison 
                texinfo is roughly 20Mb
                man-db is roughly 21Mb
                NO DEP...you decide
                but both can be read by text editor etc

                original sample rc file is in this TCE
                modified rc file is in main TCE

Change-log:     2026/10/21 v 1.4.9 
Current:        2026/10/21 ' > $P-doc.tcz.info
# no dep set 

echo 'Title:          ratpoison.tcz
Description:    window manager mainly for non-mouse users
Version:        1.4.9
Author:         Shawn Betts & contributors
Original-site:  http://mirror.accum.se/mirror/gnu.org/savannah/ratpoison/
Copying-policy: GPL v 2
Size:           88K
Extension_by:   aus9 @ linuxquestions.org
Tags:           window manager wm
Comments:       Uses a concept called frames kind of on one workspace
                I have created 5 workspaces read the config on use please.
                Recommend read doc TCE....load this TCE inside your 
                current WM and read my read write ~/.ratpoisonrc
                as it contains hints instead of reading this info file.
 
                Ratpoison prefers C-t to indicate Ctrl + t THEN release keys
                run box is handy to remember C-t !
                full list of keybindings is C-t ? 

                TCEs...dep=dependency
                config made nano default & dep ( my preference)
                sgmenu and its doc TCE if interested...not a dep
                .......allows generate and navigate menu by kb or mouse
                config made mc default file manager but not a dep 
                To use the nicer left pointer suggest you use lxappearance
                with xcursor-themes....none are deps  
               
Change-log:     2020/08/29 v 1.4.9 (Juanito)
Current:        2026/10/21 rebuilt on 17x (aus9) ' > $P.tcz.info

readelf -d $P/usr/local/bin/* | grep 'NEEDED' # ignore TCBs
 #libXft.so.2] libXft
 #libXrandr.so.2] libXrandr
 #libXtst.so.6] libXtst...redundant its a dep according to submitqc...readded
 #libX11.so.6]libX11 redundant dep

echo 'nano.tcz
aterm.tcz
perl5.tcz
libXft.tcz
libXrandr.tcz
libXtst.tcz     ' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync

