ref: 1fd6a3738a4775ee3a326a31a750778c1d0ddda1
dir: /img/
#!/bin/rc
# 2022-05-01T18:49:30-04:00
# upload an image to http://img.stanleylieber.com
rfork e
argv0=$0
barf=/usr/sl/www/werc/sites/img.stanleylieber.com
if(! ~ `{cat /dev/sysname} gaff)
barf=/n/gaff^$barf
fn usage {
echo usage: $argv0 '[ -f file] [ -l link ] [ -t tags ]' >[1=2]
exit usage
}
file=()
img=()
link=()
tags=()
while(~ $1 -*){
switch($1){
case -f
file=$2
shift
case -l
link=$2
shift
case -t
tags=$2
shift
case *
usage
}
shift
}
if(! ~ $#* 0)
usage
if(~ $#file 1){
a_id=`{echo `{ls -p $barf/src | sort -n | tail -1}^+1 | bc}
if(~ $#a_id 0)
a_id=1
while(test -d $barf/src/$a_id)
a_id=`{echo $a_id^+1 | bc}
a_dir=$barf/src/$a_id
mkdir -p $a_dir/img $a_dir/tags
date >$a_dir/date
echo $"link >$a_dir/link
a_tags=`{echo $"tags | sed 's/[^A-Za-z0-9_\- ]//g'}
ifs=' '{a_tags=`{echo -n $a_tags}}
{
t=1
while(test $t -le $#a_tags){
>$a_dir/tags/$a_tags($t)
t=`{echo $t^+1 | bc}
}
}
for(i in $a_tags)
echo $a_id'/tags/'$i >>$barf/tags
nimg=$a_dir/img/^`{date -n}^.^`{echo $"file |
sed 's/^.*\.(gif|GIF)$/gif/g;
s/^.*\.(jpg|jpeg|JPG|JPEG)$/jpg/g;
s/^.*\.(png|PNG)$/png/g;
s/^.*\.(tif|TIF|tiff|TIFF)$/tif/g'
}
thumb=$a_dir/img/small.^`{basename $nimg | sed 's/\..*$//g'}^.png
switch($file){
case http*
hget $"file >$nimg
case *
fcp $"file $nimg
}
switch($nimg){
case *.bmp
cmd=bmp
case *.gif
cmd=gif
case *.ico
cmd=ico
case *.jpg
cmd=jpg
case *.png
cmd=png
case *.tif
cmd=tif
case *.tga
cmd=tga
}
eval $cmd -9et <$nimg | resample -x 500 | topng >$thumb
for(i in `{du -a $a_dir | sed 's/^.* //g'}){
chgrp www $i
chmod 775 $i
}
echo -n http://
echo -n `{basename $barf}
echo -n /src/$a_id/img/
echo `{basename $nimg}
}
if not {
hpost -u https://img.stanleylieber.com -p / fake:fake url: submit:add a_func:add_post a_img:$img a_link:$link a_tags:$tags |
grep -e 'img.stanleylieber.com\/src\/' |
sed 1q |
sed 's/^.........//' |
sed 's/" target.*$//g'
}