summaryrefslogblamecommitdiffstats
path: root/skripti/java_package_manager.sh
blob: b445abbeed8e0c2508b00c0b3be0fd052f45c7a8 (plain) (tree)













































                                                                                                                                                                               
#!/bin/sh
set -xeuo pipefail
clean () {
	sed -n '/^# java_package_manager.begin$/,/^# java_package_manager.end$/{/^# java_package_manager.begin$/!{/^# java_package_manager.end$/!p}}' .gitignore | while read l
	do
		rd=`rev <<<$l | cut -d/ -f2- | rev`
		rm $l
		[ `ls $rd | wc -l` -eq 0 ] && rmdir $rd

	done
	sed -i '/^# java_package_manager.begin$/,/^# java_package_manager.end$/d' .gitignore
}
case $1 in
	i*|I*)
		[ -f java_package_manager.txt ] || { echo no java_package_manager.txt, refusing to run; exit 2; }
		if grep '^# java_package_manager.begin$' .gitignore > /dev/null
		then
			echo was already installed. cleaning before reinstalling.
			clean
		fi
		echo '# java_package_manager.begin' >> .gitignore
		c=0
		grep -v '^#' java_package_manager.txt | while read l
		do
			c=$(($c+1))
			[ $c -eq 1 ] && { d=$l; continue; }
			find $l -type f | while read line
			do
				dst=`sed s,$l,$d, <<<$line`
				dstd=`rev <<<$dst | cut -d/ -f2- | rev`
				[ -d $dstd ] || mkdir -p $dstd 
				cp --no-clobber $line $dst
				echo $dst >> .gitignore
			done

		done
		echo '# java_package_manager.end' >> .gitignore
		;;
	c*|C*)
		clean
		;;
	*)
		echo wrong option
		exit 1
		;;
esac