Created
November 17, 2016 12:06
-
-
Save ldante86/cf4c52960928e9c6f8f2405c46951040 to your computer and use it in GitHub Desktop.
a work-in-progress configure script for my shell games
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash - | |
# | |
# SCRIPT: configure | |
# AUTHOR: Luciano D. Cecere | |
# YEAR: 2015 | |
######################################################################## | |
# | |
# configure - generate install, uninstall and clean scripts for programs | |
# | |
# Copyright (C) 2015 Luciano D. Cecere <[email protected]> | |
# | |
# 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, see <http://www.gnu.org/licenses/>. | |
# | |
######################################################################## | |
### TODO/BUGS ### | |
# If there are files in the topdir named install, uninstall or clean, | |
# this script over-writes those files. I need create more unique | |
# filenames. | |
# Multiple files with the same name cause problems. If there are 2 files | |
# with the same name, the second file will have the symlink installed. | |
# I need a routine that searches for manual files and another to install | |
# them. | |
# I should throw in some command-line flags for information and flags for | |
# specifying the target (topdir) directory from the command-line. | |
################ | |
export PATH=/bin:/usr/bin | |
unalias -a | |
origin="${PWD}/games" | |
dest="${1:-/usr/local/games}" | |
if [ ! -d "$dest" ]; then | |
echo "$dest is not a directory" | |
exit 1 | |
fi | |
dir=( $(ls -R "${origin}" | grep './' | tr -d ":") ) | |
progs=() | |
for i in ${dir[@]} | |
do | |
cd "$i" | |
for f in * | |
do | |
if [ -x "$f" ] && [ ! -d "$f" ] && [ "$f" != "Makefile" ]; then | |
progs+=("$i/$f") | |
fi | |
done | |
cd - >/dev/null | |
done | |
> install | |
> uninstall | |
> clean | |
cat > install <<-eof | |
#!/bin/bash | |
# This file was created by ${0##*/} | |
sudo id >/dev/null # Trigger sudo password | |
_link() | |
{ | |
dest=$dest | |
stack+=( "\$@" ) | |
for i in \${stack[@]} | |
do | |
p="\${i##*/}" | |
p="\${p%%.*}" | |
echo "linking \${i} to \${dest}/\${p}" | |
sudo ln -fs "\${i}" "\${dest}"/"\${p}" | |
done | |
} | |
echo Installing programs to $dest | |
_link \\ | |
eof | |
cat > uninstall <<-eof | |
#!/bin/bash | |
# This file was created by ${0##*/} | |
sudo id >/dev/null # Trigger sudo password | |
echo Removing progs from $dest | |
sudo rm -v \\ | |
eof | |
cat > clean <<-eof | |
#!/bin/bash | |
# This file was created by ${0##*/} | |
[ -e install ] & rm -v install | |
[ -e uninstall ] & rm -v uninstall | |
[ -e clean ] & rm -v clean | |
echo ...done | |
eof | |
for ((i=0; i<${#progs[@]}; i++)) | |
do | |
p="${progs[i]}" | |
p="${p##*/}" | |
p="${p%%.*}" | |
if [ $i -eq $((${#progs[@]}-1)) ]; then | |
echo "${progs[i]}" >> install | |
echo "${dest}/${p}" >> uninstall | |
else | |
echo "${progs[i]} \\" >> install | |
echo "${dest}/${p} \\" >> uninstall | |
fi | |
done | |
echo 'echo ...done' >> install | |
echo 'echo ...done' >> uninstall | |
chmod +x install | |
chmod +x uninstall | |
chmod +x clean | |
cat <<-eof | |
Scripts created: install, uninstall, clean | |
run ./install to install symlinks to $dest | |
run ./uninstall to uninstall symlinks from $dest | |
run ./clean to remove these three files | |
eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment